From 6660936ee44ba727399ebab3e5c64a014c532450 Mon Sep 17 00:00:00 2001 From: stitch Date: Fri, 1 Jul 2022 10:27:58 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=EC=9D=B4=EC=8A=88=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EB=AF=B8=EB=A6=AC=EB=B3=B4=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Markwon 라이브러리 이용 마크원 라이브러리를 통해 텍스트 뷰 내용을 마크다운 형식으로 변환 --- app/build.gradle | 6 ++- .../issue/register/RegisterIssueFragment.kt | 43 +++++++++++++++++-- .../drawable/edittext_enabled_text_color.xml | 5 +++ .../res/layout/fragment_register_issue.xml | 19 ++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/edittext_enabled_text_color.xml diff --git a/app/build.gradle b/app/build.gradle index 434f48ba85..093a09f173 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,5 +86,9 @@ dependencies { // Glide implementation 'com.github.bumptech.glide:glide:4.13.0' - annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0' + kapt 'com.github.bumptech.glide:compiler:4.13.0' + + // MarkWon + implementation "io.noties.markwon:core:4.2.0" + implementation "io.noties.markwon:image:4.2.0" } \ No newline at end of file diff --git a/app/src/main/java/com/example/it/issuetracker/presentation/main/issue/register/RegisterIssueFragment.kt b/app/src/main/java/com/example/it/issuetracker/presentation/main/issue/register/RegisterIssueFragment.kt index 14a2105373..a44f5fb44a 100644 --- a/app/src/main/java/com/example/it/issuetracker/presentation/main/issue/register/RegisterIssueFragment.kt +++ b/app/src/main/java/com/example/it/issuetracker/presentation/main/issue/register/RegisterIssueFragment.kt @@ -1,23 +1,58 @@ package com.example.it.issuetracker.presentation.main.issue.register +import android.content.Context import android.os.Bundle import android.view.View +import android.view.inputmethod.InputMethodManager import com.example.it.issuetracker.R import com.example.it.issuetracker.databinding.FragmentRegisterIssueBinding import com.example.it.issuetracker.presentation.common.DataBindingBaseFragment +import io.noties.markwon.Markwon class RegisterIssueFragment : DataBindingBaseFragment(R.layout.fragment_register_issue) { + private val imm: InputMethodManager by lazy { activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager } + private lateinit var markOne: Markwon + private var markDownFlag = false + private var previousText = "" + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + markOne = Markwon.builder(requireContext()) + .build() + initView() } override fun initView() { - TODO("Not yet implemented") + previewMarkDown() + binding.etText.text.toString() + } + + private fun previewMarkDown() { + binding.btn.setOnClickListener { + if (!markDownFlag) getMarkDownView() + else getEditView() + } } - override fun observerData() { - TODO("Not yet implemented") + private fun getMarkDownView() { + previousText = binding.etText.text.toString() + binding.etText.isEnabled = false + imm.hideSoftInputFromWindow(binding.etText.windowToken, 0) + markOne.setMarkdown(binding.etText, binding.etText.text.toString()) + markDownFlag = true } + + private fun getEditView() { + with(binding) { + etText.setText(previousText) + etText.isEnabled = true + etText.setSelection(etText.text.toString().length) + } + imm.showSoftInput(binding.etText, 0) + previousText = "" + markDownFlag = false + } + + override fun observerData() = Unit } \ No newline at end of file diff --git a/app/src/main/res/drawable/edittext_enabled_text_color.xml b/app/src/main/res/drawable/edittext_enabled_text_color.xml new file mode 100644 index 0000000000..16f1b8d6e4 --- /dev/null +++ b/app/src/main/res/drawable/edittext_enabled_text_color.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_register_issue.xml b/app/src/main/res/layout/fragment_register_issue.xml index c3906a9b40..d70c4611b6 100644 --- a/app/src/main/res/layout/fragment_register_issue.xml +++ b/app/src/main/res/layout/fragment_register_issue.xml @@ -1,5 +1,6 @@ @@ -11,5 +12,23 @@ android:layout_height="match_parent" tools:context=".presentation.main.issue.register.RegisterIssueFragment"> + + +