feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 84155570df
commit 9dc8983585
  1. 8
      app/src/main/java/io/legado/app/ui/about/AboutFragment.kt
  2. 42
      app/src/main/java/io/legado/app/ui/about/UpdateLog.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
  5. 8
      app/src/main/java/io/legado/app/ui/book/read/page/TextChapter.kt
  6. 5
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  7. 64
      app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt
  8. 3
      app/src/main/res/layout/view_book_page.xml
  9. 2
      app/src/main/res/xml/pref_config_read.xml

@ -9,6 +9,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App
import io.legado.app.R
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.toast
class AboutFragment : PreferenceFragmentCompat() {
@ -30,7 +31,7 @@ class AboutFragment : PreferenceFragmentCompat() {
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) {
"contributors" -> openIntent(Intent.ACTION_VIEW, R.string.contributors_url)
"update_log" -> UpdateLog().show(childFragmentManager, "update_log")
"update_log" -> showUpdateLog()
"check_update" -> openIntent(Intent.ACTION_VIEW, R.string.latest_release_url)
"mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com")
"git" -> openIntent(Intent.ACTION_VIEW, R.string.this_github_url)
@ -56,4 +57,9 @@ class AboutFragment : PreferenceFragmentCompat() {
}
}
private fun showUpdateLog() {
val log = String(requireContext().assets.open("updateLog.md").readBytes())
TextDialog.show(childFragmentManager, log, TextDialog.MD)
}
}

@ -1,42 +0,0 @@
package io.legado.app.ui.about
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import io.legado.app.R
import kotlinx.android.synthetic.main.dialog_text_view.*
import ru.noties.markwon.Markwon
class UpdateLog : DialogFragment() {
override fun onStart() {
super.onStart()
val dm = DisplayMetrics()
activity?.windowManager?.defaultDisplay?.getMetrics(dm)
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_text_view, container)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
text_view.post {
Markwon.create(requireContext())
.setMarkdown(
text_view,
String(requireContext().assets.open("updateLog.md").readBytes())
)
}
}
}

@ -45,6 +45,7 @@ import io.legado.app.ui.changesource.ChangeSourceDialog
import io.legado.app.ui.chapterlist.ChapterListActivity
import io.legado.app.ui.replacerule.ReplaceRuleActivity
import io.legado.app.ui.replacerule.edit.ReplaceEditDialog
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_read.*
import kotlinx.android.synthetic.main.dialog_download_choice.view.*
@ -251,9 +252,8 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
noButton()
}.show().applyTint().requestInputMethod()
}
R.id.menu_copy_text -> {
}
R.id.menu_copy_text ->
TextDialog.show(supportFragmentManager, ReadBook.curTextChapter?.getContent())
R.id.menu_update_toc -> ReadBook.book?.let {
viewModel.loadChapterList(it)
}

@ -7,15 +7,12 @@ import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.Gravity
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
import io.legado.app.R
import io.legado.app.constant.AppConst.TIME_FORMAT
import io.legado.app.constant.PreferKey
import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.view_book_page.view.*
import org.jetbrains.anko.matchParent
import org.jetbrains.anko.sdk27.listeners.onScrollChange
import java.io.File
import java.util.*
@ -25,10 +22,6 @@ class ContentView : FrameLayout {
var callBack: CallBack? = null
private var isScroll: Boolean = false
private var pageSize: Int = 0
private val bgImage: AppCompatImageView = AppCompatImageView(context)
.apply {
scaleType = ImageView.ScaleType.CENTER_CROP
}
constructor(context: Context) : super(context) {
this.isScroll = true
@ -42,7 +35,6 @@ class ContentView : FrameLayout {
fun init() {
//设置背景防止切换背景时文字重叠
setBackgroundColor(context.getCompatColor(R.color.background))
addView(bgImage, LayoutParams(matchParent, matchParent))
inflate(context, R.layout.view_book_page, this)
top_bar.layoutParams.height = context.getStatusBarHeight()
upStyle()
@ -97,7 +89,7 @@ class ContentView : FrameLayout {
}
fun setBg(bg: Drawable?) {
bgImage.background = bg
page_panel.background = bg
}
fun upTime() {

@ -92,5 +92,13 @@ data class TextChapter(
}
return 0
}
fun getContent(): String {
val stringBuilder = StringBuilder()
pages.forEach {
stringBuilder.append(it.text)
}
return stringBuilder.toString()
}
}

@ -20,11 +20,11 @@ import io.legado.app.help.storage.Backup
import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.about.UpdateLog
import io.legado.app.ui.main.bookshelf.BookshelfFragment
import io.legado.app.ui.main.explore.ExploreFragment
import io.legado.app.ui.main.my.MyFragment
import io.legado.app.ui.main.rss.RssFragment
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_main.*
@ -85,7 +85,8 @@ class MainActivity : VMBaseActivity<MainViewModel>(R.layout.activity_main),
if (getPrefInt(PreferKey.versionCode) != App.INSTANCE.versionCode) {
putPrefInt(PreferKey.versionCode, App.INSTANCE.versionCode)
if (!BuildConfig.DEBUG) {
UpdateLog().show(supportFragmentManager, "updateLog")
val log = String(assets.open("updateLog.md").readBytes())
TextDialog.show(supportFragmentManager, log, TextDialog.MD)
}
}
}

@ -0,0 +1,64 @@
package io.legado.app.ui.widget.dialog
import android.os.Bundle
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 kotlinx.android.synthetic.main.dialog_text_view.*
import ru.noties.markwon.Markwon
class TextDialog : DialogFragment() {
companion object {
const val MD = 1
fun show(fragmentManager: FragmentManager, content: String?, mode: Int = 0) {
TextDialog().apply {
val bundle = Bundle()
bundle.putString("content", content)
bundle.putInt("mode", mode)
arguments = bundle
}.show(fragmentManager, "textDialog")
}
}
override fun onStart() {
super.onStart()
val dm = DisplayMetrics()
activity?.windowManager?.defaultDisplay?.getMetrics(dm)
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt())
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_text_view, container)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
arguments?.let {
val content = it.getString("content") ?: ""
when (it.getInt("mode")) {
MD -> text_view.post {
Markwon.create(requireContext())
.setMarkdown(
text_view,
content
)
}
else -> text_view.text = content
}
}
}
}

@ -31,8 +31,7 @@
android:id="@+id/content_text_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textIsSelectable="true" />
android:layout_weight="1" />
<LinearLayout
android:id="@+id/bottom_bar"

@ -41,7 +41,7 @@
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="true"
android:defaultValue="false"
android:title="@string/selectText"
android:key="selectText"
app:iconSpaceReserved="false" />

Loading…
Cancel
Save