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 b4fbdb149..5c35f51c0 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 @@ -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) + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/about/UpdateLog.kt b/app/src/main/java/io/legado/app/ui/about/UpdateLog.kt deleted file mode 100644 index 2bab8c1de..000000000 --- a/app/src/main/java/io/legado/app/ui/about/UpdateLog.kt +++ /dev/null @@ -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()) - ) - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 7d7ef8c67..978120805 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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(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) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt index cc9e9e666..70bdc120e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt @@ -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() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextChapter.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextChapter.kt index a4dacac60..8eebb8908 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextChapter.kt @@ -92,5 +92,13 @@ data class TextChapter( } return 0 } + + fun getContent(): String { + val stringBuilder = StringBuilder() + pages.forEach { + stringBuilder.append(it.text) + } + return stringBuilder.toString() + } } 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 455a0de73..ba125d7db 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 @@ -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(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) } } } 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 new file mode 100644 index 000000000..01a55f2da --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextDialog.kt @@ -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 + } + } + + } + +} diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index 410efe662..b4588d768 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -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" />