feat: 优化代码

pull/154/head
kunfei 5 years ago
parent 8e9609c886
commit c117f91121
  1. 2
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  3. 35
      app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt
  4. 26
      app/src/main/res/layout/dialog_text_view.xml

@ -73,7 +73,7 @@ class AboutFragment : PreferenceFragmentCompat() {
private fun showUpdateLog() { private fun showUpdateLog() {
val log = String(requireContext().assets.open("updateLog.md").readBytes()) 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() { private fun showQqGroups() {

@ -78,7 +78,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
putPrefInt(PreferKey.versionCode, App.INSTANCE.versionCode) putPrefInt(PreferKey.versionCode, App.INSTANCE.versionCode)
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
val log = String(assets.open("updateLog.md").readBytes()) val log = String(assets.open("updateLog.md").readBytes())
TextDialog.show(supportFragmentManager, log, TextDialog.MD) TextDialog.show(supportFragmentManager, log, TextDialog.MD, 5000)
} }
} }
} }

@ -5,29 +5,40 @@ import android.util.DisplayMetrics
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import kotlinx.android.synthetic.main.dialog_text_view.* import kotlinx.android.synthetic.main.dialog_text_view.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import ru.noties.markwon.Markwon import ru.noties.markwon.Markwon
class TextDialog : DialogFragment() { class TextDialog : BaseDialogFragment() {
companion object { companion object {
const val MD = 1 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 { TextDialog().apply {
val bundle = Bundle() val bundle = Bundle()
bundle.putString("content", content) bundle.putString("content", content)
bundle.putInt("mode", mode) bundle.putInt("mode", mode)
bundle.putLong("time", time)
arguments = bundle arguments = bundle
isCancelable = false
}.show(fragmentManager, "textDialog") }.show(fragmentManager, "textDialog")
} }
} }
private var time = 0L
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
val dm = DisplayMetrics() val dm = DisplayMetrics()
@ -43,8 +54,7 @@ class TextDialog : DialogFragment() {
return inflater.inflate(R.layout.dialog_text_view, container) return inflater.inflate(R.layout.dialog_text_view, container)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.let { arguments?.let {
val content = it.getString("content") ?: "" val content = it.getString("content") ?: ""
when (it.getInt("mode")) { when (it.getInt("mode")) {
@ -57,8 +67,21 @@ class TextDialog : DialogFragment() {
} }
else -> text_view.text = content 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)
}
}
}
} }
} }
} }

@ -1,7 +1,25 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<io.legado.app.ui.widget.text.InertiaScrollTextView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="12dp" xmlns:app="http://schemas.android.com/apk/res-auto">
android:textIsSelectable="true" />
<io.legado.app.ui.widget.text.InertiaScrollTextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp"
android:textIsSelectable="true" />
<io.legado.app.ui.widget.text.BadgeView
android:id="@+id/badge_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:visibility="invisible"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save