From 07d4fa66b685ded2fbba1f2bb0baab53589098af Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 21:19:38 +0800 Subject: [PATCH 01/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/help/FirstTopListUpCallback.kt | 34 ---- .../ui/book/arrange/ArrangeBookActivity.kt | 4 +- .../app/ui/book/group/GroupManageDialog.kt | 4 +- .../app/ui/book/group/GroupSelectDialog.kt | 4 +- .../legado/app/ui/book/read/TextActionMenu.kt | 2 + .../app/ui/book/read/config/TocRegexDialog.kt | 4 +- .../book/source/manage/BookSourceActivity.kt | 3 +- .../book/source/manage/GroupManageDialog.kt | 8 +- .../app/ui/changesource/ChangeSourceDialog.kt | 4 +- .../app/ui/chapterlist/BookmarkFragment.kt | 4 +- .../app/ui/chapterlist/ChapterListFragment.kt | 4 +- .../app/ui/explore/ExploreShowActivity.kt | 4 +- .../app/ui/filechooser/FileChooserDialog.kt | 8 +- .../app/ui/replacerule/GroupManageDialog.kt | 8 +- .../app/ui/replacerule/ReplaceRuleActivity.kt | 3 +- .../app/ui/rss/article/RssArticlesActivity.kt | 4 +- .../ui/rss/favorites/RssFavoritesActivity.kt | 4 +- .../ui/rss/source/manage/GroupManageDialog.kt | 8 +- .../ui/rss/source/manage/RssSourceActivity.kt | 3 +- .../app/ui/widget/recycler/DividerNoLast.kt | 159 ++++++++++++++++++ .../widget/recycler/VerticalDivider.kt} | 9 +- 21 files changed, 216 insertions(+), 69 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt create mode 100644 app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt rename app/src/main/java/io/legado/app/{utils/RecyclerViewExtensions.kt => ui/widget/recycler/VerticalDivider.kt} (52%) diff --git a/app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt b/app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt deleted file mode 100644 index a35f0cd8c..000000000 --- a/app/src/main/java/io/legado/app/help/FirstTopListUpCallback.kt +++ /dev/null @@ -1,34 +0,0 @@ -package io.legado.app.help - -import androidx.recyclerview.widget.ListUpdateCallback -import androidx.recyclerview.widget.RecyclerView -import io.legado.app.base.adapter.ItemViewHolder - -class FirstTopListUpCallback : ListUpdateCallback { - var firstInsert = -1 - lateinit var adapter: RecyclerView.Adapter - - override fun onChanged(position: Int, count: Int, payload: Any?) { - adapter.notifyItemRangeChanged(position, count, payload) - } - - override fun onMoved(fromPosition: Int, toPosition: Int) { - if (toPosition == 0) { - firstInsert = 0 - } - adapter.notifyItemMoved(fromPosition, toPosition) - } - - override fun onInserted(position: Int, count: Int) { - if (firstInsert == -1 || firstInsert > position) { - firstInsert = position - } - adapter.notifyItemRangeInserted(position, count) - } - - override fun onRemoved(position: Int, count: Int) { - adapter.notifyItemRangeRemoved(position, count) - } - - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index e3ca00964..671736dc8 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -19,8 +19,8 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.group.GroupManageDialog import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.widget.SelectActionBar +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint -import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_arrange_book.* @@ -60,7 +60,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter select_action_bar.setMainActionText(R.string.move_to_group) diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index e982cbbe0..1a4322da6 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -28,8 +28,8 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint -import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_edit_text.view.* @@ -77,7 +77,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { .isChecked = AppConst.bookGroupAudioShow adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, Observer { val diffResult = diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 2d90a82e2..b290bc5df 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -28,8 +28,8 @@ import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint -import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_book_group_picker.* @@ -98,7 +98,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.menu.findItem(R.id.menu_group_audio).isVisible = false adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index fe56a18be..acc4e4f1d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -20,6 +20,7 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.ui.widget.recycler.DividerNoLast import io.legado.app.utils.isAbsUrl import io.legado.app.utils.sendToClip import kotlinx.android.synthetic.main.item_fillet_text.view.* @@ -45,6 +46,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun initRecyclerView() = with(contentView) { val adapter = Adapter(context) recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) + recycler_view.addItemDecoration(DividerNoLast(context, DividerNoLast.HORIZONTAL)) recycler_view.adapter = adapter val menu = MenuBuilder(context) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index ba9b23a44..0fb6a856c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -28,8 +28,8 @@ import io.legado.app.lib.dialogs.cancelButton import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.okButton import io.legado.app.model.localBook.AnalyzeTxtFile +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint -import io.legado.app.utils.getVerticalDivider import kotlinx.android.synthetic.main.dialog_toc_regex.* import kotlinx.android.synthetic.main.dialog_toc_regex_edit.* import kotlinx.android.synthetic.main.dialog_toc_regex_edit.view.* @@ -76,7 +76,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private fun initView() { adapter = TocRegexAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 5b375b4cf..c94b59d7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -30,6 +30,7 @@ import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.widget.SelectActionBar +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source.* @@ -109,7 +110,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) adapter = BookSourceAdapter(this, this) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index 314b45d08..d4a466948 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -22,7 +22,11 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.* +import io.legado.app.ui.widget.recycler.VerticalDivider +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.requestInputMethod +import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -60,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter App.db.bookSourceDao().liveGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index 4b129acea..d1ce27f2e 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -18,8 +18,8 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getVerticalDivider import io.legado.app.utils.getViewModel import io.legado.app.utils.putPrefBoolean import kotlinx.android.synthetic.main.dialog_change_source.* @@ -92,7 +92,7 @@ class ChangeSourceDialog : DialogFragment(), private fun initRecyclerView() { adapter = ChangeSourceAdapter(requireContext(), this) recycler_view.layoutManager = LinearLayoutManager(context) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index c32c8bc42..b2337d0d9 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -14,7 +14,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.Bookmark import io.legado.app.lib.theme.ATH -import io.legado.app.utils.getVerticalDivider +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_bookmark.* @@ -38,7 +38,7 @@ class BookmarkFragment : VMBaseFragment(R.layout.fragment_ ATH.applyEdgeEffectColor(recycler_view) adapter = BookmarkAdapter(this) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter } diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 0d9234e36..0bfc9a765 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -15,7 +15,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.UpLinearLayoutManager -import io.legado.app.utils.getVerticalDivider +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.fragment_chapter_list.* @@ -48,7 +48,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme adapter = ChapterListAdapter(requireContext(), this) mLayoutManager = UpLinearLayoutManager(requireContext()) recycler_view.layoutManager = mLayoutManager - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter } diff --git a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt index 8cc5d7c7e..08a96a340 100644 --- a/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt +++ b/app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt @@ -10,7 +10,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.widget.recycler.LoadMoreView -import io.legado.app.utils.getVerticalDivider +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_explore_show.* import org.jetbrains.anko.startActivity @@ -34,7 +34,7 @@ class ExploreShowActivity : VMBaseActivity(R.layout.activi private fun initRecyclerView() { adapter = ExploreShowAdapter(this, this) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) recycler_view.adapter = adapter loadMoreView = LoadMoreView(this) adapter.addFooterView(loadMoreView) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt index 46c1271fc..af8cf50f4 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/FileChooserDialog.kt @@ -15,7 +15,11 @@ import io.legado.app.R import io.legado.app.constant.Theme import io.legado.app.ui.filechooser.adapter.FileAdapter import io.legado.app.ui.filechooser.adapter.PathAdapter -import io.legado.app.utils.* +import io.legado.app.ui.widget.recycler.VerticalDivider +import io.legado.app.utils.FileUtils +import io.legado.app.utils.applyTint +import io.legado.app.utils.gone +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.dialog_file_chooser.* @@ -133,7 +137,7 @@ class FileChooserDialog : DialogFragment(), fileAdapter = FileAdapter(requireContext(), this) pathAdapter = PathAdapter(requireContext(), this) - rv_file.addItemDecoration(rv_file.getVerticalDivider()) + rv_file.addItemDecoration(VerticalDivider(requireContext())) rv_file.layoutManager = LinearLayoutManager(activity) rv_file.adapter = fileAdapter diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt index 6f9a61f4c..df39b9a1d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt @@ -22,7 +22,11 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.* +import io.legado.app.ui.widget.recycler.VerticalDivider +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.requestInputMethod +import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -60,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter App.db.replaceRuleDao().liveGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 9474ad4d1..331c87a5d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -28,6 +28,7 @@ import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.replacerule.edit.ReplaceEditDialog import io.legado.app.ui.widget.SelectActionBar +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_replace_rule.* @@ -77,7 +78,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi recycler_view.layoutManager = LinearLayoutManager(this) adapter = ReplaceRuleAdapter(this, this) recycler_view.adapter = adapter - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter itemTouchCallback.isCanDrag = true diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 5476657a4..3b53a6475 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -15,7 +15,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.read.ReadRssActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.widget.recycler.LoadMoreView -import io.legado.app.utils.getVerticalDivider +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_rss_artivles.* import kotlinx.android.synthetic.main.view_load_more.view.* @@ -70,7 +70,7 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) adapter = RssArticlesAdapter(this, this) recycler_view.adapter = adapter loadMoreView = LoadMoreView(this) diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index a8eb39cea..f50329296 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -10,7 +10,7 @@ import io.legado.app.base.BaseActivity import io.legado.app.data.entities.RssStar import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.read.ReadRssActivity -import io.legado.app.utils.getVerticalDivider +import io.legado.app.ui.widget.recycler.VerticalDivider import kotlinx.android.synthetic.main.view_refresh_recycler.* import org.jetbrains.anko.startActivity @@ -29,7 +29,7 @@ class RssFavoritesActivity : BaseActivity(R.layout.activity_rss_favorites), private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) adapter = RssFavoritesAdapter(this, this) recycler_view.adapter = adapter } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt index 1ba2a567b..391281a4e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/GroupManageDialog.kt @@ -22,7 +22,11 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton -import io.legado.app.utils.* +import io.legado.app.ui.widget.recycler.VerticalDivider +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.requestInputMethod +import io.legado.app.utils.splitNotBlank import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_group_manage.view.* @@ -60,7 +64,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.setOnMenuItemClickListener(this) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter App.db.rssSourceDao().liveGroup().observe(viewLifecycleOwner, Observer { val groups = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index e83a15c19..0af2de45b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -29,6 +29,7 @@ import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.widget.SelectActionBar +import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.text.AutoCompleteTextView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_rss_source.* @@ -104,7 +105,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) - recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.addItemDecoration(VerticalDivider(this)) adapter = RssSourceAdapter(this, this) recycler_view.adapter = adapter val itemTouchCallback = ItemTouchCallback() diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt new file mode 100644 index 000000000..3a005960d --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt @@ -0,0 +1,159 @@ +package io.legado.app.ui.widget.recycler + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Rect +import android.graphics.drawable.Drawable +import android.util.Log +import android.view.View +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView + +/** + * 不画最后一条分隔线 + */ +class DividerNoLast(context: Context, orientation: Int) : + RecyclerView.ItemDecoration() { + + companion object { + const val HORIZONTAL = LinearLayout.HORIZONTAL + const val VERTICAL = LinearLayout.VERTICAL + } + + private val tag = "DividerItem" + private val attrs = intArrayOf(android.R.attr.listDivider) + + private var mDivider: Drawable? = null + + /** + * Current orientation. Either [.HORIZONTAL] or [.VERTICAL]. + */ + private var mOrientation = 0 + + private val mBounds = Rect() + + init { + val a = context.obtainStyledAttributes(attrs) + mDivider = a.getDrawable(0) + if (mDivider == null) { + Log.w( + tag, "@android:attr/listDivider was not set in the theme used for this " + + "DividerItemDecoration. Please set that attribute all call setDrawable()" + ) + } + a.recycle() + setOrientation(orientation) + } + + /** + * Sets the orientation for this divider. This should be called if + * [RecyclerView.LayoutManager] changes orientation. + * + * @param orientation [.HORIZONTAL] or [.VERTICAL] + */ + fun setOrientation(orientation: Int) { + require(!(orientation != HORIZONTAL && orientation != VERTICAL)) { "Invalid orientation. It should be either HORIZONTAL or VERTICAL" } + mOrientation = orientation + } + + /** + * Sets the [Drawable] for this divider. + * + * @param drawable Drawable that should be used as a divider. + */ + fun setDrawable(drawable: Drawable) { + requireNotNull(drawable) { "Drawable cannot be null." } + mDivider = drawable + } + + /** + * @return the [Drawable] for this divider. + */ + fun getDrawable(): Drawable? { + return mDivider + } + + override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { + if (parent.layoutManager == null || mDivider == null) { + return + } + if (mOrientation == VERTICAL) { + drawVertical(c, parent) + } else { + drawHorizontal(c, parent) + } + } + + private fun drawVertical( + canvas: Canvas, + parent: RecyclerView + ) { + canvas.save() + val left: Int + val right: Int + if (parent.clipToPadding) { + left = parent.paddingLeft + right = parent.width - parent.paddingRight + canvas.clipRect( + left, parent.paddingTop, right, + parent.height - parent.paddingBottom + ) + } else { + left = 0 + right = parent.width + } + val childCount = parent.childCount + for (i in 0 until childCount - 1) { + val child = parent.getChildAt(i) + parent.getDecoratedBoundsWithMargins(child, mBounds) + val bottom = mBounds.bottom + Math.round(child.translationY) + val top = bottom - mDivider!!.intrinsicHeight + mDivider!!.setBounds(left, top, right, bottom) + mDivider!!.draw(canvas) + } + canvas.restore() + } + + private fun drawHorizontal(canvas: Canvas, parent: RecyclerView) { + canvas.save() + val top: Int + val bottom: Int + if (parent.clipToPadding) { + top = parent.paddingTop + bottom = parent.height - parent.paddingBottom + canvas.clipRect( + parent.paddingLeft, top, + parent.width - parent.paddingRight, bottom + ) + } else { + top = 0 + bottom = parent.height + } + val childCount = parent.childCount + for (i in 0 until childCount - 1) { + val child = parent.getChildAt(i) + parent.layoutManager!!.getDecoratedBoundsWithMargins(child, mBounds) + val right = mBounds.right + Math.round(child.translationX) + val left = right - mDivider!!.intrinsicWidth + mDivider!!.setBounds(left, top, right, bottom) + mDivider!!.draw(canvas) + } + canvas.restore() + } + + override fun getItemOffsets( + outRect: Rect, view: View, parent: RecyclerView, + state: RecyclerView.State + ) { + if (mDivider == null) { + outRect[0, 0, 0] = 0 + return + } + if (mOrientation == VERTICAL) { + outRect[0, 0, 0] = mDivider!!.intrinsicHeight + } else { + outRect[0, 0, mDivider!!.intrinsicWidth] = 0 + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/VerticalDivider.kt similarity index 52% rename from app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt rename to app/src/main/java/io/legado/app/ui/widget/recycler/VerticalDivider.kt index 7dbed87ce..2ea450d4c 100644 --- a/app/src/main/java/io/legado/app/utils/RecyclerViewExtensions.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/VerticalDivider.kt @@ -1,15 +1,16 @@ -package io.legado.app.utils +package io.legado.app.ui.widget.recycler +import android.content.Context import androidx.core.content.ContextCompat import androidx.recyclerview.widget.DividerItemDecoration -import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +class VerticalDivider(context: Context) : DividerItemDecoration(context, VERTICAL) { -fun RecyclerView.getVerticalDivider(): DividerItemDecoration { - return DividerItemDecoration(context, DividerItemDecoration.VERTICAL).apply { + init { ContextCompat.getDrawable(context, R.drawable.ic_divider)?.let { this.setDrawable(it) } } + } \ No newline at end of file From 1481ce288dadcd7d19a7a3dd8dad8cb8bafb5f6e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 21:33:36 +0800 Subject: [PATCH 02/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/TextActionMenu.kt | 2 -- .../app/ui/widget/recycler/DividerNoLast.kt | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index acc4e4f1d..fe56a18be 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -20,7 +20,6 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter -import io.legado.app.ui.widget.recycler.DividerNoLast import io.legado.app.utils.isAbsUrl import io.legado.app.utils.sendToClip import kotlinx.android.synthetic.main.item_fillet_text.view.* @@ -46,7 +45,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun initRecyclerView() = with(contentView) { val adapter = Adapter(context) recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) - recycler_view.addItemDecoration(DividerNoLast(context, DividerNoLast.HORIZONTAL)) recycler_view.adapter = adapter val menu = MenuBuilder(context) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt index 3a005960d..5c9e38e4d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt @@ -8,6 +8,8 @@ import android.util.Log import android.view.View import android.widget.LinearLayout import androidx.recyclerview.widget.RecyclerView +import kotlin.math.roundToInt + /** * 不画最后一条分隔线 @@ -106,7 +108,7 @@ class DividerNoLast(context: Context, orientation: Int) : for (i in 0 until childCount - 1) { val child = parent.getChildAt(i) parent.getDecoratedBoundsWithMargins(child, mBounds) - val bottom = mBounds.bottom + Math.round(child.translationY) + val bottom = mBounds.bottom + child.translationY.roundToInt() val top = bottom - mDivider!!.intrinsicHeight mDivider!!.setBounds(left, top, right, bottom) mDivider!!.draw(canvas) @@ -133,7 +135,7 @@ class DividerNoLast(context: Context, orientation: Int) : for (i in 0 until childCount - 1) { val child = parent.getChildAt(i) parent.layoutManager!!.getDecoratedBoundsWithMargins(child, mBounds) - val right = mBounds.right + Math.round(child.translationX) + val right = mBounds.right + child.translationX.roundToInt() val left = right - mDivider!!.intrinsicWidth mDivider!!.setBounds(left, top, right, bottom) mDivider!!.draw(canvas) @@ -149,10 +151,18 @@ class DividerNoLast(context: Context, orientation: Int) : outRect[0, 0, 0] = 0 return } + if (mOrientation == VERTICAL) { outRect[0, 0, 0] = mDivider!!.intrinsicHeight } else { - outRect[0, 0, mDivider!!.intrinsicWidth] = 0 + val childAdapterPosition = parent.getChildAdapterPosition(view) + val lastCount = parent.adapter!!.itemCount - 1 + //如果不是最后一条 正常赋值 如果是最后一条 赋值为0 + if (childAdapterPosition != lastCount) { + outRect[0, 0, mDivider!!.intrinsicWidth] = 0 + } else { + outRect[0, 0, 0] = 0 + } } } From 7e1b37b36de4abd4ed782a18abe241284589436f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 21:36:46 +0800 Subject: [PATCH 03/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/drawable/recyclerview_divider_horizontal.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/drawable/recyclerview_divider_horizontal.xml b/app/src/main/res/drawable/recyclerview_divider_horizontal.xml index d6b50f883..2d2d95362 100644 --- a/app/src/main/res/drawable/recyclerview_divider_horizontal.xml +++ b/app/src/main/res/drawable/recyclerview_divider_horizontal.xml @@ -1,7 +1,7 @@ - + From 0b53a2c4b428d9ca04c808c03e8905b2087ae1c4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 22:42:11 +0800 Subject: [PATCH 04/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../java/io/legado/app/help/ReadBookConfig.kt | 124 +++++++++++++++++- .../app/ui/book/read/ReadBookActivity.kt | 6 +- .../book/read/config/PaddingConfigDialog.kt | 4 +- .../ui/book/read/config/ReadStyleDialog.kt | 19 +-- .../app/ui/book/read/page/ChapterProvider.kt | 36 ++--- .../app/ui/book/read/page/ContentTextView.kt | 4 +- .../app/ui/book/read/page/ContentView.kt | 4 +- 8 files changed, 155 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index ce49d6023..50ab1c873 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -37,4 +37,5 @@ object PreferKey { const val lastBackup = "lastBackup" const val bodyIndent = "textIndent" const val shareLayout = "shareLayout" + const val readStyleSelect = "readStyleSelect" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 75777d51b..7bf7a7e9d 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -6,6 +6,7 @@ import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable import io.legado.app.App import io.legado.app.R +import io.legado.app.constant.PreferKey import io.legado.app.help.coroutine.Coroutine import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.utils.* @@ -23,12 +24,19 @@ object ReadBookConfig { val json = String(App.INSTANCE.assets.open(readConfigFileName).readBytes()) GSON.fromJsonArray(json)!! } - val durConfig - get() = getConfig(styleSelect) + val durConfig get() = getConfig(styleSelect) + private val shareConfig get() = getConfig(5) - var styleSelect - get() = App.INSTANCE.getPrefInt("readStyleSelect") - set(value) = App.INSTANCE.putPrefInt("readStyleSelect", value) + var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) + set(value) { + field = value + App.INSTANCE.putPrefInt(PreferKey.readStyleSelect, value) + } + var shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) + set(value) { + field = value + App.INSTANCE.putPrefBoolean(PreferKey.shareLayout) + } var bg: Drawable? = null init { @@ -40,6 +48,9 @@ object ReadBookConfig { if (configList.size < 5) { resetAll() } + if (configList.size < 6) { + configList.add(Config()) + } return configList[index] } @@ -94,7 +105,106 @@ object ReadBookConfig { } } - data class Config( + //配置写入读取 + var textBold: Boolean + get() = if (shareLayout) shareConfig.textBold else durConfig.textBold + set(value) = if (shareLayout) shareConfig.textBold = value else durConfig.textBold = value + + var textSize: Int + get() = if (shareLayout) shareConfig.textSize else durConfig.textSize + set(value) = if (shareLayout) shareConfig.textSize = value else durConfig.textSize = value + + var letterSpacing: Float + get() = if (shareLayout) shareConfig.letterSpacing else durConfig.letterSpacing + set(value) = + if (shareLayout) shareConfig.letterSpacing = value else durConfig.letterSpacing = value + + var lineSpacingExtra: Int + get() = if (shareLayout) shareConfig.lineSpacingExtra else durConfig.lineSpacingExtra + set(value) = + if (shareLayout) shareConfig.lineSpacingExtra = value + else durConfig.lineSpacingExtra = value + + var paragraphSpacing: Int + get() = if (shareLayout) shareConfig.paragraphSpacing else durConfig.paragraphSpacing + set(value) = + if (shareLayout) shareConfig.paragraphSpacing = value + else durConfig.paragraphSpacing = value + + var titleCenter: Boolean + get() = if (shareLayout) shareConfig.titleCenter else durConfig.titleCenter + set(value) = + if (shareLayout) shareConfig.titleCenter = value else durConfig.titleCenter = value + + var paddingBottom: Int + get() = if (shareLayout) shareConfig.paddingBottom else durConfig.paddingBottom + set(value) = + if (shareLayout) shareConfig.paddingBottom = value else durConfig.paddingBottom = value + + var paddingLeft: Int + get() = if (shareLayout) shareConfig.paddingLeft else durConfig.paddingLeft + set(value) = + if (shareLayout) shareConfig.paddingLeft = value else durConfig.paddingLeft = value + + var paddingRight: Int + get() = if (shareLayout) shareConfig.paddingRight else durConfig.paddingRight + set(value) = + if (shareLayout) shareConfig.paddingRight = value else durConfig.paddingRight = value + + var paddingTop: Int + get() = if (shareLayout) shareConfig.paddingTop else durConfig.paddingTop + set(value) = + if (shareLayout) shareConfig.paddingTop = value else durConfig.paddingTop = value + + var headerPaddingBottom: Int + get() = if (shareLayout) shareConfig.headerPaddingBottom else durConfig.headerPaddingBottom + set(value) = + if (shareLayout) shareConfig.headerPaddingBottom = value + else durConfig.headerPaddingBottom = value + + var headerPaddingLeft: Int + get() = if (shareLayout) shareConfig.headerPaddingLeft else durConfig.headerPaddingLeft + set(value) = + if (shareLayout) shareConfig.headerPaddingLeft = value + else durConfig.headerPaddingLeft = value + + var headerPaddingRight: Int + get() = if (shareLayout) shareConfig.headerPaddingRight else durConfig.headerPaddingRight + set(value) = + if (shareLayout) shareConfig.headerPaddingRight = value + else durConfig.headerPaddingRight = value + + var headerPaddingTop: Int + get() = if (shareLayout) shareConfig.headerPaddingTop else durConfig.headerPaddingTop + set(value) = + if (shareLayout) shareConfig.headerPaddingTop = value + else durConfig.headerPaddingTop = value + + var footerPaddingBottom: Int + get() = if (shareLayout) shareConfig.footerPaddingBottom else durConfig.footerPaddingBottom + set(value) = + if (shareLayout) shareConfig.footerPaddingBottom = value + else durConfig.footerPaddingBottom = value + + var footerPaddingLeft: Int + get() = if (shareLayout) shareConfig.footerPaddingLeft else durConfig.footerPaddingLeft + set(value) = + if (shareLayout) shareConfig.footerPaddingLeft = value + else durConfig.footerPaddingLeft = value + + var footerPaddingRight: Int + get() = if (shareLayout) shareConfig.footerPaddingRight else durConfig.footerPaddingRight + set(value) = + if (shareLayout) shareConfig.footerPaddingRight = value + else durConfig.footerPaddingRight = value + + var footerPaddingTop: Int + get() = if (shareLayout) shareConfig.footerPaddingTop else durConfig.footerPaddingTop + set(value) = + if (shareLayout) shareConfig.footerPaddingTop = value + else durConfig.footerPaddingTop = value + + class Config( var bgStr: String = "#EEEEEE",//白天背景 var bgStrNight: String = "#000000",//夜间背景 var bgType: Int = 0,//白天背景类型 @@ -138,7 +248,7 @@ object ReadBookConfig { } else { textColor = "#${color.hexString}" } - ChapterProvider.upStyle(this) + ChapterProvider.upStyle() } fun setStatusIconDark(isDark: Boolean) { 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 7d3d747aa..a081b33a3 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 @@ -385,12 +385,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo cursor_left, Gravity.BOTTOM or Gravity.START, cursor_left.x.toInt() + cursor_left.width, - page_view.height - cursor_left.y.toInt() + ReadBookConfig.durConfig.textSize.dp + popup.height + page_view.height - cursor_left.y.toInt() + ReadBookConfig.textSize.dp + popup.height ) } else { popup.update( cursor_left.x.toInt() + cursor_left.width, - page_view.height - cursor_left.y.toInt() + ReadBookConfig.durConfig.textSize.dp + popup.height, + page_view.height - cursor_left.y.toInt() + ReadBookConfig.textSize.dp + popup.height, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) } @@ -665,7 +665,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo upSystemUiVisibility() page_view.upBg() page_view.upStyle() - ChapterProvider.upStyle(ReadBookConfig.durConfig) + ChapterProvider.upStyle() if (it) { ReadBook.loadContent() } else { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index 1cb0715e3..0dd4e8a7d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -49,7 +49,7 @@ class PaddingConfigDialog : DialogFragment() { ReadBookConfig.save() } - private fun initData() = with(ReadBookConfig.durConfig) { + private fun initData() = with(ReadBookConfig) { //正文 dsb_padding_top.progress = paddingTop dsb_padding_bottom.progress = paddingBottom @@ -67,7 +67,7 @@ class PaddingConfigDialog : DialogFragment() { dsb_footer_padding_right.progress = footerPaddingRight } - private fun initView() = with(ReadBookConfig.durConfig) { + private fun initView() = with(ReadBookConfig) { //正文 dsb_padding_top.onChanged = { paddingTop = it diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index b1f80b354..701b7e6df 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -76,7 +76,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { } private fun initData() { - cb_share_layout.isChecked = getPrefBoolean(PreferKey.shareLayout) + cb_share_layout.isChecked = ReadBookConfig.shareLayout requireContext().getPrefInt(PreferKey.pageAnim).let { if (it >= 0 && it < rg_page_anim.childCount) { rg_page_anim.check(rg_page_anim[it].id) @@ -92,14 +92,14 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) } tv_title_center.onClick { - ReadBookConfig.durConfig.apply { + ReadBookConfig.apply { titleCenter = !titleCenter tv_title_center.isSelected = titleCenter } postEvent(EventBus.UP_CONFIG, true) } tv_text_bold.onClick { - ReadBookConfig.durConfig.apply { + ReadBookConfig.apply { textBold = !textBold tv_text_bold.isSelected = textBold } @@ -125,19 +125,19 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { } } dsb_text_size.onChanged = { - ReadBookConfig.durConfig.textSize = it + 5 + ReadBookConfig.textSize = it + 5 postEvent(EventBus.UP_CONFIG, true) } dsb_text_letter_spacing.onChanged = { - ReadBookConfig.durConfig.letterSpacing = (it - 50) / 100f + ReadBookConfig.letterSpacing = (it - 50) / 100f postEvent(EventBus.UP_CONFIG, true) } dsb_line_size.onChanged = { - ReadBookConfig.durConfig.lineSpacingExtra = it + ReadBookConfig.lineSpacingExtra = it postEvent(EventBus.UP_CONFIG, true) } dsb_paragraph_spacing.onChanged = { - ReadBookConfig.durConfig.paragraphSpacing = it + ReadBookConfig.paragraphSpacing = it postEvent(EventBus.UP_CONFIG, true) } rg_page_anim.onCheckedChange { _, checkedId -> @@ -154,7 +154,8 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { } cb_share_layout.onCheckedChangeListener = { checkBox, isChecked -> if (checkBox.isPressed) { - putPrefBoolean(PreferKey.shareLayout, isChecked) + ReadBookConfig.shareLayout = isChecked + upStyle() } } bg0.onClick { changeBg(0) } @@ -190,7 +191,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { } private fun upStyle() { - ReadBookConfig.durConfig.let { + ReadBookConfig.let { tv_title_center.isSelected = it.titleCenter tv_text_bold.isSelected = it.textBold dsb_text_size.progress = it.textSize - 5 diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 8a4a46e06..e2756096a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -32,7 +32,7 @@ object ChapterProvider { private var bodyIndent = BookHelp.bodyIndent init { - upStyle(ReadBookConfig.durConfig) + upStyle() } /** @@ -160,7 +160,7 @@ object ChapterProvider { //最后一行 textLine.text = "$words\n" stringBuilder.append("\n") - var x = if (ReadBookConfig.durConfig.titleCenter) + var x = if (ReadBookConfig.titleCenter) (visibleWidth - layout.getLineMax(lineIndex)) / 2 else 0f for (i in words.indices) { @@ -297,7 +297,7 @@ object ChapterProvider { /** * 更新样式 */ - fun upStyle(config: ReadBookConfig.Config) { + fun upStyle() { typeface = try { val fontPath = App.INSTANCE.getPrefString(PreferKey.readBookFont) if (!TextUtils.isEmpty(fontPath)) { @@ -311,34 +311,34 @@ object ChapterProvider { } //标题 titlePaint.isAntiAlias = true - titlePaint.color = config.textColor() - titlePaint.letterSpacing = config.letterSpacing + titlePaint.color = ReadBookConfig.durConfig.textColor() + titlePaint.letterSpacing = ReadBookConfig.letterSpacing titlePaint.typeface = Typeface.create(typeface, Typeface.BOLD) //正文 contentPaint.isAntiAlias = true - contentPaint.color = config.textColor() - contentPaint.letterSpacing = config.letterSpacing - val bold = if (config.textBold) Typeface.BOLD else Typeface.NORMAL + contentPaint.color = ReadBookConfig.durConfig.textColor() + contentPaint.letterSpacing = ReadBookConfig.letterSpacing + val bold = if (ReadBookConfig.textBold) Typeface.BOLD else Typeface.NORMAL contentPaint.typeface = Typeface.create(typeface, bold) //间距 - lineSpacingExtra = config.lineSpacingExtra.dp.toFloat() - paragraphSpacing = config.paragraphSpacing.dp - titlePaint.textSize = (config.textSize + 2).dp.toFloat() - contentPaint.textSize = config.textSize.dp.toFloat() + lineSpacingExtra = ReadBookConfig.lineSpacingExtra.dp.toFloat() + paragraphSpacing = ReadBookConfig.paragraphSpacing.dp + titlePaint.textSize = (ReadBookConfig.textSize + 2).dp.toFloat() + contentPaint.textSize = ReadBookConfig.textSize.dp.toFloat() bodyIndent = BookHelp.bodyIndent - upSize(config) + upSize() } /** * 更新View尺寸 */ - fun upSize(config: ReadBookConfig.Config) { - paddingLeft = config.paddingLeft.dp - paddingTop = config.paddingTop.dp - visibleWidth = viewWidth - paddingLeft - config.paddingRight.dp - visibleHeight = viewHeight - paddingTop - config.paddingBottom.dp + fun upSize() { + paddingLeft = ReadBookConfig.paddingLeft.dp + paddingTop = ReadBookConfig.paddingTop.dp + visibleWidth = viewWidth - paddingLeft - ReadBookConfig.paddingRight.dp + visibleHeight = viewHeight - paddingTop - ReadBookConfig.paddingBottom.dp } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index eeae9d33b..ff066f5b4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -51,10 +51,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) - ReadBookConfig.durConfig.let { + ReadBookConfig.let { ChapterProvider.viewWidth = w ChapterProvider.viewHeight = h - ChapterProvider.upSize(ReadBookConfig.durConfig) + ChapterProvider.upSize() } } 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 abb2b82c4..2334e481a 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 @@ -28,7 +28,7 @@ class ContentView(context: Context) : FrameLayout(context) { } fun upStyle() { - ReadBookConfig.durConfig.apply { + ReadBookConfig.apply { tv_top_left.typeface = ChapterProvider.typeface tv_top_right.typeface = ChapterProvider.typeface tv_bottom_left.typeface = ChapterProvider.typeface @@ -61,7 +61,7 @@ class ContentView(context: Context) : FrameLayout(context) { footerPaddingRight.dp, footerPaddingBottom.dp ) - textColor().let { + durConfig.textColor().let { tv_top_left.setTextColor(it) tv_top_right.setTextColor(it) tv_bottom_left.setTextColor(it) From ec66201564a54329f8108341c3785cd42e990cce Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 22:44:53 +0800 Subject: [PATCH 05/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 701b7e6df..73d4c074c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -156,6 +156,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { if (checkBox.isPressed) { ReadBookConfig.shareLayout = isChecked upStyle() + postEvent(EventBus.UP_CONFIG, true) } } bg0.onClick { changeBg(0) } From 57045acd517255373a68627e2d7fa9c584462c1f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 22:45:28 +0800 Subject: [PATCH 06/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/ReadBookConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 7bf7a7e9d..befd0fda6 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -214,7 +214,7 @@ object ReadBookConfig { var textColor: String = "#3E3D3B",//白天文字颜色 var textColorNight: String = "#adadad",//夜间文字颜色 var textBold: Boolean = false,//是否粗体字 - var textSize: Int = 15,//文字大小 + var textSize: Int = 20,//文字大小 var letterSpacing: Float = 1f,//字间距 var lineSpacingExtra: Int = 12,//行间距 var paragraphSpacing: Int = 12,//段距 From aafb0e13faaab3a265ee3153eea33f92f1e65de7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 22:52:40 +0800 Subject: [PATCH 07/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ReadBookConfig.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index befd0fda6..e165e5d4f 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -205,14 +205,14 @@ object ReadBookConfig { else durConfig.footerPaddingTop = value class Config( - var bgStr: String = "#EEEEEE",//白天背景 - var bgStrNight: String = "#000000",//夜间背景 - var bgType: Int = 0,//白天背景类型 - var bgTypeNight: Int = 0,//夜间背景类型 - var darkStatusIcon: Boolean = true,//白天是否暗色状态栏 - var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏 - var textColor: String = "#3E3D3B",//白天文字颜色 - var textColorNight: String = "#adadad",//夜间文字颜色 + private var bgStr: String = "#EEEEEE",//白天背景 + private var bgStrNight: String = "#000000",//夜间背景 + private var bgType: Int = 0,//白天背景类型 + private var bgTypeNight: Int = 0,//夜间背景类型 + private var darkStatusIcon: Boolean = true,//白天是否暗色状态栏 + private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏 + private var textColor: String = "#3E3D3B",//白天文字颜色 + private var textColorNight: String = "#ADADAD",//夜间文字颜色 var textBold: Boolean = false,//是否粗体字 var textSize: Int = 20,//文字大小 var letterSpacing: Float = 1f,//字间距 From a095b75d2de78bb46f7ce517ac83f48eeb8a1c81 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 07:50:38 +0800 Subject: [PATCH 08/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index a4227619b..e87f74051 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -268,7 +268,9 @@ object BookHelp { } } } - c = "$title\n$c" + if (!c.startsWith(title)) { + c = "$title\n$c" + } when (AppConfig.chineseConverterType) { 1 -> c = ZhConvertBootstrap.newInstance().toSimple(c) 2 -> c = ZhConvertBootstrap.newInstance().toTraditional(c) From 702b0d0022beff830bd878c1970e2a57f9339624 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 08:03:27 +0800 Subject: [PATCH 09/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 41 ++++++++++--------- .../app/ui/book/read/page/ContentTextView.kt | 36 +++++----------- .../ui/book/read/page/entities/TextChar.kt | 4 +- .../ui/book/read/page/entities/TextLine.kt | 1 + .../ui/book/read/page/entities/TextPoint.kt | 6 --- 5 files changed, 36 insertions(+), 52 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index e2756096a..cd8c5c0e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -10,7 +10,10 @@ import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig -import io.legado.app.ui.book.read.page.entities.* +import io.legado.app.ui.book.read.page.entities.TextChapter +import io.legado.app.ui.book.read.page.entities.TextChar +import io.legado.app.ui.book.read.page.entities.TextLine +import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.dp import io.legado.app.utils.getPrefString import io.legado.app.utils.removePref @@ -131,10 +134,11 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineBottom = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() textLine.lineTop = (paddingTop + durY - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() + textLine.lineBase = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() + textLine.lineBottom = textLine.lineBase + titlePaint.fontMetrics.descent val words = title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -150,8 +154,8 @@ object ChapterProvider { val x1 = if (i != words.lastIndex) (x + cw + d) else (x + cw) val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 @@ -169,14 +173,13 @@ object ChapterProvider { val x1 = x + cw val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 } } - textLine.lineBottom = textLine.lineBottom + titlePaint.fontMetrics.descent } durY += paragraphSpacing return durY @@ -214,10 +217,11 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineBottom = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() textLine.lineTop = (paddingTop + durY - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() + textLine.lineBase = (paddingTop + durY - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() + textLine.lineBottom = textLine.lineBase + contentPaint.fontMetrics.descent var words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -231,8 +235,8 @@ object ChapterProvider { val x1 = x + icw val textChar = TextChar( charData = bodyIndent[i].toString(), - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 @@ -246,8 +250,8 @@ object ChapterProvider { val x1 = if (i != words.lastIndex) x + cw + d else x + cw val textChar1 = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar1) x = x1 @@ -263,8 +267,8 @@ object ChapterProvider { val x1 = x + cw val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 @@ -280,14 +284,13 @@ object ChapterProvider { val x1 = if (i != words.lastIndex) x + cw + d else x + cw val textChar = TextChar( charData = char, - leftBottomPosition = TextPoint(paddingLeft + x, textLine.lineBottom), - rightTopPosition = TextPoint(paddingLeft + x1, textLine.lineTop) + start = paddingLeft + x, + end = paddingLeft + x1 ) textLine.textChars.add(textChar) x = x1 } } - textLine.lineBottom = textLine.lineBottom + contentPaint.fontMetrics.descent } durY += paragraphSpacing return durY diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index ff066f5b4..882c47d2d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -95,17 +95,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ReadBookConfig.durConfig.textColor() } textLine.textChars.forEach { - canvas.drawText( - it.charData, - it.leftBottomPosition.x, - it.leftBottomPosition.y, - textPaint - ) + canvas.drawText(it.charData, it.start, textLine.lineBase, textPaint) if (it.selected) { canvas.drawRect( - it.leftBottomPosition.x, + it.start, textLine.lineTop, - it.rightTopPosition.x, + it.end, textLine.lineBottom, selectedPaint ) @@ -158,21 +153,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() selectLineStart = lineIndex selectCharStart = charIndex selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedStart( - textChar.leftBottomPosition.x, - textChar.leftBottomPosition.y - ) - upSelectedEnd( - textChar.rightTopPosition.x, - textChar.leftBottomPosition.y - ) + upSelectedStart(textChar.start, textLine.lineBottom) + upSelectedEnd(textChar.end, textLine.lineBottom) return true } } @@ -186,14 +175,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + if (x > textChar.start && x < textChar.end) { if (selectLineStart != lineIndex || selectCharStart != charIndex) { selectLineStart = lineIndex selectCharStart = charIndex - upSelectedStart( - textChar.leftBottomPosition.x, - textChar.leftBottomPosition.y - ) + upSelectedStart(textChar.start, textLine.lineBottom) upSelectChars(textPage) } break @@ -208,13 +194,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { - if (x > textChar.leftBottomPosition.x && x < textChar.rightTopPosition.x) { + if (x > textChar.start && x < textChar.end) { if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd( - textChar.rightTopPosition.x, - textChar.leftBottomPosition.y + textChar.end, + textLine.lineBottom ) upSelectChars(textPage) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt index 9883e6dab..6fed2fe97 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChar.kt @@ -3,6 +3,6 @@ package io.legado.app.ui.book.read.page.entities data class TextChar( val charData: String, var selected: Boolean = false, - val leftBottomPosition: TextPoint, - val rightTopPosition: TextPoint + val start: Float, + val end: Float ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 00ae4bff6..26fb31e90 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -4,6 +4,7 @@ data class TextLine( var text: String = "", val textChars: ArrayList = arrayListOf(), var lineTop: Float = 0f, + var lineBase: Float = 0f, var lineBottom: Float = 0f, val isTitle: Boolean = false, var isReadAloud: Boolean = false diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt deleted file mode 100644 index 07bb142b6..000000000 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPoint.kt +++ /dev/null @@ -1,6 +0,0 @@ -package io.legado.app.ui.book.read.page.entities - -data class TextPoint( - val x: Float, - val y: Float -) \ No newline at end of file From 7af2b7ade0a365765c531b607ad2abce8d3b71f3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 08:21:43 +0800 Subject: [PATCH 10/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/ReadBookActivity.kt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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 a081b33a3..5cbd9bac9 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 @@ -7,6 +7,7 @@ import android.net.Uri import android.os.Bundle import android.os.Handler import android.view.* +import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.appcompat.view.menu.MenuItemImpl import androidx.core.view.get import androidx.core.view.isVisible @@ -379,20 +380,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo textActionMenu ?: let { textActionMenu = TextActionMenu(this, this) } + val x = cursor_left.x.toInt() + cursor_left.width + val y = (page_view.height - cursor_left.y + ReadBookConfig.textSize.dp * 1.5).toInt() textActionMenu?.let { popup -> if (!popup.isShowing) { - popup.showAtLocation( - cursor_left, - Gravity.BOTTOM or Gravity.START, - cursor_left.x.toInt() + cursor_left.width, - page_view.height - cursor_left.y.toInt() + ReadBookConfig.textSize.dp + popup.height - ) + popup.showAtLocation(cursor_left, Gravity.BOTTOM or Gravity.START, x, y) } else { - popup.update( - cursor_left.x.toInt() + cursor_left.width, - page_view.height - cursor_left.y.toInt() + ReadBookConfig.textSize.dp + popup.height, - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT - ) + popup.update(x, y, WRAP_CONTENT, WRAP_CONTENT) } } } From 8af0e0e311ac60c6ffda2997c908058d77bfd0f2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 08:36:30 +0800 Subject: [PATCH 11/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 6 +++++- app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt | 2 +- .../java/io/legado/app/ui/book/read/page/ContentView.kt | 6 +++--- app/src/main/java/io/legado/app/ui/widget/TitleBar.kt | 8 ++++---- .../main/java/io/legado/app/utils/ContextExtensions.kt | 7 ++++--- 5 files changed, 17 insertions(+), 12 deletions(-) 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 5cbd9bac9..11602b208 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 @@ -381,7 +381,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo textActionMenu = TextActionMenu(this, this) } val x = cursor_left.x.toInt() + cursor_left.width - val y = (page_view.height - cursor_left.y + ReadBookConfig.textSize.dp * 1.5).toInt() + val y = if (cursor_left.y - statusBarHeight > ReadBookConfig.textSize.dp * 1.5 + 20.dp) { + (page_view.height - cursor_left.y + ReadBookConfig.textSize.dp * 1.5).toInt() + } else { + (page_view.height - cursor_left.y - cursor_left.height - 40.dp).toInt() + } textActionMenu?.let { popup -> if (!popup.isShowing) { popup.showAtLocation(cursor_left, Gravity.BOTTOM or Gravity.START, x, y) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 12bbb6d8b..076215c40 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -201,7 +201,7 @@ class ReadMenu : FrameLayout { height = if (context.getPrefBoolean(PreferKey.hideNavigationBar) && Help.isNavigationBarExist(activity) - ) context.getNavigationBarHeight() + ) context.navigationBarHeight else 0 } } 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 2334e481a..5c387ac92 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 @@ -36,7 +36,7 @@ class ContentView(context: Context) : FrameLayout(context) { //显示状态栏时隐藏header if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { ll_header.layoutParams = - ll_header.layoutParams.apply { height = context.getStatusBarHeight() } + ll_header.layoutParams.apply { height = context.statusBarHeight } ll_header.setPadding( headerPaddingLeft.dp, headerPaddingTop.dp, @@ -47,7 +47,7 @@ class ContentView(context: Context) : FrameLayout(context) { page_panel.setPadding(0, 0, 0, 0) } else { ll_header.gone() - page_panel.setPadding(0, context.getStatusBarHeight(), 0, 0) + page_panel.setPadding(0, context.statusBarHeight, 0, 0) } content_text_view.setPadding( paddingLeft.dp, @@ -75,7 +75,7 @@ class ContentView(context: Context) : FrameLayout(context) { return if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { ll_header.height } else { - context.getStatusBarHeight() + context.statusBarHeight } } diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index ab931f3ab..d19c8929f 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -12,8 +12,8 @@ import com.google.android.material.appbar.AppBarLayout import io.legado.app.R import io.legado.app.lib.theme.primaryColor import io.legado.app.utils.activity -import io.legado.app.utils.getNavigationBarHeight -import io.legado.app.utils.getStatusBarHeight +import io.legado.app.utils.navigationBarHeight +import io.legado.app.utils.statusBarHeight import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.bottomPadding import org.jetbrains.anko.topPadding @@ -132,11 +132,11 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a } if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) { - topPadding = context.getStatusBarHeight() + topPadding = context.statusBarHeight } if (a.getBoolean(R.styleable.TitleBar_fitNavigationBar, false)) { - bottomPadding = context.getNavigationBarHeight() + bottomPadding = context.navigationBarHeight } backgroundColor = context.primaryColor diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 5b266a343..cb1eb6fe9 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -30,7 +30,6 @@ fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = fun Context.putPrefBoolean(key: String, value: Boolean = false) = defaultSharedPreferences.edit { putBoolean(key, value) } - fun Context.getPrefInt(key: String, defValue: Int = 0) = defaultSharedPreferences.getInt(key, defValue) @@ -79,12 +78,14 @@ fun Context.getScreenOffTime(): Int { return screenOffTime } -fun Context.getStatusBarHeight(): Int { +val Context.statusBarHeight: Int + get() { val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") return resources.getDimensionPixelSize(resourceId) } -fun Context.getNavigationBarHeight(): Int { +val Context.navigationBarHeight: Int + get() { val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android") return resources.getDimensionPixelSize(resourceId) } From 6b49b0c6af1a52ad02dcd5dae94cefea8209489c Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 08:50:09 +0800 Subject: [PATCH 12/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...cityReceiver.kt => TimeBatteryReceiver.kt} | 6 ++-- .../app/ui/book/read/ReadBookActivity.kt | 12 +++---- .../io/legado/app/utils/ContextExtensions.kt | 35 ++++++++++--------- 3 files changed, 28 insertions(+), 25 deletions(-) rename app/src/main/java/io/legado/app/receiver/{TimeElectricityReceiver.kt => TimeBatteryReceiver.kt} (85%) diff --git a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt b/app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt similarity index 85% rename from app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt rename to app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt index 765d05b3e..ce2e04fbe 100644 --- a/app/src/main/java/io/legado/app/receiver/TimeElectricityReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt @@ -9,12 +9,12 @@ import io.legado.app.constant.EventBus import io.legado.app.utils.postEvent -class TimeElectricityReceiver : BroadcastReceiver() { +class TimeBatteryReceiver : BroadcastReceiver() { companion object { - fun register(context: Context): TimeElectricityReceiver { - val receiver = TimeElectricityReceiver() + fun register(context: Context): TimeBatteryReceiver { + val receiver = TimeBatteryReceiver() val filter = IntentFilter() filter.addAction(Intent.ACTION_TIME_TICK) filter.addAction(Intent.ACTION_BATTERY_CHANGED) 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 11602b208..3ba0c965c 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 @@ -26,7 +26,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.accentColor -import io.legado.app.receiver.TimeElectricityReceiver +import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook @@ -81,7 +81,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private val keepScreenRunnable: Runnable = Runnable { Help.keepScreenOn(window, false) } private var screenTimeOut: Long = 0 - private var timeElectricityReceiver: TimeElectricityReceiver? = null + private var timeBatteryReceiver: TimeBatteryReceiver? = null override val pageFactory: TextPageFactory get() = page_view.pageFactory override val headerHeight: Int get() = page_view.curPage.headerHeight @@ -106,15 +106,15 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun onResume() { super.onResume() upSystemUiVisibility() - timeElectricityReceiver = TimeElectricityReceiver.register(this) + timeBatteryReceiver = TimeBatteryReceiver.register(this) page_view.upTime() } override fun onPause() { super.onPause() - timeElectricityReceiver?.let { + timeBatteryReceiver?.let { unregisterReceiver(it) - timeElectricityReceiver = null + timeBatteryReceiver = null } upSystemUiVisibility() } @@ -719,7 +719,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo Help.keepScreenOn(window, true) return } - val t = screenTimeOut - getScreenOffTime() + val t = screenTimeOut - sysScreenOffTime if (t > 0) { mHandler.removeCallbacks(keepScreenRunnable) Help.keepScreenOn(window, true) diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index cb1eb6fe9..90415484a 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -1,3 +1,4 @@ +@file:Suppress("unused") package io.legado.app.utils import android.annotation.SuppressLint @@ -68,26 +69,27 @@ fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = /** * 系统息屏时间 */ -fun Context.getScreenOffTime(): Int { - var screenOffTime = 0 - try { - screenOffTime = Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) - } catch (e: Exception) { - e.printStackTrace() - } - return screenOffTime +val Context.sysScreenOffTime: Int + get() { + var screenOffTime = 0 + try { + screenOffTime = Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) + } catch (e: Exception) { + e.printStackTrace() + } + return screenOffTime } val Context.statusBarHeight: Int get() { - val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") - return resources.getDimensionPixelSize(resourceId) + val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") + return resources.getDimensionPixelSize(resourceId) } val Context.navigationBarHeight: Int get() { - val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android") - return resources.getDimensionPixelSize(resourceId) + val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android") + return resources.getDimensionPixelSize(resourceId) } fun Context.shareText(title: String, text: String) { @@ -150,10 +152,11 @@ fun Context.sysIsDarkMode(): Boolean { /** * 获取电量 */ -fun Context.getBettery(): Int { - val iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) - val batteryStatus = registerReceiver(null, iFilter) - return batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1 +val Context.sysBattery: Int + get() { + val iFilter = IntentFilter(Intent.ACTION_BATTERY_CHANGED) + val batteryStatus = registerReceiver(null, iFilter) + return batteryStatus?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: -1 } fun Context.openUrl(url: String) { From d6a81504d44a52e8f1a19f526a994aeaf814a3d4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 08:52:39 +0800 Subject: [PATCH 13/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 12083c652..00c9d0522 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -45,7 +45,7 @@ class MediaButtonReceiver : BroadcastReceiver() { } } } - return false + return true } private fun readAloud(context: Context) { From ff4721019c2cbc966a307c410d3cf23afb2a1e70 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 08:59:37 +0800 Subject: [PATCH 14/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/PageView.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index a0c6c962a..d2cae1e92 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -101,14 +101,16 @@ class PageView(context: Context, attrs: AttributeSet) : } fun upContent(position: Int = 0) { - pageFactory.let { + if (isScrollDelegate) { + curPage.setContent(pageFactory.currentPage()) + } else { when (position) { - -1 -> prevPage.setContent(it.previousPage()) - 1 -> nextPage.setContent(it.nextPage()) + -1 -> prevPage.setContent(pageFactory.previousPage()) + 1 -> nextPage.setContent(pageFactory.nextPage()) else -> { - curPage.setContent(it.currentPage()) - nextPage.setContent(it.nextPage()) - prevPage.setContent(it.previousPage()) + curPage.setContent(pageFactory.currentPage()) + nextPage.setContent(pageFactory.nextPage()) + prevPage.setContent(pageFactory.previousPage()) } } } From d0ebf389997f85d38a64c7b2025007d7e3d86c3d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 09:16:19 +0800 Subject: [PATCH 15/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ReadBookConfig.kt | 8 +++++++- .../app/ui/book/read/config/ReadStyleDialog.kt | 11 +++++++---- .../app/ui/book/read/page/ContentTextView.kt | 15 ++------------- .../io/legado/app/ui/book/read/page/DataSource.kt | 1 - .../io/legado/app/ui/book/read/page/PageView.kt | 13 ++++--------- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index e165e5d4f..08302561f 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -26,7 +26,6 @@ object ReadBookConfig { } val durConfig get() = getConfig(styleSelect) private val shareConfig get() = getConfig(5) - var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) set(value) { field = value @@ -37,6 +36,13 @@ object ReadBookConfig { field = value App.INSTANCE.putPrefBoolean(PreferKey.shareLayout) } + var pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) + set(value) { + field = value + isScroll = value == 3 + App.INSTANCE.putPrefInt(PreferKey.pageAnim, value) + } + var isScroll = pageAnim == 3 var bg: Drawable? = null init { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 73d4c074c..590985d48 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -19,7 +19,10 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.book.read.Help import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog -import io.legado.app.utils.* +import io.legado.app.utils.getPrefString +import io.legado.app.utils.postEvent +import io.legado.app.utils.putPrefInt +import io.legado.app.utils.putPrefString import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_read_book_style.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange @@ -77,7 +80,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { private fun initData() { cb_share_layout.isChecked = ReadBookConfig.shareLayout - requireContext().getPrefInt(PreferKey.pageAnim).let { + ReadBookConfig.pageAnim.let { if (it >= 0 && it < rg_page_anim.childCount) { rg_page_anim.check(rg_page_anim[it].id) } @@ -143,10 +146,10 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { rg_page_anim.onCheckedChange { _, checkedId -> for (i in 0 until rg_page_anim.childCount) { if (checkedId == rg_page_anim[i].id) { - requireContext().putPrefInt(PreferKey.pageAnim, i) + ReadBookConfig.pageAnim = i val activity = activity if (activity is ReadBookActivity) { - activity.page_view.upPageAnim(i) + activity.page_view.upPageAnim() } break } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 882c47d2d..8d8d9632d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -60,6 +60,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at override fun onDraw(canvas: Canvas) { super.onDraw(canvas) + if (textPage.textLines.isEmpty()) { drawMsg(canvas, textPage.text) } else { @@ -117,19 +118,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at offset = -maxScrollOffset } - if (!isLastPage || offset < 0) { - pageOffset += offset - isLastPage = false - } - // 首页 - if (pageOffset < 0 && !pageFactory.hasPrev()) { - pageOffset = 0f - } - - val cHeight = if (textPage.height > 0) textPage.height else height - if (offset > 0 && pageOffset > cHeight) { - - } + pageOffset += offset } fun resetPageOffset() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt index ed223a4cf..c10d4bdd2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.book.read.page import io.legado.app.ui.book.read.page.entities.TextChapter interface DataSource { - val isScrollDelegate: Boolean val pageIndex: Int diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index d2cae1e92..b2fc6fad4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -6,13 +6,11 @@ import android.graphics.Canvas import android.util.AttributeSet import android.view.MotionEvent import android.widget.FrameLayout -import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.delegate.* import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.utils.activity -import io.legado.app.utils.getPrefInt class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), @@ -37,7 +35,7 @@ class PageView(context: Context, attrs: AttributeSet) : upBg() setWillNotDraw(false) pageFactory = TextPageFactory(this) - upPageAnim(context.getPrefInt(PreferKey.pageAnim)) + upPageAnim() } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { @@ -87,10 +85,10 @@ class PageView(context: Context, attrs: AttributeSet) : } } - fun upPageAnim(pageAnim: Int) { + fun upPageAnim() { pageDelegate?.onDestroy() pageDelegate = null - pageDelegate = when (pageAnim) { + pageDelegate = when (ReadBookConfig.pageAnim) { 0 -> CoverPageDelegate(this) 1 -> SlidePageDelegate(this) 2 -> SimulationPageDelegate(this) @@ -101,7 +99,7 @@ class PageView(context: Context, attrs: AttributeSet) : } fun upContent(position: Int = 0) { - if (isScrollDelegate) { + if (ReadBookConfig.isScroll) { curPage.setContent(pageFactory.currentPage()) } else { when (position) { @@ -165,9 +163,6 @@ class PageView(context: Context, attrs: AttributeSet) : nextPage.upBattery(battery) } - override val isScrollDelegate: Boolean - get() = pageDelegate is ScrollPageDelegate - override val pageIndex: Int get() = ReadBook.durChapterPos() From d590cc186a024246ec5df1f48348d1eab2fc43f2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 09:56:53 +0800 Subject: [PATCH 16/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 8 ++-- .../app/ui/book/read/page/ContentTextView.kt | 28 ++++---------- .../ui/book/read/page/entities/TextPage.kt | 37 +++++++++++++++++++ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index cd8c5c0e8..559997c02 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -23,10 +23,10 @@ import io.legado.app.utils.removePref object ChapterProvider { var viewWidth = 0 var viewHeight = 0 - private var visibleWidth = 0 - private var visibleHeight = 0 - private var paddingLeft = 0 - private var paddingTop = 0 + var visibleWidth = 0 + var visibleHeight = 0 + var paddingLeft = 0 + var paddingTop = 0 private var lineSpacingExtra = 0f private var paragraphSpacing = 0 var typeface: Typeface = Typeface.SANS_SERIF diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 8d8d9632d..404413fe0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -3,8 +3,6 @@ package io.legado.app.ui.book.read.page import android.content.Context import android.graphics.Canvas import android.graphics.Paint -import android.text.Layout -import android.text.StaticLayout import android.util.AttributeSet import android.view.View import io.legado.app.R @@ -30,7 +28,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private var selectCharStart = 0 private var selectLineEnd = 0 private var selectCharEnd = 0 - private var textPage: TextPage = TextPage() + private var textPage: TextPage = TextPage().textToLine() //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory private val maxScrollOffset = 100f @@ -60,29 +58,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at override fun onDraw(canvas: Canvas) { super.onDraw(canvas) - - if (textPage.textLines.isEmpty()) { - drawMsg(canvas, textPage.text) + if (ReadBookConfig.isScroll) { + drawScrollPage(canvas) } else { drawHorizontalPage(canvas) } } - @Suppress("DEPRECATION") - private fun drawMsg(canvas: Canvas, msg: String) { - val layout = StaticLayout( - msg, ChapterProvider.contentPaint, width, - Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false - ) - val y = (height - layout.height) / 2f - for (lineIndex in 0 until layout.lineCount) { - val x = (width - layout.getLineMax(lineIndex)) / 2 - val words = - msg.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) - canvas.drawText(words, x, y, ChapterProvider.contentPaint) - } - } - private fun drawHorizontalPage(canvas: Canvas) { textPage.textLines.forEach { textLine -> val textPaint = if (textLine.isTitle) { @@ -110,6 +92,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + private fun drawScrollPage(canvas: Canvas) { + + } + fun onScroll(mOffset: Float) { var offset = mOffset if (offset > maxScrollOffset) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 92d91b1e5..c52a0834e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -1,7 +1,10 @@ package io.legado.app.ui.book.read.page.entities +import android.text.Layout +import android.text.StaticLayout import io.legado.app.App import io.legado.app.R +import io.legado.app.ui.book.read.page.ChapterProvider data class TextPage( var index: Int = 0, @@ -14,6 +17,40 @@ data class TextPage( var height: Int = 0 ) { + @Suppress("DEPRECATION") + fun textToLine(): TextPage { + if (textLines.isEmpty()) { + val layout = StaticLayout( + text, ChapterProvider.contentPaint, ChapterProvider.visibleWidth, + Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false + ) + var y = (ChapterProvider.visibleHeight - layout.height) / 2f + if (y < 0) y = 0f + for (lineIndex in 0 until layout.lineCount) { + val textLine = TextLine() + textLine.lineTop = (ChapterProvider.paddingTop + y - + (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))) + textLine.lineBase = (ChapterProvider.paddingTop + y - + (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))) + textLine.lineBottom = + textLine.lineBase + ChapterProvider.contentPaint.fontMetrics.descent + var x = (ChapterProvider.visibleWidth - layout.getLineMax(lineIndex)) / 2 + textLine.text = + text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) + for (i in textLine.text.indices) { + val char = textLine.text[i].toString() + val cw = StaticLayout.getDesiredWidth(char, ChapterProvider.contentPaint) + val x1 = x + cw + textLine.textChars.add(TextChar(charData = char, start = x, end = x1)) + x = x1 + } + textLines.add(textLine) + } + height = ChapterProvider.visibleHeight + } + return this + } + fun removePageAloudSpan(): TextPage { textLines.forEach { textLine -> textLine.isReadAloud = false From b5457fe80c6cd37076fb663defd6db2e19f730f8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 10:04:41 +0800 Subject: [PATCH 17/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ContentTextView.kt | 11 +++++------ .../legado/app/ui/book/read/page/entities/TextPage.kt | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 404413fe0..5abb7175f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -28,7 +28,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private var selectCharStart = 0 private var selectLineEnd = 0 private var selectCharEnd = 0 - private var textPage: TextPage = TextPage().textToLine() + private var textPage: TextPage = TextPage() //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory private val maxScrollOffset = 100f @@ -49,11 +49,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) - ReadBookConfig.let { - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upSize() - } + ChapterProvider.viewWidth = w + ChapterProvider.viewHeight = h + ChapterProvider.upSize() + textPage.format() } override fun onDraw(canvas: Canvas) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index c52a0834e..4e6089ddd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -18,8 +18,8 @@ data class TextPage( ) { @Suppress("DEPRECATION") - fun textToLine(): TextPage { - if (textLines.isEmpty()) { + fun format(): TextPage { + if (textLines.isEmpty() && ChapterProvider.visibleWidth > 0) { val layout = StaticLayout( text, ChapterProvider.contentPaint, ChapterProvider.visibleWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false From fdb68976a46669931985641d7c0d9f2d204556a1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 10:20:43 +0800 Subject: [PATCH 18/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/config/TocRegexDialog.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index 0fb6a856c..f2046ac4b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -31,7 +31,6 @@ import io.legado.app.model.localBook.AnalyzeTxtFile import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint import kotlinx.android.synthetic.main.dialog_toc_regex.* -import kotlinx.android.synthetic.main.dialog_toc_regex_edit.* import kotlinx.android.synthetic.main.dialog_toc_regex_edit.view.* import kotlinx.android.synthetic.main.item_toc_regex.view.* import kotlinx.coroutines.Dispatchers.IO @@ -150,7 +149,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } } okButton { - rootView?.let { + rootView?.apply { tocRule.name = tv_rule_name.text.toString() tocRule.rule = tv_rule_regex.text.toString() saveRule(tocRule, rule) From 2ee5376abc037d8e4076eb18c9ca107ad377e2b5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 11:09:52 +0800 Subject: [PATCH 19/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 6 +- .../app/ui/book/read/page/ContentTextView.kt | 102 +++++++++++++++++- .../app/ui/book/read/page/PageFactory.kt | 6 +- .../legado/app/ui/book/read/page/PageView.kt | 12 +-- .../app/ui/book/read/page/TextPageFactory.kt | 9 +- 5 files changed, 117 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 559997c02..74136ba5c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -119,12 +119,12 @@ object ChapterProvider { Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingExtra, true ) for (lineIndex in 0 until layout.lineCount) { + textPages.last().height = durY durY = durY + layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex) val textLine = TextLine(isTitle = true) if (durY < visibleHeight) { textPages.last().textLines.add(textLine) } else { - textPages.last().height = durY textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) @@ -202,12 +202,12 @@ object ChapterProvider { Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingExtra, true ) for (lineIndex in 0 until layout.lineCount) { - val textLine = TextLine(isTitle = false) + textPages.last().height = durY durY = durY + layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex) + val textLine = TextLine() if (durY < visibleHeight) { textPages.last().textLines.add(textLine) } else { - textPages.last().height = durY textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 5abb7175f..28b803b90 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -77,7 +77,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ReadBookConfig.durConfig.textColor() } textLine.textChars.forEach { - canvas.drawText(it.charData, it.start, textLine.lineBase, textPaint) + canvas.drawText( + it.charData, + it.start, + textLine.lineBase, + textPaint + ) if (it.selected) { canvas.drawRect( it.start, @@ -92,11 +97,101 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private fun drawScrollPage(canvas: Canvas) { - + if (pageOffset <= 0) { + textPage.textLines.forEach { textLine -> + val textPaint = if (textLine.isTitle) { + ChapterProvider.titlePaint + } else { + ChapterProvider.contentPaint + } + textPaint.color = if (textLine.isReadAloud) { + context.accentColor + } else { + ReadBookConfig.durConfig.textColor() + } + textLine.textChars.forEach { + canvas.drawText( + it.charData, + it.start, + textLine.lineBase + pageOffset, + textPaint + ) + if (it.selected) { + canvas.drawRect( + it.start, + textLine.lineTop + pageOffset, + it.end, + textLine.lineBottom + pageOffset, + selectedPaint + ) + } + } + } + pageFactory.nextPage?.textLines?.forEach { textLine -> + val textPaint = if (textLine.isTitle) { + ChapterProvider.titlePaint + } else { + ChapterProvider.contentPaint + } + textPaint.color = if (textLine.isReadAloud) { + context.accentColor + } else { + ReadBookConfig.durConfig.textColor() + } + textLine.textChars.forEach { + canvas.drawText( + it.charData, + it.start, + textLine.lineBase + pageOffset + textPage.height - ChapterProvider.paddingTop, + textPaint + ) + if (it.selected) { + canvas.drawRect( + it.start, + textLine.lineTop + pageOffset + textPage.height - ChapterProvider.paddingTop, + it.end, + textLine.lineBottom + pageOffset + textPage.height - ChapterProvider.paddingTop, + selectedPaint + ) + } + } + } + } else { + textPage.textLines.forEach { textLine -> + val textPaint = if (textLine.isTitle) { + ChapterProvider.titlePaint + } else { + ChapterProvider.contentPaint + } + textPaint.color = if (textLine.isReadAloud) { + context.accentColor + } else { + ReadBookConfig.durConfig.textColor() + } + textLine.textChars.forEach { + canvas.drawText( + it.charData, + it.start, + textLine.lineBase + pageOffset, + textPaint + ) + if (it.selected) { + canvas.drawRect( + it.start, + textLine.lineTop + pageOffset, + it.end, + textLine.lineBottom + pageOffset, + selectedPaint + ) + } + } + } + } } fun onScroll(mOffset: Float) { - var offset = mOffset + if (mOffset == 0f) return + var offset = -mOffset if (offset > maxScrollOffset) { offset = maxScrollOffset } else if (offset < -maxScrollOffset) { @@ -104,6 +199,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } pageOffset += offset + invalidate() } fun resetPageOffset() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt index 6f39f2992..a335505ff 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt @@ -10,11 +10,11 @@ abstract class PageFactory(protected val dataSource: DataSource) { abstract fun moveToPrevious(): Boolean - abstract fun nextPage(): DATA? + abstract val nextPage: DATA? - abstract fun previousPage(): DATA? + abstract val prevPage: DATA? - abstract fun currentPage(): DATA? + abstract val currentPage: DATA? abstract fun hasNext(): Boolean diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index b2fc6fad4..ac7671406 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -100,15 +100,15 @@ class PageView(context: Context, attrs: AttributeSet) : fun upContent(position: Int = 0) { if (ReadBookConfig.isScroll) { - curPage.setContent(pageFactory.currentPage()) + curPage.setContent(pageFactory.currentPage) } else { when (position) { - -1 -> prevPage.setContent(pageFactory.previousPage()) - 1 -> nextPage.setContent(pageFactory.nextPage()) + -1 -> prevPage.setContent(pageFactory.prevPage) + 1 -> nextPage.setContent(pageFactory.nextPage) else -> { - curPage.setContent(pageFactory.currentPage()) - nextPage.setContent(pageFactory.nextPage()) - prevPage.setContent(pageFactory.previousPage()) + curPage.setContent(pageFactory.currentPage) + nextPage.setContent(pageFactory.nextPage) + prevPage.setContent(pageFactory.prevPage) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt index 018f75bab..cfcf3f6c9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt @@ -52,11 +52,13 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource false } - override fun currentPage(): TextPage? = with(dataSource) { + override val currentPage: TextPage? + get() = with(dataSource) { return getCurrentChapter()?.page(pageIndex) } - override fun nextPage(): TextPage? = with(dataSource) { + override val nextPage: TextPage? + get() = with(dataSource) { getCurrentChapter()?.let { if (pageIndex < it.pageSize() - 1) { return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() @@ -65,7 +67,8 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource return getNextChapter()?.page(0)?.removePageAloudSpan() } - override fun previousPage(): TextPage? = with(dataSource) { + override val prevPage: TextPage? + get() = with(dataSource) { if (pageIndex > 0) { return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() } From 2864bc28eacbfe831e7421a54609b47d8453e4b4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 11:41:41 +0800 Subject: [PATCH 20/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 199 +++++++----------- 1 file changed, 73 insertions(+), 126 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 28b803b90..752927c51 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -9,6 +9,7 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor +import io.legado.app.ui.book.read.page.entities.TextChar import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.activity import io.legado.app.utils.getCompatColor @@ -66,125 +67,82 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private fun drawHorizontalPage(canvas: Canvas) { textPage.textLines.forEach { textLine -> - val textPaint = if (textLine.isTitle) { - ChapterProvider.titlePaint - } else { - ChapterProvider.contentPaint - } - textPaint.color = if (textLine.isReadAloud) { - context.accentColor - } else { - ReadBookConfig.durConfig.textColor() - } - textLine.textChars.forEach { - canvas.drawText( - it.charData, - it.start, - textLine.lineBase, - textPaint - ) - if (it.selected) { - canvas.drawRect( - it.start, - textLine.lineTop, - it.end, - textLine.lineBottom, - selectedPaint - ) - } - } + drawChars( + canvas, + textLine.textChars, + textLine.lineTop, + textLine.lineBase, + textLine.lineBottom, + textLine.isTitle, + textLine.isReadAloud + ) } } private fun drawScrollPage(canvas: Canvas) { - if (pageOffset <= 0) { - textPage.textLines.forEach { textLine -> - val textPaint = if (textLine.isTitle) { - ChapterProvider.titlePaint - } else { - ChapterProvider.contentPaint - } - textPaint.color = if (textLine.isReadAloud) { - context.accentColor - } else { - ReadBookConfig.durConfig.textColor() - } - textLine.textChars.forEach { - canvas.drawText( - it.charData, - it.start, - textLine.lineBase + pageOffset, - textPaint - ) - if (it.selected) { - canvas.drawRect( - it.start, - textLine.lineTop + pageOffset, - it.end, - textLine.lineBottom + pageOffset, - selectedPaint - ) - } - } - } - pageFactory.nextPage?.textLines?.forEach { textLine -> - val textPaint = if (textLine.isTitle) { - ChapterProvider.titlePaint - } else { - ChapterProvider.contentPaint - } - textPaint.color = if (textLine.isReadAloud) { - context.accentColor - } else { - ReadBookConfig.durConfig.textColor() - } - textLine.textChars.forEach { - canvas.drawText( - it.charData, - it.start, - textLine.lineBase + pageOffset + textPage.height - ChapterProvider.paddingTop, - textPaint - ) - if (it.selected) { - canvas.drawRect( - it.start, - textLine.lineTop + pageOffset + textPage.height - ChapterProvider.paddingTop, - it.end, - textLine.lineBottom + pageOffset + textPage.height - ChapterProvider.paddingTop, - selectedPaint - ) - } - } - } - } else { - textPage.textLines.forEach { textLine -> - val textPaint = if (textLine.isTitle) { - ChapterProvider.titlePaint - } else { - ChapterProvider.contentPaint - } - textPaint.color = if (textLine.isReadAloud) { - context.accentColor - } else { - ReadBookConfig.durConfig.textColor() - } - textLine.textChars.forEach { - canvas.drawText( - it.charData, - it.start, - textLine.lineBase + pageOffset, - textPaint - ) - if (it.selected) { - canvas.drawRect( - it.start, - textLine.lineTop + pageOffset, - it.end, - textLine.lineBottom + pageOffset, - selectedPaint - ) - } - } + textPage.textLines.forEach { textLine -> + val yPy = pageOffset + val lineTop = textLine.lineTop + yPy + val lineBase = textLine.lineBase + yPy + val lineBottom = textLine.lineBottom + yPy + drawChars( + canvas, + textLine.textChars, + lineTop, + lineBase, + lineBottom, + textLine.isTitle, + textLine.isReadAloud + ) + } + pageFactory.nextPage?.textLines?.forEach { textLine -> + val yPy = pageOffset + textPage.height - ChapterProvider.paddingTop + val lineTop = textLine.lineTop + yPy + val lineBase = textLine.lineBase + yPy + val lineBottom = textLine.lineBottom + yPy + drawChars( + canvas, + textLine.textChars, + lineTop, + lineBase, + lineBottom, + textLine.isTitle, + textLine.isReadAloud + ) + } + pageFactory.prevPage?.textLines?.forEach { textLine -> + val yPy = pageOffset + ChapterProvider.paddingTop + val lineTop = -textLine.lineTop + yPy + val lineBase = -textLine.lineBase + yPy + val lineBottom = -textLine.lineBottom + yPy + drawChars( + canvas, + textLine.textChars, + lineTop, + lineBase, + lineBottom, + textLine.isTitle, + textLine.isReadAloud + ) + } + } + + private fun drawChars( + canvas: Canvas, + textChars: List, + lineTop: Float, + lineBase: Float, + lineBottom: Float, + isTitle: Boolean, + isReadAloud: Boolean + ) { + val textPaint = if (isTitle) ChapterProvider.titlePaint else ChapterProvider.contentPaint + textPaint.color = + if (isReadAloud) context.accentColor else ReadBookConfig.durConfig.textColor() + textChars.forEach { + canvas.drawText(it.charData, it.start, lineBase, textPaint) + if (it.selected) { + canvas.drawRect(it.start, lineTop, it.end, lineBottom, selectedPaint) } } } @@ -208,17 +166,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at isLastPage = false } - private fun switchToPageOffset(offset: Int) { - when (offset) { - 1 -> { - - } - -1 -> { - - } - } - } - fun selectText(x: Float, y: Float): Boolean { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { From 3c8def787d4859fc15749d6879140c4c8277e1c2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 12:07:36 +0800 Subject: [PATCH 21/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ContentTextView.kt | 2 -- .../io/legado/app/ui/book/read/page/ContentView.kt | 4 ++++ .../io/legado/app/ui/book/read/page/PageView.kt | 1 + .../book/read/page/delegate/ScrollPageDelegate.kt | 13 ++++++++----- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 752927c51..dfaa208ba 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -35,7 +35,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private val maxScrollOffset = 100f private var pageOffset = 0f private var linePos = 0 - private var isLastPage = false init { callBack = activity as CallBack @@ -163,7 +162,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun resetPageOffset() { pageOffset = 0f linePos = 0 - isLastPage = false } fun selectText(x: Float, y: Float): Boolean { 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 5c387ac92..d6ae6eb3a 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 @@ -111,6 +111,10 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.onScroll(offset) } + fun resetPageOffset() { + content_text_view.resetPageOffset() + } + fun upSelectAble(selectAble: Boolean) { content_text_view.selectAble = selectAble } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index ac7671406..4b5ee7dbd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -100,6 +100,7 @@ class PageView(context: Context, attrs: AttributeSet) : fun upContent(position: Int = 0) { if (ReadBookConfig.isScroll) { + curPage.resetPageOffset() curPage.setContent(pageFactory.currentPage) } else { when (position) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 714c26f89..c9e097808 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -31,11 +31,14 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } } - override fun onDown(e: MotionEvent): Boolean { - abort() - mVelocity.clear() - mVelocity.addMovement(e) - return super.onDown(e) + override fun onTouch(event: MotionEvent): Boolean { + if (event.action == MotionEvent.ACTION_DOWN) { + setStartPoint(event.x, event.y) + abort() + mVelocity.clear() + mVelocity.addMovement(event) + } + return super.onTouch(event) } override fun onScroll( From 2c314a074590c7f391cc00845d272a7b0043128e Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 12:25:11 +0800 Subject: [PATCH 22/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 7 +++++ .../app/ui/book/read/page/PageFactory.kt | 2 +- .../legado/app/ui/book/read/page/PageView.kt | 2 +- .../app/ui/book/read/page/TextPageFactory.kt | 27 +++++++++---------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index dfaa208ba..38b9f2d0b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -156,6 +156,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } pageOffset += offset + if (pageOffset > 0) { + pageFactory.moveToPrev() + pageOffset -= textPage.height + } else if (pageOffset < -textPage.height) { + pageOffset += textPage.height + pageFactory.moveToNext() + } invalidate() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt index a335505ff..db504b6f4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageFactory.kt @@ -8,7 +8,7 @@ abstract class PageFactory(protected val dataSource: DataSource) { abstract fun moveToNext():Boolean - abstract fun moveToPrevious(): Boolean + abstract fun moveToPrev(): Boolean abstract val nextPage: DATA? diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 4b5ee7dbd..a4841e3f0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -74,7 +74,7 @@ class PageView(context: Context, attrs: AttributeSet) : fun fillPage(direction: PageDelegate.Direction) { when (direction) { PageDelegate.Direction.PREV -> { - pageFactory.moveToPrevious() + pageFactory.moveToPrev() upContent() } PageDelegate.Direction.NEXT -> { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt index cfcf3f6c9..db28bd813 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt @@ -29,8 +29,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToNext(): Boolean = with(dataSource) { return if (hasNext()) { - if (getCurrentChapter()?.isLastIndex(pageIndex) == true - ) { + if (getCurrentChapter()?.isLastIndex(pageIndex) == true) { ReadBook.moveToNextChapter(false) } else { setPageIndex(pageIndex.plus(1)) @@ -40,7 +39,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource false } - override fun moveToPrevious(): Boolean = with(dataSource) { + override fun moveToPrev(): Boolean = with(dataSource) { return if (hasPrev()) { if (pageIndex <= 0) { ReadBook.moveToPrevChapter(false) @@ -54,26 +53,26 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override val currentPage: TextPage? get() = with(dataSource) { - return getCurrentChapter()?.page(pageIndex) - } + return getCurrentChapter()?.page(pageIndex) + } override val nextPage: TextPage? get() = with(dataSource) { - getCurrentChapter()?.let { - if (pageIndex < it.pageSize() - 1) { - return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() + getCurrentChapter()?.let { + if (pageIndex < it.pageSize() - 1) { + return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() + } } + return getNextChapter()?.page(0)?.removePageAloudSpan() } - return getNextChapter()?.page(0)?.removePageAloudSpan() - } override val prevPage: TextPage? get() = with(dataSource) { - if (pageIndex > 0) { - return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() + if (pageIndex > 0) { + return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() + } + return getPreviousChapter()?.lastPage()?.removePageAloudSpan() } - return getPreviousChapter()?.lastPage()?.removePageAloudSpan() - } } From de369e3b72abaa14149514ffc335db779ae32169 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 12:30:35 +0800 Subject: [PATCH 23/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/help/ReadBook.kt | 6 ++++++ .../io/legado/app/ui/book/read/ReadBookActivity.kt | 6 ------ .../io/legado/app/ui/book/read/page/PageView.kt | 13 +------------ 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index d038ad600..4e718a09c 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -127,6 +127,12 @@ object ReadBook { saveRead() } + fun setPageIndex(pageIndex: Int) { + durPageIndex = pageIndex + saveRead() + curPageChanged() + } + fun curPageChanged() { callBack?.upPageProgress() if (BaseReadAloudService.isRun) { 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 3ba0c965c..a10e21f74 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 @@ -505,12 +505,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo viewModel.changeTo(book) } - override fun setPageIndex(pageIndex: Int) { - ReadBook.durPageIndex = pageIndex - ReadBook.saveRead() - ReadBook.curPageChanged() - } - override fun clickCenter() { if (BaseReadAloudService.isRun) { showReadAloudDialog() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index a4841e3f0..7ebb215ce 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -168,7 +168,7 @@ class PageView(context: Context, attrs: AttributeSet) : get() = ReadBook.durChapterPos() override fun setPageIndex(pageIndex: Int) { - callBack.setPageIndex(pageIndex) + ReadBook.setPageIndex(pageIndex) } override fun getChapterPosition(): Int { @@ -196,19 +196,8 @@ class PageView(context: Context, attrs: AttributeSet) : } interface CallBack { - val isInitFinish: Boolean - - /** - * 保存页数 - */ - fun setPageIndex(pageIndex: Int) - - /** - * 点击屏幕中间 - */ fun clickCenter() - fun screenOffTimerStart() } } From 9f46589320fa56cc0c19cd442fc59ef96ec1925b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 12:45:47 +0800 Subject: [PATCH 24/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 38b9f2d0b..eec3b5cb2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -158,10 +158,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageOffset += offset if (pageOffset > 0) { pageFactory.moveToPrev() + textPage = pageFactory.currentPage ?: TextPage().format() pageOffset -= textPage.height } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() + textPage = pageFactory.currentPage ?: TextPage().format() } invalidate() } From af31324bb7af557bdf87ea4c3d070fbd591fcd6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 13:28:54 +0800 Subject: [PATCH 25/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/service/help/ReadBook.kt | 4 ++-- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 4 ++-- .../legado/app/ui/book/read/page/ContentTextView.kt | 3 +++ .../io/legado/app/ui/book/read/page/ContentView.kt | 11 +++++------ .../java/io/legado/app/ui/book/read/page/PageView.kt | 7 +++---- app/src/main/res/layout/dialog_read_aloud.xml | 4 ++-- app/src/main/res/values/strings.xml | 1 + 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 4e718a09c..ecbeb74a1 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -133,7 +133,7 @@ object ReadBook { curPageChanged() } - fun curPageChanged() { + private fun curPageChanged() { callBack?.upPageProgress() if (BaseReadAloudService.isRun) { readAloud(!BaseReadAloudService.pause) @@ -312,7 +312,7 @@ object ReadBook { } interface CallBack { - fun upContent(position: Int = 0) + fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) fun upView() fun upPageProgress() fun contentLoadFinish() 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 a10e21f74..fec5bfa27 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 @@ -456,9 +456,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 更新内容 */ - override fun upContent(position: Int) { + override fun upContent(relativePosition: Int, resetScrollOffset: Boolean) { launch { - page_view.upContent(position) + page_view.upContent(relativePosition) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index eec3b5cb2..fc0576f60 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -160,10 +160,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() pageOffset -= textPage.height + callBack.upContent(0, false) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() textPage = pageFactory.currentPage ?: TextPage().format() + callBack.upContent(0, false) } invalidate() } @@ -301,6 +303,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } interface CallBack { + fun upContent(relativePosition: Int, resetScrollOffset: Boolean) fun upSelectedStart(x: Float, y: Float) fun upSelectedEnd(x: Float, y: Float) fun onCancelSelect() 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 d6ae6eb3a..d0d6ac377 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 @@ -91,12 +91,15 @@ class ContentView(context: Context) : FrameLayout(context) { tv_top_right.text = context.getString(R.string.battery_show, battery) } - fun setContent(textPage: TextPage?) { + fun setContent(textPage: TextPage?, resetScrollOffset: Boolean = true) { if (textPage != null) { - content_text_view.setContent(textPage) tv_bottom_left.text = textPage.title pageSize = textPage.pageSize setPageIndex(textPage.index) + if (resetScrollOffset) { + content_text_view.resetPageOffset() + content_text_view.setContent(textPage) + } } } @@ -111,10 +114,6 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.onScroll(offset) } - fun resetPageOffset() { - content_text_view.resetPageOffset() - } - fun upSelectAble(selectAble: Boolean) { content_text_view.selectAble = selectAble } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 7ebb215ce..076462d0a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -98,12 +98,11 @@ class PageView(context: Context, attrs: AttributeSet) : upContent() } - fun upContent(position: Int = 0) { + fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) { if (ReadBookConfig.isScroll) { - curPage.resetPageOffset() - curPage.setContent(pageFactory.currentPage) + curPage.setContent(pageFactory.currentPage, resetScrollOffset) } else { - when (position) { + when (relativePosition) { -1 -> prevPage.setContent(pageFactory.prevPage) 1 -> nextPage.setContent(pageFactory.nextPage) else -> { diff --git a/app/src/main/res/layout/dialog_read_aloud.xml b/app/src/main/res/layout/dialog_read_aloud.xml index 282f9cdfe..ea04696d4 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -154,8 +154,8 @@ android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:background="?android:attr/selectableItemBackgroundBorderless" - android:tooltipText="@string/other_setting" - android:contentDescription="@string/other_setting" + android:tooltipText="@string/other_aloud_setting" + android:contentDescription="@string/other_aloud_setting" android:src="@drawable/ic_settings" android:tint="@color/tv_text_default" tools:ignore="UnusedAttribute" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3b121d53f..f64f60c5a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -626,4 +626,5 @@ 更多菜单 + 其它朗读设置 From f83479ab8abb8a15ba58e9210c20961c8a8a5a06 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 14:40:08 +0800 Subject: [PATCH 26/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 11 ++++---- .../app/ui/book/read/page/ContentView.kt | 1 + .../book/read/page/delegate/PageDelegate.kt | 23 ++++++---------- .../read/page/delegate/ScrollPageDelegate.kt | 26 ++++++++----------- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index fc0576f60..fb7ad11c5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -4,6 +4,7 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.util.AttributeSet +import android.util.Log import android.view.View import io.legado.app.R import io.legado.app.constant.PreferKey @@ -80,10 +81,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private fun drawScrollPage(canvas: Canvas) { textPage.textLines.forEach { textLine -> - val yPy = pageOffset - val lineTop = textLine.lineTop + yPy - val lineBase = textLine.lineBase + yPy - val lineBottom = textLine.lineBottom + yPy + val lineTop = textLine.lineTop + pageOffset + val lineBase = textLine.lineBase + pageOffset + val lineBottom = textLine.lineBottom + pageOffset drawChars( canvas, textLine.textChars, @@ -148,7 +148,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun onScroll(mOffset: Float) { if (mOffset == 0f) return - var offset = -mOffset + var offset = mOffset if (offset > maxScrollOffset) { offset = maxScrollOffset } else if (offset < -maxScrollOffset) { @@ -159,6 +159,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (pageOffset > 0) { pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() + Log.e("pageOffSet", pageOffset.toString() + " " + textPage.height) pageOffset -= textPage.height callBack.upContent(0, false) } else if (pageOffset < -textPage.height) { 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 d0d6ac377..3140e6d1a 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 @@ -100,6 +100,7 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.resetPageOffset() content_text_view.setContent(textPage) } + content_text_view.invalidate() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 2a90c79f1..681159059 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -6,9 +6,9 @@ import android.graphics.Canvas import android.graphics.RectF import android.view.GestureDetector import android.view.MotionEvent +import android.view.animation.DecelerateInterpolator import android.widget.Scroller import androidx.annotation.CallSuper -import androidx.interpolator.view.animation.FastOutLinearInInterpolator import com.google.android.material.snackbar.Snackbar import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig @@ -47,16 +47,13 @@ abstract class PageDelegate(protected val pageView: PageView) : protected var viewWidth: Int = pageView.width protected var viewHeight: Int = pageView.height - //textView在顶端或低端 - protected var atTop: Boolean = false - protected var atBottom: Boolean = false private val snackBar: Snackbar by lazy { Snackbar.make(pageView, "", Snackbar.LENGTH_SHORT) } private val scroller: Scroller by lazy { - Scroller(pageView.context, FastOutLinearInInterpolator()) + Scroller(pageView.context, DecelerateInterpolator()) } private val detector: GestureDetector by lazy { @@ -83,7 +80,7 @@ abstract class PageDelegate(protected val pageView: PageView) : touchY = y if (invalidate) { - invalidate() + pageView.invalidate() } } @@ -93,7 +90,7 @@ abstract class PageDelegate(protected val pageView: PageView) : touchY = y if (invalidate) { - invalidate() + pageView.postInvalidate() } onScroll() @@ -103,10 +100,6 @@ abstract class PageDelegate(protected val pageView: PageView) : detector.setIsLongpressEnabled(selectAble) } - protected fun invalidate() { - pageView.invalidate() - } - open fun fling( startX: Int, startY: Int, velocityX: Int, velocityY: Int, minX: Int, maxX: Int, minY: Int, maxY: Int @@ -114,7 +107,7 @@ abstract class PageDelegate(protected val pageView: PageView) : scroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY) isRunning = true isStarted = true - invalidate() + pageView.invalidate() } protected fun startScroll(startX: Int, startY: Int, dx: Int, dy: Int) { @@ -127,13 +120,13 @@ abstract class PageDelegate(protected val pageView: PageView) : ) isRunning = true isStarted = true - invalidate() + pageView.invalidate() } private fun stopScroll() { isRunning = false isStarted = false - invalidate() + pageView.invalidate() bitmap?.recycle() bitmap = null } @@ -141,7 +134,7 @@ abstract class PageDelegate(protected val pageView: PageView) : fun setViewSize(width: Int, height: Int) { viewWidth = width viewHeight = height - invalidate() + pageView.invalidate() centerRectF.set( width * 0.33f, height * 0.33f, width * 0.66f, height * 0.66f diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index c9e097808..894e4b9b8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -22,7 +22,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun onDraw(canvas: Canvas) { - curPage.onScroll(lastY - touchY) + curPage.onScroll(touchY - lastY) } override fun onAnimStop() { @@ -52,23 +52,19 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { if (!isMoved && abs(distanceX) < abs(distanceY)) { if (distanceY < 0) { - if (atTop) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return true - } - setDirection(Direction.PREV) + //如果上一页不存在 + if (!hasPrev()) { + noNext = true + return true } + setDirection(Direction.PREV) } else { - if (atBottom) { - //如果不存在表示没有下一页了 - if (!hasNext()) { - noNext = true - return true - } - setDirection(Direction.NEXT) + //如果上一页不存在 + if (!hasNext()) { + noNext = true + return true } + setDirection(Direction.PREV) } isMoved = true } From 41ea3a7eb4761ae03735187503238e5cfe508e78 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 14:48:19 +0800 Subject: [PATCH 27/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/delegate/PageDelegate.kt | 18 ++++++------------ .../read/page/delegate/ScrollPageDelegate.kt | 3 +-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 681159059..fec677deb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -34,14 +34,9 @@ abstract class PageDelegate(protected val pageView: PageView) : protected var touchX: Float = 0f protected var touchY: Float = 0f - protected val nextPage: ContentView - get() = pageView.nextPage - - protected val curPage: ContentView - get() = pageView.curPage - - protected val prevPage: ContentView - get() = pageView.prevPage + protected val nextPage: ContentView get() = pageView.nextPage + protected val curPage: ContentView get() = pageView.curPage + protected val prevPage: ContentView get() = pageView.prevPage protected var bitmap: Bitmap? = null @@ -90,7 +85,7 @@ abstract class PageDelegate(protected val pageView: PageView) : touchY = y if (invalidate) { - pageView.postInvalidate() + pageView.invalidate() } onScroll() @@ -187,12 +182,11 @@ abstract class PageDelegate(protected val pageView: PageView) : abstract fun onAnimStart()//scroller start - abstract fun onDraw(canvas: Canvas)//绘制 + open fun onDraw(canvas: Canvas) {}//绘制 abstract fun onAnimStop()//scroller finish - open fun onScroll() {//移动contentView, slidePage - } + open fun onScroll() {}//移动contentView, slidePage @CallSuper open fun setDirection(direction: Direction) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 894e4b9b8..eca83b12a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.read.page.delegate -import android.graphics.Canvas import android.view.MotionEvent import android.view.VelocityTracker import io.legado.app.ui.book.read.page.PageView @@ -21,7 +20,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { ) } - override fun onDraw(canvas: Canvas) { + override fun onScroll() { curPage.onScroll(touchY - lastY) } From 3aa9b034d5b90526ca0423d04bf1d992c1f3f0cc Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:04:46 +0800 Subject: [PATCH 28/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 6 ++---- .../java/io/legado/app/ui/book/read/page/ContentView.kt | 3 ++- .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index fb7ad11c5..eafa79676 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -4,7 +4,6 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.util.AttributeSet -import android.util.Log import android.view.View import io.legado.app.R import io.legado.app.constant.PreferKey @@ -159,14 +158,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (pageOffset > 0) { pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() - Log.e("pageOffSet", pageOffset.toString() + " " + textPage.height) pageOffset -= textPage.height - callBack.upContent(0, false) +// callBack.upContent(0, false) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() textPage = pageFactory.currentPage ?: TextPage().format() - callBack.upContent(0, false) +// callBack.upContent(0, false) } invalidate() } 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 3140e6d1a..45fa4c1d7 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 @@ -99,8 +99,9 @@ class ContentView(context: Context) : FrameLayout(context) { if (resetScrollOffset) { content_text_view.resetPageOffset() content_text_view.setContent(textPage) + } else { + content_text_view.invalidate() } - content_text_view.invalidate() } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index fec677deb..b6f9be6a4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -140,7 +140,7 @@ abstract class PageDelegate(protected val pageView: PageView) : if (scroller.computeScrollOffset()) { setTouchPoint(scroller.currX.toFloat(), scroller.currY.toFloat()) } else if (isStarted) { - setTouchPoint(scroller.finalX.toFloat(), scroller.finalY.toFloat(), false) + setTouchPoint(scroller.currY.toFloat(), scroller.finalY.toFloat(), false) onAnimStop() stopScroll() } From 2480af6ba854ccc443d071121543e62d2da0e27d Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:14:39 +0800 Subject: [PATCH 29/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/DataSource.kt | 7 ++----- .../java/io/legado/app/ui/book/read/page/PageView.kt | 11 ----------- .../legado/app/ui/book/read/page/TextPageFactory.kt | 12 ++++++------ 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt index c10d4bdd2..6fe49e43f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt @@ -1,14 +1,11 @@ package io.legado.app.ui.book.read.page +import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.entities.TextChapter interface DataSource { - val pageIndex: Int - - fun setPageIndex(pageIndex: Int) - - fun getChapterPosition(): Int + val pageIndex: Int get() = ReadBook.durChapterPos() fun getCurrentChapter(): TextChapter? diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 076462d0a..8421b68d9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -163,17 +163,6 @@ class PageView(context: Context, attrs: AttributeSet) : nextPage.upBattery(battery) } - override val pageIndex: Int - get() = ReadBook.durChapterPos() - - override fun setPageIndex(pageIndex: Int) { - ReadBook.setPageIndex(pageIndex) - } - - override fun getChapterPosition(): Int { - return ReadBook.durChapterIndex - } - override fun getCurrentChapter(): TextChapter? { return if (callBack.isInitFinish) ReadBook.textChapter(0) else null } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt index db28bd813..307423955 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/TextPageFactory.kt @@ -14,17 +14,17 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun moveToFirst() { - dataSource.setPageIndex(0) + ReadBook.setPageIndex(0) } override fun moveToLast() = with(dataSource) { getCurrentChapter()?.let { if (it.pageSize() == 0) { - setPageIndex(0) + ReadBook.setPageIndex(0) } else { - setPageIndex(it.pageSize().minus(1)) + ReadBook.setPageIndex(it.pageSize().minus(1)) } - } ?: setPageIndex(0) + } ?: ReadBook.setPageIndex(0) } override fun moveToNext(): Boolean = with(dataSource) { @@ -32,7 +32,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource if (getCurrentChapter()?.isLastIndex(pageIndex) == true) { ReadBook.moveToNextChapter(false) } else { - setPageIndex(pageIndex.plus(1)) + ReadBook.setPageIndex(pageIndex.plus(1)) } true } else @@ -44,7 +44,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource if (pageIndex <= 0) { ReadBook.moveToPrevChapter(false) } else { - setPageIndex(pageIndex.minus(1)) + ReadBook.setPageIndex(pageIndex.minus(1)) } true } else From bcc8377f7dc4e4ba4800dc1086465c91ce54936f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:22:06 +0800 Subject: [PATCH 30/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/service/help/ReadBook.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index ecbeb74a1..845fccbb2 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -26,10 +26,10 @@ object ReadBook { var book: Book? = null var inBookshelf = false var chapterSize = 0 - var callBack: CallBack? = null var durChapterIndex = 0 var durPageIndex = 0 var isLocalBook = true + var callBack: CallBack? = null var prevTextChapter: TextChapter? = null var curTextChapter: TextChapter? = null var nextTextChapter: TextChapter? = null From a9eadf79f828802be46010fbf6aabb0d76902a52 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:44:45 +0800 Subject: [PATCH 31/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/ReadBookActivity.kt | 2 +- .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 4 ++-- .../app/ui/book/read/page/delegate/ScrollPageDelegate.kt | 6 ------ 3 files changed, 3 insertions(+), 9 deletions(-) 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 fec5bfa27..abe5f1925 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 @@ -458,7 +458,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun upContent(relativePosition: Int, resetScrollOffset: Boolean) { launch { - page_view.upContent(relativePosition) + page_view.upContent(relativePosition, resetScrollOffset) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index b6f9be6a4..275105fde 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -180,11 +180,11 @@ abstract class PageDelegate(protected val pageView: PageView) : onAnimStart() } - abstract fun onAnimStart()//scroller start + open fun onAnimStart() {}//scroller start open fun onDraw(canvas: Canvas) {}//绘制 - abstract fun onAnimStop()//scroller finish + open fun onAnimStop() {}//scroller finish open fun onScroll() {}//移动contentView, slidePage diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index eca83b12a..68c024d96 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -24,12 +24,6 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { curPage.onScroll(touchY - lastY) } - override fun onAnimStop() { - if (!isCancel) { - pageView.fillPage(mDirection) - } - } - override fun onTouch(event: MotionEvent): Boolean { if (event.action == MotionEvent.ACTION_DOWN) { setStartPoint(event.x, event.y) From c35e393ebbfd6877b228935d25861db4f27cd7b6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:48:49 +0800 Subject: [PATCH 32/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index eafa79676..bb759b079 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -159,12 +159,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() pageOffset -= textPage.height -// callBack.upContent(0, false) + callBack.upContent(0, false) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() textPage = pageFactory.currentPage ?: TextPage().format() -// callBack.upContent(0, false) + callBack.upContent(0, false) } invalidate() } From 67f679194f6d4a501aeab7919d6a7959e9134c92 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:50:18 +0800 Subject: [PATCH 33/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 8b1acd8d9..031dd29fb 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,6 +2,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/24** +* 滚动暂时可以滚了,先这样吧,头大 + **2020/02/23** * 修复BUG * 本地目录正则自定义完成 From a9dee51b45e6e0d46c9c990b7a4345ade95edcec Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 15:54:58 +0800 Subject: [PATCH 34/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index e87f74051..0e97cf940 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -268,7 +268,7 @@ object BookHelp { } } } - if (!c.startsWith(title)) { + if (!c.substringBefore("\n").contains(title)) { c = "$title\n$c" } when (AppConfig.chineseConverterType) { From 284fe6ce569db28c0c7f1fe02f473e5ac05b1e12 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 16:07:41 +0800 Subject: [PATCH 35/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 10 ++++++++-- .../legado/app/ui/book/read/config/ReadStyleDialog.kt | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 0e97cf940..c7560b819 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -237,8 +237,14 @@ object BookHelp { private var bookName: String? = null private var bookOrigin: String? = null private var replaceRules: List = arrayListOf() - val bodyIndent - get() = " ".repeat(App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2)) + var bodyIndentCount = App.INSTANCE.getPrefInt(PreferKey.bodyIndent, 2) + set(value) { + field = value + App.INSTANCE.putPrefInt(PreferKey.bodyIndent, value) + bodyIndent = " ".repeat(value) + } + var bodyIndent = " ".repeat(bodyIndentCount) + fun disposeContent( title: String, diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index 590985d48..c78466569 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -11,6 +11,7 @@ import androidx.fragment.app.DialogFragment import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.BookHelp import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.lib.dialogs.selector @@ -21,7 +22,6 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.widget.font.FontSelectDialog import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent -import io.legado.app.utils.putPrefInt import io.legado.app.utils.putPrefString import kotlinx.android.synthetic.main.activity_book_read.* import kotlinx.android.synthetic.main.dialog_read_book_style.* @@ -116,7 +116,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { title = getString(R.string.text_indent), items = resources.getStringArray(R.array.indent).toList() ) { _, index -> - putPrefInt(PreferKey.bodyIndent, index) + BookHelp.bodyIndentCount = index postEvent(EventBus.UP_CONFIG, true) } } From 9c15e9401cdc936d70164c0725ea4ce7360a11e3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 16:58:14 +0800 Subject: [PATCH 36/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/help/ReadBook.kt | 2 +- .../legado/app/ui/book/read/ReadBookActivity.kt | 4 ++-- .../app/ui/book/read/page/ContentTextView.kt | 8 ++++---- .../legado/app/ui/book/read/page/ContentView.kt | 15 ++++++++------- .../io/legado/app/ui/book/read/page/DataSource.kt | 1 - .../io/legado/app/ui/book/read/page/PageView.kt | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 845fccbb2..207c34ec6 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -312,7 +312,7 @@ object ReadBook { } interface CallBack { - fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) + fun upContent(relativePosition: Int = 0) fun upView() fun upPageProgress() fun contentLoadFinish() 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 abe5f1925..16b198626 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 @@ -456,9 +456,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 更新内容 */ - override fun upContent(relativePosition: Int, resetScrollOffset: Boolean) { + override fun upContent(relativePosition: Int) { launch { - page_view.upContent(relativePosition, resetScrollOffset) + page_view.upContent(relativePosition) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index bb759b079..33388fc63 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -17,6 +17,8 @@ import io.legado.app.utils.getPrefBoolean class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { + var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) + var upView: ((TextPage) -> Unit)? = null private val selectedPaint by lazy { Paint().apply { color = context.getCompatColor(R.color.btn_bg_press_2) @@ -24,7 +26,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } private var callBack: CallBack - var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) private var selectLineStart = 0 private var selectCharStart = 0 private var selectLineEnd = 0 @@ -159,12 +160,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageFactory.moveToPrev() textPage = pageFactory.currentPage ?: TextPage().format() pageOffset -= textPage.height - callBack.upContent(0, false) + upView?.invoke(textPage) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() textPage = pageFactory.currentPage ?: TextPage().format() - callBack.upContent(0, false) + upView?.invoke(textPage) } invalidate() } @@ -302,7 +303,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } interface CallBack { - fun upContent(relativePosition: Int, resetScrollOffset: Boolean) fun upSelectedStart(x: Float, y: Float) fun upSelectedEnd(x: Float, y: Float) fun onCancelSelect() 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 45fa4c1d7..3613f17bd 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 @@ -25,6 +25,11 @@ class ContentView(context: Context) : FrameLayout(context) { upStyle() upTime() + content_text_view.upView = { + tv_bottom_left.text = it.title + pageSize = it.pageSize + setPageIndex(it.index) + } } fun upStyle() { @@ -91,17 +96,13 @@ class ContentView(context: Context) : FrameLayout(context) { tv_top_right.text = context.getString(R.string.battery_show, battery) } - fun setContent(textPage: TextPage?, resetScrollOffset: Boolean = true) { + fun setContent(textPage: TextPage?) { if (textPage != null) { tv_bottom_left.text = textPage.title pageSize = textPage.pageSize setPageIndex(textPage.index) - if (resetScrollOffset) { - content_text_view.resetPageOffset() - content_text_view.setContent(textPage) - } else { - content_text_view.invalidate() - } + content_text_view.resetPageOffset() + content_text_view.setContent(textPage) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt index 6fe49e43f..106e2e4db 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/DataSource.kt @@ -16,5 +16,4 @@ interface DataSource { fun hasNextChapter(): Boolean fun hasPrevChapter(): Boolean - } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 8421b68d9..f115eabce 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -98,9 +98,9 @@ class PageView(context: Context, attrs: AttributeSet) : upContent() } - fun upContent(relativePosition: Int = 0, resetScrollOffset: Boolean = true) { + fun upContent(relativePosition: Int = 0) { if (ReadBookConfig.isScroll) { - curPage.setContent(pageFactory.currentPage, resetScrollOffset) + curPage.setContent(pageFactory.currentPage) } else { when (relativePosition) { -1 -> prevPage.setContent(pageFactory.prevPage) From b13d4cccd8db3c459f6e2cab15d61f3fed46da56 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 17:01:35 +0800 Subject: [PATCH 37/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 031dd29fb..1cb677260 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,7 @@ **2020/02/24** * 滚动暂时可以滚了,先这样吧,头大 +* 紧急修复朗读报错的bug **2020/02/23** * 修复BUG From acd2108f47b426f82fd2ad31b60f420dddedd777 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 18:47:50 +0800 Subject: [PATCH 38/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/ReadBookConfig.kt | 2 ++ .../main/java/io/legado/app/help/storage/Restore.kt | 9 ++++++++- app/src/main/java/io/legado/app/ui/book/read/Help.kt | 9 +++------ .../main/java/io/legado/app/ui/book/read/ReadMenu.kt | 7 +++---- .../app/ui/book/read/config/MoreConfigDialog.kt | 11 +++++++++-- .../app/ui/book/read/config/PaddingConfigDialog.kt | 2 ++ .../io/legado/app/ui/book/read/page/ContentView.kt | 5 ++--- app/src/main/res/layout/dialog_read_padding.xml | 1 + 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 08302561f..3b05df869 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -112,6 +112,8 @@ object ReadBookConfig { } //配置写入读取 + var hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) + var hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) var textBold: Boolean get() = if (shareLayout) shareConfig.textBold else durConfig.textBold set(value) = if (shareLayout) shareConfig.textBold = value else durConfig.textBold = value diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 123332df6..9fd939f74 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -104,7 +104,14 @@ object Restore { else -> Unit } edit.putInt(PreferKey.versionCode, App.INSTANCE.versionCode) - edit.commit() + edit.apply() + } + ReadBookConfig.apply { + styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) + shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) + pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) + hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) + hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) } } LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon)) diff --git a/app/src/main/java/io/legado/app/ui/book/read/Help.kt b/app/src/main/java/io/legado/app/ui/book/read/Help.kt index 3a3e04191..549b7b987 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/Help.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/Help.kt @@ -10,7 +10,6 @@ import android.view.View.NO_ID import android.widget.EditText import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Bookmark import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig @@ -23,7 +22,6 @@ import io.legado.app.lib.theme.ThemeStore import io.legado.app.service.help.Download import io.legado.app.service.help.ReadBook import io.legado.app.utils.applyTint -import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.requestInputMethod import kotlinx.android.synthetic.main.dialog_download_choice.view.* import kotlinx.android.synthetic.main.dialog_edit_text.view.* @@ -42,15 +40,14 @@ object Help { or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_IMMERSIVE or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) - val hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) - if (hideNavigationBar) { + if (ReadBookConfig.hideNavigationBar) { flag = flag or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION } if (toolBarHide) { - if (App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar)) { + if (ReadBookConfig.hideStatusBar) { flag = flag or View.SYSTEM_UI_FLAG_FULLSCREEN } - if (hideNavigationBar) { + if (ReadBookConfig.hideNavigationBar) { flag = flag or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 076215c40..6dec43d12 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -10,8 +10,8 @@ import android.widget.SeekBar import androidx.core.view.isVisible import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig +import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.buttonDisabledColor import io.legado.app.service.help.ReadBook @@ -199,9 +199,8 @@ class ReadMenu : FrameLayout { vw_menu_bg.onClick { runMenuOut() } vwNavigationBar.layoutParams = vwNavigationBar.layoutParams.apply { height = - if (context.getPrefBoolean(PreferKey.hideNavigationBar) - && Help.isNavigationBarExist(activity) - ) context.navigationBarHeight + if (ReadBookConfig.hideNavigationBar && Help.isNavigationBarExist(activity)) + context.navigationBarHeight else 0 } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index b087a1508..9b975e7e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -14,6 +14,7 @@ import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.read.Help import io.legado.app.utils.getPrefBoolean @@ -92,8 +93,14 @@ class MoreConfigDialog : DialogFragment() { key: String? ) { when (key) { - PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true) - PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true) + PreferKey.hideStatusBar -> { + ReadBookConfig.hideStatusBar = getPrefBoolean(PreferKey.hideStatusBar) + postEvent(EventBus.UP_CONFIG, true) + } + PreferKey.hideNavigationBar -> { + ReadBookConfig.hideNavigationBar = getPrefBoolean(PreferKey.hideNavigationBar) + postEvent(EventBus.UP_CONFIG, true) + } PreferKey.keepLight -> postEvent(key, true) PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key)) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index 0dd4e8a7d..c72e1a417 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -11,6 +11,7 @@ import io.legado.app.constant.EventBus import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.Help import io.legado.app.utils.postEvent +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.dialog_read_padding.* class PaddingConfigDialog : DialogFragment() { @@ -56,6 +57,7 @@ class PaddingConfigDialog : DialogFragment() { dsb_padding_left.progress = paddingLeft dsb_padding_right.progress = paddingRight //页眉 + tv_header_padding.visible(hideStatusBar) dsb_header_padding_top.progress = headerPaddingTop dsb_header_padding_bottom.progress = headerPaddingBottom dsb_header_padding_left.progress = headerPaddingLeft 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 3613f17bd..bcf3098a8 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,7 +7,6 @@ import android.view.MotionEvent import android.widget.FrameLayout 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.ui.book.read.page.entities.TextPage import io.legado.app.utils.* @@ -39,7 +38,7 @@ class ContentView(context: Context) : FrameLayout(context) { tv_bottom_left.typeface = ChapterProvider.typeface tv_bottom_right.typeface = ChapterProvider.typeface //显示状态栏时隐藏header - if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { + if (hideStatusBar) { ll_header.layoutParams = ll_header.layoutParams.apply { height = context.statusBarHeight } ll_header.setPadding( @@ -77,7 +76,7 @@ class ContentView(context: Context) : FrameLayout(context) { val headerHeight: Int get() { - return if (context.getPrefBoolean(PreferKey.hideStatusBar, false)) { + return if (ReadBookConfig.hideStatusBar) { ll_header.height } else { context.statusBarHeight diff --git a/app/src/main/res/layout/dialog_read_padding.xml b/app/src/main/res/layout/dialog_read_padding.xml index 648f062a3..37e3b8cc4 100644 --- a/app/src/main/res/layout/dialog_read_padding.xml +++ b/app/src/main/res/layout/dialog_read_padding.xml @@ -8,6 +8,7 @@ android:orientation="vertical"> Date: Mon, 24 Feb 2020 18:50:08 +0800 Subject: [PATCH 39/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/page/ContentTextView.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 33388fc63..c06c74618 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -80,10 +80,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private fun drawScrollPage(canvas: Canvas) { + val mPageOffset = pageOffset textPage.textLines.forEach { textLine -> - val lineTop = textLine.lineTop + pageOffset - val lineBase = textLine.lineBase + pageOffset - val lineBottom = textLine.lineBottom + pageOffset + val lineTop = textLine.lineTop + mPageOffset + val lineBase = textLine.lineBase + mPageOffset + val lineBottom = textLine.lineBottom + mPageOffset drawChars( canvas, textLine.textChars, @@ -95,7 +96,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ) } pageFactory.nextPage?.textLines?.forEach { textLine -> - val yPy = pageOffset + textPage.height - ChapterProvider.paddingTop + val yPy = mPageOffset + textPage.height - ChapterProvider.paddingTop val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy val lineBottom = textLine.lineBottom + yPy @@ -110,7 +111,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ) } pageFactory.prevPage?.textLines?.forEach { textLine -> - val yPy = pageOffset + ChapterProvider.paddingTop + val yPy = mPageOffset + ChapterProvider.paddingTop val lineTop = -textLine.lineTop + yPy val lineBase = -textLine.lineBase + yPy val lineBottom = -textLine.lineBottom + yPy From 9f7514685c58b04b28f83c33fe0788d824b410f5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 19:03:57 +0800 Subject: [PATCH 40/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/page/delegate/PageDelegate.kt | 1 - .../legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 275105fde..0e7c10d0d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -140,7 +140,6 @@ abstract class PageDelegate(protected val pageView: PageView) : if (scroller.computeScrollOffset()) { setTouchPoint(scroller.currX.toFloat(), scroller.currY.toFloat()) } else if (isStarted) { - setTouchPoint(scroller.currY.toFloat(), scroller.finalY.toFloat(), false) onAnimStop() stopScroll() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 68c024d96..6ac2f8757 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -26,10 +26,10 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { override fun onTouch(event: MotionEvent): Boolean { if (event.action == MotionEvent.ACTION_DOWN) { + lastY = event.y setStartPoint(event.x, event.y) abort() mVelocity.clear() - mVelocity.addMovement(event) } return super.onTouch(event) } From f4b287fe51f112a99539589c97f8a25b6caf3165 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 19:34:56 +0800 Subject: [PATCH 41/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/page/delegate/ScrollPageDelegate.kt | 12 +++++++----- .../main/java/io/legado/app/ui/widget/LabelsBar.kt | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 6ac2f8757..3a1b9a5eb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -25,11 +25,13 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } override fun onTouch(event: MotionEvent): Boolean { - if (event.action == MotionEvent.ACTION_DOWN) { - lastY = event.y - setStartPoint(event.x, event.y) - abort() - mVelocity.clear() + when (event.action) { + MotionEvent.ACTION_DOWN -> { + lastY = event.y + setStartPoint(event.x, event.y) + abort() + mVelocity.clear() + } } return super.onTouch(event) } diff --git a/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt b/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt index ab933edbb..2d830ca55 100644 --- a/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt @@ -12,6 +12,7 @@ class LabelsBar(context: Context, attrs: AttributeSet?) : LinearLayout(context, private val unUsedViews = arrayListOf() private val usedViews = arrayListOf() + var textSize = 12f fun setLabels(labels: Array) { clear() @@ -51,6 +52,7 @@ class LabelsBar(context: Context, attrs: AttributeSet?) : LinearLayout(context, unUsedViews.removeAt(unUsedViews.lastIndex) } } + tv.textSize = textSize tv.text = label addView(tv) } From 831b282b383295fd895907849a1862cf87c984cd Mon Sep 17 00:00:00 2001 From: hingbong Date: Mon, 24 Feb 2020 19:45:37 +0800 Subject: [PATCH 42/49] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=AF=8F=E6=AC=A1?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E9=83=BD=E5=B0=86=E4=B9=8B=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=96=87=E4=BB=B6=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原本的代码, 如果已经存在的备份文件有600KB, 而将要备份的内容有500KB, 则新的备份文件还是600KB, 只有前500KB有改动, 导致不是合法的JSON格式, 从而无法还原, 例如原本有6本书, 备份之后删掉一本再备份将无法还原(Android 10) --- app/src/main/java/io/legado/app/help/storage/Backup.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index c7de266ca..4076c96a7 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -100,12 +100,16 @@ object Backup { for (fileName in backupFileNames) { val file = File(backupPath + File.separator + fileName) if (file.exists()) { - val doc = treeDoc.findFile(fileName) ?: treeDoc.createFile("", fileName) + var doc = treeDoc.findFile(fileName) + if (null != doc && doc.exists()) { + doc.delete() + } + doc = treeDoc.createFile("", fileName) doc?.let { DocumentUtils.writeText( context, file.readText(), - doc.uri + it.uri ) } } From a0175af74e2373c0ebb9370c94d08f9c058033a9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 20:07:31 +0800 Subject: [PATCH 43/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/delegate/ScrollPageDelegate.kt | 56 ++++--------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 3a1b9a5eb..3a25854d5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.delegate import android.view.MotionEvent import android.view.VelocityTracker +import android.view.ViewConfiguration import io.legado.app.ui.book.read.page.PageView import kotlin.math.abs @@ -11,6 +12,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { private val velocityDuration = 1000 //速度追踪器 private val mVelocity: VelocityTracker = VelocityTracker.obtain() + private val slop = ViewConfiguration.get(pageView.context).scaledTouchSlop override fun onAnimStart() { //惯性滚动 @@ -27,58 +29,22 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { override fun onTouch(event: MotionEvent): Boolean { when (event.action) { MotionEvent.ACTION_DOWN -> { - lastY = event.y - setStartPoint(event.x, event.y) abort() mVelocity.clear() } - } - return super.onTouch(event) - } - - override fun onScroll( - e1: MotionEvent, - e2: MotionEvent, - distanceX: Float, - distanceY: Float - ): Boolean { - mVelocity.addMovement(e2) - mVelocity.computeCurrentVelocity(velocityDuration) - - if (!isMoved && abs(distanceX) < abs(distanceY)) { - if (distanceY < 0) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return true + MotionEvent.ACTION_MOVE -> { + mVelocity.addMovement(event) + mVelocity.computeCurrentVelocity(velocityDuration) + setTouchPoint(event.x, event.y) + if (!isMoved) { + isMoved = abs(startY - event.y) > slop } - setDirection(Direction.PREV) - } else { - //如果上一页不存在 - if (!hasNext()) { - noNext = true - return true + if (isMoved) { + isRunning = true } - setDirection(Direction.PREV) } - isMoved = true } - if (isMoved) { - isRunning = true - //设置触摸点 - setTouchPoint(e2.x, e2.y) - } - return isMoved - } - - override fun onFling( - e1: MotionEvent?, - e2: MotionEvent?, - velocityX: Float, - velocityY: Float - ): Boolean { - mVelocity.addMovement(e2) - return super.onFling(e1, e2, velocityX, velocityY) + return super.onTouch(event) } override fun onDestroy() { From 3424d7d8f4f2de7df2e1cd9b7f8f237bab68e704 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 20:24:39 +0800 Subject: [PATCH 44/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/read/page/PageView.kt | 3 ++- .../legado/app/ui/book/read/page/delegate/PageDelegate.kt | 5 ++--- .../app/ui/book/read/page/delegate/ScrollPageDelegate.kt | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index f115eabce..3009af02e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -62,8 +62,9 @@ class PageView(context: Context, attrs: AttributeSet) : @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { + pageDelegate?.onTouch(event) callBack.screenOffTimerStart() - return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) + return true } fun onDestroy() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 0e7c10d0d..1f6ab9fa9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -204,8 +204,8 @@ abstract class PageDelegate(protected val pageView: PageView) : * 触摸事件处理 */ @CallSuper - open fun onTouch(event: MotionEvent): Boolean { - if (isStarted) return false + open fun onTouch(event: MotionEvent) { + if (isStarted) return if (!detector.onTouchEvent(event)) { //GestureDetector.onFling小幅移动不会触发,所以要自己判断 if (event.action == MotionEvent.ACTION_UP && isMoved) { @@ -215,7 +215,6 @@ abstract class PageDelegate(protected val pageView: PageView) : if (!noNext) onAnimStart() } } - return true } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 3a25854d5..342e31cc6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -26,9 +26,11 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { curPage.onScroll(touchY - lastY) } - override fun onTouch(event: MotionEvent): Boolean { + override fun onTouch(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_DOWN -> { + lastY = event.y + setTouchPoint(event.x, event.y) abort() mVelocity.clear() } @@ -44,7 +46,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { } } } - return super.onTouch(event) + super.onTouch(event) } override fun onDestroy() { From 57c9216bcf68d117943339bea8c8829104fc25bd Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 21:04:27 +0800 Subject: [PATCH 45/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/delegate/HorizontalPageDelegate.kt | 62 +++++++++---------- .../book/read/page/delegate/PageDelegate.kt | 11 ++-- .../read/page/delegate/ScrollPageDelegate.kt | 4 +- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index f129d41ff..f64d14f78 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -6,41 +6,41 @@ import kotlin.math.abs abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) { - override fun onScroll( - e1: MotionEvent, - e2: MotionEvent, - distanceX: Float, - distanceY: Float - ): Boolean { - if (!isMoved) { - if (abs(distanceX) > abs(distanceY)) { - if (distanceX < 0) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return true + override fun onTouch(event: MotionEvent) { + when (event.action) { + MotionEvent.ACTION_MOVE -> { + //判断是否移动了 + if (!isMoved) { + isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop + if (isMoved) { + if (event.x - startX > 0) { + //如果上一页不存在 + if (!hasPrev()) { + noNext = true + return + } + setDirection(Direction.PREV) + setBitmap() + } else { + //如果不存在表示没有下一页了 + if (!hasNext()) { + noNext = true + return + } + setDirection(Direction.NEXT) + setBitmap() + } } - setDirection(Direction.PREV) - setBitmap() - } else { - //如果不存在表示没有下一页了 - if (!hasNext()) { - noNext = true - return true - } - setDirection(Direction.NEXT) - setBitmap() } - isMoved = true + if (isMoved) { + isCancel = if (mDirection == Direction.NEXT) touchX > lastX else touchX < lastX + isRunning = true + //设置触摸点 + setTouchPoint(event.x, event.y) + } } } - if (isMoved) { - isCancel = if (mDirection == Direction.NEXT) distanceX < 0 else distanceX > 0 - isRunning = true - //设置触摸点 - setTouchPoint(e2.x, e2.y) - } - return isMoved + super.onTouch(event) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 1f6ab9fa9..1bbbb0dc0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -6,15 +6,14 @@ import android.graphics.Canvas import android.graphics.RectF import android.view.GestureDetector import android.view.MotionEvent +import android.view.ViewConfiguration import android.view.animation.DecelerateInterpolator import android.widget.Scroller import androidx.annotation.CallSuper import com.google.android.material.snackbar.Snackbar -import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.ui.book.read.page.ContentView import io.legado.app.ui.book.read.page.PageView -import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.screenshot import kotlin.math.abs @@ -25,10 +24,12 @@ abstract class PageDelegate(protected val pageView: PageView) : pageView.width * 0.66f, pageView.height * 0.66f ) protected val context: Context = pageView.context + protected val slop = ViewConfiguration.get(context).scaledTouchSlop //起始点 protected var startX: Float = 0f protected var startY: Float = 0f //上一个触碰点 + protected var lastX: Float = 0f protected var lastY: Float = 0f //触碰点 protected var touchX: Float = 0f @@ -52,9 +53,7 @@ abstract class PageDelegate(protected val pageView: PageView) : } private val detector: GestureDetector by lazy { - GestureDetector(pageView.context, this).apply { - setIsLongpressEnabled(context.getPrefBoolean(PreferKey.textSelectAble)) - } + GestureDetector(pageView.context, this) } var isMoved = false @@ -70,6 +69,7 @@ abstract class PageDelegate(protected val pageView: PageView) : open fun setStartPoint(x: Float, y: Float, invalidate: Boolean = true) { startX = x startY = y + lastX = x lastY = y touchX = x touchY = y @@ -80,6 +80,7 @@ abstract class PageDelegate(protected val pageView: PageView) : } open fun setTouchPoint(x: Float, y: Float, invalidate: Boolean = true) { + lastX = touchX lastY = touchY touchX = x touchY = y diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 342e31cc6..7db2924f5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -2,7 +2,6 @@ package io.legado.app.ui.book.read.page.delegate import android.view.MotionEvent import android.view.VelocityTracker -import android.view.ViewConfiguration import io.legado.app.ui.book.read.page.PageView import kotlin.math.abs @@ -12,7 +11,6 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { private val velocityDuration = 1000 //速度追踪器 private val mVelocity: VelocityTracker = VelocityTracker.obtain() - private val slop = ViewConfiguration.get(pageView.context).scaledTouchSlop override fun onAnimStart() { //惯性滚动 @@ -39,7 +37,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { mVelocity.computeCurrentVelocity(velocityDuration) setTouchPoint(event.x, event.y) if (!isMoved) { - isMoved = abs(startY - event.y) > slop + isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop } if (isMoved) { isRunning = true From 2fec1585338e5578d0082d0907ed083c39f26d0b Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 21:39:28 +0800 Subject: [PATCH 46/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/delegate/HorizontalPageDelegate.kt | 64 +++++++++++-------- .../book/read/page/delegate/PageDelegate.kt | 11 ++-- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index f64d14f78..91e8fb252 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.page.delegate +import android.util.Log import android.view.MotionEvent import io.legado.app.ui.book.read.page.PageView import kotlin.math.abs @@ -9,38 +10,45 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie override fun onTouch(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_MOVE -> { - //判断是否移动了 - if (!isMoved) { - isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop - if (isMoved) { - if (event.x - startX > 0) { - //如果上一页不存在 - if (!hasPrev()) { - noNext = true - return - } - setDirection(Direction.PREV) - setBitmap() - } else { - //如果不存在表示没有下一页了 - if (!hasNext()) { - noNext = true - return - } - setDirection(Direction.NEXT) - setBitmap() - } - } - } - if (isMoved) { - isCancel = if (mDirection == Direction.NEXT) touchX > lastX else touchX < lastX - isRunning = true - //设置触摸点 - setTouchPoint(event.x, event.y) + if (isTextSelected) { + Log.e("selected", "--------------------------") + } else { + scroll(event) } } } super.onTouch(event) } + private fun scroll(event: MotionEvent) { + //判断是否移动了 + if (!isMoved) { + isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop + if (isMoved) { + if (event.x - startX > 0) { + //如果上一页不存在 + if (!hasPrev()) { + noNext = true + return + } + setDirection(Direction.PREV) + setBitmap() + } else { + //如果不存在表示没有下一页了 + if (!hasNext()) { + noNext = true + return + } + setDirection(Direction.NEXT) + setBitmap() + } + } + } + if (isMoved) { + isCancel = if (mDirection == Direction.NEXT) touchX > lastX else touchX < lastX + isRunning = true + //设置触摸点 + setTouchPoint(event.x, event.y) + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 1bbbb0dc0..61dbda2d8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -65,6 +65,7 @@ abstract class PageDelegate(protected val pageView: PageView) : var isRunning = false var isStarted = false var isTextSelected = false + var selectedOnDown = false open fun setStartPoint(x: Float, y: Float, invalidate: Boolean = true) { startX = x @@ -210,8 +211,8 @@ abstract class PageDelegate(protected val pageView: PageView) : if (!detector.onTouchEvent(event)) { //GestureDetector.onFling小幅移动不会触发,所以要自己判断 if (event.action == MotionEvent.ACTION_UP && isMoved) { - if (isTextSelected) { - isTextSelected = false + if (selectedOnDown) { + selectedOnDown = false } if (!noNext) onAnimStart() } @@ -224,6 +225,8 @@ abstract class PageDelegate(protected val pageView: PageView) : override fun onDown(e: MotionEvent): Boolean { if (isTextSelected) { curPage.cancelSelect() + isTextSelected = false + selectedOnDown = true } //是否移动 isMoved = false @@ -244,8 +247,8 @@ abstract class PageDelegate(protected val pageView: PageView) : * 单击 */ override fun onSingleTapUp(e: MotionEvent): Boolean { - if (isTextSelected) { - isTextSelected = false + if (selectedOnDown) { + selectedOnDown = false return true } val x = e.x From 9ea581aabfaf015f6b1259b8f8f04d2023618591 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 22:12:18 +0800 Subject: [PATCH 47/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ContentTextView.kt | 28 ++++++++++++++----- .../app/ui/book/read/page/ContentView.kt | 12 ++++++-- .../page/delegate/HorizontalPageDelegate.kt | 17 +++++++++-- .../book/read/page/delegate/PageDelegate.kt | 9 +++++- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index c06c74618..7d2262824 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -176,7 +176,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at linePos = 0 } - fun selectText(x: Float, y: Float): Boolean { + fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { @@ -189,13 +189,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectCharEnd = charIndex upSelectedStart(textChar.start, textLine.lineBottom) upSelectedEnd(textChar.end, textLine.lineBottom) - return true + select(lineIndex, charIndex) } } break } } - return false } fun selectStartMove(x: Float, y: Float) { @@ -217,6 +216,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + fun selectStartMoveIndex(lineIndex: Int, charIndex: Int) { + selectLineStart = lineIndex + selectCharStart = charIndex + val textLine = textPage.textLines[lineIndex] + val textChar = textLine.textChars[charIndex] + upSelectedStart(textChar.start, textLine.lineBottom) + upSelectChars(textPage) + } + fun selectEndMove(x: Float, y: Float) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop && y < textLine.lineBottom) { @@ -225,10 +233,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedEnd( - textChar.end, - textLine.lineBottom - ) + upSelectedEnd(textChar.end, textLine.lineBottom) upSelectChars(textPage) } break @@ -239,6 +244,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + fun selectEndMoveIndex(lineIndex: Int, charIndex: Int) { + selectLineEnd = lineIndex + selectCharEnd = charIndex + val textLine = textPage.textLines[lineIndex] + val textChar = textLine.textChars[charIndex] + upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectChars(textPage) + } + private fun upSelectChars(textPage: TextPage) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { 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 bcf3098a8..512f778a7 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 @@ -120,19 +120,27 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.selectAble = selectAble } - fun selectText(e: MotionEvent): Boolean { + fun selectText(e: MotionEvent, select: (lineIndex: Int, charIndex: Int) -> Unit) { val y = e.y - headerHeight - return content_text_view.selectText(e.x, y) + return content_text_view.selectText(e.x, y, select) } fun selectStartMove(x: Float, y: Float) { content_text_view.selectStartMove(x, y - headerHeight) } + fun selectStartMoveIndex(lineIndex: Int, charIndex: Int) { + content_text_view.selectStartMoveIndex(lineIndex, charIndex) + } + fun selectEndMove(x: Float, y: Float) { content_text_view.selectEndMove(x, y - headerHeight) } + fun selectEndMoveIndex(lineIndex: Int, charIndex: Int) { + content_text_view.selectEndMoveIndex(lineIndex, charIndex) + } + fun cancelSelect() { content_text_view.cancelSelect() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 91e8fb252..703fe4e17 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -1,6 +1,5 @@ package io.legado.app.ui.book.read.page.delegate -import android.util.Log import android.view.MotionEvent import io.legado.app.ui.book.read.page.PageView import kotlin.math.abs @@ -11,7 +10,7 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie when (event.action) { MotionEvent.ACTION_MOVE -> { if (isTextSelected) { - Log.e("selected", "--------------------------") + selectText(event) } else { scroll(event) } @@ -51,4 +50,18 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie setTouchPoint(event.x, event.y) } } + + private fun selectText(event: MotionEvent) { + curPage.selectText(event) { lineIndex, charIndex -> + if (lineIndex > firstLineIndex + || (lineIndex == firstLineIndex && charIndex > firstCharIndex) + ) { + curPage.selectStartMoveIndex(firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(lineIndex, charIndex) + } else { + curPage.selectEndMoveIndex(firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(lineIndex, charIndex) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index 61dbda2d8..a8a42660c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -67,6 +67,9 @@ abstract class PageDelegate(protected val pageView: PageView) : var isTextSelected = false var selectedOnDown = false + var firstLineIndex: Int = 0 + var firstCharIndex: Int = 0 + open fun setStartPoint(x: Float, y: Float, invalidate: Boolean = true) { startX = x startY = y @@ -283,7 +286,11 @@ abstract class PageDelegate(protected val pageView: PageView) : * 长按选择 */ override fun onLongPress(e: MotionEvent) { - isTextSelected = curPage.selectText(e) + curPage.selectText(e) { lineIndex, charIndex -> + isTextSelected = true + firstLineIndex = lineIndex + firstCharIndex = charIndex + } } /** From ed1391b3bb2a7fa9bc7484f762801c1007d8cb17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 22:23:16 +0800 Subject: [PATCH 48/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/delegate/HorizontalPageDelegate.kt | 17 ++----------- .../book/read/page/delegate/PageDelegate.kt | 22 ++++++++++++----- .../read/page/delegate/ScrollPageDelegate.kt | 24 ++++++++++++------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 703fe4e17..263e2029d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -12,14 +12,14 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie if (isTextSelected) { selectText(event) } else { - scroll(event) + onScroll(event) } } } super.onTouch(event) } - private fun scroll(event: MotionEvent) { + private fun onScroll(event: MotionEvent) { //判断是否移动了 if (!isMoved) { isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop @@ -51,17 +51,4 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie } } - private fun selectText(event: MotionEvent) { - curPage.selectText(event) { lineIndex, charIndex -> - if (lineIndex > firstLineIndex - || (lineIndex == firstLineIndex && charIndex > firstCharIndex) - ) { - curPage.selectStartMoveIndex(firstLineIndex, firstCharIndex) - curPage.selectEndMoveIndex(lineIndex, charIndex) - } else { - curPage.selectEndMoveIndex(firstLineIndex, firstCharIndex) - curPage.selectStartMoveIndex(lineIndex, charIndex) - } - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt index a8a42660c..234ce8097 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt @@ -264,15 +264,11 @@ abstract class PageDelegate(protected val pageView: PageView) : AppConfig.clickAllNext ) { //设置动画方向 - if (!hasNext()) { - return true - } + if (!hasNext()) return true setDirection(Direction.NEXT) setBitmap() } else { - if (!hasPrev()) { - return true - } + if (!hasPrev()) return true setDirection(Direction.PREV) setBitmap() } @@ -293,6 +289,20 @@ abstract class PageDelegate(protected val pageView: PageView) : } } + protected fun selectText(event: MotionEvent) { + curPage.selectText(event) { lineIndex, charIndex -> + if (lineIndex > firstLineIndex + || (lineIndex == firstLineIndex && charIndex > firstCharIndex) + ) { + curPage.selectStartMoveIndex(firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(lineIndex, charIndex) + } else { + curPage.selectEndMoveIndex(firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(lineIndex, charIndex) + } + } + } + /** * 判断是否有上一页 */ diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index 7db2924f5..fbf7ced77 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -33,20 +33,28 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { mVelocity.clear() } MotionEvent.ACTION_MOVE -> { - mVelocity.addMovement(event) - mVelocity.computeCurrentVelocity(velocityDuration) - setTouchPoint(event.x, event.y) - if (!isMoved) { - isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop - } - if (isMoved) { - isRunning = true + if (isTextSelected) { + selectText(event) + } else { + onScroll(event) } } } super.onTouch(event) } + private fun onScroll(event: MotionEvent) { + mVelocity.addMovement(event) + mVelocity.computeCurrentVelocity(velocityDuration) + setTouchPoint(event.x, event.y) + if (!isMoved) { + isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop + } + if (isMoved) { + isRunning = true + } + } + override fun onDestroy() { super.onDestroy() mVelocity.recycle() From 57659b00264d525932d64a53ff4249f23d6d5e0f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 24 Feb 2020 22:28:29 +0800 Subject: [PATCH 49/49] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/delegate/ScrollPageDelegate.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt index fbf7ced77..d90ee8649 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/ScrollPageDelegate.kt @@ -27,8 +27,7 @@ class ScrollPageDelegate(pageView: PageView) : PageDelegate(pageView) { override fun onTouch(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_DOWN -> { - lastY = event.y - setTouchPoint(event.x, event.y) + setStartPoint(event.x, event.y) abort() mVelocity.clear() }