From c117f91121e58d5b39e865ad220978e68b3d78db Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 12 Mar 2020 20:45:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/about/AboutFragment.kt | 2 +- .../io/legado/app/ui/main/MainActivity.kt | 2 +- .../legado/app/ui/widget/dialog/TextDialog.kt | 35 +++++++++++++++---- app/src/main/res/layout/dialog_text_view.xml | 26 +++++++++++--- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 365381fbd..6725b3eb4 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -73,7 +73,7 @@ class AboutFragment : PreferenceFragmentCompat() { private fun showUpdateLog() { val log = String(requireContext().assets.open("updateLog.md").readBytes()) - TextDialog.show(childFragmentManager, log, TextDialog.MD) + TextDialog.show(childFragmentManager, log, TextDialog.MD, 5000) } private fun showQqGroups() { diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 0d43b28c2..96424cc9b 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -78,7 +78,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), putPrefInt(PreferKey.versionCode, App.INSTANCE.versionCode) if (!BuildConfig.DEBUG) { val log = String(assets.open("updateLog.md").readBytes()) - TextDialog.show(supportFragmentManager, log, TextDialog.MD) + TextDialog.show(supportFragmentManager, log, TextDialog.MD, 5000) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt index 01a55f2da..648949abd 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt @@ -5,29 +5,40 @@ import android.util.DisplayMetrics import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager import io.legado.app.R +import io.legado.app.base.BaseDialogFragment import kotlinx.android.synthetic.main.dialog_text_view.* +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import ru.noties.markwon.Markwon -class TextDialog : DialogFragment() { +class TextDialog : BaseDialogFragment() { companion object { const val MD = 1 - fun show(fragmentManager: FragmentManager, content: String?, mode: Int = 0) { + fun show( + fragmentManager: FragmentManager, + content: String?, + mode: Int = 0, + time: Long = 0 + ) { TextDialog().apply { val bundle = Bundle() bundle.putString("content", content) bundle.putInt("mode", mode) + bundle.putLong("time", time) arguments = bundle + isCancelable = false }.show(fragmentManager, "textDialog") } } + private var time = 0L + override fun onStart() { super.onStart() val dm = DisplayMetrics() @@ -43,8 +54,7 @@ class TextDialog : DialogFragment() { return inflater.inflate(R.layout.dialog_text_view, container) } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { arguments?.let { val content = it.getString("content") ?: "" when (it.getInt("mode")) { @@ -57,8 +67,21 @@ class TextDialog : DialogFragment() { } else -> text_view.text = content } + time = it.getLong("time", 0L) + } + if (time > 0) { + badge_view.setBadgeCount((time / 1000).toInt()) + launch { + while (time > 0) { + delay(1000) + time -= 1000 + badge_view.setBadgeCount((time / 1000).toInt()) + if (time <= 0) { + dialog?.setCancelable(true) + } + } + } } - } } diff --git a/app/src/main/res/layout/dialog_text_view.xml b/app/src/main/res/layout/dialog_text_view.xml index 3a2b347c3..c1a1a70a6 100644 --- a/app/src/main/res/layout/dialog_text_view.xml +++ b/app/src/main/res/layout/dialog_text_view.xml @@ -1,7 +1,25 @@ - + xmlns:app="http://schemas.android.com/apk/res-auto"> + + + + + + + +