From 71f4dc517197747245686dc2cdcd99a31149006e Mon Sep 17 00:00:00 2001 From: Mupceet Date: Sat, 22 Feb 2020 21:32:01 +0800 Subject: [PATCH 001/169] fix: default theme summary not change when the default theme changing, it also need to update theme name --- app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index ed5e8cf9a..1a1851ca1 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -141,6 +141,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar AppConfig.isNightTheme = true } } + putPrefInt("defaultTheme", which) App.INSTANCE.applyDayNight() recreateActivities() } From e2463037a40ae01f361f6b15d3ec48590fea34fb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 22:26:22 +0800 Subject: [PATCH 002/169] =?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/ReadBookActivity.kt | 4 ++ .../app/ui/book/read/config/TocRegexDialog.kt | 44 +++++++++++++++++ .../app/ui/book/read/page/ContentTextView.kt | 1 + app/src/main/res/layout/dialog_toc_regex.xml | 49 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt create mode 100644 app/src/main/res/layout/dialog_toc_regex.xml 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 0d62c791c..021338077 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 @@ -214,6 +214,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo R.id.menu_book_info -> ReadBook.book?.let { startActivity(Pair("bookUrl", it.bookUrl)) } + R.id.menu_toc_regex -> TocRegexDialog.show( + supportFragmentManager, + ReadBook.book?.tocUrl + ) } return super.onCompatOptionsItemSelected(item) } 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 new file mode 100644 index 000000000..971cf998d --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -0,0 +1,44 @@ +package io.legado.app.ui.book.read.config + +import android.os.Bundle +import android.util.DisplayMetrics +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.FragmentManager +import io.legado.app.R +import io.legado.app.base.BaseDialogFragment + + +class TocRegexDialog : BaseDialogFragment() { + + companion object { + fun show(fragmentManager: FragmentManager, tocRegex: String? = null) { + val dialog = TocRegexDialog() + val bundle = Bundle() + bundle.putString("tocRegex", tocRegex) + dialog.arguments = bundle + dialog.show(fragmentManager, "tocRegexDialog") + } + } + + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.8).toInt()) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_toc_regex, container) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + } +} \ 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 c25fd0664..233922f21 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 @@ -130,6 +130,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageOffset = 0f } + val cHeight = if (textPage.height > 0) textPage.height else height } diff --git a/app/src/main/res/layout/dialog_toc_regex.xml b/app/src/main/res/layout/dialog_toc_regex.xml new file mode 100644 index 000000000..43d0c5d3b --- /dev/null +++ b/app/src/main/res/layout/dialog_toc_regex.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file From fc319e606d53703ec72da91bf455f4cc6fffeb64 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 22:35:10 +0800 Subject: [PATCH 003/169] =?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/config/TocRegexDialog.kt | 15 ++++++++++++++- app/src/main/res/menu/read_book.xml | 2 +- app/src/main/res/menu/txt_toc_regex.xml | 4 ++++ app/src/main/res/values/strings.xml | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/menu/txt_toc_regex.xml 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 971cf998d..9ff3b69fe 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 @@ -3,14 +3,19 @@ package io.legado.app.ui.book.read.config import android.os.Bundle import android.util.DisplayMetrics import android.view.LayoutInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.constant.Theme +import io.legado.app.utils.applyTint +import kotlinx.android.synthetic.main.dialog_toc_regex.* -class TocRegexDialog : BaseDialogFragment() { +class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { companion object { fun show(fragmentManager: FragmentManager, tocRegex: String? = null) { @@ -39,6 +44,14 @@ class TocRegexDialog : BaseDialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + tool_bar.setTitle(R.string.txt_toc_regex) + tool_bar.inflateMenu(R.menu.txt_toc_regex) + tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) + tool_bar.setOnMenuItemClickListener(this) + } + + override fun onMenuItemClick(item: MenuItem?): Boolean { + return false } } \ No newline at end of file diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml index b27cd41ff..5d776e519 100644 --- a/app/src/main/res/menu/read_book.xml +++ b/app/src/main/res/menu/read_book.xml @@ -43,7 +43,7 @@ diff --git a/app/src/main/res/menu/txt_toc_regex.xml b/app/src/main/res/menu/txt_toc_regex.xml new file mode 100644 index 000000000..e73b6af79 --- /dev/null +++ b/app/src/main/res/menu/txt_toc_regex.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2aeb59f2a..9f1e0c46b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -334,7 +334,7 @@ 显示所有发现 关闭则只显示勾选源的发现 更新目录 - txt目录正则 + Txt目录正则 设置编码 倒序-顺序 排序 From e77e67696bb78a3a7a11379c0482708da8885f52 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 22:40:19 +0800 Subject: [PATCH 004/169] =?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/menu/txt_toc_regex.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/menu/txt_toc_regex.xml b/app/src/main/res/menu/txt_toc_regex.xml index e73b6af79..d2797eff5 100644 --- a/app/src/main/res/menu/txt_toc_regex.xml +++ b/app/src/main/res/menu/txt_toc_regex.xml @@ -1,4 +1,11 @@ - + + + \ No newline at end of file From 30be66aeae596d5dad4e7e2214158b948a08e4f1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 08:48:49 +0800 Subject: [PATCH 005/169] =?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 | 13 +++++++++++++ 1 file changed, 13 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 233922f21..fe9a8998e 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 @@ -131,7 +131,20 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } val cHeight = if (textPage.height > 0) textPage.height else height + if (offset > 0 && pageOffset > cHeight) { + } + } + + private fun switchToPageOffset(offset: Int) { + when (offset) { + 1 -> { + + } + -1 -> { + + } + } } fun selectText(x: Float, y: Float): Boolean { From 4873fbf57df3255388e961ad6c6d23cff878de1b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 08:50:40 +0800 Subject: [PATCH 006/169] =?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 56e29ad68..edfb033ee 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/23** +* 修复BUG + **2020/02/22** * 长按选择完成 From dc51d9735610ffbad2dd634c70b72d58d14e8e08 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 09:21:05 +0800 Subject: [PATCH 007/169] =?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/ReadBookActivity.kt | 6 ++++ .../app/ui/book/read/config/TocRegexDialog.kt | 22 +++++++++++++ .../app/ui/book/read/page/ContentTextView.kt | 7 +++++ app/src/main/res/layout/item_toc_regex.xml | 31 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 app/src/main/res/layout/item_toc_regex.xml 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 021338077..5e9b4b56b 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,6 +385,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo cursor_left.x.toInt() + cursor_left.width, page_view.height - cursor_left.y.toInt() + ReadBookConfig.durConfig.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, + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT + ) } } } 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 9ff3b69fe..f0cd6b31a 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 @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.config +import android.content.Context import android.os.Bundle import android.util.DisplayMetrics import android.view.LayoutInflater @@ -10,7 +11,10 @@ import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme +import io.legado.app.data.entities.TxtTocRule import io.legado.app.utils.applyTint import kotlinx.android.synthetic.main.dialog_toc_regex.* @@ -48,10 +52,28 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.inflateMenu(R.menu.txt_toc_regex) tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) tool_bar.setOnMenuItemClickListener(this) + initView() + } + + private fun initView() { + } override fun onMenuItemClick(item: MenuItem?): Boolean { return false } + + + inner class TocRegexDialog(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_toc_regex) { + + override fun convert(holder: ItemViewHolder, item: TxtTocRule, payloads: MutableList) { + + } + + override fun registerListener(holder: ItemViewHolder) { + + } + } } \ 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 fe9a8998e..6267136fb 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,6 +35,7 @@ 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 { @@ -136,6 +137,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + fun resetPageOffset() { + pageOffset = 0f + linePos = 0 + isLastPage = false + } + private fun switchToPageOffset(offset: Int) { when (offset) { 1 -> { diff --git a/app/src/main/res/layout/item_toc_regex.xml b/app/src/main/res/layout/item_toc_regex.xml new file mode 100644 index 000000000..2022bad71 --- /dev/null +++ b/app/src/main/res/layout/item_toc_regex.xml @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file From 08df196ef331418d3292b08f1301c6d0c6421ba7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 09:47:07 +0800 Subject: [PATCH 008/169] =?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/TextActionMenu.kt | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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 e788d10a7..299c9c829 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 @@ -2,9 +2,14 @@ package io.legado.app.ui.book.read import android.annotation.SuppressLint import android.content.Context +import android.content.Intent +import android.content.pm.ResolveInfo +import android.os.Build import android.view.LayoutInflater +import android.view.Menu import android.view.ViewGroup import android.widget.PopupWindow +import androidx.annotation.RequiresApi import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuItemImpl @@ -39,6 +44,9 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac recycler_view.adapter = adapter val menu = MenuBuilder(context) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + onInitializeMenu(menu) + } adapter.setItems(menu.visibleItems) } @@ -69,10 +77,49 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun onMenuItemSelected(item: MenuItemImpl) { when (item.itemId) { R.id.menu_copy -> context.sendToClip(callBack.selectedText) + } callBack.onMenuActionFinally() } + @RequiresApi(Build.VERSION_CODES.M) + private fun createProcessTextIntent(): Intent { + return Intent() + .setAction(Intent.ACTION_PROCESS_TEXT) + .setType("text/plain") + } + + @RequiresApi(Build.VERSION_CODES.M) + private fun getSupportedActivities(): List? { + return context.packageManager + .queryIntentActivities(createProcessTextIntent(), 0) + } + + @RequiresApi(Build.VERSION_CODES.M) + private fun createProcessTextIntentForResolveInfo(info: ResolveInfo): Intent? { + return createProcessTextIntent() + .putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false) + .setClassName(info.activityInfo.packageName, info.activityInfo.name) + } + + /** + * Start with a menu Item order value that is high enough + * so that your "PROCESS_TEXT" menu items appear after the + * standard selection menu items like Cut, Copy, Paste. + */ + @RequiresApi(Build.VERSION_CODES.M) + private fun onInitializeMenu(menu: Menu) { + // Start with a menu Item order value that is high enough + // so that your "PROCESS_TEXT" menu items appear after the + // standard selection menu items like Cut, Copy, Paste. + var menuItemOrder = 100 + for (resolveInfo in getSupportedActivities()!!) { + menu.add( + Menu.NONE, Menu.NONE, + menuItemOrder++, resolveInfo!!.loadLabel(context.packageManager) + ).intent = createProcessTextIntentForResolveInfo(resolveInfo) + } + } interface CallBack { val selectedText: String From 59b2e46fbbde34b0d5c1bfe6954181828e66a5ca Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 10:00:15 +0800 Subject: [PATCH 009/169] =?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/TextActionMenu.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 299c9c829..42506132c 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 @@ -77,7 +77,12 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun onMenuItemSelected(item: MenuItemImpl) { when (item.itemId) { R.id.menu_copy -> context.sendToClip(callBack.selectedText) - + else -> item.intent.let { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) + context.startActivity(it) + } + } } callBack.onMenuActionFinally() } From da365657ba0b2c63ada4cbe96f517c12fa56c40c Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 10:01:25 +0800 Subject: [PATCH 010/169] =?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/ui/book/read/ReadBookActivity.kt | 1 + 1 file changed, 1 insertion(+) 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 5e9b4b56b..7ec794f88 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 @@ -416,6 +416,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun onMenuActionFinally() { textActionMenu?.dismiss() + page_view.curPage.cancelSelect() page_view.pageDelegate?.isTextSelected = false } From 9f78d86a803fdd2a71825caf8e44b362624c7acf Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 10:25:32 +0800 Subject: [PATCH 011/169] =?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/ChapterProvider.kt | 2 ++ .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 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 3215c5464..8a4a46e06 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 @@ -176,6 +176,7 @@ object ChapterProvider { x = x1 } } + textLine.lineBottom = textLine.lineBottom + titlePaint.fontMetrics.descent } durY += paragraphSpacing return durY @@ -286,6 +287,7 @@ object ChapterProvider { 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 6267136fb..6902ae399 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 @@ -104,9 +104,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (it.selected) { canvas.drawRect( it.leftBottomPosition.x, - it.rightTopPosition.y, + textLine.lineTop, it.rightTopPosition.x, - it.leftBottomPosition.y, + textLine.lineBottom, selectedPaint ) } From 3bd20e995e84b4f278acf2827cba33b1e620e135 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 10:29:33 +0800 Subject: [PATCH 012/169] =?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/ReadBookActivity.kt | 2 +- .../main/java/io/legado/app/ui/book/read/page/PageView.kt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 7ec794f88..a04ab024f 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 @@ -632,7 +632,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo super.onDestroy() mHandler.removeCallbacks(keepScreenRunnable) textActionMenu?.dismiss() - page_view.pageDelegate?.onDestroy() + page_view.onDestroy() } override fun observeLiveBus() { 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 919de9c54..5a2eae133 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 @@ -70,6 +70,11 @@ class PageView(context: Context, attrs: AttributeSet) : return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) } + fun onDestroy() { + pageDelegate?.onDestroy() + curPage.cancelSelect() + } + fun fillPage(direction: PageDelegate.Direction) { when (direction) { PageDelegate.Direction.PREV -> { From 76fec52adb0b9089fd0ed301f87a458ed2040738 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 10:46:22 +0800 Subject: [PATCH 013/169] =?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/model/localBook/AnalyzeTxtFile.kt | 10 ++++------ .../io/legado/app/ui/book/read/TextActionMenu.kt | 13 ++++++++++++- app/src/main/res/menu/content_select_action.xml | 4 ++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 99b6b95d3..93e1c8e4a 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -226,12 +226,10 @@ object AnalyzeTxtFile { private fun getTocRules(): List { val rules = App.db.txtTocRule().all - if (rules.isEmpty()) { - App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> - GSON.fromJsonArray(String(byteArray))?.let { - App.db.txtTocRule().insert(*it.toTypedArray()) - return it - } + App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> + GSON.fromJsonArray(String(byteArray))?.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + return it } } return rules 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 42506132c..1b29cb097 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 @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.pm.ResolveInfo +import android.net.Uri import android.os.Build import android.view.LayoutInflater import android.view.Menu @@ -22,6 +23,7 @@ import io.legado.app.utils.sendToClip import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.popup_action_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.toast class TextActionMenu(private val context: Context, private val callBack: CallBack) : @@ -77,7 +79,16 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun onMenuItemSelected(item: MenuItemImpl) { when (item.itemId) { R.id.menu_copy -> context.sendToClip(callBack.selectedText) - else -> item.intent.let { + R.id.menu_browser -> { + try { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(callBack.selectedText) + context.startActivity(intent) + } catch (e: Exception) { + context.toast(R.string.can_not_open) + } + } + else -> item.intent?.let { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) context.startActivity(it) diff --git a/app/src/main/res/menu/content_select_action.xml b/app/src/main/res/menu/content_select_action.xml index b9bdf7b40..52ac3e0f6 100644 --- a/app/src/main/res/menu/content_select_action.xml +++ b/app/src/main/res/menu/content_select_action.xml @@ -9,4 +9,8 @@ android:id="@+id/menu_copy" android:title="@android:string/copy" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f1e0c46b..a19395ca8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -619,4 +619,5 @@ 文本选择开始位置 共用布局 标题居中 + 浏览器 From 3aed6c2aad3632b439a8bdf1a3d84857aeeb7ac4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 11:17:01 +0800 Subject: [PATCH 014/169] =?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/about/AboutActivity.kt | 15 ++--------- .../io/legado/app/ui/about/AboutFragment.kt | 27 ++++++++++--------- .../io/legado/app/ui/about/DonateFragment.kt | 21 ++++----------- .../legado/app/ui/book/read/TextActionMenu.kt | 3 ++- .../io/legado/app/utils/ContextExtensions.kt | 19 +++++++++++++ 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt index 18e3bcdb9..33587d0a2 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt @@ -1,14 +1,12 @@ package io.legado.app.ui.about -import android.content.Intent -import android.net.Uri import android.os.Bundle import android.view.Menu import android.view.MenuItem import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.utils.openUrl import io.legado.app.utils.shareText -import org.jetbrains.anko.toast class AboutActivity : BaseActivity(R.layout.activity_about) { @@ -28,7 +26,7 @@ class AboutActivity : BaseActivity(R.layout.activity_about) { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_scoring -> openIntent("market://details?id=$packageName") + R.id.menu_scoring -> openUrl("market://details?id=$packageName") R.id.menu_share_it -> shareText( "App Share", getString(R.string.app_share_description) @@ -37,13 +35,4 @@ class AboutActivity : BaseActivity(R.layout.activity_about) { return super.onCompatOptionsItemSelected(item) } - private fun openIntent(address: String) { - try { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(address) - startActivity(intent) - } catch (e: Exception) { - toast(R.string.can_not_open) - } - } } diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index 8579a0783..365381fbd 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -11,6 +11,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.lib.dialogs.alert import io.legado.app.ui.widget.dialog.TextDialog +import io.legado.app.utils.openUrl import io.legado.app.utils.sendToClip import io.legado.app.utils.toast @@ -41,14 +42,14 @@ class AboutFragment : PreferenceFragmentCompat() { override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "contributors" -> openIntent(Intent.ACTION_VIEW, R.string.contributors_url) + "contributors" -> openUrl(R.string.contributors_url) "update_log" -> showUpdateLog() - "check_update" -> openIntent(Intent.ACTION_VIEW, R.string.latest_release_url) - "mail" -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com") - "git" -> openIntent(Intent.ACTION_VIEW, R.string.this_github_url) - "home_page" -> openIntent(Intent.ACTION_VIEW, R.string.home_page_url) - "license" -> openIntent(Intent.ACTION_VIEW, licenseUrl) - "disclaimer" -> openIntent(Intent.ACTION_VIEW, disclaimerUrl) + "check_update" -> openUrl(R.string.latest_release_url) + "mail" -> sendMail() + "git" -> openUrl(R.string.this_github_url) + "home_page" -> openUrl(R.string.home_page_url) + "license" -> requireContext().openUrl(licenseUrl) + "disclaimer" -> requireContext().openUrl(disclaimerUrl) "qq" -> showQqGroups() "gzGzh" -> requireContext().sendToClip("开源阅读软件") } @@ -56,17 +57,17 @@ class AboutFragment : PreferenceFragmentCompat() { } @Suppress("SameParameterValue") - private fun openIntent(intentName: String, @StringRes addressID: Int) { - openIntent(intentName, getString(addressID)) + private fun openUrl(@StringRes addressID: Int) { + requireContext().openUrl(getString(addressID)) } - private fun openIntent(intentName: String, address: String) { + private fun sendMail() { try { - val intent = Intent(intentName) - intent.data = Uri.parse(address) + val intent = Intent(Intent.ACTION_SENDTO) + intent.data = Uri.parse("mailto:kunfei.ge@gmail.com") startActivity(intent) } catch (e: Exception) { - toast(R.string.can_not_open) + toast(e.localizedMessage ?: "Error") } } diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt index 08daf95ab..0270b3f77 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt @@ -9,8 +9,8 @@ import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R import io.legado.app.utils.ACache +import io.legado.app.utils.openUrl import io.legado.app.utils.sendToClip -import io.legado.app.utils.toast import org.jetbrains.anko.longToast import java.net.URLEncoder @@ -32,10 +32,10 @@ class DonateFragment : PreferenceFragmentCompat() { override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "wxZsm" -> openIntent(Intent.ACTION_VIEW, wxZsRwmUrl) - "zfbHbRwm" -> openIntent(Intent.ACTION_VIEW, zfbHbRwmUrl) - "zfbSkRwm" -> openIntent(Intent.ACTION_VIEW, zfbSkRwmUrl) - "qqSkRwm" -> openIntent(Intent.ACTION_VIEW, qqSkRwmUrl) + "wxZsm" -> requireContext().openUrl(wxZsRwmUrl) + "zfbHbRwm" -> requireContext().openUrl(zfbHbRwmUrl) + "zfbSkRwm" -> requireContext().openUrl(zfbSkRwmUrl) + "qqSkRwm" -> requireContext().openUrl(qqSkRwmUrl) "zfbSk" -> aliDonate(requireContext()) "zfbHbSsm" -> getZfbHb(requireContext()) "gzGzh" -> requireContext().sendToClip("开源阅读软件") @@ -43,17 +43,6 @@ class DonateFragment : PreferenceFragmentCompat() { return super.onPreferenceTreeClick(preference) } - @Suppress("SameParameterValue") - private fun openIntent(intentName: String, address: String) { - try { - val intent = Intent(intentName) - intent.data = Uri.parse(address) - startActivity(intent) - } catch (e: Exception) { - toast(R.string.can_not_open) - } - } - private fun getZfbHb(context: Context) { requireContext().sendToClip("537954522") context.longToast("高级功能已开启\n红包码已复制\n支付宝首页搜索“537954522” 立即领红包") 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 1b29cb097..c7044b2ae 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 @@ -85,7 +85,8 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac intent.data = Uri.parse(callBack.selectedText) context.startActivity(intent) } catch (e: Exception) { - context.toast(R.string.can_not_open) + e.printStackTrace() + context.toast(e.localizedMessage ?: "ERROR") } } else -> item.intent?.let { 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 25c74ec23..5b266a343 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -6,6 +6,7 @@ import android.content.res.ColorStateList import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.drawable.Drawable +import android.net.Uri import android.os.BatteryManager import android.provider.Settings import androidx.annotation.ColorRes @@ -152,4 +153,22 @@ fun Context.getBettery(): Int { 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) { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(url) + if (intent.resolveActivity(packageManager) != null) { + try { + startActivity(intent) + } catch (e: Exception) { + toast(e.localizedMessage ?: "open url error") + } + } else { + try { + startActivity(Intent.createChooser(intent, "请选择浏览器")) + } catch (e: Exception) { + toast(e.localizedMessage ?: "open url error") + } + } } \ No newline at end of file From 3a79bc8bff4f7bd8c17cf613e3902e7986c0cf93 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 11:27:58 +0800 Subject: [PATCH 015/169] =?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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 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 c7044b2ae..bcc815ee6 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 @@ -1,6 +1,7 @@ package io.legado.app.ui.book.read import android.annotation.SuppressLint +import android.app.SearchManager import android.content.Context import android.content.Intent import android.content.pm.ResolveInfo @@ -19,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.utils.isAbsUrl import io.legado.app.utils.sendToClip import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.popup_action_menu.view.* @@ -81,8 +83,15 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac R.id.menu_copy -> context.sendToClip(callBack.selectedText) R.id.menu_browser -> { try { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(callBack.selectedText) + val intent = if (callBack.selectedText.isAbsUrl()) { + Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse(callBack.selectedText) + } + } else { + Intent(Intent.ACTION_WEB_SEARCH).apply { + putExtra(SearchManager.QUERY, callBack.selectedText) + } + } context.startActivity(intent) } catch (e: Exception) { e.printStackTrace() From 8158da607c61ddd42b6151f6ec16d655456a4186 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 11:31:20 +0800 Subject: [PATCH 016/169] =?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 ++++-- 1 file changed, 4 insertions(+), 2 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 a04ab024f..2e7fa5bde 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 @@ -405,8 +405,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun onMenuItemSelected(item: MenuItemImpl): Boolean { when (item.itemId) { - R.id.menu_replace -> ReplaceEditDialog - .show(supportFragmentManager, pattern = selectedText) + R.id.menu_replace -> { + ReplaceEditDialog.show(supportFragmentManager, pattern = selectedText) + return true + } } return false } From 1a5c9bfacfa8dda493bfa16256d7f365c0bd1139 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 11:51:40 +0800 Subject: [PATCH 017/169] =?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/data/dao/TxtTocRuleDao.kt | 4 ++ .../app/ui/book/read/config/TocRegexDialog.kt | 47 ++++++++++++++----- app/src/main/res/layout/item_group_manage.xml | 1 + app/src/main/res/layout/item_group_select.xml | 1 + app/src/main/res/layout/item_toc_regex.xml | 4 +- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt index 119daa651..c63133164 100644 --- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -1,11 +1,15 @@ package io.legado.app.data.dao +import androidx.lifecycle.LiveData import androidx.room.* import io.legado.app.data.entities.TxtTocRule @Dao interface TxtTocRuleDao { + @Query("select * from txtTocRules order by serialNumber") + fun observeAll(): LiveData> + @get:Query("select * from txtTocRules order by serialNumber") val all: List 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 f0cd6b31a..4359b15d5 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 @@ -9,6 +9,10 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.base.adapter.ItemViewHolder @@ -16,20 +20,15 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme import io.legado.app.data.entities.TxtTocRule 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.item_toc_regex.view.* class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { - companion object { - fun show(fragmentManager: FragmentManager, tocRegex: String? = null) { - val dialog = TocRegexDialog() - val bundle = Bundle() - bundle.putString("tocRegex", tocRegex) - dialog.arguments = bundle - dialog.show(fragmentManager, "tocRegexDialog") - } - } + private lateinit var adapter: TocRegexAdapter + private var tocRegexLiveData: LiveData>? = null override fun onStart() { super.onStart() @@ -53,10 +52,22 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) tool_bar.setOnMenuItemClickListener(this) initView() + initData() } private fun initView() { + adapter = TocRegexAdapter(requireContext()) + recycler_view.layoutManager = LinearLayoutManager(requireContext()) + recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) + recycler_view.adapter = adapter + } + private fun initData() { + tocRegexLiveData?.removeObservers(viewLifecycleOwner) + tocRegexLiveData = App.db.txtTocRule().observeAll() + tocRegexLiveData?.observe(viewLifecycleOwner, Observer { + adapter.setItems(it) + }) } override fun onMenuItemClick(item: MenuItem?): Boolean { @@ -65,15 +76,29 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } - inner class TocRegexDialog(context: Context) : + inner class TocRegexAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_toc_regex) { override fun convert(holder: ItemViewHolder, item: TxtTocRule, payloads: MutableList) { - + holder.itemView.apply { + rb_regex_name.text = item.name + } } override fun registerListener(holder: ItemViewHolder) { } } + + + companion object { + fun show(fragmentManager: FragmentManager, tocRegex: String? = null) { + val dialog = TocRegexDialog() + val bundle = Bundle() + bundle.putString("tocRegex", tocRegex) + dialog.arguments = bundle + dialog.show(fragmentManager, "tocRegexDialog") + } + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/item_group_manage.xml b/app/src/main/res/layout/item_group_manage.xml index d7d85630a..763a19acd 100644 --- a/app/src/main/res/layout/item_group_manage.xml +++ b/app/src/main/res/layout/item_group_manage.xml @@ -4,6 +4,7 @@ android:layout_height="wrap_content" android:background="@color/background" android:padding="8dp" + android:gravity="center_vertical" android:orientation="horizontal"> + android:layout_weight="1" + android:maxLines="1" /> Date: Sun, 23 Feb 2020 12:54:57 +0800 Subject: [PATCH 018/169] =?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/data/dao/TxtTocRuleDao.kt | 3 + .../io/legado/app/help/ItemTouchCallback.kt | 2 +- .../app/ui/book/read/config/TocRegexDialog.kt | 74 +++++++++++++++++-- app/src/main/res/menu/txt_toc_regex.xml | 11 ++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt index c63133164..fea5818fa 100644 --- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -19,6 +19,9 @@ interface TxtTocRuleDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg rule: TxtTocRule) + @Update(onConflict = OnConflictStrategy.REPLACE) + fun update(vararg rule: TxtTocRule) + @Delete fun delete(vararg rule: TxtTocRule) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt index 0e9a29351..99ba74ef1 100644 --- a/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/help/ItemTouchCallback.kt @@ -128,7 +128,7 @@ class ItemTouchCallback : ItemTouchHelper.Callback() { * @return 开发者处理了操作应该返回true,开发者没有处理就返回false */ fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - return false + return true } fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { 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 4359b15d5..04185bcdb 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 @@ -12,6 +12,7 @@ import androidx.fragment.app.FragmentManager import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -19,16 +20,22 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme import io.legado.app.data.entities.TxtTocRule +import io.legado.app.help.ItemTouchCallback 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.item_toc_regex.view.* +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.launch +import java.util.* class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var adapter: TocRegexAdapter private var tocRegexLiveData: LiveData>? = null + var selectedName: String? = null + var durRegex: String? = null override fun onStart() { super.onStart() @@ -47,6 +54,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + durRegex = arguments?.getString("tocRegex") tool_bar.setTitle(R.string.txt_toc_regex) tool_bar.inflateMenu(R.menu.txt_toc_regex) tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) @@ -60,33 +68,89 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(recycler_view.getVerticalDivider()) recycler_view.adapter = adapter + val itemTouchCallback = ItemTouchCallback() + itemTouchCallback.onItemTouchCallbackListener = adapter + itemTouchCallback.isCanDrag = true } private fun initData() { tocRegexLiveData?.removeObservers(viewLifecycleOwner) tocRegexLiveData = App.db.txtTocRule().observeAll() - tocRegexLiveData?.observe(viewLifecycleOwner, Observer { - adapter.setItems(it) + tocRegexLiveData?.observe(viewLifecycleOwner, Observer { tocRules -> + initSelectedName(tocRules) + adapter.setItems(tocRules) }) } - override fun onMenuItemClick(item: MenuItem?): Boolean { + private fun initSelectedName(tocRules: List) { + if (selectedName == null && durRegex != null) { + tocRules.forEach { + if (durRegex == it.rule) { + selectedName = it.name + return@forEach + } + } + if (selectedName == null) { + selectedName = "" + } + } + } + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_add -> { + } + R.id.menu_default -> { + } + } return false } inner class TocRegexAdapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_toc_regex) { + SimpleRecyclerAdapter(context, R.layout.item_toc_regex), + ItemTouchCallback.OnItemTouchCallbackListener { override fun convert(holder: ItemViewHolder, item: TxtTocRule, payloads: MutableList) { holder.itemView.apply { - rb_regex_name.text = item.name + if (payloads.isEmpty()) { + rb_regex_name.text = item.name + rb_regex_name.isChecked = item.name == selectedName + } else { + rb_regex_name.isChecked = item.name == selectedName + } } } override fun registerListener(holder: ItemViewHolder) { + holder.itemView.rb_regex_name.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed && isChecked) { + selectedName = getItem(holder.layoutPosition)?.name + updateItems(0, itemCount - 1, true) + } + } + } + + private var isMoved = false + override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { + Collections.swap(getItems(), srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) + isMoved = true + return super.onMove(srcPosition, targetPosition) + } + + override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + super.clearView(recyclerView, viewHolder) + if (isMoved) { + for ((index, item) in getItems().withIndex()) { + item.serialNumber = index + 1 + } + launch(IO) { + App.db.txtTocRule().update(*getItems().toTypedArray()) + } + } + isMoved = false } } diff --git a/app/src/main/res/menu/txt_toc_regex.xml b/app/src/main/res/menu/txt_toc_regex.xml index d2797eff5..38a50e8cc 100644 --- a/app/src/main/res/menu/txt_toc_regex.xml +++ b/app/src/main/res/menu/txt_toc_regex.xml @@ -1,11 +1,18 @@ - + app:showAsAction="always" + tools:ignore="AlwaysShowAction" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a19395ca8..0efb23246 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -620,4 +620,5 @@ 共用布局 标题居中 浏览器 + 导入默认规则 From 9384ad3aa6ff78a5d3547f071a80a0c5e8096b0f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 13:10:28 +0800 Subject: [PATCH 019/169] =?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/data/dao/TxtTocRuleDao.kt | 1 + .../app/model/localBook/AnalyzeTxtFile.kt | 9 ++++- .../app/ui/book/read/config/TocRegexDialog.kt | 39 +++++++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt index fea5818fa..5812b419c 100644 --- a/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/TxtTocRuleDao.kt @@ -24,4 +24,5 @@ interface TxtTocRuleDao { @Delete fun delete(vararg rule: TxtTocRule) + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 93e1c8e4a..86e64bb02 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -226,12 +226,19 @@ object AnalyzeTxtFile { private fun getTocRules(): List { val rules = App.db.txtTocRule().all + if (rules.isEmpty()) { + return getDefaultRules() + } + return rules + } + + fun getDefaultRules(): List { App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> GSON.fromJsonArray(String(byteArray))?.let { App.db.txtTocRule().insert(*it.toTypedArray()) return it } } - return rules + return emptyList() } } \ No newline at end of file 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 04185bcdb..74272fd01 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 @@ -21,12 +21,14 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme import io.legado.app.data.entities.TxtTocRule import io.legado.app.help.ItemTouchCallback +import io.legado.app.model.localBook.AnalyzeTxtFile 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.item_toc_regex.view.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch +import org.jetbrains.anko.sdk27.listeners.onClick import java.util.* @@ -98,14 +100,23 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { - R.id.menu_add -> { - } - R.id.menu_default -> { - } + R.id.menu_add -> editRule() + R.id.menu_default -> importDefault() } return false } + private fun importDefault() { + launch(IO) { + AnalyzeTxtFile.getDefaultRules().let { + App.db.txtTocRule().insert(*it.toTypedArray()) + } + } + } + + private fun editRule(rule: TxtTocRule? = null) { + + } inner class TocRegexAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_toc_regex), @@ -123,10 +134,22 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } override fun registerListener(holder: ItemViewHolder) { - holder.itemView.rb_regex_name.setOnCheckedChangeListener { buttonView, isChecked -> - if (buttonView.isPressed && isChecked) { - selectedName = getItem(holder.layoutPosition)?.name - updateItems(0, itemCount - 1, true) + holder.itemView.apply { + rb_regex_name.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed && isChecked) { + selectedName = getItem(holder.layoutPosition)?.name + updateItems(0, itemCount - 1, true) + } + } + tv_edit.onClick { + editRule(getItem(holder.layoutPosition)) + } + tv_del.onClick { + getItem(holder.layoutPosition)?.let { item -> + launch(IO) { + App.db.txtTocRule().delete(item) + } + } } } } From 80c242f4add15d8fde75e56f8685fdc5542075c6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 16:39:42 +0800 Subject: [PATCH 020/169] =?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/layout/dialog_read_aloud.xml | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/main/res/layout/dialog_read_aloud.xml b/app/src/main/res/layout/dialog_read_aloud.xml index 37c5cc0d6..282f9cdfe 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -23,7 +23,7 @@ android:contentDescription="@string/chapter_list" android:src="@drawable/ic_toc" android:tint="@color/tv_text_default" - android:tooltipText="@string/auto_next_page" + android:tooltipText="@string/chapter_list" app:backgroundTint="@color/background_menu" app:elevation="2dp" app:fabSize="mini" @@ -43,7 +43,7 @@ android:contentDescription="@string/to_backstage" android:src="@drawable/ic_visibility_off" android:tint="@color/tv_text_default" - android:tooltipText="@string/replace_rule_title" + android:tooltipText="@string/to_backstage" app:backgroundTint="@color/background_menu" app:elevation="2dp" app:fabSize="mini" @@ -79,9 +79,11 @@ android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:background="?android:attr/selectableItemBackgroundBorderless" + android:tooltipText="@string/menu" android:contentDescription="@string/menu" android:src="@drawable/ic_menu" - android:tint="@color/tv_text_default" /> + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> @@ -160,8 +172,11 @@ + android:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + Date: Sun, 23 Feb 2020 17:27:18 +0800 Subject: [PATCH 021/169] =?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/data/entities/TxtTocRule.kt | 2 +- .../app/ui/book/read/config/TocRegexDialog.kt | 44 ++++++++++++++++++- .../io/legado/app/ui/widget/DetailSeekBar.kt | 4 +- .../main/res/layout/dialog_toc_regex_edit.xml | 31 +++++++++++++ app/src/main/res/layout/item_book_source.xml | 1 + app/src/main/res/layout/item_toc_regex.xml | 41 +++++++++++------ .../main/res/layout/view_detail_seek_bar.xml | 6 ++- .../res/layout/view_select_action_bar.xml | 4 +- app/src/main/res/values/strings.xml | 5 +++ 9 files changed, 117 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/layout/dialog_toc_regex_edit.xml diff --git a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt index c9cd51d4d..cdfca7567 100644 --- a/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/TxtTocRule.kt @@ -9,6 +9,6 @@ data class TxtTocRule( @PrimaryKey var name: String = "", var rule: String = "", - var serialNumber: Int, + var serialNumber: Int = -1, var enable: Boolean = true ) \ No newline at end of file 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 74272fd01..10ca38a5b 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 @@ -1,5 +1,6 @@ package io.legado.app.ui.book.read.config +import android.annotation.SuppressLint import android.content.Context import android.os.Bundle import android.util.DisplayMetrics @@ -21,10 +22,16 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.Theme import io.legado.app.data.entities.TxtTocRule import io.legado.app.help.ItemTouchCallback +import io.legado.app.lib.dialogs.alert +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.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.* import kotlinx.android.synthetic.main.item_toc_regex.view.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch @@ -114,8 +121,40 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } } + @SuppressLint("InflateParams") private fun editRule(rule: TxtTocRule? = null) { + val tocRule = rule?.copy() ?: TxtTocRule() + requireContext().alert(titleResource = R.string.txt_toc_regex) { + var rootView: View? = null + customView { + LayoutInflater.from(requireContext()) + .inflate(R.layout.dialog_toc_regex_edit, null).apply { + rootView = this + tv_rule_name.setText(tocRule.name) + tv_rule_regex.setText(tocRule.rule) + } + } + okButton { + rootView?.let { + tocRule.name = tv_rule_name.text.toString() + tocRule.rule = tv_rule_regex.text.toString() + saveRule(rule, tocRule) + } + } + cancelButton() + }.show().applyTint() + } + private fun saveRule(oldRule: TxtTocRule?, rule: TxtTocRule) { + launch(IO) { + if (rule.serialNumber < 0) { + rule.serialNumber = adapter.getItems().lastOrNull()?.serialNumber ?: 0 + 1 + } + oldRule?.let { + App.db.txtTocRule().delete(oldRule) + } + App.db.txtTocRule().insert(rule) + } } inner class TocRegexAdapter(context: Context) : @@ -127,6 +166,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { if (payloads.isEmpty()) { rb_regex_name.text = item.name rb_regex_name.isChecked = item.name == selectedName + swt_enabled.isChecked = item.enable } else { rb_regex_name.isChecked = item.name == selectedName } @@ -141,10 +181,10 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { updateItems(0, itemCount - 1, true) } } - tv_edit.onClick { + iv_edit.onClick { editRule(getItem(holder.layoutPosition)) } - tv_del.onClick { + iv_delete.onClick { getItem(holder.layoutPosition)?.let { item -> launch(IO) { App.db.txtTocRule().delete(item) diff --git a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt index a959ce515..504837afd 100644 --- a/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt @@ -34,11 +34,11 @@ class DetailSeekBar(context: Context, attrs: AttributeSet?) : FrameLayout(contex seek_bar.max = typedArray.getInteger(R.styleable.DetailSeekBar_max, 0) typedArray.recycle() - iv_seek_add.onClick { + iv_seek_plus.onClick { seek_bar.progressAdd(1) onChanged?.invoke(seek_bar.progress) } - iv_seek_remove.onClick { + iv_seek_reduce.onClick { seek_bar.progressAdd(-1) onChanged?.invoke(seek_bar.progress) } diff --git a/app/src/main/res/layout/dialog_toc_regex_edit.xml b/app/src/main/res/layout/dialog_toc_regex_edit.xml new file mode 100644 index 000000000..13abef871 --- /dev/null +++ b/app/src/main/res/layout/dialog_toc_regex_edit.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index ee1174355..3ae65e3b9 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -62,6 +62,7 @@ android:id="@+id/iv_explore" android:layout_width="8dp" android:layout_height="8dp" + android:contentDescription="@string/more_menu" android:src="@color/md_green_600" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/item_toc_regex.xml b/app/src/main/res/layout/item_toc_regex.xml index 0434ac4dc..6872044c4 100644 --- a/app/src/main/res/layout/item_toc_regex.xml +++ b/app/src/main/res/layout/item_toc_regex.xml @@ -1,5 +1,6 @@ - + android:layout_height="wrap_content" /> - + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_detail_seek_bar.xml b/app/src/main/res/layout/view_detail_seek_bar.xml index 57261a37a..af87a83bb 100644 --- a/app/src/main/res/layout/view_detail_seek_bar.xml +++ b/app/src/main/res/layout/view_detail_seek_bar.xml @@ -15,9 +15,10 @@ tools:ignore="HardcodedText" /> @@ -31,9 +32,10 @@ android:max="10" /> diff --git a/app/src/main/res/layout/view_select_action_bar.xml b/app/src/main/res/layout/view_select_action_bar.xml index 97d775dc3..e725a57b7 100644 --- a/app/src/main/res/layout/view_select_action_bar.xml +++ b/app/src/main/res/layout/view_select_action_bar.xml @@ -46,10 +46,12 @@ android:layout_width="36dp" android:layout_height="36dp" android:background="?attr/selectableItemBackgroundBorderless" + android:contentDescription="@string/more_menu" + android:tooltipText="@string/more_menu" android:padding="6dp" android:src="@drawable/ic_more_vert" android:tint="@color/tv_text_default" android:visibility="gone" - tools:ignore="RtlHardcoded" /> + tools:ignore="RtlHardcoded,UnusedAttribute" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0efb23246..c456ce6ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -621,4 +621,9 @@ 标题居中 浏览器 导入默认规则 + 名称 + 正则 + 更多菜单 + + From 571677dd2807036ae1bcd2c68864c8a694894472 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 18:02:53 +0800 Subject: [PATCH 022/169] =?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/model/localBook/AnalyzeTxtFile.kt | 3 ++ .../app/ui/book/read/ReadBookActivity.kt | 8 +++++ .../app/ui/book/read/ReadBookViewModel.kt | 1 + .../app/ui/book/read/config/TocRegexDialog.kt | 35 +++++++++++++++++-- .../main/res/layout/dialog_toc_regex_edit.xml | 5 ++- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 86e64bb02..fad747b34 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -205,6 +205,9 @@ object AnalyzeTxtFile { } private fun getTocRule(book: Book, bookStream: RandomAccessFile, charset: Charset): Pattern? { + if (book.tocUrl.isNotEmpty()) { + return Pattern.compile(book.tocUrl, Pattern.MULTILINE) + } val tocRules = getTocRules() var rulePattern: Pattern? = null //首先获取128k的数据 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 2e7fa5bde..903dc3ebd 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 @@ -62,6 +62,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, ReadBook.CallBack, + TocRegexDialog.CallBack, ColorPickerDialogListener { private val requestCodeChapterList = 568 private val requestCodeEditSource = 111 @@ -600,6 +601,13 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun onDialogDismissed(dialogId: Int) = Unit + override fun onTocRegexDialogResult(tocRegex: String) { + ReadBook.book?.let { + it.tocUrl = tocRegex + viewModel.loadChapterList(it) + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index db7529cab..2ebab7875 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -99,6 +99,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { execute { if (book.isLocalBook()) { AnalyzeTxtFile.analyze(context, book).let { + App.db.bookChapterDao().delByBook(book.bookUrl) App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookDao().update(book) ReadBook.chapterSize = it.size 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 10ca38a5b..ba9b23a44 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 @@ -12,6 +12,7 @@ import androidx.appcompat.widget.Toolbar import androidx.fragment.app.FragmentManager import androidx.lifecycle.LiveData import androidx.lifecycle.Observer +import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.App @@ -44,7 +45,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var adapter: TocRegexAdapter private var tocRegexLiveData: LiveData>? = null var selectedName: String? = null - var durRegex: String? = null + private var durRegex: String? = null override fun onStart() { super.onStart() @@ -80,6 +81,20 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter itemTouchCallback.isCanDrag = true + ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) + tv_cancel.onClick { + dismiss() + } + tv_ok.onClick { + adapter.getItems().forEach { tocRule -> + if (selectedName == tocRule.name) { + val callBack = activity as? CallBack + callBack?.onTocRegexDialogResult(tocRule.rule) + dismiss() + return@onClick + } + } + } } private fun initData() { @@ -138,14 +153,14 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { rootView?.let { tocRule.name = tv_rule_name.text.toString() tocRule.rule = tv_rule_regex.text.toString() - saveRule(rule, tocRule) + saveRule(tocRule, rule) } } cancelButton() }.show().applyTint() } - private fun saveRule(oldRule: TxtTocRule?, rule: TxtTocRule) { + private fun saveRule(rule: TxtTocRule, oldRule: TxtTocRule? = null) { launch(IO) { if (rule.serialNumber < 0) { rule.serialNumber = adapter.getItems().lastOrNull()?.serialNumber ?: 0 + 1 @@ -181,6 +196,16 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { updateItems(0, itemCount - 1, true) } } + swt_enabled.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed) { + getItem(holder.layoutPosition)?.let { + it.enable = isChecked + launch(IO) { + App.db.txtTocRule().update(it) + } + } + } + } iv_edit.onClick { editRule(getItem(holder.layoutPosition)) } @@ -228,4 +253,8 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { } } + interface CallBack { + fun onTocRegexDialogResult(tocRegex: String) {} + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_toc_regex_edit.xml b/app/src/main/res/layout/dialog_toc_regex_edit.xml index 13abef871..07c0816a4 100644 --- a/app/src/main/res/layout/dialog_toc_regex_edit.xml +++ b/app/src/main/res/layout/dialog_toc_regex_edit.xml @@ -2,7 +2,10 @@ + android:layout_height="match_parent" + android:paddingTop="10dp" + android:paddingStart="10dp" + android:paddingEnd="10dp"> Date: Sun, 23 Feb 2020 18:10:08 +0800 Subject: [PATCH 023/169] =?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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index edfb033ee..8b1acd8d9 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,8 @@ **2020/02/23** * 修复BUG +* 本地目录正则自定义完成 +* 选择文本修复框选不全的问题,增加操作按钮 **2020/02/22** * 长按选择完成 From 469f893ef1095b846f5266b1d87bb560a06c343f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 18:51:33 +0800 Subject: [PATCH 024/169] =?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 --- .../book/read/page/delegate/PageDelegate.kt | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 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 eab124233..4402767c1 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 @@ -29,7 +29,6 @@ abstract class PageDelegate(protected val pageView: PageView) : 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 @@ -79,7 +78,6 @@ 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 @@ -90,7 +88,6 @@ 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 @@ -230,7 +227,16 @@ abstract class PageDelegate(protected val pageView: PageView) : @CallSuper open fun onTouch(event: MotionEvent): Boolean { if (isStarted) return false - return detector.onTouchEvent(event) + if (!detector.onTouchEvent(event)) { + //GestureDetector.onFling小幅移动不会触发,所以要自己判断 + if (event.action == MotionEvent.ACTION_UP && isMoved) { + if (isTextSelected) { + isTextSelected = false + } + if (!noNext) onAnimStart() + } + } + return true } /** @@ -298,22 +304,6 @@ abstract class PageDelegate(protected val pageView: PageView) : isTextSelected = curPage.selectText(e) } - /** - * 移动结束 - */ - override fun onFling( - e1: MotionEvent?, - e2: MotionEvent?, - velocityX: Float, - velocityY: Float - ): Boolean { - if (isTextSelected) { - isTextSelected = false - } - if (!noNext) onAnimStart() - return true - } - /** * 判断是否有上一页 */ From 943e5fb76ccd5b64ff066b4bcc71acf86ae0e998 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:04:56 +0800 Subject: [PATCH 025/169] =?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/PageView.kt | 33 +++++++++---------- .../book/read/page/delegate/PageDelegate.kt | 8 ++--- 2 files changed, 19 insertions(+), 22 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 5a2eae133..6dc9c15a0 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 @@ -19,8 +19,8 @@ class PageView(context: Context, attrs: AttributeSet) : ContentView.CallBack, DataSource { - var callBack: CallBack? = null - var pageFactory: TextPageFactory? = null + var callBack: CallBack + var pageFactory: TextPageFactory var pageDelegate: PageDelegate? = null var prevPage: ContentView @@ -28,7 +28,7 @@ class PageView(context: Context, attrs: AttributeSet) : var nextPage: ContentView init { - callBack = activity as? CallBack + callBack = activity as CallBack prevPage = ContentView(context) addView(prevPage) nextPage = ContentView(context) @@ -66,7 +66,7 @@ class PageView(context: Context, attrs: AttributeSet) : @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(event: MotionEvent): Boolean { - callBack?.screenOffTimerStart() + callBack.screenOffTimerStart() return pageDelegate?.onTouch(event) ?: super.onTouchEvent(event) } @@ -78,11 +78,11 @@ class PageView(context: Context, attrs: AttributeSet) : fun fillPage(direction: PageDelegate.Direction) { when (direction) { PageDelegate.Direction.PREV -> { - pageFactory?.moveToPrevious() + pageFactory.moveToPrevious() upContent() } PageDelegate.Direction.NEXT -> { - pageFactory?.moveToNext() + pageFactory.moveToNext() upContent() } else -> Unit @@ -103,7 +103,7 @@ class PageView(context: Context, attrs: AttributeSet) : } fun upContent(position: Int = 0) { - pageFactory?.let { + pageFactory.let { when (position) { -1 -> prevPage.setContent(it.previousPage()) 1 -> nextPage.setContent(it.nextPage()) @@ -114,7 +114,7 @@ class PageView(context: Context, attrs: AttributeSet) : } } } - callBack?.screenOffTimerStart() + callBack.screenOffTimerStart() } fun moveToPrevPage(noAnim: Boolean = true) { @@ -172,7 +172,7 @@ class PageView(context: Context, attrs: AttributeSet) : get() = ReadBook.durChapterPos() override fun setPageIndex(pageIndex: Int) { - callBack?.setPageIndex(pageIndex) + callBack.setPageIndex(pageIndex) } override fun getChapterPosition(): Int { @@ -180,15 +180,15 @@ class PageView(context: Context, attrs: AttributeSet) : } override fun getCurrentChapter(): TextChapter? { - return if (callBack?.isInitFinish == true) ReadBook.textChapter(0) else null + return if (callBack.isInitFinish) ReadBook.textChapter(0) else null } override fun getNextChapter(): TextChapter? { - return if (callBack?.isInitFinish == true) ReadBook.textChapter(1) else null + return if (callBack.isInitFinish) ReadBook.textChapter(1) else null } override fun getPreviousChapter(): TextChapter? { - return if (callBack?.isInitFinish == true) ReadBook.textChapter(-1) else null + return if (callBack.isInitFinish) ReadBook.textChapter(-1) else null } override fun hasNextChapter(): Boolean { @@ -196,10 +196,7 @@ class PageView(context: Context, attrs: AttributeSet) : } override fun hasPrevChapter(): Boolean { - callBack?.let { - return ReadBook.durChapterIndex > 0 - } - return false + return ReadBook.durChapterIndex > 0 } override fun scrollToLine(line: Int) { @@ -207,7 +204,7 @@ class PageView(context: Context, attrs: AttributeSet) : ReadBook.textChapter()?.let { val pageIndex = it.getPageIndex(line) curPage.setPageIndex(pageIndex) - callBack?.setPageIndex(pageIndex) + callBack.setPageIndex(pageIndex) } } } @@ -215,7 +212,7 @@ class PageView(context: Context, attrs: AttributeSet) : override fun scrollToLast() { if (isScrollDelegate) { ReadBook.textChapter()?.let { - callBack?.setPageIndex(it.lastIndex()) + callBack.setPageIndex(it.lastIndex()) curPage.setPageIndex(it.lastIndex()) } } 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 4402767c1..8075ce49c 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 @@ -130,7 +130,7 @@ abstract class PageDelegate(protected val pageView: PageView) : invalidate() } - protected fun stopScroll() { + private fun stopScroll() { isRunning = false isStarted = false invalidate() @@ -272,7 +272,7 @@ abstract class PageDelegate(protected val pageView: PageView) : val x = e.x val y = e.y if (centerRectF.contains(x, y)) { - pageView.callBack?.clickCenter() + pageView.callBack.clickCenter() setTouchPoint(x, y) } else { if (x > viewWidth / 2 || @@ -308,7 +308,7 @@ abstract class PageDelegate(protected val pageView: PageView) : * 判断是否有上一页 */ fun hasPrev(): Boolean { - val hasPrev = pageView.pageFactory?.hasPrev() == true + val hasPrev = pageView.pageFactory.hasPrev() if (!hasPrev) { if (!snackBar.isShown) { snackBar.setText("没有上一页") @@ -322,7 +322,7 @@ abstract class PageDelegate(protected val pageView: PageView) : * 判断是否有下一页 */ fun hasNext(): Boolean { - val hasNext = pageView.pageFactory?.hasNext() == true + val hasNext = pageView.pageFactory.hasNext() if (!hasNext) { if (!snackBar.isShown) { snackBar.setText("没有下一页") From 56910ffbc311e49cde78d10f47160fcb4fa15baa Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:08:40 +0800 Subject: [PATCH 026/169] =?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/ContentView.kt | 5 ----- .../legado/app/ui/book/read/page/PageView.kt | 21 ------------------- 2 files changed, 26 deletions(-) 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 1b2692333..abb2b82c4 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 @@ -16,7 +16,6 @@ import java.util.* class ContentView(context: Context) : FrameLayout(context) { - var callBack: CallBack? = null private var pageSize: Int = 0 init { @@ -135,8 +134,4 @@ class ContentView(context: Context) : FrameLayout(context) { val selectedText: String get() = content_text_view.selectedText - interface CallBack { - fun scrollToLine(line: Int) - fun scrollToLast() - } } \ 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 6dc9c15a0..a0c6c962a 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 @@ -16,7 +16,6 @@ import io.legado.app.utils.getPrefInt class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), - ContentView.CallBack, DataSource { var callBack: CallBack @@ -39,7 +38,6 @@ class PageView(context: Context, attrs: AttributeSet) : setWillNotDraw(false) pageFactory = TextPageFactory(this) upPageAnim(context.getPrefInt(PreferKey.pageAnim)) - curPage.callBack = this } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { @@ -199,25 +197,6 @@ class PageView(context: Context, attrs: AttributeSet) : return ReadBook.durChapterIndex > 0 } - override fun scrollToLine(line: Int) { - if (isScrollDelegate) { - ReadBook.textChapter()?.let { - val pageIndex = it.getPageIndex(line) - curPage.setPageIndex(pageIndex) - callBack.setPageIndex(pageIndex) - } - } - } - - override fun scrollToLast() { - if (isScrollDelegate) { - ReadBook.textChapter()?.let { - callBack.setPageIndex(it.lastIndex()) - curPage.setPageIndex(it.lastIndex()) - } - } - } - interface CallBack { val isInitFinish: Boolean From b924cff588e2bd630d05a263e45bb713099d3293 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:34:07 +0800 Subject: [PATCH 027/169] =?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/ReadBookActivity.kt | 3 +- .../app/ui/book/read/page/ContentTextView.kt | 15 +++++----- .../app/ui/book/read/page/TextPageFactory.kt | 28 +++---------------- .../book/read/page/delegate/PageDelegate.kt | 11 ++------ 4 files changed, 16 insertions(+), 41 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 903dc3ebd..7d3d747aa 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 @@ -36,6 +36,7 @@ import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView +import io.legado.app.ui.book.read.page.TextPageFactory import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog @@ -80,7 +81,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo private var screenTimeOut: Long = 0 private var timeElectricityReceiver: TimeElectricityReceiver? = null - + override val pageFactory: TextPageFactory get() = page_view.pageFactory override val headerHeight: Int get() = page_view.curPage.headerHeight override fun onActivityCreated(savedInstanceState: Bundle?) { 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 6902ae399..eeae9d33b 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 @@ -11,7 +11,6 @@ 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.service.help.ReadBook import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.activity import io.legado.app.utils.getCompatColor @@ -25,7 +24,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at style = Paint.Style.FILL } } - private var activityCallBack: CallBack + private var callBack: CallBack var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) private var selectLineStart = 0 private var selectCharStart = 0 @@ -33,13 +32,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at private var selectCharEnd = 0 private var textPage: TextPage = TextPage() //滚动参数 + private val pageFactory: TextPageFactory get() = callBack.pageFactory private val maxScrollOffset = 100f private var pageOffset = 0f private var linePos = 0 private var isLastPage = false init { - activityCallBack = activity as CallBack + callBack = activity as CallBack contentDescription = textPage.text } @@ -127,7 +127,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at isLastPage = false } // 首页 - if (pageOffset < 0 && ReadBook.durChapterIndex == 0 && ReadBook.durPageIndex == 0) { + if (pageOffset < 0 && !pageFactory.hasPrev()) { pageOffset = 0f } @@ -245,11 +245,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private fun upSelectedStart(x: Float, y: Float) { - activityCallBack.upSelectedStart(x, y + activityCallBack.headerHeight) + callBack.upSelectedStart(x, y + callBack.headerHeight) } private fun upSelectedEnd(x: Float, y: Float) { - activityCallBack.upSelectedEnd(x, y + activityCallBack.headerHeight) + callBack.upSelectedEnd(x, y + callBack.headerHeight) } fun cancelSelect() { @@ -259,7 +259,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } invalidate() - activityCallBack.onCancelSelect() + callBack.onCancelSelect() } val selectedText: String @@ -295,5 +295,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at fun upSelectedEnd(x: Float, y: Float) fun onCancelSelect() val headerHeight: Int + val pageFactory: TextPageFactory } } 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 03a222b94..018f75bab 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 @@ -6,20 +6,11 @@ import io.legado.app.ui.book.read.page.entities.TextPage class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource) { override fun hasPrev(): Boolean = with(dataSource) { - return if (isScrollDelegate) { - hasPrevChapter() - } else { - hasPrevChapter() || pageIndex > 0 - } + return hasPrevChapter() || pageIndex > 0 } override fun hasNext(): Boolean = with(dataSource) { - return if (isScrollDelegate) { - hasNextChapter() - } else { - hasNextChapter() - || getCurrentChapter()?.isLastIndex(pageIndex) != true - } + return hasNextChapter() || getCurrentChapter()?.isLastIndex(pageIndex) != true } override fun moveToFirst() { @@ -39,7 +30,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToNext(): Boolean = with(dataSource) { return if (hasNext()) { if (getCurrentChapter()?.isLastIndex(pageIndex) == true - || isScrollDelegate ) { ReadBook.moveToNextChapter(false) } else { @@ -52,7 +42,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToPrevious(): Boolean = with(dataSource) { return if (hasPrev()) { - if (pageIndex <= 0 || isScrollDelegate) { + if (pageIndex <= 0) { ReadBook.moveToPrevChapter(false) } else { setPageIndex(pageIndex.minus(1)) @@ -63,17 +53,10 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun currentPage(): TextPage? = with(dataSource) { - return if (isScrollDelegate) { - getCurrentChapter()?.scrollPage() - } else { - getCurrentChapter()?.page(pageIndex) - } + return getCurrentChapter()?.page(pageIndex) } override fun nextPage(): TextPage? = with(dataSource) { - if (isScrollDelegate) { - return getNextChapter()?.scrollPage() - } getCurrentChapter()?.let { if (pageIndex < it.pageSize() - 1) { return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() @@ -83,9 +66,6 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun previousPage(): TextPage? = with(dataSource) { - if (isScrollDelegate) { - return getPreviousChapter()?.scrollPage() - } if (pageIndex > 0) { return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() } 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 8075ce49c..2a90c79f1 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 @@ -134,15 +134,8 @@ abstract class PageDelegate(protected val pageView: PageView) : isRunning = false isStarted = false invalidate() - if (pageView.isScrollDelegate) { - pageView.postDelayed({ - bitmap?.recycle() - bitmap = null - }, 100) - } else { - bitmap?.recycle() - bitmap = null - } + bitmap?.recycle() + bitmap = null } fun setViewSize(width: Int, height: Int) { From 8ad566b8be52e1079cd1c7316747346ecc61413f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:38:34 +0800 Subject: [PATCH 028/169] =?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/TextActionMenu.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 bcc815ee6..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 @@ -116,13 +116,13 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac } @RequiresApi(Build.VERSION_CODES.M) - private fun getSupportedActivities(): List? { + private fun getSupportedActivities(): List { return context.packageManager .queryIntentActivities(createProcessTextIntent(), 0) } @RequiresApi(Build.VERSION_CODES.M) - private fun createProcessTextIntentForResolveInfo(info: ResolveInfo): Intent? { + private fun createProcessTextIntentForResolveInfo(info: ResolveInfo): Intent { return createProcessTextIntent() .putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false) .setClassName(info.activityInfo.packageName, info.activityInfo.name) @@ -139,10 +139,10 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac // so that your "PROCESS_TEXT" menu items appear after the // standard selection menu items like Cut, Copy, Paste. var menuItemOrder = 100 - for (resolveInfo in getSupportedActivities()!!) { + for (resolveInfo in getSupportedActivities()) { menu.add( Menu.NONE, Menu.NONE, - menuItemOrder++, resolveInfo!!.loadLabel(context.packageManager) + menuItemOrder++, resolveInfo.loadLabel(context.packageManager) ).intent = createProcessTextIntentForResolveInfo(resolveInfo) } } From 7bfaaf556d31aa4bfa954d5f5985e93eced951da Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:43:39 +0800 Subject: [PATCH 029/169] =?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/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c456ce6ab..9e36f18e0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,7 +86,7 @@ 下载选择的章节到本地 换源 - \u3000\u3000这是一款开源的阅读软件,你可以fork我们的代码自己编译APK。欢迎提交代码帮助改善应用。\n\u3000\u3000公众号[开源阅读软件]! + \u3000\u3000这是一款使用Kotlin全新开发的开源的阅读软件,欢迎您的加入。\n\u3000\u3000公众号[开源阅读软件]! 阅读3.0下载地址:\nhttps://play.google.com/store/apps/details?id=io.legado.app From 455db2ccfac28cbe287c9c87981fc7754743b5e5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:45:07 +0800 Subject: [PATCH 030/169] =?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/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9e36f18e0..3b121d53f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,7 +86,7 @@ 下载选择的章节到本地 换源 - \u3000\u3000这是一款使用Kotlin全新开发的开源的阅读软件,欢迎您的加入。\n\u3000\u3000公众号[开源阅读软件]! + \u3000\u3000这是一款使用Kotlin全新开发的开源的阅读软件,欢迎您的加入。关注公众号[开源阅读软件]! 阅读3.0下载地址:\nhttps://play.google.com/store/apps/details?id=io.legado.app From 1afb68b233663eeab3771fa7296ef24a71bab6f4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 19:55:31 +0800 Subject: [PATCH 031/169] =?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/utils/BitmapUtils.kt | 2 +- app/src/main/java/io/legado/app/utils/ColorUtils.kt | 7 +++++-- app/src/main/java/io/legado/app/utils/FloatExtensions.kt | 5 ++--- app/src/main/java/io/legado/app/utils/StringExtensions.kt | 2 -- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 00f1d4c58..14212f442 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -147,7 +147,7 @@ object BitmapUtils { //图片不被压缩 fun convertViewToBitmap(view: View, bitmapWidth: Int, bitmapHeight: Int): Bitmap { - val bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888) + val bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888) view.draw(Canvas(bitmap)) return bitmap } diff --git a/app/src/main/java/io/legado/app/utils/ColorUtils.kt b/app/src/main/java/io/legado/app/utils/ColorUtils.kt index 3ca7ab5bc..9eceb6724 100644 --- a/app/src/main/java/io/legado/app/utils/ColorUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ColorUtils.kt @@ -4,6 +4,9 @@ import android.graphics.Color import androidx.annotation.ColorInt import androidx.annotation.FloatRange +import kotlin.math.max +import kotlin.math.min +import kotlin.math.roundToInt @Suppress("unused") object ColorUtils { @@ -53,7 +56,7 @@ object ColorUtils { @ColorInt fun adjustAlpha(@ColorInt color: Int, @FloatRange(from = 0.0, to = 1.0) factor: Float): Int { - val alpha = Math.round(Color.alpha(color) * factor) + val alpha = (Color.alpha(color) * factor).roundToInt() val red = Color.red(color) val green = Color.green(color) val blue = Color.blue(color) @@ -62,7 +65,7 @@ object ColorUtils { @ColorInt fun withAlpha(@ColorInt baseColor: Int, @FloatRange(from = 0.0, to = 1.0) alpha: Float): Int { - val a = Math.min(255, Math.max(0, (alpha * 255).toInt())) shl 24 + val a = min(255, max(0, (alpha * 255).toInt())) shl 24 val rgb = 0x00ffffff and baseColor return a + rgb } diff --git a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt index af9576c00..4e3c7f9ed 100644 --- a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt @@ -2,14 +2,13 @@ package io.legado.app.utils import android.content.res.Resources - -val Float.dp: Float // [xxhdpi](360 -> 1080) +val Float.dp: Float get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics ) -val Float.sp: Float // [xxhdpi](360 -> 1080) +val Float.sp: Float get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics ) diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 02faf53c3..63954162e 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -1,7 +1,5 @@ package io.legado.app.utils -// import org.apache.commons.text.StringEscapeUtils - fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true From 07d4fa66b685ded2fbba1f2bb0baab53589098af Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 21:19:38 +0800 Subject: [PATCH 032/169] =?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 033/169] =?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 034/169] =?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 035/169] =?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 036/169] =?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 037/169] =?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 038/169] =?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 039/169] =?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 040/169] =?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 041/169] =?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 042/169] =?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 043/169] =?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 044/169] =?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 045/169] =?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 046/169] =?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 047/169] =?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 048/169] =?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 049/169] =?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 050/169] =?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 051/169] =?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 052/169] =?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 053/169] =?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 054/169] =?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 055/169] =?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 056/169] =?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 057/169] =?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 058/169] =?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 059/169] =?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 060/169] =?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 061/169] =?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 062/169] =?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 063/169] =?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 064/169] =?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 065/169] =?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 066/169] =?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 067/169] =?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 068/169] =?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 069/169] =?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 070/169] =?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 071/169] =?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 072/169] =?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 073/169] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E5=A4=87=E4=BB=BD=E9=83=BD=E5=B0=86=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=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 074/169] =?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 075/169] =?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 076/169] =?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 077/169] =?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 078/169] =?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 079/169] =?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 080/169] =?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() } From 8079f7a5892144906c4430dbf1b11801d12a1dd8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:16:53 +0800 Subject: [PATCH 081/169] =?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/ReadBookActivity.kt | 9 +- .../legado/app/ui/book/read/TextActionMenu.kt | 6 +- .../app/ui/book/read/page/ChapterProvider.kt | 8 +- .../read/page/content/BaseContentTextView.kt | 113 ++++++++++++++++++ .../page/{ => content}/ContentTextView.kt | 111 +---------------- app/src/main/res/layout/view_book_page.xml | 2 +- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 8 files changed, 136 insertions(+), 119 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt rename app/src/main/java/io/legado/app/ui/book/read/page/{ => content}/ContentTextView.kt (69%) 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 16b198626..7b68d844d 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 @@ -8,7 +8,6 @@ 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 import androidx.core.view.size @@ -35,9 +34,9 @@ import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider -import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory +import io.legado.app.ui.book.read.page.content.BaseContentTextView import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog @@ -59,7 +58,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, - ContentTextView.CallBack, + BaseContentTextView.CallBack, ReadMenu.CallBack, ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, @@ -403,8 +402,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 文本选择菜单操作 */ - override fun onMenuItemSelected(item: MenuItemImpl): Boolean { - when (item.itemId) { + override fun onMenuItemSelected(itemId: Int): Boolean { + when (itemId) { R.id.menu_replace -> { ReplaceEditDialog.show(supportFragmentManager, pattern = selectedText) return true 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..9d0959177 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 @@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.popup_action_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.toast - +@SuppressLint("RestrictedApi") class TextActionMenu(private val context: Context, private val callBack: CallBack) : PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { @@ -70,7 +70,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac override fun registerListener(holder: ItemViewHolder) { holder.itemView.onClick { getItem(holder.layoutPosition)?.let { - if (!callBack.onMenuItemSelected(it)) { + if (!callBack.onMenuItemSelected(it.itemId)) { onMenuItemSelected(it) } } @@ -150,7 +150,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac interface CallBack { val selectedText: String - fun onMenuItemSelected(item: MenuItemImpl): Boolean + fun onMenuItemSelected(itemId: Int): Boolean fun onMenuActionFinally() } 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 74136ba5c..7618ddc51 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,12 @@ import io.legado.app.utils.removePref object ChapterProvider { var viewWidth = 0 var viewHeight = 0 - var visibleWidth = 0 - var visibleHeight = 0 var paddingLeft = 0 var paddingTop = 0 + var visibleWidth = 0 + var visibleHeight = 0 + var visibleRight = 0 + var visibleBottom = 0 private var lineSpacingExtra = 0f private var paragraphSpacing = 0 var typeface: Typeface = Typeface.SANS_SERIF @@ -342,6 +344,8 @@ object ChapterProvider { paddingTop = ReadBookConfig.paddingTop.dp visibleWidth = viewWidth - paddingLeft - ReadBookConfig.paddingRight.dp visibleHeight = viewHeight - paddingTop - ReadBookConfig.paddingBottom.dp + visibleRight = paddingLeft + visibleWidth + visibleBottom = paddingTop + visibleHeight } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt new file mode 100644 index 000000000..0f0693db3 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt @@ -0,0 +1,113 @@ +package io.legado.app.ui.book.read.page.content + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.util.AttributeSet +import android.view.View +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.ChapterProvider +import io.legado.app.ui.book.read.page.TextPageFactory +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 +import io.legado.app.utils.getPrefBoolean + +abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) { + + var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) + var upView: ((TextPage) -> Unit)? = null + protected val selectedPaint by lazy { + Paint().apply { + color = context.getCompatColor(R.color.btn_bg_press_2) + style = Paint.Style.FILL + } + } + protected var callBack: CallBack + protected var selectLineStart = 0 + protected var selectCharStart = 0 + protected var selectLineEnd = 0 + protected var selectCharEnd = 0 + protected var textPage: TextPage = TextPage() + //滚动参数 + protected val pageFactory: TextPageFactory get() = callBack.pageFactory + protected val maxScrollOffset = 100f + protected var pageOffset = 0f + protected var linePos = 0 + + init { + callBack = activity as CallBack + contentDescription = textPage.text + } + + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + ChapterProvider.viewWidth = w + ChapterProvider.viewHeight = h + ChapterProvider.upSize() + textPage.format() + } + + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.clipRect( + ChapterProvider.paddingLeft, + ChapterProvider.paddingTop, + ChapterProvider.visibleRight, + ChapterProvider.visibleBottom + ) + if (ReadBookConfig.isScroll) { + drawScrollPage(canvas) + } else { + drawHorizontalPage(canvas) + } + } + + abstract fun drawScrollPage(canvas: Canvas) + + abstract fun drawHorizontalPage(canvas: Canvas) + + protected 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) + } + } + } + + + protected fun upSelectedStart(x: Float, y: Float) { + callBack.upSelectedStart(x, y + callBack.headerHeight) + } + + protected fun upSelectedEnd(x: Float, y: Float) { + callBack.upSelectedEnd(x, y + callBack.headerHeight) + } + + + interface CallBack { + fun upSelectedStart(x: Float, y: Float) + fun upSelectedEnd(x: Float, y: Float) + fun onCancelSelect() + val headerHeight: Int + val pageFactory: TextPageFactory + } +} \ 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/content/ContentTextView.kt similarity index 69% rename from app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt rename to app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index 7d2262824..be3057a48 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/content/ContentTextView.kt @@ -1,46 +1,14 @@ -package io.legado.app.ui.book.read.page +package io.legado.app.ui.book.read.page.content import android.content.Context import android.graphics.Canvas -import android.graphics.Paint import android.util.AttributeSet -import android.view.View -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.ChapterProvider import io.legado.app.ui.book.read.page.entities.TextPage -import io.legado.app.utils.activity -import io.legado.app.utils.getCompatColor -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) - style = Paint.Style.FILL - } - } - private var callBack: CallBack - private var selectLineStart = 0 - private var selectCharStart = 0 - private var selectLineEnd = 0 - private var selectCharEnd = 0 - private var textPage: TextPage = TextPage() - //滚动参数 - private val pageFactory: TextPageFactory get() = callBack.pageFactory - private val maxScrollOffset = 100f - private var pageOffset = 0f - private var linePos = 0 - - init { - callBack = activity as CallBack - contentDescription = textPage.text - } +class ContentTextView(context: Context, attrs: AttributeSet?) : + BaseContentTextView(context, attrs) { fun setContent(textPage: TextPage) { this.textPage = textPage @@ -48,24 +16,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at invalidate() } - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upSize() - textPage.format() - } - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - if (ReadBookConfig.isScroll) { - drawScrollPage(canvas) - } else { - drawHorizontalPage(canvas) - } - } - - private fun drawHorizontalPage(canvas: Canvas) { + override fun drawHorizontalPage(canvas: Canvas) { textPage.textLines.forEach { textLine -> drawChars( canvas, @@ -79,7 +30,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } - private fun drawScrollPage(canvas: Canvas) { + override fun drawScrollPage(canvas: Canvas) { val mPageOffset = pageOffset textPage.textLines.forEach { textLine -> val lineTop = textLine.lineTop + mPageOffset @@ -110,41 +61,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textLine.isReadAloud ) } - pageFactory.prevPage?.textLines?.forEach { textLine -> - val yPy = mPageOffset + 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) - } - } } fun onScroll(mOffset: Float) { @@ -271,14 +187,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at invalidate() } - private fun upSelectedStart(x: Float, y: Float) { - callBack.upSelectedStart(x, y + callBack.headerHeight) - } - - private fun upSelectedEnd(x: Float, y: Float) { - callBack.upSelectedEnd(x, y + callBack.headerHeight) - } - fun cancelSelect() { textPage.textLines.forEach { textLine -> textLine.textChars.forEach { @@ -317,11 +225,4 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at return stringBuilder.toString() } - interface CallBack { - fun upSelectedStart(x: Float, y: Float) - fun upSelectedEnd(x: Float, y: Float) - fun onCancelSelect() - val headerHeight: Int - val pageFactory: TextPageFactory - } } diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index 81c9e09d4..325e8a75c 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -32,7 +32,7 @@ android:background="@color/divider" android:visibility="invisible" /> - Date: Tue, 25 Feb 2020 09:34:44 +0800 Subject: [PATCH 082/169] =?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/content/BaseContentTextView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt index 0f0693db3..036678e5c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt @@ -21,7 +21,7 @@ abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : Vie var selectAble = context.getPrefBoolean(PreferKey.textSelectAble) var upView: ((TextPage) -> Unit)? = null - protected val selectedPaint by lazy { + private val selectedPaint by lazy { Paint().apply { color = context.getCompatColor(R.color.btn_bg_press_2) style = Paint.Style.FILL @@ -69,9 +69,9 @@ abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : Vie } } - abstract fun drawScrollPage(canvas: Canvas) + protected abstract fun drawScrollPage(canvas: Canvas) - abstract fun drawHorizontalPage(canvas: Canvas) + protected abstract fun drawHorizontalPage(canvas: Canvas) protected fun drawChars( canvas: Canvas, From d400a67f534145652fa660e49e3220fbf31dff0f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:44:15 +0800 Subject: [PATCH 083/169] =?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/ContentView.kt | 4 ++++ .../io/legado/app/ui/book/read/page/delegate/PageDelegate.kt | 4 ++++ 2 files changed, 8 insertions(+) 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 512f778a7..2f77ac986 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 @@ -105,6 +105,10 @@ class ContentView(context: Context) : FrameLayout(context) { } } + fun resetPageOffset() { + content_text_view.resetPageOffset() + } + @SuppressLint("SetTextI18n") fun setPageIndex(pageIndex: Int?) { pageIndex?.let { 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 234ce8097..7c453d9c7 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 @@ -70,6 +70,10 @@ abstract class PageDelegate(protected val pageView: PageView) : var firstLineIndex: Int = 0 var firstCharIndex: Int = 0 + init { + curPage.resetPageOffset() + } + open fun setStartPoint(x: Float, y: Float, invalidate: Boolean = true) { startX = x startY = y From 1cb1c3b2ea8b0416c4d007ce61d7aacb6089de31 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:45:08 +0800 Subject: [PATCH 084/169] =?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/content/BaseContentTextView.kt | 1 - .../io/legado/app/ui/book/read/page/content/ContentTextView.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt index 036678e5c..95fd796ea 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt @@ -37,7 +37,6 @@ abstract class BaseContentTextView(context: Context, attrs: AttributeSet?) : Vie protected val pageFactory: TextPageFactory get() = callBack.pageFactory protected val maxScrollOffset = 100f protected var pageOffset = 0f - protected var linePos = 0 init { callBack = activity as CallBack diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index be3057a48..e1013bb65 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -89,7 +89,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : fun resetPageOffset() { pageOffset = 0f - linePos = 0 } fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { From f753bc33e75274a87972e3ff005371c1f95fffc0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 09:49:19 +0800 Subject: [PATCH 085/169] =?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/content/ContentTextView.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index e1013bb65..20e6728b2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.book.read.page.content import android.content.Context import android.graphics.Canvas import android.util.AttributeSet -import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.entities.TextPage @@ -47,7 +46,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : ) } pageFactory.nextPage?.textLines?.forEach { textLine -> - val yPy = mPageOffset + textPage.height - ChapterProvider.paddingTop + val yPy = mPageOffset + textPage.height val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy val lineBottom = textLine.lineBottom + yPy From 854d11b0b07833e4626ee7d1034d49239ec2bcdf Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 10:12:37 +0800 Subject: [PATCH 086/169] =?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/ContentView.kt | 14 +++---- .../app/ui/book/read/page/DataSource.kt | 6 +-- .../legado/app/ui/book/read/page/PageView.kt | 9 +++-- .../app/ui/book/read/page/TextPageFactory.kt | 40 +++++++++++++------ .../book/read/page/content/ContentTextView.kt | 7 ++-- 5 files changed, 47 insertions(+), 29 deletions(-) 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 2f77ac986..574020c45 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 @@ -95,14 +95,12 @@ class ContentView(context: Context) : FrameLayout(context) { tv_top_right.text = context.getString(R.string.battery_show, battery) } - fun setContent(textPage: TextPage?) { - if (textPage != null) { - tv_bottom_left.text = textPage.title - pageSize = textPage.pageSize - setPageIndex(textPage.index) - content_text_view.resetPageOffset() - content_text_view.setContent(textPage) - } + fun setContent(textPage: TextPage) { + tv_bottom_left.text = textPage.title + pageSize = textPage.pageSize + setPageIndex(textPage.index) + content_text_view.resetPageOffset() + content_text_view.setContent(textPage) } 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 106e2e4db..1d188f598 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 @@ -7,11 +7,11 @@ interface DataSource { val pageIndex: Int get() = ReadBook.durChapterPos() - fun getCurrentChapter(): TextChapter? + val currentChapter: TextChapter? - fun getNextChapter(): TextChapter? + val nextChapter: TextChapter? - fun getPreviousChapter(): TextChapter? + val prevChapter: TextChapter? fun hasNextChapter(): 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 3009af02e..d5a46d734 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 @@ -164,15 +164,18 @@ class PageView(context: Context, attrs: AttributeSet) : nextPage.upBattery(battery) } - override fun getCurrentChapter(): TextChapter? { + override val currentChapter: TextChapter? + get() { return if (callBack.isInitFinish) ReadBook.textChapter(0) else null } - override fun getNextChapter(): TextChapter? { + override val nextChapter: TextChapter? + get() { return if (callBack.isInitFinish) ReadBook.textChapter(1) else null } - override fun getPreviousChapter(): TextChapter? { + override val prevChapter: TextChapter? + get() { return if (callBack.isInitFinish) ReadBook.textChapter(-1) 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 307423955..f10f99c5a 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 @@ -10,7 +10,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun hasNext(): Boolean = with(dataSource) { - return hasNextChapter() || getCurrentChapter()?.isLastIndex(pageIndex) != true + return hasNextChapter() || currentChapter?.isLastIndex(pageIndex) != true } override fun moveToFirst() { @@ -18,7 +18,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource } override fun moveToLast() = with(dataSource) { - getCurrentChapter()?.let { + currentChapter?.let { if (it.pageSize() == 0) { ReadBook.setPageIndex(0) } else { @@ -29,7 +29,7 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource override fun moveToNext(): Boolean = with(dataSource) { return if (hasNext()) { - if (getCurrentChapter()?.isLastIndex(pageIndex) == true) { + if (currentChapter?.isLastIndex(pageIndex) == true) { ReadBook.moveToNextChapter(false) } else { ReadBook.setPageIndex(pageIndex.plus(1)) @@ -51,27 +51,43 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource false } - override val currentPage: TextPage? + override val currentPage: TextPage get() = with(dataSource) { - return getCurrentChapter()?.page(pageIndex) + currentChapter?.let { + return@with it.page(pageIndex) + ?: TextPage(title = it.title).format() + } + return TextPage().format() } - override val nextPage: TextPage? + override val nextPage: TextPage get() = with(dataSource) { - getCurrentChapter()?.let { + currentChapter?.let { if (pageIndex < it.pageSize() - 1) { - return getCurrentChapter()?.page(pageIndex + 1)?.removePageAloudSpan() + return@with it.page(pageIndex + 1)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() } } - return getNextChapter()?.page(0)?.removePageAloudSpan() + nextChapter?.let { + return@with it.page(0)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() + } + return TextPage().format() } - override val prevPage: TextPage? + override val prevPage: TextPage get() = with(dataSource) { if (pageIndex > 0) { - return getCurrentChapter()?.page(pageIndex - 1)?.removePageAloudSpan() + currentChapter?.let { + return@with it.page(pageIndex - 1)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() + } + } + prevChapter?.let { + return@with it.lastPage()?.removePageAloudSpan() + ?: TextPage(title = it.title).format() } - return getPreviousChapter()?.lastPage()?.removePageAloudSpan() + return TextPage().format() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index 20e6728b2..7bb9c4d6e 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -45,7 +45,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } - pageFactory.nextPage?.textLines?.forEach { textLine -> + pageFactory.nextPage.textLines.forEach { textLine -> val yPy = mPageOffset + textPage.height val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy @@ -60,6 +60,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } + } fun onScroll(mOffset: Float) { @@ -74,13 +75,13 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : pageOffset += offset if (pageOffset > 0) { pageFactory.moveToPrev() - textPage = pageFactory.currentPage ?: TextPage().format() + textPage = pageFactory.currentPage pageOffset -= textPage.height upView?.invoke(textPage) } else if (pageOffset < -textPage.height) { pageOffset += textPage.height pageFactory.moveToNext() - textPage = pageFactory.currentPage ?: TextPage().format() + textPage = pageFactory.currentPage upView?.invoke(textPage) } invalidate() From aafa690692629a699c5841b899137440718c3098 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 10:39:52 +0800 Subject: [PATCH 087/169] =?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/PageFactory.kt | 8 ++++--- .../app/ui/book/read/page/TextPageFactory.kt | 18 +++++++++++++++ .../book/read/page/content/ContentTextView.kt | 22 +++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) 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 db504b6f4..85cdecbd5 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,13 @@ abstract class PageFactory(protected val dataSource: DataSource) { abstract fun moveToPrev(): Boolean - abstract val nextPage: DATA? + abstract val nextPage: DATA - abstract val prevPage: DATA? + abstract val prevPage: DATA - abstract val currentPage: DATA? + abstract val currentPage: DATA + + abstract val nextPagePlus: DATA abstract fun hasNext(): Boolean 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 f10f99c5a..fe18f1b26 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 @@ -90,5 +90,23 @@ class TextPageFactory(dataSource: DataSource) : PageFactory(dataSource return TextPage().format() } + override val nextPagePlus: TextPage + get() = with(dataSource) { + currentChapter?.let { + if (pageIndex < it.pageSize() - 2) { + return@with it.page(pageIndex + 2)?.removePageAloudSpan() + ?: TextPage(title = it.title).format() + } + nextChapter?.let { nc -> + if (pageIndex < it.pageSize() - 1) { + return@with nc.page(0)?.removePageAloudSpan() + ?: TextPage(title = nc.title).format() + } + return@with nc.page(1)?.removePageAloudSpan() + ?: TextPage(title = nc.title).format() + } + } + return TextPage().format() + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt index 7bb9c4d6e..4060012af 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.book.read.page.content import android.content.Context import android.graphics.Canvas import android.util.AttributeSet +import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.entities.TextPage @@ -45,7 +46,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } - pageFactory.nextPage.textLines.forEach { textLine -> + val nextPage = pageFactory.nextPage + nextPage.textLines.forEach { textLine -> val yPy = mPageOffset + textPage.height val lineTop = textLine.lineTop + yPy val lineBase = textLine.lineBase + yPy @@ -60,7 +62,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } - + if (mPageOffset + textPage.height + nextPage.height < ChapterProvider.visibleHeight) { + pageFactory.nextPagePlus.textLines.forEach { textLine -> + val yPy = mPageOffset + textPage.height + nextPage.height + 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 + ) + } + } } fun onScroll(mOffset: Float) { From ee1f04f42cfbe4bdadda06eedd1ee1560c6a716b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 12:05:50 +0800 Subject: [PATCH 088/169] =?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/ContentView.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 574020c45..9f2631ea6 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 @@ -15,7 +15,6 @@ import java.util.* class ContentView(context: Context) : FrameLayout(context) { - private var pageSize: Int = 0 init { //设置背景防止切换背景时文字重叠 @@ -26,8 +25,7 @@ class ContentView(context: Context) : FrameLayout(context) { upTime() content_text_view.upView = { tv_bottom_left.text = it.title - pageSize = it.pageSize - setPageIndex(it.index) + setPageIndex(it.index, it.pageSize) } } @@ -97,8 +95,7 @@ class ContentView(context: Context) : FrameLayout(context) { fun setContent(textPage: TextPage) { tv_bottom_left.text = textPage.title - pageSize = textPage.pageSize - setPageIndex(textPage.index) + setPageIndex(textPage.index, textPage.pageSize) content_text_view.resetPageOffset() content_text_view.setContent(textPage) } @@ -108,7 +105,7 @@ class ContentView(context: Context) : FrameLayout(context) { } @SuppressLint("SetTextI18n") - fun setPageIndex(pageIndex: Int?) { + fun setPageIndex(pageIndex: Int?, pageSize: Int) { pageIndex?.let { tv_bottom_right.text = "${pageIndex.plus(1)}/${pageSize}" } From f800991eeb107fe58a22019897294013f08f09f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 12:16:33 +0800 Subject: [PATCH 089/169] =?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/ReadBookActivity.kt | 4 +- .../page/{content => }/ContentTextView.kt | 124 ++++++++++++++---- .../read/page/content/BaseContentTextView.kt | 112 ---------------- app/src/main/res/layout/view_book_page.xml | 2 +- 4 files changed, 102 insertions(+), 140 deletions(-) rename app/src/main/java/io/legado/app/ui/book/read/page/{content => }/ContentTextView.kt (68%) delete mode 100644 app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt 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 7b68d844d..cf88a03dd 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 @@ -34,9 +34,9 @@ import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR import io.legado.app.ui.book.read.page.ChapterProvider +import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory -import io.legado.app.ui.book.read.page.content.BaseContentTextView import io.legado.app.ui.book.read.page.delegate.PageDelegate import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog @@ -58,7 +58,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo View.OnTouchListener, PageView.CallBack, TextActionMenu.CallBack, - BaseContentTextView.CallBack, + ContentTextView.CallBack, ReadMenu.CallBack, ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt similarity index 68% rename from app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt rename to app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt index 4060012af..5f482f8f6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/ContentTextView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt @@ -1,14 +1,45 @@ -package io.legado.app.ui.book.read.page.content +package io.legado.app.ui.book.read.page import android.content.Context import android.graphics.Canvas +import android.graphics.Paint import android.util.AttributeSet -import io.legado.app.ui.book.read.page.ChapterProvider +import android.view.View +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 +import io.legado.app.utils.getPrefBoolean -class ContentTextView(context: Context, attrs: AttributeSet?) : - BaseContentTextView(context, attrs) { +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) + style = Paint.Style.FILL + } + } + private var callBack: CallBack + private var selectLineStart = 0 + private var selectCharStart = 0 + private var selectLineEnd = 0 + private var selectCharEnd = 0 + private var textPage: TextPage = TextPage() + //滚动参数 + private val pageFactory: TextPageFactory get() = callBack.pageFactory + private val maxScrollOffset = 100f + private var pageOffset = 0f + + init { + callBack = activity as CallBack + contentDescription = textPage.text + } fun setContent(textPage: TextPage) { this.textPage = textPage @@ -16,21 +47,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : invalidate() } - override fun drawHorizontalPage(canvas: Canvas) { - textPage.textLines.forEach { textLine -> - drawChars( - canvas, - textLine.textChars, - textLine.lineTop, - textLine.lineBase, - textLine.lineBottom, - textLine.isTitle, - textLine.isReadAloud - ) - } + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + ChapterProvider.viewWidth = w + ChapterProvider.viewHeight = h + ChapterProvider.upSize() + textPage.format() } - override fun drawScrollPage(canvas: Canvas) { + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.clipRect( + ChapterProvider.paddingLeft, + ChapterProvider.paddingTop, + ChapterProvider.visibleRight, + ChapterProvider.visibleBottom + ) + drawPage(canvas) + } + + private fun drawPage(canvas: Canvas) { val mPageOffset = pageOffset textPage.textLines.forEach { textLine -> val lineTop = textLine.lineTop + mPageOffset @@ -46,6 +82,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : textLine.isReadAloud ) } + if (!ReadBookConfig.isScroll) { + return + } val nextPage = pageFactory.nextPage nextPage.textLines.forEach { textLine -> val yPy = mPageOffset + textPage.height @@ -81,6 +120,26 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : } } + 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) + } + } + } + fun onScroll(mOffset: Float) { if (mOffset == 0f) return var offset = mOffset @@ -111,7 +170,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : 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) { + if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { textChar.selected = true @@ -120,8 +179,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : selectCharStart = charIndex selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedStart(textChar.start, textLine.lineBottom) - upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) select(lineIndex, charIndex) } } @@ -132,7 +191,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : fun selectStartMove(x: Float, y: Float) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop && y < textLine.lineBottom) { + if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineStart != lineIndex || selectCharStart != charIndex) { @@ -154,19 +213,19 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : selectCharStart = charIndex val textLine = textPage.textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedStart(textChar.start, textLine.lineBottom) + upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) upSelectChars(textPage) } fun selectEndMove(x: Float, y: Float) { for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop && y < textLine.lineBottom) { + if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) upSelectChars(textPage) } break @@ -182,7 +241,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : selectCharEnd = charIndex val textLine = textPage.textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedEnd(textChar.end, textLine.lineBottom) + upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) upSelectChars(textPage) } @@ -204,6 +263,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : invalidate() } + private fun upSelectedStart(x: Float, y: Float) { + callBack.upSelectedStart(x, y + callBack.headerHeight) + } + + private fun upSelectedEnd(x: Float, y: Float) { + callBack.upSelectedEnd(x, y + callBack.headerHeight) + } + fun cancelSelect() { textPage.textLines.forEach { textLine -> textLine.textChars.forEach { @@ -242,4 +309,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : return stringBuilder.toString() } + interface CallBack { + fun upSelectedStart(x: Float, y: Float) + fun upSelectedEnd(x: Float, y: Float) + fun onCancelSelect() + val headerHeight: Int + val pageFactory: TextPageFactory + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt deleted file mode 100644 index 95fd796ea..000000000 --- a/app/src/main/java/io/legado/app/ui/book/read/page/content/BaseContentTextView.kt +++ /dev/null @@ -1,112 +0,0 @@ -package io.legado.app.ui.book.read.page.content - -import android.content.Context -import android.graphics.Canvas -import android.graphics.Paint -import android.util.AttributeSet -import android.view.View -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.ChapterProvider -import io.legado.app.ui.book.read.page.TextPageFactory -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 -import io.legado.app.utils.getPrefBoolean - -abstract class BaseContentTextView(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) - style = Paint.Style.FILL - } - } - protected var callBack: CallBack - protected var selectLineStart = 0 - protected var selectCharStart = 0 - protected var selectLineEnd = 0 - protected var selectCharEnd = 0 - protected var textPage: TextPage = TextPage() - //滚动参数 - protected val pageFactory: TextPageFactory get() = callBack.pageFactory - protected val maxScrollOffset = 100f - protected var pageOffset = 0f - - init { - callBack = activity as CallBack - contentDescription = textPage.text - } - - - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upSize() - textPage.format() - } - - - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - canvas.clipRect( - ChapterProvider.paddingLeft, - ChapterProvider.paddingTop, - ChapterProvider.visibleRight, - ChapterProvider.visibleBottom - ) - if (ReadBookConfig.isScroll) { - drawScrollPage(canvas) - } else { - drawHorizontalPage(canvas) - } - } - - protected abstract fun drawScrollPage(canvas: Canvas) - - protected abstract fun drawHorizontalPage(canvas: Canvas) - - protected 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) - } - } - } - - - protected fun upSelectedStart(x: Float, y: Float) { - callBack.upSelectedStart(x, y + callBack.headerHeight) - } - - protected fun upSelectedEnd(x: Float, y: Float) { - callBack.upSelectedEnd(x, y + callBack.headerHeight) - } - - - interface CallBack { - fun upSelectedStart(x: Float, y: Float) - fun upSelectedEnd(x: Float, y: Float) - fun onCancelSelect() - val headerHeight: Int - val pageFactory: TextPageFactory - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/view_book_page.xml b/app/src/main/res/layout/view_book_page.xml index 325e8a75c..81c9e09d4 100644 --- a/app/src/main/res/layout/view_book_page.xml +++ b/app/src/main/res/layout/view_book_page.xml @@ -32,7 +32,7 @@ android:background="@color/divider" android:visibility="invisible" /> - Date: Tue, 25 Feb 2020 12:22:37 +0800 Subject: [PATCH 090/169] =?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, 1 insertion(+), 1 deletion(-) 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 5f482f8f6..8c88fe856 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 @@ -197,7 +197,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (selectLineStart != lineIndex || selectCharStart != charIndex) { selectLineStart = lineIndex selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom) + upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) upSelectChars(textPage) } break From 37d5643b8daa6d650905895d34ae662fe9b713eb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 12:32:13 +0800 Subject: [PATCH 091/169] =?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 | 18 ++++++++++++------ 1 file changed, 12 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 8c88fe856..4cd54223b 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,6 +3,7 @@ package io.legado.app.ui.book.read.page import android.content.Context import android.graphics.Canvas import android.graphics.Paint +import android.graphics.RectF import android.util.AttributeSet import android.view.View import io.legado.app.R @@ -26,6 +27,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } private var callBack: CallBack + private val visibleRect = RectF() private var selectLineStart = 0 private var selectCharStart = 0 private var selectLineEnd = 0 @@ -52,17 +54,18 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at ChapterProvider.viewWidth = w ChapterProvider.viewHeight = h ChapterProvider.upSize() + visibleRect.set( + ChapterProvider.paddingLeft.toFloat(), + ChapterProvider.paddingTop.toFloat(), + ChapterProvider.visibleRight.toFloat(), + ChapterProvider.visibleBottom.toFloat() + ) textPage.format() } override fun onDraw(canvas: Canvas) { super.onDraw(canvas) - canvas.clipRect( - ChapterProvider.paddingLeft, - ChapterProvider.paddingTop, - ChapterProvider.visibleRight, - ChapterProvider.visibleBottom - ) + canvas.clipRect(visibleRect) drawPage(canvas) } @@ -169,6 +172,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { + if (!visibleRect.contains(x, y)) return for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { @@ -190,6 +194,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun selectStartMove(x: Float, y: Float) { + if (!visibleRect.contains(x, y)) return for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { @@ -218,6 +223,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun selectEndMove(x: Float, y: Float) { + if (!visibleRect.contains(x, y)) return for ((lineIndex, textLine) in textPage.textLines.withIndex()) { if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { From 4337c773ff51958429b414395f6492431fd536da Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 13:43:40 +0800 Subject: [PATCH 092/169] =?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 | 263 +++++++++++++++--- .../app/ui/book/read/page/ContentView.kt | 13 +- .../book/read/page/delegate/PageDelegate.kt | 39 ++- 3 files changed, 256 insertions(+), 59 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 4cd54223b..cc366e886 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,8 +28,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private var callBack: CallBack private val visibleRect = RectF() + private var selectPageStart = 0 private var selectLineStart = 0 private var selectCharStart = 0 + private var selectPageEnd = 0 private var selectLineEnd = 0 private var selectCharEnd = 0 private var textPage: TextPage = TextPage() @@ -69,12 +71,15 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at drawPage(canvas) } + /** + * 绘制页面 + */ private fun drawPage(canvas: Canvas) { - val mPageOffset = pageOffset + var relativeOffset = relativeOffset(0) textPage.textLines.forEach { textLine -> - val lineTop = textLine.lineTop + mPageOffset - val lineBase = textLine.lineBase + mPageOffset - val lineBottom = textLine.lineBottom + mPageOffset + val lineTop = textLine.lineTop + relativeOffset + val lineBase = textLine.lineBase + relativeOffset + val lineBottom = textLine.lineBottom + relativeOffset drawChars( canvas, textLine.textChars, @@ -85,15 +90,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textLine.isReadAloud ) } - if (!ReadBookConfig.isScroll) { - return - } - val nextPage = pageFactory.nextPage + if (!ReadBookConfig.isScroll) return + //滚动翻页 + val nextPage = relativePage(1) + relativeOffset = relativeOffset(1) nextPage.textLines.forEach { textLine -> - val yPy = mPageOffset + textPage.height - val lineTop = textLine.lineTop + yPy - val lineBase = textLine.lineBase + yPy - val lineBottom = textLine.lineBottom + yPy + val lineTop = textLine.lineTop + relativeOffset + val lineBase = textLine.lineBase + relativeOffset + val lineBottom = textLine.lineBottom + relativeOffset drawChars( canvas, textLine.textChars, @@ -104,12 +108,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at textLine.isReadAloud ) } - if (mPageOffset + textPage.height + nextPage.height < ChapterProvider.visibleHeight) { - pageFactory.nextPagePlus.textLines.forEach { textLine -> - val yPy = mPageOffset + textPage.height + nextPage.height - val lineTop = textLine.lineTop + yPy - val lineBase = textLine.lineBase + yPy - val lineBottom = textLine.lineBottom + yPy + relativeOffset = relativeOffset(2) + if (relativeOffset < ChapterProvider.visibleHeight) { + relativePage(2).textLines.forEach { textLine -> + val lineTop = textLine.lineTop + relativeOffset + val lineBase = textLine.lineBase + relativeOffset + val lineBottom = textLine.lineBottom + relativeOffset drawChars( canvas, textLine.textChars, @@ -123,6 +127,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 绘制文字 + */ private fun drawChars( canvas: Canvas, textChars: List, @@ -143,6 +150,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 滚动事件 + */ fun onScroll(mOffset: Float) { if (mOffset == 0f) return var offset = mOffset @@ -171,83 +181,232 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageOffset = 0f } - fun selectText(x: Float, y: Float, select: (lineIndex: Int, charIndex: Int) -> Unit) { + /** + * 选择初始文字 + */ + fun selectText( + x: Float, + y: Float, + select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit + ) { if (!visibleRect.contains(x, y)) return + var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + textChar.selected = true + invalidate() + selectPageStart = 0 + selectLineStart = lineIndex + selectCharStart = charIndex + selectPageEnd = 0 + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + select(0, lineIndex, charIndex) + return + } + } + return + } + } + if (!ReadBookConfig.isScroll) return + //滚动翻页 + relativeOffset = relativeOffset(1) + if (relativeOffset >= ChapterProvider.visibleHeight) return + val nextPage = relativePage(1) + for ((lineIndex, textLine) in nextPage.textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + textChar.selected = true + invalidate() + selectPageStart = 1 + selectLineStart = lineIndex + selectCharStart = charIndex + selectPageEnd = 1 + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + select(1, lineIndex, charIndex) + return + } + } + return + } + } + relativeOffset = relativeOffset(2) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() + selectPageStart = 2 selectLineStart = lineIndex selectCharStart = charIndex + selectPageEnd = 2 selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) - upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) - select(lineIndex, charIndex) + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + select(2, lineIndex, charIndex) + return } } - break + return } } } + /** + * 开始选择符移动 + */ fun selectStartMove(x: Float, y: Float) { if (!visibleRect.contains(x, y)) return + var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineStart != lineIndex || selectCharStart != charIndex) { + selectPageStart = 0 selectLineStart = lineIndex selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + pageOffset) + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectChars(textPage) } - break + return } } - break + return + } + } + if (!ReadBookConfig.isScroll) return + //滚动翻页 + relativeOffset = relativeOffset(1) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineStart != lineIndex || selectCharStart != charIndex) { + selectPageStart = 1 + selectLineStart = lineIndex + selectCharStart = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return + } + } + relativeOffset = relativeOffset(2) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineStart != lineIndex || selectCharStart != charIndex) { + selectPageStart = 1 + selectLineStart = lineIndex + selectCharStart = charIndex + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return } } } - 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 + pageOffset) - upSelectChars(textPage) - } - + /** + * 结束选择符移动 + */ fun selectEndMove(x: Float, y: Float) { if (!visibleRect.contains(x, y)) return + var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - if (y > textLine.lineTop + pageOffset && y < textLine.lineBottom + pageOffset) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return + } + } + if (!ReadBookConfig.isScroll) return + //滚动翻页 + relativeOffset = relativeOffset(1) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(1).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + if (x > textChar.start && x < textChar.end) { + if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { + selectLineEnd = lineIndex + selectCharEnd = charIndex + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars(textPage) + } + return + } + } + return + } + } + relativeOffset = relativeOffset(2) + if (relativeOffset >= ChapterProvider.visibleHeight) return + for ((lineIndex, textLine) in relativePage(2).textLines.withIndex()) { + if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { selectLineEnd = lineIndex selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) upSelectChars(textPage) } - break + return } } - break + return } } } - fun selectEndMoveIndex(lineIndex: Int, charIndex: Int) { + fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + selectPageStart = relativePage + selectLineStart = lineIndex + selectCharStart = charIndex + val textLine = relativePage(relativePage).textLines[lineIndex] + val textChar = textLine.textChars[charIndex] + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) + upSelectChars(textPage) + } + + fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + selectPageEnd = relativePage selectLineEnd = lineIndex selectCharEnd = charIndex - val textLine = textPage.textLines[lineIndex] + val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedEnd(textChar.end, textLine.lineBottom + pageOffset) + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectChars(textPage) } @@ -315,6 +474,22 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at return stringBuilder.toString() } + private fun relativeOffset(relativePos: Int): Float { + return when (relativePos) { + 0 -> pageOffset + 1 -> pageOffset + textPage.height + else -> pageOffset + textPage.height + pageFactory.nextPage.height + } + } + + private fun relativePage(relativePos: Int): TextPage { + return when (relativePos) { + 0 -> textPage + 1 -> pageFactory.nextPage + else -> pageFactory.nextPagePlus + } + } + interface CallBack { fun upSelectedStart(x: Float, y: Float) fun upSelectedEnd(x: Float, y: Float) 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 9f2631ea6..c39ca8f14 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 @@ -119,7 +119,10 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.selectAble = selectAble } - fun selectText(e: MotionEvent, select: (lineIndex: Int, charIndex: Int) -> Unit) { + fun selectText( + e: MotionEvent, + select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit + ) { val y = e.y - headerHeight return content_text_view.selectText(e.x, y, select) } @@ -128,16 +131,16 @@ class ContentView(context: Context) : FrameLayout(context) { content_text_view.selectStartMove(x, y - headerHeight) } - fun selectStartMoveIndex(lineIndex: Int, charIndex: Int) { - content_text_view.selectStartMoveIndex(lineIndex, charIndex) + fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + content_text_view.selectStartMoveIndex(relativePage, 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 selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { + content_text_view.selectEndMoveIndex(relativePage, lineIndex, charIndex) } fun cancelSelect() { 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 7c453d9c7..e7b76fc6e 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,7 @@ abstract class PageDelegate(protected val pageView: PageView) : var isTextSelected = false var selectedOnDown = false + var firstRelativePage = 0 var firstLineIndex: Int = 0 var firstCharIndex: Int = 0 @@ -286,23 +287,41 @@ abstract class PageDelegate(protected val pageView: PageView) : * 长按选择 */ override fun onLongPress(e: MotionEvent) { - curPage.selectText(e) { lineIndex, charIndex -> + curPage.selectText(e) { relativePage, lineIndex, charIndex -> isTextSelected = true + firstRelativePage = relativePage firstLineIndex = lineIndex firstCharIndex = charIndex } } 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) + curPage.selectText(event) { relativePage, lineIndex, charIndex -> + when { + relativePage > firstRelativePage -> { + curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(relativePage, lineIndex, charIndex) + } + relativePage < firstRelativePage -> { + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(relativePage, lineIndex, charIndex) + } + lineIndex > firstLineIndex -> { + curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(relativePage, lineIndex, charIndex) + } + lineIndex < firstLineIndex -> { + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(relativePage, lineIndex, charIndex) + } + charIndex > firstCharIndex -> { + curPage.selectStartMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectEndMoveIndex(relativePage, lineIndex, charIndex) + } + else -> { + curPage.selectEndMoveIndex(firstRelativePage, firstLineIndex, firstCharIndex) + curPage.selectStartMoveIndex(relativePage, lineIndex, charIndex) + } } } } From edb0335919553669330b182a103ebe1ab7864369 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 14:25:37 +0800 Subject: [PATCH 093/169] =?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 | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 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 cc366e886..9c23ff89a 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 @@ -278,7 +278,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineStart = lineIndex selectCharStart = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -299,7 +299,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineStart = lineIndex selectCharStart = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -318,7 +318,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineStart = lineIndex selectCharStart = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -342,7 +342,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -362,7 +362,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -380,7 +380,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectLineEnd = lineIndex selectCharEnd = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars(textPage) + upSelectChars() } return } @@ -390,6 +390,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } } + /** + * 选择开始文字 + */ fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { selectPageStart = relativePage selectLineStart = lineIndex @@ -397,9 +400,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) - upSelectChars(textPage) + upSelectChars() } + /** + * 选择结束文字 + */ fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { selectPageEnd = relativePage selectLineEnd = lineIndex @@ -407,22 +413,35 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) - upSelectChars(textPage) + upSelectChars() } - private fun upSelectChars(textPage: TextPage) { - for ((lineIndex, textLine) in textPage.textLines.withIndex()) { - for ((charIndex, textChar) in textLine.textChars.withIndex()) { - textChar.selected = - if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { - charIndex in selectCharStart..selectCharEnd - } else if (lineIndex == selectLineStart) { - charIndex >= selectCharStart - } else if (lineIndex == selectLineEnd) { - charIndex <= selectCharEnd - } else { - lineIndex in (selectLineStart + 1) until selectLineEnd - } + private fun upSelectChars() { + val last = if (ReadBookConfig.isScroll) 2 else 0 + for (relativePos in 0..last) { + for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { + for ((charIndex, textChar) in textLine.textChars.withIndex()) { + textChar.selected = + if (relativePos == selectPageStart + && relativePos == selectPageEnd + && lineIndex == selectLineStart + && lineIndex == selectLineEnd + ) { + charIndex in selectCharStart..selectCharEnd + } else if (relativePos == selectPageStart && lineIndex == selectLineStart) { + charIndex >= selectCharStart + } else if (relativePos == selectPageEnd && lineIndex == selectLineEnd) { + charIndex <= selectCharEnd + } else if (relativePos == selectPageStart && relativePos == selectPageEnd) { + lineIndex in (selectLineStart + 1) until selectLineEnd + } else if (relativePos == selectPageStart) { + lineIndex > selectLineStart + } else if (relativePos == selectPageEnd) { + lineIndex < selectLineEnd + } else { + relativePos in selectPageStart + 1 until selectPageEnd + } + } } } invalidate() From 4546a2ad97aa0c65faa5eddc17f8a2c8c1acd0bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 14:26:53 +0800 Subject: [PATCH 094/169] =?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/ContentTextView.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 9c23ff89a..6b4c329e1 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 @@ -456,9 +456,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } fun cancelSelect() { - textPage.textLines.forEach { textLine -> - textLine.textChars.forEach { - it.selected = false + val last = if (ReadBookConfig.isScroll) 2 else 0 + for (relativePos in 0..last) { + relativePage(relativePos).textLines.forEach { textLine -> + textLine.textChars.forEach { + it.selected = false + } } } invalidate() From 1e8bdb489fe4dd11600595f081a0d72b3e16b441 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:01:09 +0800 Subject: [PATCH 095/169] =?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 | 71 +++++++++++++------ 1 file changed, 51 insertions(+), 20 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 6b4c329e1..282e5578b 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 @@ -471,26 +471,57 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val selectedText: String get() { val stringBuilder = StringBuilder() - for (lineIndex in selectLineStart..selectLineEnd) { - if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { - stringBuilder.append( - textPage.textLines[lineIndex].text.substring( - selectCharStart, - selectCharEnd + 1 - ) - ) - } else if (lineIndex == selectLineStart) { - stringBuilder.append( - textPage.textLines[lineIndex].text.substring( - selectCharStart - ) - ) - } else if (lineIndex == selectLineEnd) { - stringBuilder.append( - textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) - ) - } else { - stringBuilder.append(textPage.textLines[lineIndex].text) + for (relativePos in selectPageStart..selectPageEnd) { + val textPage = relativePage(relativePos) + if (relativePos == selectPageStart && relativePos == selectPageEnd) { + for (lineIndex in selectLineStart..selectLineEnd) { + if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring( + selectCharStart, + selectCharEnd + 1 + ) + ) + } else if (lineIndex == selectLineStart) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring( + selectCharStart + ) + ) + } else if (lineIndex == selectLineEnd) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + ) + } else { + stringBuilder.append(textPage.textLines[lineIndex].text) + } + } + } else if (relativePos == selectPageStart) { + for (lineIndex in selectLineStart until relativePage(relativePos).textLines.size) { + if (lineIndex == selectLineStart) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring( + selectCharStart + ) + ) + } else { + stringBuilder.append(textPage.textLines[lineIndex].text) + } + } + } else if (relativePos == selectPageEnd) { + for (lineIndex in 0..selectLineEnd) { + if (lineIndex == selectLineEnd) { + stringBuilder.append( + textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + ) + } else { + stringBuilder.append(textPage.textLines[lineIndex].text) + } + } + } else if (relativePos in selectPageStart + 1 until selectPageEnd) { + for (lineIndex in selectLineStart..selectLineEnd) { + stringBuilder.append(textPage.textLines[lineIndex].text) + } } } return stringBuilder.toString() From 36178b6103e9c34fd02355054b81eb11051c48a2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:11:15 +0800 Subject: [PATCH 096/169] =?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 1cb677260..b9379ed02 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/25** +* 优化文本选择和滚动,感觉很完美了 + **2020/02/24** * 滚动暂时可以滚了,先这样吧,头大 * 紧急修复朗读报错的bug From ac815fecf4589767a2e37e6cf97c84334e0869df Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:26:23 +0800 Subject: [PATCH 097/169] =?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/data/dao/BookSourceDao.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 0981a94ea..fd5e2a6c9 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -14,10 +14,16 @@ interface BookSourceDao { @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") fun liveDataSearch(searchKey: String = ""): LiveData> - @Query("select * from book_sources where enabled = 1 and enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") + @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query("select * from book_sources where enabled = 1 and enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc") + @Query( + """ + select * from book_sources + where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) + order by customOrder asc + """ + ) fun liveExplore(key: String): LiveData> @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") @@ -26,7 +32,12 @@ interface BookSourceDao { @Query("select bookSourceGroup from book_sources where enabled = 1 and bookSourceGroup is not null and bookSourceGroup <> ''") fun liveGroupEnabled(): LiveData> - @Query("select bookSourceGroup from book_sources where enabled = 1 and enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and bookSourceGroup is not null and bookSourceGroup <> ''") + @Query( + """ + select bookSourceGroup from book_sources + where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and bookSourceGroup is not null and bookSourceGroup <> '' + """ + ) fun liveGroupExplore(): LiveData> @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") From 9dfe4870e7f500a060c9011607be8c8fa5c1ecf8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:38:09 +0800 Subject: [PATCH 098/169] =?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/data/dao/BookSourceDao.kt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index fd5e2a6c9..e80f590f5 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -14,30 +14,25 @@ interface BookSourceDao { @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey order by customOrder asc") fun liveDataSearch(searchKey: String = ""): LiveData> - @Query("select * from book_sources where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' order by customOrder asc") + @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> @Query( """ select * from book_sources - where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and (bookSourceGroup like :key or bookSourceName like :key) + where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc """ ) fun liveExplore(key: String): LiveData> - @Query("select bookSourceGroup from book_sources where bookSourceGroup is not null and bookSourceGroup <> ''") + @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") fun liveGroup(): LiveData> - @Query("select bookSourceGroup from book_sources where enabled = 1 and bookSourceGroup is not null and bookSourceGroup <> ''") + @Query("select bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") fun liveGroupEnabled(): LiveData> - @Query( - """ - select bookSourceGroup from book_sources - where enabledExplore = 1 and exploreUrl is not null and exploreUrl <> '' and bookSourceGroup is not null and bookSourceGroup <> '' - """ - ) + @Query("select bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> ''") fun liveGroupExplore(): LiveData> @Query("select distinct enabled from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey") From 8132afde6c408b61a6e34271fc61e74e96e9fea7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 15:45:36 +0800 Subject: [PATCH 099/169] =?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/HorizontalPageDelegate.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 263e2029d..586b3d88e 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 @@ -22,7 +22,8 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie private fun onScroll(event: MotionEvent) { //判断是否移动了 if (!isMoved) { - isMoved = abs(startX - event.x) > slop || abs(startY - event.y) > slop + isMoved = abs(startX - event.x) > slop + || abs(startX - event.x) > abs(startY - event.y) if (isMoved) { if (event.x - startX > 0) { //如果上一页不存在 From 01f886b7d1f2cbe1ed9b46838bb03fddb18c8899 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 16:58:05 +0800 Subject: [PATCH 100/169] =?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 | 208 +++++++++--------- 1 file changed, 109 insertions(+), 99 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 282e5578b..29c2a3ddb 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,12 +28,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private var callBack: CallBack private val visibleRect = RectF() - private var selectPageStart = 0 - private var selectLineStart = 0 - private var selectCharStart = 0 - private var selectPageEnd = 0 - private var selectLineEnd = 0 - private var selectCharEnd = 0 + private var selectStart = arrayOf(0, 0, 0) + private var selectEnd = arrayOf(0, 0, 0) private var textPage: TextPage = TextPage() //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory @@ -197,12 +193,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() - selectPageStart = 0 - selectLineStart = lineIndex - selectCharStart = charIndex - selectPageEnd = 0 - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectStart[0] = 0 + selectStart[1] = lineIndex + selectStart[2] = charIndex + selectEnd[0] = 0 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(0, lineIndex, charIndex) @@ -223,12 +219,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() - selectPageStart = 1 - selectLineStart = lineIndex - selectCharStart = charIndex - selectPageEnd = 1 - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectStart[0] = 1 + selectStart[1] = lineIndex + selectStart[2] = charIndex + selectEnd[0] = 1 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(1, lineIndex, charIndex) @@ -246,12 +242,12 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (x > textChar.start && x < textChar.end) { textChar.selected = true invalidate() - selectPageStart = 2 - selectLineStart = lineIndex - selectCharStart = charIndex - selectPageEnd = 2 - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectStart[0] = 2 + selectStart[1] = lineIndex + selectStart[2] = charIndex + selectEnd[0] = 2 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(2, lineIndex, charIndex) @@ -273,12 +269,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineStart != lineIndex || selectCharStart != charIndex) { - selectPageStart = 0 - selectLineStart = lineIndex - selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + selectStart[0] = 0 + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelect() } return } @@ -294,12 +289,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineStart != lineIndex || selectCharStart != charIndex) { - selectPageStart = 1 - selectLineStart = lineIndex - selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + selectStart[0] = 1 + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelect() } return } @@ -313,12 +307,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineStart != lineIndex || selectCharStart != charIndex) { - selectPageStart = 1 - selectLineStart = lineIndex - selectCharStart = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + selectStart[0] = 2 + selectStart[1] = lineIndex + selectStart[2] = charIndex + upSelect() } return } @@ -338,11 +331,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { - selectLineEnd = lineIndex - selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + selectEnd[0] = 0 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelect() } return } @@ -358,11 +351,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { - selectLineEnd = lineIndex - selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + selectEnd[0] = 1 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelect() } return } @@ -376,11 +369,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectLineEnd != lineIndex || selectCharEnd != charIndex) { - selectLineEnd = lineIndex - selectCharEnd = charIndex - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) - upSelectChars() + if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + selectEnd[0] = 2 + selectEnd[1] = lineIndex + selectEnd[2] = charIndex + upSelect() } return } @@ -394,9 +387,9 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 选择开始文字 */ fun selectStartMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { - selectPageStart = relativePage - selectLineStart = lineIndex - selectCharStart = charIndex + selectStart[0] = relativePage + selectStart[1] = lineIndex + selectStart[2] = charIndex val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) @@ -407,39 +400,56 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at * 选择结束文字 */ fun selectEndMoveIndex(relativePage: Int, lineIndex: Int, charIndex: Int) { - selectPageEnd = relativePage - selectLineEnd = lineIndex - selectCharEnd = charIndex + selectEnd[0] = relativePage + selectEnd[1] = lineIndex + selectEnd[2] = charIndex val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(relativePage)) upSelectChars() } + private fun upSelect() { + val start = selectStart[0] * 1000000 + selectStart[1] * 100000 + selectStart[2] + val end = selectEnd[0] * 1000000 + selectEnd[1] * 100000 + selectEnd[2] + if (start > end) { + val value = selectStart + selectStart = selectEnd + selectEnd = value + } + var textLine = relativePage(selectStart[0]).textLines[selectStart[1]] + var textChar = textLine.textChars[selectStart[2]] + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(selectStart[0])) + textLine = relativePage(selectEnd[0]).textLines[selectEnd[0]] + textChar = textLine.textChars[selectEnd[2]] + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(selectEnd[0])) + upSelectChars() + } + private fun upSelectChars() { val last = if (ReadBookConfig.isScroll) 2 else 0 for (relativePos in 0..last) { for ((lineIndex, textLine) in relativePage(relativePos).textLines.withIndex()) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { textChar.selected = - if (relativePos == selectPageStart - && relativePos == selectPageEnd - && lineIndex == selectLineStart - && lineIndex == selectLineEnd + if (relativePos == selectStart[0] + && relativePos == selectEnd[0] + && lineIndex == selectStart[1] + && lineIndex == selectEnd[1] ) { - charIndex in selectCharStart..selectCharEnd - } else if (relativePos == selectPageStart && lineIndex == selectLineStart) { - charIndex >= selectCharStart - } else if (relativePos == selectPageEnd && lineIndex == selectLineEnd) { - charIndex <= selectCharEnd - } else if (relativePos == selectPageStart && relativePos == selectPageEnd) { - lineIndex in (selectLineStart + 1) until selectLineEnd - } else if (relativePos == selectPageStart) { - lineIndex > selectLineStart - } else if (relativePos == selectPageEnd) { - lineIndex < selectLineEnd + charIndex in selectStart[2]..selectEnd[2] + } else if (relativePos == selectStart[0] && lineIndex == selectStart[1]) { + charIndex >= selectStart[2] + } else if (relativePos == selectEnd[0] && lineIndex == selectEnd[1]) { + charIndex <= selectEnd[2] + } else if (relativePos == selectStart[0] && relativePos == selectEnd[0]) { + lineIndex in (selectStart[1] + 1) until selectEnd[1] + } else if (relativePos == selectStart[0]) { + lineIndex > selectStart[1] + } else if (relativePos == selectEnd[0]) { + lineIndex < selectEnd[1] } else { - relativePos in selectPageStart + 1 until selectPageEnd + relativePos in selectStart[0] + 1 until selectEnd[0] } } } @@ -471,55 +481,55 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at val selectedText: String get() { val stringBuilder = StringBuilder() - for (relativePos in selectPageStart..selectPageEnd) { + for (relativePos in selectStart[0]..selectEnd[0]) { val textPage = relativePage(relativePos) - if (relativePos == selectPageStart && relativePos == selectPageEnd) { - for (lineIndex in selectLineStart..selectLineEnd) { - if (lineIndex == selectLineStart && lineIndex == selectLineEnd) { + if (relativePos == selectStart[0] && relativePos == selectEnd[0]) { + for (lineIndex in selectStart[1]..selectEnd[1]) { + if (lineIndex == selectStart[1] && lineIndex == selectEnd[1]) { stringBuilder.append( textPage.textLines[lineIndex].text.substring( - selectCharStart, - selectCharEnd + 1 + selectStart[2], + selectEnd[2] + 1 ) ) - } else if (lineIndex == selectLineStart) { + } else if (lineIndex == selectStart[1]) { stringBuilder.append( textPage.textLines[lineIndex].text.substring( - selectCharStart + selectStart[2] ) ) - } else if (lineIndex == selectLineEnd) { + } else if (lineIndex == selectEnd[1]) { stringBuilder.append( - textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + textPage.textLines[lineIndex].text.substring(0, selectEnd[2] + 1) ) } else { stringBuilder.append(textPage.textLines[lineIndex].text) } } - } else if (relativePos == selectPageStart) { - for (lineIndex in selectLineStart until relativePage(relativePos).textLines.size) { - if (lineIndex == selectLineStart) { + } else if (relativePos == selectStart[0]) { + for (lineIndex in selectStart[1] until relativePage(relativePos).textLines.size) { + if (lineIndex == selectStart[1]) { stringBuilder.append( textPage.textLines[lineIndex].text.substring( - selectCharStart + selectStart[2] ) ) } else { stringBuilder.append(textPage.textLines[lineIndex].text) } } - } else if (relativePos == selectPageEnd) { - for (lineIndex in 0..selectLineEnd) { - if (lineIndex == selectLineEnd) { + } else if (relativePos == selectEnd[0]) { + for (lineIndex in 0..selectEnd[1]) { + if (lineIndex == selectEnd[1]) { stringBuilder.append( - textPage.textLines[lineIndex].text.substring(0, selectCharEnd + 1) + textPage.textLines[lineIndex].text.substring(0, selectEnd[2] + 1) ) } else { stringBuilder.append(textPage.textLines[lineIndex].text) } } - } else if (relativePos in selectPageStart + 1 until selectPageEnd) { - for (lineIndex in selectLineStart..selectLineEnd) { + } else if (relativePos in selectStart[0] + 1 until selectEnd[0]) { + for (lineIndex in selectStart[1]..selectEnd[1]) { stringBuilder.append(textPage.textLines[lineIndex].text) } } From 1e533559fe84cfc818a8ebd82ca996d89836e649 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 17:00:28 +0800 Subject: [PATCH 101/169] =?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, 1 insertion(+), 1 deletion(-) 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 29c2a3ddb..33dcb8a8d 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 @@ -420,7 +420,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at var textLine = relativePage(selectStart[0]).textLines[selectStart[1]] var textChar = textLine.textChars[selectStart[2]] upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(selectStart[0])) - textLine = relativePage(selectEnd[0]).textLines[selectEnd[0]] + textLine = relativePage(selectEnd[0]).textLines[selectEnd[1]] textChar = textLine.textChars[selectEnd[2]] upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(selectEnd[0])) upSelectChars() From 70450a1fa7acb9dc5ac3bb771632173af5f60857 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 17:28:14 +0800 Subject: [PATCH 102/169] =?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 | 71 +++++++++++-------- 1 file changed, 40 insertions(+), 31 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 33dcb8a8d..270acbff3 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,8 +28,8 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } private var callBack: CallBack private val visibleRect = RectF() - private var selectStart = arrayOf(0, 0, 0) - private var selectEnd = arrayOf(0, 0, 0) + private val selectStart = arrayOf(0, 0, 0) + private val selectEnd = arrayOf(0, 0, 0) private var textPage: TextPage = TextPage() //滚动参数 private val pageFactory: TextPageFactory get() = callBack.pageFactory @@ -269,11 +269,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectStart[0] != 0 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(0, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } selectStart[0] = 0 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelect() + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) } return } @@ -289,11 +292,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectStart[0] != 1 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(1, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } selectStart[0] = 1 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelect() + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) } return } @@ -307,11 +313,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectStart[0] != 2 || selectStart[1] != lineIndex || selectStart[2] != charIndex) { + if (selectToInt(2, lineIndex, charIndex) > selectToInt(selectEnd)) { + return + } selectStart[0] = 2 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelect() + upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) } return } @@ -331,11 +340,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectEnd[0] != 0 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(0, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } selectEnd[0] = 0 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelect() + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) } return } @@ -351,11 +363,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectEnd[0] != 1 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(1, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } selectEnd[0] = 1 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelect() + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) } return } @@ -369,11 +384,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at if (y > textLine.lineTop + relativeOffset && y < textLine.lineBottom + relativeOffset) { for ((charIndex, textChar) in textLine.textChars.withIndex()) { if (x > textChar.start && x < textChar.end) { - if (selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectEnd[0] != 2 || selectEnd[1] != lineIndex || selectEnd[2] != charIndex) { + if (selectToInt(2, lineIndex, charIndex) < selectToInt(selectStart)) { + return + } selectEnd[0] = 2 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelect() + upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) } return } @@ -409,23 +427,6 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at upSelectChars() } - private fun upSelect() { - val start = selectStart[0] * 1000000 + selectStart[1] * 100000 + selectStart[2] - val end = selectEnd[0] * 1000000 + selectEnd[1] * 100000 + selectEnd[2] - if (start > end) { - val value = selectStart - selectStart = selectEnd - selectEnd = value - } - var textLine = relativePage(selectStart[0]).textLines[selectStart[1]] - var textChar = textLine.textChars[selectStart[2]] - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(selectStart[0])) - textLine = relativePage(selectEnd[0]).textLines[selectEnd[1]] - textChar = textLine.textChars[selectEnd[2]] - upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset(selectEnd[0])) - upSelectChars() - } - private fun upSelectChars() { val last = if (ReadBookConfig.isScroll) 2 else 0 for (relativePos in 0..last) { @@ -537,6 +538,14 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at return stringBuilder.toString() } + private fun selectToInt(page: Int, line: Int, char: Int): Int { + return page * 1000000 + line * 100000 + char + } + + private fun selectToInt(select: Array): Int { + return select[0] * 1000000 + select[1] * 100000 + select[2] + } + private fun relativeOffset(relativePos: Int): Float { return when (relativePos) { 0 -> pageOffset From 187d904ac7ccbeb3334faea465b8456bbd3fef21 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 17:36:23 +0800 Subject: [PATCH 103/169] =?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 ++++++ 1 file changed, 6 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 270acbff3..c31fedde6 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 @@ -277,6 +277,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[1] = lineIndex selectStart[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -300,6 +301,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[1] = lineIndex selectStart[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -321,6 +323,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[1] = lineIndex selectStart[2] = charIndex upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -348,6 +351,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[1] = lineIndex selectEnd[2] = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -371,6 +375,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[1] = lineIndex selectEnd[2] = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } return } @@ -392,6 +397,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[1] = lineIndex selectEnd[2] = charIndex upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) + upSelectChars() } return } From 37b212dcb00b20a6cc1e0165ace6f393235b42e2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 19:15:52 +0800 Subject: [PATCH 104/169] =?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/config/PaddingConfigDialog.kt | 10 +++++++++- app/src/main/res/layout/dialog_read_padding.xml | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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 c72e1a417..1155e1d7d 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 @@ -10,6 +10,7 @@ import io.legado.app.R 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.dp import io.legado.app.utils.postEvent import io.legado.app.utils.visible import kotlinx.android.synthetic.main.dialog_read_padding.* @@ -51,13 +52,20 @@ class PaddingConfigDialog : DialogFragment() { } private fun initData() = with(ReadBookConfig) { + if (hideStatusBar) { + tv_header_padding.visible() + dsb_header_padding_top.visible() + dsb_header_padding_bottom.visible() + dsb_header_padding_left.visible() + dsb_header_padding_right.visible() + tv_body_padding.setPadding(0, 10.dp, 0, 10.dp) + } //正文 dsb_padding_top.progress = paddingTop dsb_padding_bottom.progress = paddingBottom 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/res/layout/dialog_read_padding.xml b/app/src/main/res/layout/dialog_read_padding.xml index 37e3b8cc4..1b600959e 100644 --- a/app/src/main/res/layout/dialog_read_padding.xml +++ b/app/src/main/res/layout/dialog_read_padding.xml @@ -13,12 +13,14 @@ android:layout_height="wrap_content" android:paddingBottom="10dp" android:textSize="18sp" + android:visibility="gone" android:text="@string/header" /> @@ -26,6 +28,7 @@ android:id="@+id/dsb_header_padding_bottom" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="gone" app:title="@string/padding_bottom" app:max="100" /> @@ -33,6 +36,7 @@ android:id="@+id/dsb_header_padding_left" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="gone" app:title="@string/padding_left" app:max="100" /> @@ -40,13 +44,14 @@ android:id="@+id/dsb_header_padding_right" android:layout_width="match_parent" android:layout_height="wrap_content" + android:visibility="gone" app:title="@string/padding_right" app:max="100" /> From 4055c5b5b51038f6690ef2584ad51e6c68e899c0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 19:27:23 +0800 Subject: [PATCH 105/169] =?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/data/dao/BookSourceDao.kt | 10 ++-------- .../main/java/io/legado/app/data/dao/RssSourceDao.kt | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index e80f590f5..94fe063f4 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -17,13 +17,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query( - """ - select * from book_sources - where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) - order by customOrder asc - """ - ) + @Query(" select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc ") fun liveExplore(key: String): LiveData> @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") @@ -47,7 +41,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") fun getEnabledByGroup(group: String): List - @get:Query("select * from book_sources where bookUrlPattern is not null || bookUrlPattern <> ''") + @get:Query("select * from book_sources where trim(bookUrlPattern) <> ''") val hasBookUrlPattern: List @get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''") diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index c1c1e85d9..5436ee26c 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -28,7 +28,7 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources where enabled = 1 order by customOrder") fun liveEnabled(): LiveData> - @Query("select sourceGroup from rssSources where sourceGroup is not null and sourceGroup <> ''") + @Query("select sourceGroup from rssSources where trim(sourceGroup) <> ''") fun liveGroup(): LiveData> @get:Query("select min(customOrder) from rssSources") From 438647f43e5652f8868df9125dcaff1682551ba1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 19:34:33 +0800 Subject: [PATCH 106/169] =?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/data/dao/BookSourceDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 94fe063f4..9ce5c65be 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -17,7 +17,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query(" select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc ") + @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc") fun liveExplore(key: String): LiveData> @Query("select bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") From ad6a56239e43fbf3361dadeb559bfe058f954b1f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 20:13:27 +0800 Subject: [PATCH 107/169] =?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/delegate/PageDelegate.kt | 2 +- .../ui/book/read/page/delegate/SimulationPageDelegate.kt | 6 +++++- 2 files changed, 6 insertions(+), 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 e7b76fc6e..c710367c7 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 @@ -136,7 +136,7 @@ abstract class PageDelegate(protected val pageView: PageView) : bitmap = null } - fun setViewSize(width: Int, height: Int) { + open fun setViewSize(width: Int, height: Int) { viewWidth = width viewHeight = height pageView.invalidate() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 789fb61e1..cdffc0457 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -115,6 +115,11 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mFrontShadowDrawableHBT.gradientType = GradientDrawable.LINEAR_GRADIENT } + override fun setViewSize(width: Int, height: Int) { + super.setViewSize(width, height) + mMaxLength = hypot(viewWidth.toDouble(), viewWidth.toDouble()).toFloat() + } + override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { super.setStartPoint(x, y, invalidate) calcCornerXY(x, y) @@ -171,7 +176,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun onAnimStart() { var dx: Float val dy: Float - // dx 水平方向滑动的距离,负值会使滚动向左滚动 // dy 垂直方向滑动的距离,负值会使滚动向上滚动 if (isCancel) { dx = if (mCornerX > 0 && mDirection == Direction.NEXT) { From ce5cf8a3f251972928f60ba2407ea6bf9ca441b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 20:25:10 +0800 Subject: [PATCH 108/169] =?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/SimulationPageDelegate.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index cdffc0457..ca4048c8d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -484,8 +484,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi private fun calcPoints() { mTouchX = touchX mTouchY = touchY + mMiddleX = (mTouchX + mCornerX) / 2 mMiddleY = (mTouchY + mCornerY) / 2 + mBezierControl1.x = mMiddleX - (mCornerY - mMiddleY) * (mCornerY - mMiddleY) / (mCornerX - mMiddleX) mBezierControl1.y = mCornerY.toFloat() @@ -496,6 +498,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } else { mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) } + mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 mBezierStart1.y = mCornerY.toFloat() //固定左边上下两个点 @@ -504,24 +507,27 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi if (mBezierStart1.x < 0) mBezierStart1.x = viewWidth - mBezierStart1.x - val f1: Float = abs(mCornerX - mTouchX) - val f2: Float = viewWidth * f1 / mBezierStart1.x + val f1 = abs(mCornerX - mTouchX) + val f2 = viewWidth * f1 / mBezierStart1.x mTouchX = abs(mCornerX - f2) - val f3: Float = abs(mCornerX - mTouchX) * abs(mCornerY - mTouchY) / f1 + val f3 = abs(mCornerX - mTouchX) * abs(mCornerY - mTouchY) / f1 mTouchY = abs(mCornerY - f3) mMiddleX = (mTouchX + mCornerX) / 2 mMiddleY = (mTouchY + mCornerY) / 2 + mBezierControl1.x = mMiddleX - (mCornerY - mMiddleY) * (mCornerY - mMiddleY) / (mCornerX - mMiddleX) mBezierControl1.y = mCornerY.toFloat() + mBezierControl2.x = mCornerX.toFloat() mBezierControl2.y = if ((mCornerY - mMiddleY).toInt() == 0) { mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f } else { mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) } - mBezierStart1.x = (mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2) + + mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 } } mBezierStart2.x = mCornerX.toFloat() From 1f771d4fc0f0775c98161a2311fd7938d1f7fa17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 21:28:29 +0800 Subject: [PATCH 109/169] =?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/SimulationPageDelegate.kt | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index ca4048c8d..6e41fcac5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -221,13 +221,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun onDraw(canvas: Canvas) { if (mDirection === Direction.NEXT) { calcPoints() - drawCurrentPageArea(canvas, curBitmap, mPath0) + drawCurrentPageArea(canvas, curBitmap) drawNextPageAreaAndShadow(canvas, nextBitmap) drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, curBitmap) } else { calcPoints() - drawCurrentPageArea(canvas, prevBitmap, mPath0) + drawCurrentPageArea(canvas, prevBitmap) drawNextPageAreaAndShadow(canvas, curBitmap) drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, prevBitmap) @@ -258,7 +258,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi val left: Int val right: Int if (mIsRtOrLb) { - left = mBezierStart1.x.toInt() - 1 + left = (mBezierStart1.x - 1).toInt() right = (mBezierStart1.x + f3 + 1).toInt() mFolderShadowDrawable = mFolderShadowDrawableLR } else { @@ -337,17 +337,16 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi var mCurrentPageShadow: GradientDrawable if (mIsRtOrLb) { leftX = mBezierControl1.x.toInt() - rightX = mBezierControl1.x.toInt() + 25 + rightX = (mBezierControl1.x + 25).toInt() mCurrentPageShadow = mFrontShadowDrawableVLR } else { - leftX = mBezierControl1.x.toInt() - 25 - rightX = mBezierControl1.x.toInt() + 1 + leftX = (mBezierControl1.x - 25).toInt() + rightX = (mBezierControl1.x + 1).toInt() mCurrentPageShadow = mFrontShadowDrawableVRL } - var rotateDegrees: Float = - Math.toDegrees( - atan2(mTouchX - mBezierControl1.x, mBezierControl1.y - mTouchY).toDouble() - ).toFloat() + var rotateDegrees = Math.toDegrees( + atan2(mTouchX - mBezierControl1.x, mBezierControl1.y - mTouchY).toDouble() + ).toFloat() canvas.rotate(rotateDegrees, mBezierControl1.x, mBezierControl1.y) mCurrentPageShadow.setBounds( leftX, (mBezierControl1.y - mMaxLength).toInt(), @@ -372,24 +371,25 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi if (mIsRtOrLb) { leftX = mBezierControl2.y.toInt() - rightX = mBezierControl2.y.toInt() + 25 + rightX = (mBezierControl2.y + 25).toInt() mCurrentPageShadow = mFrontShadowDrawableHTB } else { - leftX = mBezierControl2.y.toInt() - 25 - rightX = mBezierControl2.y.toInt() + 1 + leftX = (mBezierControl2.y - 25).toInt() + rightX = (mBezierControl2.y + 1).toInt() mCurrentPageShadow = mFrontShadowDrawableHBT } rotateDegrees = Math.toDegrees( atan2(mBezierControl2.y - mTouchY, mBezierControl2.x - mTouchX).toDouble() ).toFloat() canvas.rotate(rotateDegrees, mBezierControl2.x, mBezierControl2.y) - val temp: Float = - if (mBezierControl2.y < 0) mBezierControl2.y - viewHeight else mBezierControl2.y - val hmg = hypot(mBezierControl2.x.toDouble(), temp.toDouble()).toInt() + val temp = + if (mBezierControl2.y < 0) (mBezierControl2.y - viewHeight).toDouble() + else mBezierControl2.y.toDouble() + val hmg = hypot(mBezierControl2.x.toDouble(), temp) if (hmg > mMaxLength) mCurrentPageShadow.setBounds( - (mBezierControl2.x - 25).toInt() - hmg, leftX, - (mBezierControl2.x + mMaxLength).toInt() - hmg, rightX + (mBezierControl2.x - 25 - hmg).toInt(), leftX, + (mBezierControl2.x + mMaxLength - hmg).toInt(), rightX ) else mCurrentPageShadow.setBounds( @@ -400,6 +400,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi canvas.restore() } + // private fun drawNextPageAreaAndShadow( canvas: Canvas, bitmap: Bitmap? @@ -447,10 +448,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi canvas.restore() } + // private fun drawCurrentPageArea( canvas: Canvas, - bitmap: Bitmap?, - path: Path + bitmap: Bitmap? ) { bitmap ?: return mPath0.reset() @@ -461,11 +462,12 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y) mPath0.lineTo(mCornerX.toFloat(), mCornerY.toFloat()) mPath0.close() + canvas.save() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - canvas.clipOutPath(path) + canvas.clipOutPath(mPath0) } else { - canvas.clipPath(path, Region.Op.XOR) + canvas.clipPath(mPath0, Region.Op.XOR) } canvas.drawBitmap(bitmap, 0f, 0f, null) canvas.restore() From 764c362af1e1931ec33e7a617da934585b18cd6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 21:33:37 +0800 Subject: [PATCH 110/169] =?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/SimulationPageDelegate.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 6e41fcac5..385ed7140 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -40,7 +40,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi private var mMiddleY = 0f private var mDegrees = 0f private var mTouchToCornerDis = 0f - private var mColorMatrixFilter: ColorMatrixColorFilter = ColorMatrixColorFilter( + private var mColorMatrixFilter = ColorMatrixColorFilter( ColorMatrix( floatArrayOf( 1f, 0f, 0f, 0f, 0f, From 0cdea9b7d97388a5bbbac358b2af877ee0a2fd85 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 21:52:15 +0800 Subject: [PATCH 111/169] =?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/SimulationPageDelegate.kt | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 385ed7140..713748aed 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -219,18 +219,22 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } override fun onDraw(canvas: Canvas) { - if (mDirection === Direction.NEXT) { - calcPoints() - drawCurrentPageArea(canvas, curBitmap) - drawNextPageAreaAndShadow(canvas, nextBitmap) - drawCurrentPageShadow(canvas) - drawCurrentBackArea(canvas, curBitmap) - } else { - calcPoints() - drawCurrentPageArea(canvas, prevBitmap) - drawNextPageAreaAndShadow(canvas, curBitmap) - drawCurrentPageShadow(canvas) - drawCurrentBackArea(canvas, prevBitmap) + when (mDirection) { + Direction.NEXT -> { + calcPoints() + drawCurrentPageArea(canvas, curBitmap) + drawNextPageAreaAndShadow(canvas, nextBitmap) + drawCurrentPageShadow(canvas) + drawCurrentBackArea(canvas, curBitmap) + } + Direction.PREV -> { + calcPoints() + drawCurrentPageArea(canvas, prevBitmap) + drawNextPageAreaAndShadow(canvas, curBitmap) + drawCurrentPageShadow(canvas) + drawCurrentBackArea(canvas, prevBitmap) + } + else -> Unit } } From 183d5d78325fb01c23f7a9bdba8ab1f7d59052a6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 22:02:52 +0800 Subject: [PATCH 112/169] =?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/SimulationPageDelegate.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 713748aed..b7a5b1666 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -126,7 +126,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) { - super.setTouchPoint(x, y, invalidate) + super.setTouchPoint(x, y, false) //触摸y中间位置吧y变成屏幕高度 if ((startY > viewHeight * 0.33 && startY < viewHeight * 0.66) || mDirection == Direction.PREV @@ -139,6 +139,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi ) { touchY = 1f } + pageView.invalidate() } override fun setDirection(direction: Direction) { @@ -234,7 +235,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi drawCurrentPageShadow(canvas) drawCurrentBackArea(canvas, prevBitmap) } - else -> Unit + else -> return } } From 716b2f4caf2334975ad06164406056b343ed40ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 25 Feb 2020 22:13:13 +0800 Subject: [PATCH 113/169] =?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/SimulationPageDelegate.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index b7a5b1666..6d7dd7bf8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -55,7 +55,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi // 是否属于右上左下 private var mIsRtOrLb = false - private var mMaxLength = 0f + private var mMaxLength = hypot(viewWidth.toDouble(), viewHeight.toDouble()).toFloat() // 背面颜色组 private var mBackShadowColors: IntArray // 前面颜色组 @@ -71,15 +71,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi private var mFrontShadowDrawableVLR: GradientDrawable private var mFrontShadowDrawableVRL: GradientDrawable - private val mPaint: Paint = Paint() + private val mPaint: Paint = Paint().apply { style = Paint.Style.FILL } private var curBitmap: Bitmap? = null private var prevBitmap: Bitmap? = null private var nextBitmap: Bitmap? = null init { - mMaxLength = hypot(viewWidth.toDouble(), viewWidth.toDouble()).toFloat() - mPaint.style = Paint.Style.FILL //设置颜色数组 val color = intArrayOf(0x333333, -0x4fcccccd) mFolderShadowDrawableRL = GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, color) @@ -117,7 +115,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun setViewSize(width: Int, height: Int) { super.setViewSize(width, height) - mMaxLength = hypot(viewWidth.toDouble(), viewWidth.toDouble()).toFloat() + mMaxLength = hypot(viewWidth.toDouble(), viewHeight.toDouble()).toFloat() } override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { From b0b62f73dc19e24bca13fbdb886f3572f3194c26 Mon Sep 17 00:00:00 2001 From: hingbong Date: Wed, 26 Feb 2020 00:15:25 +0800 Subject: [PATCH 114/169] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0:?= =?UTF-8?q?=20=E9=80=89=E6=8B=A9=E9=BB=98=E8=AE=A4=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E6=97=B6,=20=E5=8F=AF=E9=80=89=E6=8B=A9=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=AD=97=E4=BD=93(=E9=9D=9E=E8=A1=AC?= =?UTF-8?q?=E7=BA=BF),=20=E7=B3=BB=E7=BB=9F=E8=A1=AC=E7=BA=BF=E5=AD=97?= =?UTF-8?q?=E4=BD=93,=20=E7=B3=BB=E7=BB=9F=E7=AD=89=E5=AE=BD=E5=AD=97?= =?UTF-8?q?=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Android 10 开始, 谷歌给安卓提供了思源宋体作为中日韩三文的衬线字体, 或者有些手机可以自行更改, 并且加载系统内置字体性能也更佳 --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../main/java/io/legado/app/help/AppConfig.kt | 6 ++++++ .../app/ui/book/read/page/ChapterProvider.kt | 7 ++++++- .../app/ui/widget/font/FontSelectDialog.kt | 20 ++++++++++++++++--- app/src/main/res/values/arrays.xml | 5 +++++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 36 insertions(+), 4 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 50ab1c873..6be087f05 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -38,4 +38,5 @@ object PreferKey { const val bodyIndent = "textIndent" const val shareLayout = "shareLayout" const val readStyleSelect = "readStyleSelect" + const val systemTypefaces = "system_typefaces" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 1f4302fdc..f71652c23 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -86,4 +86,10 @@ object AppConfig { set(value) { App.INSTANCE.putPrefInt(PreferKey.chineseConverterType, value) } + + var systemTypefaces: Int + get() = App.INSTANCE.getPrefInt(PreferKey.systemTypefaces) + set(value) { + App.INSTANCE.putPrefInt(PreferKey.systemTypefaces, value) + } } 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 7618ddc51..4b133a001 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 @@ -8,6 +8,7 @@ import android.text.TextUtils import io.legado.app.App import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookChapter +import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.page.entities.TextChapter @@ -308,7 +309,11 @@ object ChapterProvider { if (!TextUtils.isEmpty(fontPath)) { Typeface.createFromFile(fontPath) } else { - Typeface.SANS_SERIF + when (AppConfig.systemTypefaces) { + 1 -> Typeface.SERIF + 2 -> Typeface.MONOSPACE + else -> Typeface.SANS_SERIF + } } } catch (e: Exception) { App.INSTANCE.removePref(PreferKey.readBookFont) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index be5523b58..128415769 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -16,7 +16,9 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseDialogFragment +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey +import io.legado.app.help.AppConfig import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert @@ -89,9 +91,13 @@ class FontSelectDialog : BaseDialogFragment(), R.id.menu_default -> { val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) cb?.let { - if (it.curFontPath != "") { - it.selectFile("") - } + val requireContext = requireContext() + requireContext.alert(titleResource = R.string.system_typeface) { + items(requireContext.resources.getStringArray(R.array.system_typefaces).toList()) { _, i -> + AppConfig.systemTypefaces = i + onDefaultFontChange(it) + } + }.show() } dismiss() } @@ -255,6 +261,14 @@ class FontSelectDialog : BaseDialogFragment(), } } + private fun onDefaultFontChange(callBack: CallBack){ + if (curFilePath() == "") { + postEvent(EventBus.UP_CONFIG, true) + } else { + callBack.selectFile("") + } + } + interface CallBack { fun selectFile(path: String) val curFontPath: String diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 87fd0d8e0..ff1fc875c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -152,4 +152,9 @@ 简体转繁体 + + 系统默认字体 + 系统衬线字体 + 系统等宽等宽 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f64f60c5a..8da65e500 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -627,4 +627,5 @@ 其它朗读设置 + 系统内置字体样式 From d86bd0117f4be7cfafbaa442691c8f8b682bc55c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 08:30:56 +0800 Subject: [PATCH 115/169] =?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/storage/Backup.kt | 14 +++----------- 1 file changed, 3 insertions(+), 11 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 4076c96a7..1e3c77489 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,17 +100,9 @@ object Backup { for (fileName in backupFileNames) { val file = File(backupPath + File.separator + fileName) if (file.exists()) { - var doc = treeDoc.findFile(fileName) - if (null != doc && doc.exists()) { - doc.delete() - } - doc = treeDoc.createFile("", fileName) - doc?.let { - DocumentUtils.writeText( - context, - file.readText(), - it.uri - ) + treeDoc.findFile(fileName)?.delete() + treeDoc.createFile("", fileName)?.let { + DocumentUtils.writeText(context, file.readText(), it.uri) } } } From 54b3add99a4dce6524fd12f8bee30fcf002f6318 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 10:34:54 +0800 Subject: [PATCH 116/169] =?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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index b9379ed02..fdcc66d5d 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,6 +2,10 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/26** +* 修复仿真翻页 +* 功能添加: 选择默认字体时, 可选择字体默认字体(非衬线), 系统衬线字体, 系统等宽字体by hingbong + **2020/02/25** * 优化文本选择和滚动,感觉很完美了 From e0e412e85aaae9df5f8ce2aedde2c85596628adc Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 14:24:48 +0800 Subject: [PATCH 117/169] =?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/build.gradle | 5 +- app/google-services.json | 29 ++++++++ app/src/debug/google-services.json | 69 ------------------- .../io/legado/app/ui/about/AboutActivity.kt | 8 +-- .../legado/app/ui/book/read/TextActionMenu.kt | 32 ++++++--- .../source/edit/BookSourceEditActivity.kt | 10 +-- .../legado/app/ui/rss/read/ReadRssActivity.kt | 4 +- .../rss/source/edit/RssSourceEditActivity.kt | 8 ++- .../io/legado/app/utils/ContextExtensions.kt | 11 --- app/src/main/res/layout/popup_action_menu.xml | 27 ++++++-- .../main/res/menu/content_select_action.xml | 3 + 11 files changed, 100 insertions(+), 106 deletions(-) delete mode 100644 app/src/debug/google-services.json diff --git a/app/build.gradle b/app/build.gradle index 585099975..d6f63988d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,6 +54,7 @@ android { if (project.hasProperty("RELEASE_STORE_FILE")) { signingConfig signingConfigs.myConfig } + applicationIdSuffix '.release' minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } @@ -123,7 +124,7 @@ dependencies { implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" //room - def room_version = '2.2.3' + def room_version = '2.2.4' implementation "androidx.room:room-runtime:$room_version" kapt "androidx.room:room-compiler:$room_version" @@ -175,7 +176,7 @@ dependencies { //MarkDown implementation 'ru.noties.markwon:core:3.0.2' - // 转换繁体 + //转换繁体 implementation 'com.github.houbb:opencc4j:1.4.0' } diff --git a/app/google-services.json b/app/google-services.json index 8cc19b1d5..fb88090cb 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -63,6 +63,35 @@ ] } } + }, + { + "client_info": { + "mobilesdk_app_id": "1:453392274790:android:c1481c1c3d3f51eff624a7", + "android_client_info": { + "package_name": "io.legado.app.release" + } + }, + "oauth_client": [ + { + "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } } ], "configuration_version": "1" diff --git a/app/src/debug/google-services.json b/app/src/debug/google-services.json deleted file mode 100644 index 8cc19b1d5..000000000 --- a/app/src/debug/google-services.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "project_info": { - "project_number": "453392274790", - "firebase_url": "https://legado-fca69.firebaseio.com", - "project_id": "legado-fca69", - "storage_bucket": "legado-fca69.appspot.com" - }, - "client": [ - { - "client_info": { - "mobilesdk_app_id": "1:453392274790:android:1d2b1eefbe0e78cff624a7", - "android_client_info": { - "package_name": "io.legado.app" - } - }, - "oauth_client": [ - { - "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA" - } - ], - "services": { - "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", - "client_type": 3 - } - ] - } - } - }, - { - "client_info": { - "mobilesdk_app_id": "1:453392274790:android:c4eac14b1410eec5f624a7", - "android_client_info": { - "package_name": "io.legado.app.debug" - } - }, - "oauth_client": [ - { - "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyD90mfNLhA7cAzzI9SonpSz5mrF5BnmyJA" - } - ], - "services": { - "appinvite_service": { - "other_platform_oauth_client": [ - { - "client_id": "453392274790-hnbpatpce9hbjiggj76hgo7queu86atq.apps.googleusercontent.com", - "client_type": 3 - } - ] - } - } - } - ], - "configuration_version": "1" -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt index 33587d0a2..8fc7d1294 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutActivity.kt @@ -6,7 +6,7 @@ import android.view.MenuItem import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.utils.openUrl -import io.legado.app.utils.shareText +import org.jetbrains.anko.share class AboutActivity : BaseActivity(R.layout.activity_about) { @@ -27,9 +27,9 @@ class AboutActivity : BaseActivity(R.layout.activity_about) { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_scoring -> openUrl("market://details?id=$packageName") - R.id.menu_share_it -> shareText( - "App Share", - getString(R.string.app_share_description) + R.id.menu_share_it -> share( + getString(R.string.app_share_description), + getString(R.string.app_name) ) } return super.onCompatOptionsItemSelected(item) 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 9d0959177..4dc9ba7da 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 @@ -15,6 +15,8 @@ import androidx.annotation.RequiresApi import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuItemImpl +import androidx.appcompat.widget.PopupMenu +import androidx.core.view.size import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R @@ -22,9 +24,11 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.utils.isAbsUrl import io.legado.app.utils.sendToClip +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.popup_action_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.share import org.jetbrains.anko.toast @SuppressLint("RestrictedApi") @@ -48,10 +52,27 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac recycler_view.adapter = adapter val menu = MenuBuilder(context) SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) + adapter.setItems(menu.visibleItems) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - onInitializeMenu(menu) + val popupMenu = PopupMenu(context, iv_menu_more) + onInitializeMenu(popupMenu.menu) + if (popupMenu.menu.size > 0) { + iv_menu_more.visible() + popupMenu.setOnMenuItemClickListener { item -> + item.intent?.let { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) + context.startActivity(it) + } + } + this@TextActionMenu.dismiss() + true + } + } + iv_menu_more.onClick { + popupMenu.show() + } } - adapter.setItems(menu.visibleItems) } inner class Adapter(context: Context) : @@ -81,6 +102,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun onMenuItemSelected(item: MenuItemImpl) { when (item.itemId) { R.id.menu_copy -> context.sendToClip(callBack.selectedText) + R.id.menu_share_str -> context.share(callBack.selectedText) R.id.menu_browser -> { try { val intent = if (callBack.selectedText.isAbsUrl()) { @@ -98,12 +120,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac context.toast(e.localizedMessage ?: "ERROR") } } - else -> item.intent?.let { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) - context.startActivity(it) - } - } } callBack.onMenuActionFinally() } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index f693c07ed..c0eab1b32 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -25,9 +25,13 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.* +import io.legado.app.utils.GSON +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareWithQr import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics +import org.jetbrains.anko.share import org.jetbrains.anko.startActivity import org.jetbrains.anko.toast import kotlin.math.abs @@ -84,9 +88,7 @@ class BookSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } - R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr -> - shareText(getString(R.string.share_book_source), sourceStr) - } + R.id.menu_share_str -> GSON.toJson(getSource())?.let { share(it) } R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr -> shareWithQr(getString(R.string.share_book_source), sourceStr) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index c68db66a1..ebaf05233 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -14,10 +14,10 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getViewModel -import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils +import org.jetbrains.anko.share import org.jsoup.Jsoup import org.jsoup.safety.Whitelist @@ -54,7 +54,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r when (item.itemId) { R.id.menu_rss_star -> viewModel.favorite() R.id.menu_share_it -> viewModel.rssArticle?.let { - shareText("链接分享", it.link) + share(it.link) } R.id.menu_aloud -> readAloud() } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 09839e458..22aaab453 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -21,9 +21,13 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.* +import io.legado.app.utils.GSON +import io.legado.app.utils.applyTint +import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareWithQr import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.displayMetrics +import org.jetbrains.anko.share import org.jetbrains.anko.startActivity import org.jetbrains.anko.toast import kotlin.math.abs @@ -101,7 +105,7 @@ class RssSourceEditActivity : } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> - shareText(getString(R.string.share_rss_source), sourceStr) + share(sourceStr) } R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr -> shareWithQr(getString(R.string.share_rss_source), sourceStr) 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 90415484a..2f05fa014 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -92,17 +92,6 @@ val Context.navigationBarHeight: Int return resources.getDimensionPixelSize(resourceId) } -fun Context.shareText(title: String, text: String) { - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(textIntent, title)) - } catch (e: Exception) { - toast(R.string.can_not_share) - } -} - @SuppressLint("SetWorldReadable") fun Context.shareWithQr(title: String, text: String) { QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L diff --git a/app/src/main/res/layout/popup_action_menu.xml b/app/src/main/res/layout/popup_action_menu.xml index b5273a77a..c6b9067d7 100644 --- a/app/src/main/res/layout/popup_action_menu.xml +++ b/app/src/main/res/layout/popup_action_menu.xml @@ -1,8 +1,27 @@ - + android:padding="5dp" + android:orientation="horizontal"> + + + + + + + diff --git a/app/src/main/res/menu/content_select_action.xml b/app/src/main/res/menu/content_select_action.xml index 52ac3e0f6..d11ee6154 100644 --- a/app/src/main/res/menu/content_select_action.xml +++ b/app/src/main/res/menu/content_select_action.xml @@ -13,4 +13,7 @@ android:id="@+id/menu_browser" android:title="@string/browser" /> + \ No newline at end of file From 95c14b99a3dbcb5c5ded1931e4d88b0daa97efc0 Mon Sep 17 00:00:00 2001 From: hingbong Date: Wed, 26 Feb 2020 14:43:19 +0800 Subject: [PATCH 118/169] =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=AD=97=E4=BD=93?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=BC=B9=E5=87=BA=E6=A1=86=E7=94=A8?= =?UTF-8?q?=E5=8D=8F=E7=A8=8B=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这样就不会遮盖住了, 优化一点代码 --- .../java/io/legado/app/help/storage/Backup.kt | 2 +- .../app/ui/widget/font/FontSelectDialog.kt | 66 ++++++++++--------- 2 files changed, 35 insertions(+), 33 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 1e3c77489..921910f34 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 @@ -102,7 +102,7 @@ object Backup { if (file.exists()) { treeDoc.findFile(fileName)?.delete() treeDoc.createFile("", fileName)?.let { - DocumentUtils.writeText(context, file.readText(), it.uri) + DocumentUtils.writeBytes(context, file.readBytes(), it.uri) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 128415769..0e2f21213 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -109,41 +109,43 @@ class FontSelectDialog : BaseDialogFragment(), } private fun openFolder() { - alert { - titleResource = R.string.select_folder - items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> - when (index) { - 0 -> { - val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" - putPrefString(PreferKey.fontFolder, path) - getFontFilesByPermission(path) - } - 1 -> { - try { - val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - startActivityForResult(intent, fontFolderRequestCode) - } catch (e: java.lang.Exception) { - e.printStackTrace() - requireContext().toast(e.localizedMessage ?: "ERROR") + launch(Main) { + alert { + titleResource = R.string.select_folder + items(resources.getStringArray(R.array.select_folder).toList()) { _, index -> + when (index) { + 0 -> { + val path = "${FileUtils.getSdCardPath()}${File.separator}Fonts" + putPrefString(PreferKey.fontFolder, path) + getFontFilesByPermission(path) } - } - 2 -> { - PermissionsCompat.Builder(this@FontSelectDialog) - .addPermissions(*Permissions.Group.STORAGE) - .rationale(R.string.tip_perm_request_storage) - .onGranted { - FileChooserDialog.show( - childFragmentManager, - fontFolderRequestCode, - mode = FileChooserDialog.DIRECTORY - ) + 1 -> { + try { + val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + startActivityForResult(intent, fontFolderRequestCode) + } catch (e: java.lang.Exception) { + e.printStackTrace() + requireContext().toast(e.localizedMessage ?: "ERROR") } - .request() + } + 2 -> { + PermissionsCompat.Builder(this@FontSelectDialog) + .addPermissions(*Permissions.Group.STORAGE) + .rationale(R.string.tip_perm_request_storage) + .onGranted { + FileChooserDialog.show( + childFragmentManager, + fontFolderRequestCode, + mode = FileChooserDialog.DIRECTORY + ) + } + .request() + } } } - } - }.show() + }.show() + } } @SuppressLint("DefaultLocale") @@ -261,7 +263,7 @@ class FontSelectDialog : BaseDialogFragment(), } } - private fun onDefaultFontChange(callBack: CallBack){ + private fun onDefaultFontChange(callBack: CallBack) { if (curFilePath() == "") { postEvent(EventBus.UP_CONFIG, true) } else { From d17099ba5c01f770319c8c827a2313e99a8c0895 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 16:39:10 +0800 Subject: [PATCH 119/169] =?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/ContentView.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 c39ca8f14..98eff7aad 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 @@ -37,8 +37,9 @@ class ContentView(context: Context) : FrameLayout(context) { tv_bottom_right.typeface = ChapterProvider.typeface //显示状态栏时隐藏header if (hideStatusBar) { - ll_header.layoutParams = - ll_header.layoutParams.apply { height = context.statusBarHeight } + ll_header.layoutParams = ll_header.layoutParams.apply { + height = context.statusBarHeight + headerPaddingTop.dp + headerPaddingBottom.dp + } ll_header.setPadding( headerPaddingLeft.dp, headerPaddingTop.dp, From ad19ebc2584a957fe04d7bfeaf2089052ae52097 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 18:33:26 +0800 Subject: [PATCH 120/169] =?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 --- .../rss/source/edit/RssSourceEditActivity.kt | 58 +++++++++++-------- .../rss/source/edit/RssSourceEditViewModel.kt | 12 ++++ .../ui/rss/source/manage/RssSourceActivity.kt | 2 +- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 22aaab453..944135b45 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.content.Intent import android.graphics.Rect import android.os.Bundle import android.view.Gravity @@ -19,6 +20,7 @@ import io.legado.app.constant.AppConst import io.legado.app.data.entities.RssSource import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH +import io.legado.app.ui.qrcode.QrCodeActivity import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON @@ -26,19 +28,17 @@ import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel import io.legado.app.utils.shareWithQr import kotlinx.android.synthetic.main.activity_rss_source_edit.* -import org.jetbrains.anko.displayMetrics -import org.jetbrains.anko.share -import org.jetbrains.anko.startActivity -import org.jetbrains.anko.toast +import org.jetbrains.anko.* import kotlin.math.abs class RssSourceEditActivity : VMBaseActivity(R.layout.activity_rss_source_edit, false), + ViewTreeObserver.OnGlobalLayoutListener, KeyboardToolPop.CallBack { private var mSoftKeyboardTool: PopupWindow? = null private var mIsSoftKeyBoardShowing = false - + private val qrRequestCode = 101 private val adapter = RssSourceEditAdapter() private val sourceEntities: ArrayList = ArrayList() @@ -103,6 +103,7 @@ class RssSourceEditActivity : clipboard?.setPrimaryClip(ClipData.newPlainText(null, sourceStr)) } } + R.id.menu_qr_code_camera -> startActivityForResult(qrRequestCode) R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> share(sourceStr) @@ -117,7 +118,7 @@ class RssSourceEditActivity : private fun initView() { ATH.applyEdgeEffectColor(recycler_view) mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this) - window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener()) + window.decorView.viewTreeObserver.addOnGlobalLayoutListener(this) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter } @@ -208,23 +209,34 @@ class RssSourceEditActivity : mSoftKeyboardTool?.dismiss() } - private inner class KeyboardOnGlobalChangeListener : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - val rect = Rect() - // 获取当前页面窗口的显示范围 - window.decorView.getWindowVisibleDisplayFrame(rect) - val screenHeight = this@RssSourceEditActivity.displayMetrics.heightPixels - val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 - val preShowing = mIsSoftKeyBoardShowing - if (abs(keyboardHeight) > screenHeight / 5) { - mIsSoftKeyBoardShowing = true // 超过屏幕五分之一则表示弹出了输入法 - recycler_view.setPadding(0, 0, 0, 100) - showKeyboardTopPopupWindow() - } else { - mIsSoftKeyBoardShowing = false - recycler_view.setPadding(0, 0, 0, 0) - if (preShowing) { - closePopupWindow() + override fun onGlobalLayout() { + val rect = Rect() + // 获取当前页面窗口的显示范围 + window.decorView.getWindowVisibleDisplayFrame(rect) + val screenHeight = this@RssSourceEditActivity.displayMetrics.heightPixels + val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 + val preShowing = mIsSoftKeyBoardShowing + if (abs(keyboardHeight) > screenHeight / 5) { + mIsSoftKeyBoardShowing = true // 超过屏幕五分之一则表示弹出了输入法 + recycler_view.setPadding(0, 0, 0, 100) + showKeyboardTopPopupWindow() + } else { + mIsSoftKeyBoardShowing = false + recycler_view.setPadding(0, 0, 0, 0) + if (preShowing) { + closePopupWindow() + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + qrRequestCode -> if (resultCode == RESULT_OK) { + data?.getStringExtra("result")?.let { + viewModel.importSource(it) { source: RssSource -> + upRecyclerView(source) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index ae6e8c739..eb9c4e034 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -71,4 +71,16 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati } } } + + fun importSource(text: String, finally: (source: RssSource) -> Unit) { + execute { + val text1 = text.trim() + GSON.fromJsonObject(text1)?.let { + finally.invoke(it) + } + }.onError { + toast(it.localizedMessage ?: "Error") + } + } + } \ No newline at end of file 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 0af2de45b..517290130 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 @@ -50,7 +50,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r get() = getViewModel(RssSourceViewModel::class.java) private val importRecordKey = "rssSourceRecordKey" private val qrRequestCode = 101 - private val importSource = 13141 + private val importSource = 124 private lateinit var adapter: RssSourceAdapter private var sourceLiveData: LiveData>? = null private var groups = hashSetOf() From bfa4e10b4aeb7cd392917a331b6aa389a16d1f4f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 18:56:00 +0800 Subject: [PATCH 121/169] =?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/model/webBook/BookContent.kt | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 47396ad9c..d8e874195 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -33,10 +33,14 @@ object BookContent { ) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") + val analyzeRule = AnalyzeRule(book) val content = StringBuilder() val nextUrlList = arrayListOf(baseUrl) val contentRule = bookSource.getContentRule() - var contentData = analyzeContent(body, contentRule, book, bookChapter, bookSource, baseUrl) + var contentData = analyzeContent( + analyzeRule.setContent(body, baseUrl), + contentRule, bookChapter, bookSource + ) content.append(contentData.content.replace(bookChapter.title, "")) if (contentData.nextUrl.size == 1) { var nextUrl = contentData.nextUrl[0] @@ -56,15 +60,15 @@ object BookContent { headerMapF = bookSource.getHeaderMap() ).getResponseAwait() .body?.let { nextBody -> - contentData = - analyzeContent( - nextBody, contentRule, book, - bookChapter, bookSource, baseUrl, false - ) - nextUrl = - if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" - content.append(contentData.content) - } + contentData = + analyzeContent( + analyzeRule.setContent(nextBody, nextUrl), + contentRule, bookChapter, bookSource, false + ) + nextUrl = + if (contentData.nextUrl.isNotEmpty()) contentData.nextUrl[0] else "" + content.append(contentData.content) + } } Debug.log(bookSource.bookSourceUrl, "◇本章总页数:${nextUrlList.size}") } else if (contentData.nextUrl.size > 1) { @@ -81,19 +85,20 @@ object BookContent { headerMapF = bookSource.getHeaderMap() ).getResponseAwait() .body?.let { - contentData = - analyzeContent( - it, contentRule, book, bookChapter, - bookSource, item.nextUrl, false - ) - item.content = contentData.content - } + contentData = + analyzeContent( + analyzeRule.setContent(it, item.nextUrl), + contentRule, bookChapter, bookSource, false + ) + item.content = contentData.content + } } } for (item in contentDataList) { content.append(item.content) } } + Debug.log(bookSource.bookSourceUrl, "┌获取章节名称") Debug.log(bookSource.bookSourceUrl, "└${bookChapter.title}") Debug.log(bookSource.bookSourceUrl, "┌获取正文内容") @@ -103,17 +108,13 @@ object BookContent { @Throws(Exception::class) private fun analyzeContent( - body: String, + analyzeRule: AnalyzeRule, contentRule: ContentRule, - book: Book, chapter: BookChapter, bookSource: BookSource, - baseUrl: String, printLog: Boolean = true ): ContentData> { val nextUrlList = arrayListOf() - val analyzeRule = AnalyzeRule(book) - analyzeRule.setContent(body, baseUrl) analyzeRule.chapter = chapter val nextUrlRule = contentRule.nextContentUrl if (!nextUrlRule.isNullOrEmpty()) { From d8c1721a8d2ad0de4ed34c62510ed25720c8e09f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 19:15:16 +0800 Subject: [PATCH 122/169] =?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/data/entities/BaseBook.kt | 1 + .../java/io/legado/app/data/entities/Book.kt | 2 +- .../io/legado/app/data/entities/SearchBook.kt | 2 +- .../app/model/webBook/BookChapterList.kt | 22 +++++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt index 0c96c2123..62d322b6c 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseBook.kt @@ -3,6 +3,7 @@ package io.legado.app.data.entities import io.legado.app.utils.splitNotBlank interface BaseBook { + var bookUrl: String var variableMap: HashMap? var kind: String? var wordCount: String? diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index d01919a94..d29ce696e 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -17,7 +17,7 @@ import kotlin.math.max @Entity(tableName = "books", indices = [(Index(value = ["bookUrl"], unique = true))]) data class Book( @PrimaryKey - var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径) + override var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径) var tocUrl: String = "", // 目录页Url (toc=table of Contents) var origin: String = BookType.local, // 书源URL(默认BookType.local) var originName: String = "", //书源名称 or 本地书籍文件名 diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index 2baf259e4..edd6f6e56 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -21,7 +21,7 @@ import kotlinx.android.parcel.Parcelize ) data class SearchBook( @PrimaryKey - var bookUrl: String = "", + override var bookUrl: String = "", var origin: String = "", // 书源规则 var originName: String = "", var type: Int = 0, // @BookType diff --git a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt index ff3467a8a..aa0b7de74 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt @@ -31,6 +31,7 @@ object BookChapterList { App.INSTANCE.getString(R.string.error_get_web_content, baseUrl) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${baseUrl}") + val analyzeRule = AnalyzeRule(book) val tocRule = bookSource.getTocRule() val nextUrlList = arrayListOf(baseUrl) var reverse = false @@ -43,7 +44,10 @@ object BookChapterList { listRule = listRule.substring(1) } var chapterData = - analyzeChapterList(body, baseUrl, tocRule, listRule, book, bookSource, log = true) + analyzeChapterList( + analyzeRule.setContent(body, baseUrl), + book.bookUrl, baseUrl, tocRule, listRule, bookSource, log = true + ) chapterData.chapterList?.let { chapterList.addAll(it) } @@ -63,8 +67,8 @@ object BookChapterList { ).getResponseAwait() .body?.let { nextBody -> chapterData = analyzeChapterList( - nextBody, nextUrl, tocRule, listRule, - book, bookSource, log = false + analyzeRule.setContent(nextBody, nextUrl), + book.bookUrl, nextUrl, tocRule, listRule, bookSource ) nextUrl = if (chapterData.nextUrl.isNotEmpty()) { chapterData.nextUrl[0] @@ -98,7 +102,9 @@ object BookChapterList { headerMapF = bookSource.getHeaderMap() ).getResponseAwait().body val nextChapterData = analyzeChapterList( - nextBody, item.nextUrl, tocRule, listRule, book, bookSource + analyzeRule.setContent(nextBody, item.nextUrl), + book.bookUrl, item.nextUrl, tocRule, listRule, bookSource, + false ) synchronized(chapterDataList) { val isFinished = addChapterListIsFinish( @@ -167,19 +173,17 @@ object BookChapterList { } private fun analyzeChapterList( - body: String?, + analyzeRule: AnalyzeRule, + bookUrl: String, baseUrl: String, tocRule: TocRule, listRule: String, - book: Book, bookSource: BookSource, getNextUrl: Boolean = true, log: Boolean = false ): ChapterData> { val chapterList = arrayListOf() val nextUrlList = arrayListOf() - val analyzeRule = AnalyzeRule(book) - analyzeRule.setContent(body, baseUrl) val nextTocRule = tocRule.nextTocUrl if (getNextUrl && !nextTocRule.isNullOrEmpty()) { Debug.log(bookSource.bookSourceUrl, "┌获取目录下一页列表", log) @@ -208,7 +212,7 @@ object BookChapterList { var isVip: String? for (item in elements) { analyzeRule.setContent(item) - val bookChapter = BookChapter(bookUrl = book.bookUrl) + val bookChapter = BookChapter(bookUrl = bookUrl) analyzeRule.chapter = bookChapter bookChapter.title = analyzeRule.getString(nameRule) bookChapter.url = analyzeRule.getString(urlRule, true) From 310d89d23a7d6cca63f4ac360ffdbfb7276fc8c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 19:30:08 +0800 Subject: [PATCH 123/169] =?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/config/BackupRestoreUi.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 16fd3941b..ddc41afce 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -26,7 +26,7 @@ import kotlinx.coroutines.Dispatchers.Main import org.jetbrains.anko.toast object BackupRestoreUi { - + private const val selectFolderRequestCode = 21 private const val backupSelectRequestCode = 22 private const val restoreSelectRequestCode = 33 private const val oldDataRequestCode = 11 @@ -34,7 +34,7 @@ object BackupRestoreUi { fun backup(fragment: Fragment) { val backupPath = AppConfig.backupPath if (backupPath.isNullOrEmpty()) { - selectBackupFolder(fragment) + selectBackupFolder(fragment, backupSelectRequestCode) } else { if (backupPath.isContentPath()) { val uri = Uri.parse(backupPath) @@ -46,7 +46,7 @@ object BackupRestoreUi { fragment.toast(R.string.backup_success) } } else { - selectBackupFolder(fragment) + selectBackupFolder(fragment, backupSelectRequestCode) } } else { backupUsePermission(fragment) @@ -69,7 +69,7 @@ object BackupRestoreUi { .request() } - fun selectBackupFolder(fragment: Fragment) { + fun selectBackupFolder(fragment: Fragment, requestCode: Int = selectFolderRequestCode) { fragment.alert { titleResource = R.string.select_folder items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> @@ -79,7 +79,7 @@ object BackupRestoreUi { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - fragment.startActivityForResult(intent, backupSelectRequestCode) + fragment.startActivityForResult(intent, requestCode) } catch (e: java.lang.Exception) { e.printStackTrace() fragment.toast(e.localizedMessage ?: "ERROR") @@ -88,7 +88,7 @@ object BackupRestoreUi { 2 -> { FileChooserDialog.show( fragment.childFragmentManager, - backupSelectRequestCode, + requestCode, mode = FileChooserDialog.DIRECTORY ) } @@ -264,6 +264,15 @@ object BackupRestoreUi { } } } + selectFolderRequestCode -> if (resultCode == RESULT_OK) { + data?.data?.let { uri -> + App.INSTANCE.contentResolver.takePersistableUriPermission( + uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + AppConfig.backupPath = uri.toString() + } + } oldDataRequestCode -> if (resultCode == RESULT_OK) data?.data?.let { uri -> ImportOldData.importUri(uri) From ea3db51478fce62d0caa924f68a5735a573af6ed Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 20:32:02 +0800 Subject: [PATCH 124/169] =?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/model/WebBook.kt | 77 ++++++++++--------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index 4cc2544f5..bb3f80b8d 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -86,17 +86,18 @@ class WebBook(val bookSource: BookSource) { ): Coroutine { book.type = bookSource.bookSourceType return Coroutine.async(scope, context) { - val body = if (!book.infoHtml.isNullOrEmpty()) { - book.infoHtml - } else { - val analyzeUrl = AnalyzeUrl( - book = book, - ruleUrl = book.bookUrl, - baseUrl = sourceUrl, - headerMapF = bookSource.getHeaderMap() - ) - analyzeUrl.getResponseAwait().body - } + val body = + if (!book.infoHtml.isNullOrEmpty()) { + book.infoHtml + } else { + val analyzeUrl = AnalyzeUrl( + book = book, + ruleUrl = book.bookUrl, + baseUrl = sourceUrl, + headerMapF = bookSource.getHeaderMap() + ) + analyzeUrl.getResponseAwait().body + } BookInfo.analyzeBookInfo(book, body, bookSource, book.bookUrl) book } @@ -112,16 +113,17 @@ class WebBook(val bookSource: BookSource) { ): Coroutine> { book.type = bookSource.bookSourceType return Coroutine.async(scope, context) { - val body = if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { - book.tocHtml - } else { - AnalyzeUrl( - book = book, - ruleUrl = book.tocUrl, - baseUrl = book.bookUrl, - headerMapF = bookSource.getHeaderMap() - ).getResponseAwait().body - } + val body = + if (book.bookUrl == book.tocUrl && !book.tocHtml.isNullOrEmpty()) { + book.tocHtml + } else { + AnalyzeUrl( + book = book, + ruleUrl = book.tocUrl, + baseUrl = book.bookUrl, + headerMapF = bookSource.getHeaderMap() + ).getResponseAwait().body + } BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl) } } @@ -141,22 +143,23 @@ class WebBook(val bookSource: BookSource) { Debug.log(sourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}") return@async bookChapter.url } - val body = if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { - book.tocHtml - } else { - val analyzeUrl = - AnalyzeUrl( - book = book, - ruleUrl = bookChapter.url, - baseUrl = book.tocUrl, - headerMapF = bookSource.getHeaderMap() - ) - analyzeUrl.getResponseAwait( - bookSource.bookSourceUrl, - jsStr = bookSource.getContentRule().webJs, - sourceRegex = bookSource.getContentRule().sourceRegex - ).body - } + val body = + if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) { + book.tocHtml + } else { + val analyzeUrl = + AnalyzeUrl( + book = book, + ruleUrl = bookChapter.url, + baseUrl = book.tocUrl, + headerMapF = bookSource.getHeaderMap() + ) + analyzeUrl.getResponseAwait( + bookSource.bookSourceUrl, + jsStr = bookSource.getContentRule().webJs, + sourceRegex = bookSource.getContentRule().sourceRegex + ).body + } BookContent.analyzeContent( this, body, From 6b31896cf556f3d8b2ef45072149bbb6284cd7c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 21:12:09 +0800 Subject: [PATCH 125/169] =?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/arrange/ArrangeBookActivity.kt | 1 + 1 file changed, 1 insertion(+) 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 671736dc8..95dd84d51 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 @@ -101,6 +101,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi App.db.bookDao().observeByGroup(groupId) } booksLiveData?.observe(this, Observer { + adapter.selectedBooks.clear() adapter.setItems(it) upSelectCount() }) From 8fce75a788bb23c84e3023c666731f642fbcc005 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 21:19:26 +0800 Subject: [PATCH 126/169] =?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/arrange/ArrangeBookActivity.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 95dd84d51..c0907f002 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 @@ -95,10 +95,11 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi private fun initBookData() { booksLiveData?.removeObservers(this) booksLiveData = - if (groupId == -1) { - App.db.bookDao().observeAll() - } else { - App.db.bookDao().observeByGroup(groupId) + when (groupId) { + -1 -> App.db.bookDao().observeAll() + -2 -> App.db.bookDao().observeLocal() + -3 -> App.db.bookDao().observeAudio() + else -> App.db.bookDao().observeByGroup(groupId) } booksLiveData?.observe(this, Observer { adapter.selectedBooks.clear() From b2d0bd5de27960ad2161ed48810e29620abae2d9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 22:12:47 +0800 Subject: [PATCH 127/169] =?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/search/DiffCallBack.kt | 10 ++++++---- .../io/legado/app/ui/book/search/SearchViewModel.kt | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 8db633cf8..5dc166987 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -16,10 +16,6 @@ class DiffCallBack(private val oldItems: List, private val newItems: } override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return true - } - - override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] if (oldItem.name != newItem.name) { @@ -28,6 +24,12 @@ class DiffCallBack(private val oldItems: List, private val newItems: if (oldItem.author != newItem.author) { return false } + return true + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] if (oldItem.origins?.size != newItem.origins?.size) { return false } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index df104de88..1e780737e 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -130,9 +130,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } else if (searchKey == item.author) { - for ((i, searchBook) in copyDataS.withIndex()) { + for ((index, searchBook) in copyDataS.withIndex()) { if (searchKey != searchBook.name && searchKey == searchBook.author) { - copyDataS.add(i, item) + copyDataS.add(index, item) break } } From 37bdfee1950ae27d60a706e169615675112d236c Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 23:03:43 +0800 Subject: [PATCH 128/169] =?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 | 14 +++++++++----- .../io/legado/app/ui/book/read/page/ContentView.kt | 7 +------ .../legado/app/ui/book/search/SearchViewModel.kt | 1 + 3 files changed, 11 insertions(+), 11 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 c31fedde6..35f43c811 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 @@ -47,17 +47,21 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at invalidate() } - override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { - super.onSizeChanged(w, h, oldw, oldh) - ChapterProvider.viewWidth = w - ChapterProvider.viewHeight = h - ChapterProvider.upSize() + fun upVisibleRect() { visibleRect.set( ChapterProvider.paddingLeft.toFloat(), ChapterProvider.paddingTop.toFloat(), ChapterProvider.visibleRight.toFloat(), ChapterProvider.visibleBottom.toFloat() ) + } + + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { + super.onSizeChanged(w, h, oldw, oldh) + ChapterProvider.viewWidth = w + ChapterProvider.viewHeight = h + ChapterProvider.upSize() + upVisibleRect() textPage.format() } 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 98eff7aad..fb60c6361 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 @@ -52,12 +52,7 @@ class ContentView(context: Context) : FrameLayout(context) { ll_header.gone() page_panel.setPadding(0, context.statusBarHeight, 0, 0) } - content_text_view.setPadding( - paddingLeft.dp, - paddingTop.dp, - paddingRight.dp, - paddingBottom.dp - ) + content_text_view.upVisibleRect() ll_footer.setPadding( footerPaddingLeft.dp, footerPaddingTop.dp, diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 1e780737e..33df6bde5 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -141,6 +141,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } + searchBooks = copyDataS searchBookLiveData.postValue(copyDataS) } From 98b8847d241574ebe5dd5c7a45666f2f51766056 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 23:06:54 +0800 Subject: [PATCH 129/169] =?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/ContentView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fb60c6361..7bbc2adc5 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 @@ -52,13 +52,13 @@ class ContentView(context: Context) : FrameLayout(context) { ll_header.gone() page_panel.setPadding(0, context.statusBarHeight, 0, 0) } - content_text_view.upVisibleRect() ll_footer.setPadding( footerPaddingLeft.dp, footerPaddingTop.dp, footerPaddingRight.dp, footerPaddingBottom.dp ) + content_text_view.upVisibleRect() durConfig.textColor().let { tv_top_left.setTextColor(it) tv_top_right.setTextColor(it) From ba7d3fa14d2c9d68447df48745fef04c4fb337f0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 26 Feb 2020 23:17:38 +0800 Subject: [PATCH 130/169] =?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/ReadBookActivity.kt | 2 -- app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt | 1 + 2 files changed, 1 insertion(+), 2 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 cf88a03dd..0f08df7c0 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 @@ -33,7 +33,6 @@ import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.read.config.* import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR -import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.ui.book.read.page.ContentTextView import io.legado.app.ui.book.read.page.PageView import io.legado.app.ui.book.read.page.TextPageFactory @@ -656,7 +655,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo upSystemUiVisibility() page_view.upBg() page_view.upStyle() - ChapterProvider.upStyle() if (it) { ReadBook.loadContent() } else { 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 d5a46d734..52acc8195 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 @@ -138,6 +138,7 @@ class PageView(context: Context, attrs: AttributeSet) : } fun upStyle() { + ChapterProvider.upStyle() curPage.upStyle() prevPage.upStyle() nextPage.upStyle() From aacdd2fefd82adb136486ab8a96290a98a1303b8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 08:09:14 +0800 Subject: [PATCH 131/169] =?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 fdcc66d5d..d260fe346 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/27** +* 修复bug,边距调节等一些bug + **2020/02/26** * 修复仿真翻页 * 功能添加: 选择默认字体时, 可选择字体默认字体(非衬线), 系统衬线字体, 系统等宽字体by hingbong From 864a7b4d09501dc351a070f8a7632d13c19e671c Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 10:26:34 +0800 Subject: [PATCH 132/169] =?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/data/entities/SearchBook.kt | 10 +++------- .../java/io/legado/app/ui/book/search/DiffCallBack.kt | 6 +++--- .../java/io/legado/app/ui/book/search/SearchAdapter.kt | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt index edd6f6e56..27f666547 100644 --- a/app/src/main/java/io/legado/app/data/entities/SearchBook.kt +++ b/app/src/main/java/io/legado/app/data/entities/SearchBook.kt @@ -78,16 +78,12 @@ data class SearchBook( variable = GSON.toJson(variableMap) } - @Ignore + @delegate:Ignore @IgnoredOnParcel - var origins: LinkedHashSet? = null - private set + val origins: LinkedHashSet by lazy { linkedSetOf(origin) } fun addOrigin(origin: String) { - if (origins == null) { - origins = linkedSetOf(this.origin) - } - origins?.add(origin) + origins.add(origin) } fun getDisplayLastChapterTitle(): String { diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 5dc166987..2bba67405 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -30,7 +30,7 @@ class DiffCallBack(private val oldItems: List, private val newItems: override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] - if (oldItem.origins?.size != newItem.origins?.size) { + if (oldItem.origins.size != newItem.origins.size) { return false } if (oldItem.coverUrl != newItem.coverUrl) { @@ -58,8 +58,8 @@ class DiffCallBack(private val oldItems: List, private val newItems: if (oldItem.author != newItem.author) { payload.putString("author", newItem.author) } - if (oldItem.origins?.size != newItem.origins?.size) { - payload.putInt("origins", newItem.origins?.size ?: 1) + if (oldItem.origins.size != newItem.origins.size) { + payload.putInt("origins", newItem.origins.size) } if (oldItem.coverUrl != newItem.coverUrl) { payload.putString("group", newItem.coverUrl) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index fbdcb99cf..38d1154d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -40,7 +40,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : with(itemView) { tv_name.text = searchBook.name tv_author.text = context.getString(R.string.author_show, searchBook.author) - bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) + bv_originCount.setBadgeCount(searchBook.origins.size) upLasted(itemView, searchBook.latestChapterTitle) tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) upKind(itemView, searchBook.getKindList()) @@ -56,7 +56,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : "name" -> tv_name.text = searchBook.name "author" -> tv_author.text = context.getString(R.string.author_show, searchBook.author) - "originCount" -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) + "originCount" -> bv_originCount.setBadgeCount(searchBook.origins.size) "lasted" -> upLasted(itemView, searchBook.latestChapterTitle) "introduce" -> tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) From 7fae9506fd452ddca462272a1b093b91c4e75bad Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 15:32:35 +0800 Subject: [PATCH 133/169] =?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 | 2 +- .../legado/app/ui/book/search/DiffCallBack.kt | 8 +++--- .../app/ui/book/search/SearchAdapter.kt | 6 ++--- .../app/ui/book/search/SearchViewModel.kt | 26 ++++++++++++++++++- 4 files changed, 33 insertions(+), 9 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 4b133a001..dabf7caa3 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 @@ -79,7 +79,7 @@ object ChapterProvider { durY = joinBody(text, durY, textPages, pageLines, pageLengths, stringBuilder) } } - textPages.last().height = durY + textPages.last().height = durY + 20.dp textPages.last().text = stringBuilder.toString() if (pageLines.size < textPages.size) { pageLines.add(textPages.last().textLines.size) diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 2bba67405..07a3b16c5 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -62,16 +62,16 @@ class DiffCallBack(private val oldItems: List, private val newItems: payload.putInt("origins", newItem.origins.size) } if (oldItem.coverUrl != newItem.coverUrl) { - payload.putString("group", newItem.coverUrl) + payload.putString("cover", newItem.coverUrl) } if (oldItem.kind != newItem.kind) { - payload.putString("enabled", newItem.kind) + payload.putString("kind", newItem.kind) } if (oldItem.latestChapterTitle != newItem.latestChapterTitle) { - payload.putString("enabled", newItem.latestChapterTitle) + payload.putString("last", newItem.latestChapterTitle) } if (oldItem.intro != newItem.intro) { - payload.putString("enabled", newItem.intro) + payload.putString("intro", newItem.intro) } return payload } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 38d1154d6..a96244113 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -56,9 +56,9 @@ class SearchAdapter(context: Context, val callBack: CallBack) : "name" -> tv_name.text = searchBook.name "author" -> tv_author.text = context.getString(R.string.author_show, searchBook.author) - "originCount" -> bv_originCount.setBadgeCount(searchBook.origins.size) - "lasted" -> upLasted(itemView, searchBook.latestChapterTitle) - "introduce" -> tv_introduce.text = + "origins" -> bv_originCount.setBadgeCount(searchBook.origins.size) + "last" -> upLasted(itemView, searchBook.latestChapterTitle) + "intro" -> tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) "kind" -> upKind(itemView, searchBook.getKindList()) "cover" -> iv_cover.load( diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 33df6bde5..f56ad21d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -141,7 +141,31 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } - + searchBooks.sortWith(Comparator { o1, o2 -> + if (o1.name == searchKey && o2.name != searchKey) { + 1 + } else if (o1.name != searchKey && o2.name == searchKey) { + -1 + } else if (o1.author == searchKey && o2.author != searchKey) { + 1 + } else if (o1.author != searchKey && o2.author == searchKey) { + -1 + } else if (o1.name == o2.name) { + when { + o1.origins.size > o2.origins.size -> { + 1 + } + o1.origins.size < o2.origins.size -> { + -1 + } + else -> { + 0 + } + } + } else { + 0 + } + }) searchBooks = copyDataS searchBookLiveData.postValue(copyDataS) } From 5727d11946b0ac177a7feee63966d109aecd3eee Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 15:52:09 +0800 Subject: [PATCH 134/169] =?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/search/SearchViewModel.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index f56ad21d6..47671626d 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -85,8 +85,8 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { private fun precisionSearch(searchBooks: List) { val books = arrayListOf() searchBooks.forEach { searchBook -> - if (searchBook.name.equals(searchKey, true) - || searchBook.author.equals(searchKey, true) + if (searchBook.name.contains(searchKey, true) + || searchBook.author.contains(searchKey, true) ) books.add(searchBook) } App.db.searchBookDao().insert(*books.toTypedArray()) From 00065900485958ab0b20ac7b9e412d519fe8a9d2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 15:54:59 +0800 Subject: [PATCH 135/169] =?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/changesource/ChangeSourceViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 13b145a1e..1a683427f 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -58,7 +58,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio App.db.searchBookDao().insert(searchBook) if (screenKey.isEmpty()) { searchBooks.add(searchBook) - } else if (searchBook.originName.contains(screenKey)) { + } else if (searchBook.name.contains(screenKey)) { searchBooks.add(searchBook) } upAdapter() From 02d42edaf7f7a506e804322985e49201858695e6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 15:59:18 +0800 Subject: [PATCH 136/169] =?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, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index d260fe346..730c5320f 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,7 +3,8 @@ * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 **2020/02/27** -* 修复bug,边距调节等一些bug +* 修复bug,边距调节,换源等一些bug,记不清了 +* 改了下包名,好上架应用市场 **2020/02/26** * 修复仿真翻页 From f876dbce2089cc234abb42407d52bf88df9986bc Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 16:57:17 +0800 Subject: [PATCH 137/169] =?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/widget/font/FontSelectDialog.kt | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 0e2f21213..6732bf985 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -89,17 +89,14 @@ class FontSelectDialog : BaseDialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) - cb?.let { - val requireContext = requireContext() - requireContext.alert(titleResource = R.string.system_typeface) { - items(requireContext.resources.getStringArray(R.array.system_typefaces).toList()) { _, i -> - AppConfig.systemTypefaces = i - onDefaultFontChange(it) - } - }.show() - } - dismiss() + val requireContext = requireContext() + requireContext.alert(titleResource = R.string.system_typeface) { + items(requireContext.resources.getStringArray(R.array.system_typefaces).toList()) { _, i -> + AppConfig.systemTypefaces = i + onDefaultFontChange() + dismiss() + } + }.show() } R.id.menu_other -> { openFolder() @@ -212,12 +209,9 @@ class FontSelectDialog : BaseDialogFragment(), launch(IO) { file.copyTo(FileUtils.createFileIfNotExist(fontFolder, file.name), true) .absolutePath.let { path -> - val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) - cb?.let { - if (it.curFontPath != path) { - withContext(Main) { - it.selectFile(path) - } + if (callBack?.curFontPath != path) { + withContext(Main) { + callBack?.selectFile(path) } } } @@ -226,9 +220,7 @@ class FontSelectDialog : BaseDialogFragment(), } override fun curFilePath(): String { - return (parentFragment as? CallBack)?.curFontPath - ?: (activity as? CallBack)?.curFontPath - ?: "" + return callBack?.curFontPath ?: "" } override fun onFilePicked(requestCode: Int, currentPath: String) { @@ -263,14 +255,17 @@ class FontSelectDialog : BaseDialogFragment(), } } - private fun onDefaultFontChange(callBack: CallBack) { + private fun onDefaultFontChange() { if (curFilePath() == "") { postEvent(EventBus.UP_CONFIG, true) } else { - callBack.selectFile("") + callBack?.selectFile("") } } + private val callBack: CallBack? + get() = (parentFragment as? CallBack) ?: (activity as? CallBack) + interface CallBack { fun selectFile(path: String) val curFontPath: String From 85f9fe59f684703b78a1c3294c9d777d0742a26e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 16:59:49 +0800 Subject: [PATCH 138/169] =?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/widget/font/FontAdapter.kt | 4 ++-- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index f7c73030a..f2724abcd 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -20,7 +20,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : tv_font.typeface = typeface tv_font.text = item.name this.onClick { callBack.onClick(item) } - if (item.name == callBack.curFilePath().substringAfterLast(File.separator)) { + if (item.name == callBack.curFilePath.substringAfterLast(File.separator)) { iv_checked.visible() } else { iv_checked.invisible() @@ -38,6 +38,6 @@ class FontAdapter(context: Context, val callBack: CallBack) : interface CallBack { fun onClick(file: File) - fun curFilePath(): String + val curFilePath: String } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 6732bf985..f72484338 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -209,7 +209,7 @@ class FontSelectDialog : BaseDialogFragment(), launch(IO) { file.copyTo(FileUtils.createFileIfNotExist(fontFolder, file.name), true) .absolutePath.let { path -> - if (callBack?.curFontPath != path) { + if (curFilePath != path) { withContext(Main) { callBack?.selectFile(path) } @@ -219,10 +219,6 @@ class FontSelectDialog : BaseDialogFragment(), } } - override fun curFilePath(): String { - return callBack?.curFontPath ?: "" - } - override fun onFilePicked(requestCode: Int, currentPath: String) { when (requestCode) { fontFolderRequestCode -> { @@ -256,13 +252,15 @@ class FontSelectDialog : BaseDialogFragment(), } private fun onDefaultFontChange() { - if (curFilePath() == "") { + if (curFilePath == "") { postEvent(EventBus.UP_CONFIG, true) } else { callBack?.selectFile("") } } + override val curFilePath: String get() = callBack?.curFontPath ?: "" + private val callBack: CallBack? get() = (parentFragment as? CallBack) ?: (activity as? CallBack) From 8a76129ce1de2129a45f40e772224232e34e01d9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 17:09:59 +0800 Subject: [PATCH 139/169] =?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 730c5320f..4e003f418 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,7 @@ **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了 +* 修复字体选择问题 * 改了下包名,好上架应用市场 **2020/02/26** From 6b73533992826933ecc11ea527c2cce3e42247ef Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 17:10:56 +0800 Subject: [PATCH 140/169] =?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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 4e003f418..8e1d73878 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,7 +4,7 @@ **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了 -* 修复字体选择问题 +* 修复默认字体问题 * 改了下包名,好上架应用市场 **2020/02/26** From c1bcea6964b5b1f603f855da45f98e250d1d5b17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 17:32:59 +0800 Subject: [PATCH 141/169] =?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/config/BackupRestoreUi.kt | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index ddc41afce..f314b5f1b 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -49,21 +49,30 @@ object BackupRestoreUi { selectBackupFolder(fragment, backupSelectRequestCode) } } else { - backupUsePermission(fragment) + backupUsePermission(fragment, requestCode = backupSelectRequestCode) } } } - private fun backupUsePermission(fragment: Fragment, path: String = Backup.legadoPath) { + private fun backupUsePermission( + fragment: Fragment, + path: String = Backup.legadoPath, + requestCode: Int = selectFolderRequestCode + ) { PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) .onGranted { - Coroutine.async { - AppConfig.backupPath = Backup.legadoPath - Backup.backup(fragment.requireContext(), path) - }.onSuccess { - fragment.toast(R.string.backup_success) + when (requestCode) { + selectFolderRequestCode -> AppConfig.backupPath = Backup.legadoPath + else -> { + Coroutine.async { + AppConfig.backupPath = Backup.legadoPath + Backup.backup(fragment.requireContext(), path) + }.onSuccess { + fragment.toast(R.string.backup_success) + } + } } } .request() @@ -74,7 +83,7 @@ object BackupRestoreUi { titleResource = R.string.select_folder items(fragment.resources.getStringArray(R.array.select_folder).toList()) { _, index -> when (index) { - 0 -> backupUsePermission(fragment) + 0 -> backupUsePermission(fragment, requestCode = requestCode) 1 -> { try { val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE) @@ -231,6 +240,9 @@ object BackupRestoreUi { App.INSTANCE.toast(R.string.restore_success) } } + selectFolderRequestCode -> { + AppConfig.backupPath = currentPath + } } } @@ -240,7 +252,8 @@ object BackupRestoreUi { data?.data?.let { uri -> App.INSTANCE.contentResolver.takePersistableUriPermission( uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() Coroutine.async { @@ -254,7 +267,8 @@ object BackupRestoreUi { data?.data?.let { uri -> App.INSTANCE.contentResolver.takePersistableUriPermission( uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() Coroutine.async { @@ -268,7 +282,8 @@ object BackupRestoreUi { data?.data?.let { uri -> App.INSTANCE.contentResolver.takePersistableUriPermission( uri, - Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + Intent.FLAG_GRANT_READ_URI_PERMISSION + or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) AppConfig.backupPath = uri.toString() } From 4dd307ab22e8491471407fca5630d48e273c087e Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 17:42:35 +0800 Subject: [PATCH 142/169] =?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/service/HttpReadAloudService.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 2cf46831c..c30180391 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -5,16 +5,14 @@ import android.media.MediaPlayer import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp +import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.api.HttpPostApi import io.legado.app.service.help.ReadBook import io.legado.app.utils.FileUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.postEvent -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.Job import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -27,7 +25,7 @@ class HttpReadAloudService : BaseReadAloudService(), private val mediaPlayer = MediaPlayer() private lateinit var ttsFolder: String - private var job: Job? = null + private var task: Coroutine<*>? = null private var playingIndex = -1 override fun onCreate() { @@ -40,13 +38,13 @@ class HttpReadAloudService : BaseReadAloudService(), override fun onDestroy() { super.onDestroy() - job?.cancel() + task?.cancel() mediaPlayer.release() } override fun newReadAloud(dataKey: String?, play: Boolean) { mediaPlayer.reset() - job?.cancel() + task?.cancel() playingIndex = -1 super.newReadAloud(dataKey, play) } @@ -64,7 +62,7 @@ class HttpReadAloudService : BaseReadAloudService(), } private fun downloadAudio() { - job = launch(IO) { + task = execute { FileUtils.deleteFile(ttsFolder) for (index in 0 until contentList.size) { if (isActive) { @@ -150,7 +148,7 @@ class HttpReadAloudService : BaseReadAloudService(), * 更新朗读速度 */ override fun upSpeechRate(reset: Boolean) { - job?.cancel() + task?.cancel() mediaPlayer.stop() playingIndex = -1 downloadAudio() From a7661f191c3abaa521f7fa9cf2aa6d569ae7f749 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 18:45:59 +0800 Subject: [PATCH 143/169] =?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/HttpReadAloudService.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index c30180391..9b4b56ebe 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -13,6 +13,7 @@ import io.legado.app.utils.FileUtils import io.legado.app.utils.LogUtils import io.legado.app.utils.postEvent import kotlinx.coroutines.isActive +import org.jetbrains.anko.toast import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -44,7 +45,6 @@ class HttpReadAloudService : BaseReadAloudService(), override fun newReadAloud(dataKey: String?, play: Boolean) { mediaPlayer.reset() - task?.cancel() playingIndex = -1 super.newReadAloud(dataKey, play) } @@ -62,6 +62,7 @@ class HttpReadAloudService : BaseReadAloudService(), } private fun downloadAudio() { + task?.cancel() task = execute { FileUtils.deleteFile(ttsFolder) for (index in 0 until contentList.size) { @@ -83,6 +84,8 @@ class HttpReadAloudService : BaseReadAloudService(), break } } + }.onError { + toast("下载朗读文件出错:${it.localizedMessage}") } } From 1871fed127b570e7803dc39659fa308beb19336f Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 19:44:51 +0800 Subject: [PATCH 144/169] =?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/ChapterProvider.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 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 dabf7caa3..a0ab804c1 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 @@ -146,7 +146,7 @@ object ChapterProvider { title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) textLine.text = words - val desiredWidth = layout.getLineMax(lineIndex) + val desiredWidth = layout.getLineWidth(lineIndex) if (lineIndex != layout.lineCount - 1) { val gapCount: Int = words.length - 1 val d = (visibleWidth - desiredWidth) / gapCount @@ -168,7 +168,7 @@ object ChapterProvider { textLine.text = "$words\n" stringBuilder.append("\n") var x = if (ReadBookConfig.titleCenter) - (visibleWidth - layout.getLineMax(lineIndex)) / 2 + (visibleWidth - layout.getLineWidth(lineIndex)) / 2 else 0f for (i in words.indices) { val char = words[i].toString() @@ -229,7 +229,7 @@ object ChapterProvider { text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) textLine.text = words - val desiredWidth = layout.getLineMax(lineIndex) + val desiredWidth = layout.getLineWidth(lineIndex) if (lineIndex == 0 && layout.lineCount > 1) { //第一行 var x = 0f From 20486e7852d62c9f0d1d3bc1e40574ef72a23de0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 20:55:29 +0800 Subject: [PATCH 145/169] =?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/CheckSourceService.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 18f704a6e..67874f9e4 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -14,6 +14,7 @@ import io.legado.app.model.WebBook import io.legado.app.ui.book.source.manage.BookSourceActivity import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher +import org.jetbrains.anko.toast import java.util.concurrent.Executors class CheckSourceService : BaseService() { @@ -68,6 +69,8 @@ class CheckSourceService : BaseService() { } } } + }.onError { + toast("校验书源出错:${it.localizedMessage}") } task?.invokeOnCompletion { From 6cc2e8b140747264a9335c87c50fdaaae1930902 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 27 Feb 2020 23:08:22 +0800 Subject: [PATCH 146/169] =?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 | 172 +++++++++--------- .../ui/book/read/page/entities/TextChar.kt | 4 +- .../ui/book/read/page/entities/TextLine.kt | 8 +- .../io/legado/app/utils/StringExtensions.kt | 12 +- 4 files changed, 103 insertions(+), 93 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 a0ab804c1..4a9d5bb71 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 @@ -12,7 +12,6 @@ import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp import io.legado.app.help.ReadBookConfig 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 @@ -148,40 +147,13 @@ object ChapterProvider { textLine.text = words val desiredWidth = layout.getLineWidth(lineIndex) if (lineIndex != layout.lineCount - 1) { - val gapCount: Int = words.length - 1 - val d = (visibleWidth - desiredWidth) / gapCount - var x = 0f - for (i in words.indices) { - val char = words[i].toString() - val cw = StaticLayout.getDesiredWidth(char, titlePaint) - val x1 = if (i != words.lastIndex) (x + cw + d) else (x + cw) - val textChar = TextChar( - charData = char, - start = paddingLeft + x, - end = paddingLeft + x1 - ) - textLine.textChars.add(textChar) - x = x1 - } + addCharsToLineMiddle(textLine, words, titlePaint, desiredWidth, 0f) } else { //最后一行 - textLine.text = "$words\n" - stringBuilder.append("\n") - var x = if (ReadBookConfig.titleCenter) + val x = if (ReadBookConfig.titleCenter) (visibleWidth - layout.getLineWidth(lineIndex)) / 2 else 0f - for (i in words.indices) { - val char = words[i].toString() - val cw = StaticLayout.getDesiredWidth(char, titlePaint) - val x1 = x + cw - val textChar = TextChar( - charData = char, - start = paddingLeft + x, - end = paddingLeft + x1 - ) - textLine.textChars.add(textChar) - x = x1 - } + addCharsToLineLast(textLine, words, stringBuilder, titlePaint, x) } } durY += paragraphSpacing @@ -225,80 +197,102 @@ object ChapterProvider { textLine.lineBase = (paddingTop + durY - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() textLine.lineBottom = textLine.lineBase + contentPaint.fontMetrics.descent - var words = + val words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) textLine.text = words val desiredWidth = layout.getLineWidth(lineIndex) if (lineIndex == 0 && layout.lineCount > 1) { //第一行 - var x = 0f - val icw = StaticLayout.getDesiredWidth(bodyIndent, contentPaint) / bodyIndent.length - for (i in 0..bodyIndent.lastIndex) { - val x1 = x + icw - val textChar = TextChar( - charData = bodyIndent[i].toString(), - start = paddingLeft + x, - end = paddingLeft + x1 - ) - textLine.textChars.add(textChar) - x = x1 - } - words = words.replaceFirst(bodyIndent, "") - val gapCount: Int = words.length - 1 - val d = (visibleWidth - desiredWidth) / gapCount - for (i in words.indices) { - val char = words[i].toString() - val cw = StaticLayout.getDesiredWidth(char, contentPaint) - val x1 = if (i != words.lastIndex) x + cw + d else x + cw - val textChar1 = TextChar( - charData = char, - start = paddingLeft + x, - end = paddingLeft + x1 - ) - textLine.textChars.add(textChar1) - x = x1 - } + addCharsToLineFirst(textLine, words, contentPaint, desiredWidth) } else if (lineIndex == layout.lineCount - 1) { //最后一行 - stringBuilder.append("\n") - textLine.text = "$words\n" - var x = 0f - for (i in words.indices) { - val char = words[i].toString() - val cw = StaticLayout.getDesiredWidth(char, contentPaint) - val x1 = x + cw - val textChar = TextChar( - charData = char, - start = paddingLeft + x, - end = paddingLeft + x1 - ) - textLine.textChars.add(textChar) - x = x1 - } + addCharsToLineLast(textLine, words, stringBuilder, contentPaint, 0f) } else { //中间行 - val gapCount: Int = words.length - 1 - val d = (visibleWidth - desiredWidth) / gapCount - var x = 0f - for (i in words.indices) { - val char = words[i].toString() - val cw = StaticLayout.getDesiredWidth(char, contentPaint) - val x1 = if (i != words.lastIndex) x + cw + d else x + cw - val textChar = TextChar( - charData = char, - start = paddingLeft + x, - end = paddingLeft + x1 - ) - textLine.textChars.add(textChar) - x = x1 - } + addCharsToLineMiddle(textLine, words, contentPaint, desiredWidth, 0f) } } durY += paragraphSpacing return durY } + /** + * 有缩进,两端对齐 + */ + private fun addCharsToLineFirst( + textLine: TextLine, + words: String, + textPaint: TextPaint, + desiredWidth: Float + ) { + var x = 0f + val icw = StaticLayout.getDesiredWidth(bodyIndent, textPaint) / bodyIndent.length + for (i in 0..bodyIndent.lastIndex) { + val x1 = x + icw + textLine.addTextChar( + charData = bodyIndent[i].toString(), + start = paddingLeft + x, + end = paddingLeft + x1 + ) + x = x1 + } + val words1 = words.replaceFirst(bodyIndent, "") + addCharsToLineMiddle(textLine, words1, textPaint, desiredWidth, x) + } + + /** + * 无缩进,两端对齐 + */ + private fun addCharsToLineMiddle( + textLine: TextLine, + words: String, + textPaint: TextPaint, + desiredWidth: Float, + startX: Float + ) { + val gapCount: Int = words.length - 1 + val d = (visibleWidth - desiredWidth) / gapCount + var x = startX + for (i in words.indices) { + val char = words[i] + val cw = StaticLayout.getDesiredWidth(char.toString(), textPaint) + val x1 = if (i != words.lastIndex) (x + cw + d) else (x + cw) + textLine.addTextChar( + charData = char.toString(), + start = paddingLeft + x, + end = paddingLeft + x1 + ) + x = x1 + } + } + + /** + * 最后一行,自然排列 + */ + private fun addCharsToLineLast( + textLine: TextLine, + words: String, + stringBuilder: StringBuilder, + textPaint: TextPaint, + startX: Float + ) { + stringBuilder.append("\n") + textLine.text = "$words\n" + var x = startX + for (i in words.indices) { + val char = words[i].toString() + val cw = StaticLayout.getDesiredWidth(char, textPaint) + val x1 = x + cw + textLine.addTextChar( + charData = char, + start = paddingLeft + x, + end = paddingLeft + x1 + ) + x = x1 + } + } + /** * 更新样式 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 6fed2fe97..642fc0dc6 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 @@ -2,7 +2,7 @@ package io.legado.app.ui.book.read.page.entities data class TextChar( val charData: String, - var selected: Boolean = false, val start: Float, - val end: Float + val end: Float, + var selected: Boolean = false ) \ 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 26fb31e90..547ad085d 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 @@ -8,4 +8,10 @@ data class TextLine( var lineBottom: Float = 0f, val isTitle: Boolean = false, var isReadAloud: Boolean = false -) \ No newline at end of file +) { + + fun addTextChar(charData: String, start: Float, end: Float) { + textChars.add(TextChar(charData, start = start, end = end)) + } + +} diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index 63954162e..3f4f40ee2 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -48,4 +48,14 @@ fun String.splitNotBlank(regex: Regex, limit: Int = 0): Array = run { this.split(regex, limit).map { it.trim() }.filterNot { it.isBlank() }.toTypedArray() } - +fun Char?.isHAN(): Boolean { + this ?: return false + val ub: Character.UnicodeBlock = Character.UnicodeBlock.of(this) ?: return false + return ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS + || ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A + || ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B + || ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_C + || ub === Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_D + || ub === Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS + || ub === Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT +} From e1c8c7c8e22da5c275864cd667faa259a6521519 Mon Sep 17 00:00:00 2001 From: hingbong Date: Thu, 27 Feb 2020 23:24:28 +0800 Subject: [PATCH 147/169] =?UTF-8?q?=E9=98=85=E8=AF=BB=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=B7=A6=E4=B8=8B=E8=A7=92=E7=AB=A0=E8=8A=82=E5=90=8D=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=AE=80=E4=BD=93/=E7=B9=81=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../java/io/legado/app/ui/book/read/page/ContentView.kt | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index d6f63988d..1b0c7d4b0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -140,7 +140,7 @@ dependencies { implementation 'com.jeremyliao:live-event-bus-x:1.4.5' //协程 - def coroutines_version = '1.2.2' + def coroutines_version = '1.3.3' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" 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 7bbc2adc5..7f1dcec1c 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 @@ -5,8 +5,10 @@ import android.content.Context import android.graphics.drawable.Drawable import android.view.MotionEvent import android.widget.FrameLayout +import com.github.houbb.opencc4j.core.impl.ZhConvertBootstrap import io.legado.app.R import io.legado.app.constant.AppConst.TIME_FORMAT +import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.page.entities.TextPage import io.legado.app.utils.* @@ -90,7 +92,11 @@ class ContentView(context: Context) : FrameLayout(context) { } fun setContent(textPage: TextPage) { - tv_bottom_left.text = textPage.title + tv_bottom_left.text = when (AppConfig.chineseConverterType) { + 1 -> ZhConvertBootstrap.newInstance().toSimple(textPage.title) + 2 -> ZhConvertBootstrap.newInstance().toTraditional(textPage.title) + else -> textPage.title + } setPageIndex(textPage.index, textPage.pageSize) content_text_view.resetPageOffset() content_text_view.setContent(textPage) From b15928026c271cf78f61df96fb22adc1020361b0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 09:04:25 +0800 Subject: [PATCH 148/169] =?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 | 18 ++++++++++++++++++ .../app/ui/book/read/page/entities/TextChar.kt | 4 ++-- .../app/ui/book/read/page/entities/TextLine.kt | 11 +++++++++++ 3 files changed, 31 insertions(+), 2 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 4a9d5bb71..2c3996fd8 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 @@ -265,6 +265,7 @@ object ChapterProvider { ) x = x1 } + exceed(textLine, words) } /** @@ -291,8 +292,25 @@ object ChapterProvider { ) x = x1 } + exceed(textLine, words) } + /** + * 超出边界处理 + */ + private fun exceed(textLine: TextLine, words: String) { + val endX = textLine.textChars.last().end + if (endX > visibleRight) { + val cc = (endX - visibleRight) / words.length + for (i in 0..words.lastIndex) { + textLine.getTextCharReverseAt(i).let { + val py = cc * (words.length - i) + it.start = it.start - py + it.end = it.end - py + } + } + } + } /** * 更新样式 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 642fc0dc6..72798a9ea 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 @@ -2,7 +2,7 @@ package io.legado.app.ui.book.read.page.entities data class TextChar( val charData: String, - val start: Float, - val end: Float, + var start: Float, + var end: Float, var selected: Boolean = false ) \ 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 547ad085d..a9c84fb68 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 @@ -14,4 +14,15 @@ data class TextLine( textChars.add(TextChar(charData, start = start, end = end)) } + fun getTextCharAt(index: Int): TextChar { + return textChars[index] + } + + fun getTextCharReverseAt(index: Int): TextChar { + return textChars[textChars.lastIndex - index] + } + + fun getTextCharsCount(): Int { + return textChars.size + } } From 8f5545931da8a6cb3a4dbfdcebf7f655deeb1e45 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 09:53:48 +0800 Subject: [PATCH 149/169] =?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 | 4 ++ .../app/ui/widget/image/CircleImageView.kt | 40 +++++++------------ .../res/layout/dialog_read_book_style.xml | 5 +++ 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 8e1d73878..7bf8ec04a 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,6 +2,10 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/28** +* 解决阅读界面部分字体超出范围的问题 +* + **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了 * 修复默认字体问题 diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index 253c1bef3..7f14686e8 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt @@ -24,7 +24,11 @@ import io.legado.app.utils.sp import kotlin.math.min import kotlin.math.pow -class CircleImageView : AppCompatImageView { +class CircleImageView(context: Context, attrs: AttributeSet) : + AppCompatImageView( + context, + attrs + ) { private val mDrawableRect = RectF() private val mBorderRect = RectF() @@ -59,10 +63,9 @@ class CircleImageView : AppCompatImageView { private var mBorderOverlay: Boolean = false var isDisableCircularTransformation: Boolean = false set(disableCircularTransformation) { - if (isDisableCircularTransformation == disableCircularTransformation) { + if (field == disableCircularTransformation) { return } - field = disableCircularTransformation initializeBitmap() } @@ -85,7 +88,6 @@ class CircleImageView : AppCompatImageView { if (circleBackgroundColor == mCircleBackgroundColor) { return } - mCircleBackgroundColor = circleBackgroundColor mCircleBackgroundPaint.color = circleBackgroundColor invalidate() @@ -117,23 +119,14 @@ class CircleImageView : AppCompatImageView { private var textColor = context.getCompatColor(R.color.tv_text_default) - constructor(context: Context) : super(context) { - init() - } - - @JvmOverloads - constructor(context: Context, attrs: AttributeSet, defStyle: Int = 0) : super( - context, - attrs, - defStyle - ) { - - val a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0) - - mBorderWidth = a.getDimensionPixelSize( - R.styleable.CircleImageView_civ_border_width, - DEFAULT_BORDER_WIDTH - ) + init { + super.setScaleType(SCALE_TYPE) + val a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView) + mBorderWidth = + a.getDimensionPixelSize( + R.styleable.CircleImageView_civ_border_width, + DEFAULT_BORDER_WIDTH + ) mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR) mBorderOverlay = @@ -152,11 +145,6 @@ class CircleImageView : AppCompatImageView { } a.recycle() - init() - } - - private fun init() { - super.setScaleType(SCALE_TYPE) mReady = true if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { diff --git a/app/src/main/res/layout/dialog_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml index 358d68063..2e6c05061 100644 --- a/app/src/main/res/layout/dialog_read_book_style.xml +++ b/app/src/main/res/layout/dialog_read_book_style.xml @@ -269,6 +269,7 @@ android:id="@+id/bg0" android:layout_width="48dp" android:layout_height="48dp" + android:src="@drawable/image_cover_default" app:civ_border_color="@color/tv_text_default" app:civ_border_width="1dp" app:text="@string/text" @@ -281,6 +282,7 @@ android:id="@+id/bg1" android:layout_width="48dp" android:layout_height="48dp" + android:src="@drawable/image_cover_default" app:civ_border_color="@color/tv_text_default" app:civ_border_width="1dp" app:text="@string/text" @@ -293,6 +295,7 @@ android:id="@+id/bg2" android:layout_width="48dp" android:layout_height="48dp" + android:src="@drawable/image_cover_default" app:civ_border_color="@color/tv_text_default" app:civ_border_width="1dp" app:text="@string/text" @@ -305,6 +308,7 @@ android:id="@+id/bg3" android:layout_width="48dp" android:layout_height="48dp" + android:src="@drawable/image_cover_default" app:civ_border_color="@color/tv_text_default" app:civ_border_width="1dp" app:text="@string/text" @@ -317,6 +321,7 @@ android:id="@+id/bg4" android:layout_width="48dp" android:layout_height="48dp" + android:src="@drawable/image_cover_default" app:civ_border_color="@color/tv_text_default" app:civ_border_width="1dp" app:text="@string/text" From 8152b4e87976f4e8a5979ab9037b458dc2f4ff24 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 10:01:28 +0800 Subject: [PATCH 150/169] =?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/AndroidManifest.xml | 14 ++++++++++++-- .../ui/rss/source/manage/RssSourceActivity.kt | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a8ebd70da..563605c91 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -142,7 +142,6 @@ - @@ -152,7 +151,18 @@ - + + + + + + + + + + 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 517290130..22277476e 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 @@ -57,6 +57,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r private var groupMenu: SubMenu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { + initUriScheme() initRecyclerView() initSearchView() initLiveDataGroup() @@ -102,6 +103,22 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r return true } + private fun initUriScheme() { + intent.data?.let { + when (it.path) { + "/importonline" -> it.getQueryParameter("src")?.let { url -> + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() + viewModel.importSource(url) { msg -> + title_bar.snackbar(msg) + } + } + else -> { + toast("格式不对") + } + } + } + } + private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) From 98b75d547bdfeb9a98b6380316955bcc0073ae39 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 10:28:16 +0800 Subject: [PATCH 151/169] =?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 ++- .../app/ui/book/read/page/ContentTextView.kt | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 7bf8ec04a..3a564b3fa 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,7 +4,8 @@ **2020/02/28** * 解决阅读界面部分字体超出范围的问题 -* +* 修复背景切换有时空白的bug +* 修复滚动翻页问题 **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了 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 35f43c811..1bd474c89 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 @@ -164,15 +164,23 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at pageOffset += offset if (pageOffset > 0) { - pageFactory.moveToPrev() - textPage = pageFactory.currentPage - pageOffset -= textPage.height - upView?.invoke(textPage) + if (!pageFactory.hasPrev()) { + pageOffset = 0f + } else { + pageFactory.moveToPrev() + textPage = pageFactory.currentPage + pageOffset -= textPage.height + upView?.invoke(textPage) + } } else if (pageOffset < -textPage.height) { - pageOffset += textPage.height - pageFactory.moveToNext() - textPage = pageFactory.currentPage - upView?.invoke(textPage) + if (!pageFactory.hasNext()) { + pageOffset = -textPage.height.toFloat() + } else { + pageOffset += textPage.height + pageFactory.moveToNext() + textPage = pageFactory.currentPage + upView?.invoke(textPage) + } } invalidate() } From ae3581d29cd3738733b94c67708290f49e98ae53 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 11:17:49 +0800 Subject: [PATCH 152/169] =?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/base/BaseDialogFragment.kt | 9 +++++++++ .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt index 8bb119625..e893e34c4 100644 --- a/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseDialogFragment.kt @@ -2,6 +2,7 @@ package io.legado.app.base import android.os.Bundle import androidx.fragment.app.DialogFragment +import io.legado.app.help.coroutine.Coroutine import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -21,4 +22,12 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope { super.onDestroy() job.cancel() } + + fun execute( + scope: CoroutineScope = this, + context: CoroutineContext = Dispatchers.IO, + block: suspend CoroutineScope.() -> T + ): Coroutine { + return Coroutine.async(scope, context) { block() } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index f72484338..87d87e8d6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -147,7 +147,7 @@ class FontSelectDialog : BaseDialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(doc: DocumentFile) { - launch(IO) { + execute { val docItems = DocumentUtils.listFiles(App.INSTANCE, doc.uri) fontCacheFolder.listFiles()?.forEach { fontFile -> var contain = false @@ -182,6 +182,8 @@ class FontSelectDialog : BaseDialogFragment(), } catch (e: Exception) { toast(e.localizedMessage ?: "") } + }.onError { + toast("getFontFiles:${it.localizedMessage}") } } From dee067557e91825e2378492414d5ee4a21a5526b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 11:34:10 +0800 Subject: [PATCH 153/169] =?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 | 4 ++-- .../io/legado/app/ui/book/read/config/ReadStyleDialog.kt | 8 +------- app/src/main/java/io/legado/app/utils/BitmapUtils.kt | 7 ++++++- 3 files changed, 9 insertions(+), 10 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 3b05df869..63b59278f 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -215,7 +215,7 @@ object ReadBookConfig { class Config( private var bgStr: String = "#EEEEEE",//白天背景 private var bgStrNight: String = "#000000",//夜间背景 - private var bgType: Int = 0,//白天背景类型 + private var bgType: Int = 0,//白天背景类型 0:颜色, 1:assets图片, 2其它图片 private var bgTypeNight: Int = 0,//夜间背景类型 private var darkStatusIcon: Boolean = true,//白天是否暗色状态栏 private var darkStatusIconNight: Boolean = false,//晚上是否暗色状态栏 @@ -299,7 +299,7 @@ object ReadBookConfig { 1 -> { BitmapDrawable( resources, - BitmapUtils.decodeBitmap( + BitmapUtils.decodeAssetsBitmap( App.INSTANCE, "bg" + File.separator + bgStr(), width, 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 c78466569..b7a0a330b 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 @@ -12,7 +12,6 @@ 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 import io.legado.app.lib.theme.accentColor @@ -219,12 +218,7 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack { 4 -> bg4 else -> bg0 } - ReadBookConfig.getConfig(i).apply { - when (bgType()) { - 2 -> ImageLoader.load(requireContext(), bgStr()).centerCrop().into(iv) - else -> iv.setImageDrawable(bgDrawable(100, 150)) - } - } + iv.setImageDrawable(ReadBookConfig.getConfig(i).bgDrawable(100, 150)) } } diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 14212f442..371be8122 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -121,7 +121,12 @@ object BitmapUtils { * @throws IOException */ @Throws(IOException::class) - fun decodeBitmap(context: Context, fileNameInAssets: String, width: Int, height: Int): Bitmap? { + fun decodeAssetsBitmap( + context: Context, + fileNameInAssets: String, + width: Int, + height: Int + ): Bitmap? { var inputStream = context.assets.open(fileNameInAssets) val op = BitmapFactory.Options() From 034978da883aa471c189127ef00298709f38b260 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 12:36:37 +0800 Subject: [PATCH 154/169] =?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/ui/rss/read/ReadRssActivity.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index ebaf05233..bb5700967 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -66,6 +66,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r webView.settings.apply { mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW domStorageEnabled = true + allowContentAccess = true } } From b6ed0f44e344cae089febd82fb1b0adb19e3c6ce Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 13:55:15 +0800 Subject: [PATCH 155/169] =?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/rss/read/ReadRssActivity.kt | 18 +++++++++++++++++- .../io/legado/app/utils/ContextExtensions.kt | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index bb5700967..255505178 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -5,7 +5,9 @@ import android.os.Bundle import android.view.KeyEvent import android.view.Menu import android.view.MenuItem +import android.webkit.WebResourceRequest import android.webkit.WebSettings +import android.webkit.WebView import android.webkit.WebViewClient import androidx.lifecycle.Observer import io.legado.app.R @@ -14,6 +16,7 @@ import io.legado.app.lib.theme.DrawableUtils import io.legado.app.lib.theme.primaryTextColor import io.legado.app.utils.NetworkUtils import io.legado.app.utils.getViewModel +import io.legado.app.utils.openUrl import kotlinx.android.synthetic.main.activity_rss_read.* import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils @@ -62,7 +65,20 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } private fun initWebView() { - webView.webViewClient = WebViewClient() + webView.webViewClient = object : WebViewClient() { + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest? + ): Boolean { + if (request?.url?.scheme == "http" || request?.url?.scheme == "https") { + return false + } + request?.url?.let { + openUrl(it) + } + return true + } + } webView.settings.apply { mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW domStorageEnabled = 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 2f05fa014..febb0989a 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -149,8 +149,12 @@ val Context.sysBattery: Int } fun Context.openUrl(url: String) { + openUrl(Uri.parse(url)) +} + +fun Context.openUrl(uri: Uri) { val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(url) + intent.data = uri if (intent.resolveActivity(packageManager) != null) { try { startActivity(intent) From 2f89fb2524e4c73b3e2de77bfa9c4871c54b2d60 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 13:56:38 +0800 Subject: [PATCH 156/169] =?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 3a564b3fa..6401e565f 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ * 解决阅读界面部分字体超出范围的问题 * 修复背景切换有时空白的bug * 修复滚动翻页问题 +* 添加书源一键导入 **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了 From 373d062cd4501ab158a92e571a9df73e260c5f75 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 14:11:52 +0800 Subject: [PATCH 157/169] =?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/AndroidManifest.xml | 33 ++++++++++++++----- .../app/ui/replacerule/ReplaceRuleActivity.kt | 17 ++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 563605c91..ba4789e2c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -123,9 +123,6 @@ - @@ -135,8 +132,8 @@ - - + + @@ -147,10 +144,7 @@ android:scheme="yuedu" /> - - - - + @@ -163,6 +157,27 @@ android:scheme="yuedu" /> + + + + + + + + + + + + + + + + + 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 331c87a5d..5044e2667 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 @@ -55,6 +55,7 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi private var dataInit = false override fun onActivityCreated(savedInstanceState: Bundle?) { + initUriScheme() initRecyclerView() initSearchView() initSelectActionView() @@ -73,6 +74,22 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi return super.onPrepareOptionsMenu(menu) } + private fun initUriScheme() { + intent.data?.let { + when (it.path) { + "/importonline" -> it.getQueryParameter("src")?.let { url -> + Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() + viewModel.importSource(url) { msg -> + title_bar.snackbar(msg) + } + } + else -> { + toast("格式不对") + } + } + } + } + private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) From 51c0ac8f1b88e71598632410f88365ee5dc42c67 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 14:12:34 +0800 Subject: [PATCH 158/169] =?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/AndroidManifest.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ba4789e2c..e4bc75603 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -132,7 +132,6 @@ - From a17cd1fb7b58b10ecd5c93b5b4fcfc8e7a5a7d13 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 14:46:34 +0800 Subject: [PATCH 159/169] =?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/ReadBookActivity.kt | 2 +- .../java/io/legado/app/ui/book/read/page/ContentTextView.kt | 1 + .../main/java/io/legado/app/ui/book/read/page/PageView.kt | 5 ----- .../io/legado/app/ui/book/read/page/delegate/PageDelegate.kt | 4 ---- 4 files changed, 2 insertions(+), 10 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 0f08df7c0..48bdd6cf6 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 @@ -691,7 +691,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo upScreenTimeOut() } observeEvent(PreferKey.textSelectAble) { - page_view.upSelectAble(it) + page_view.curPage.upSelectAble(it) } } 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 1bd474c89..d17e55a67 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 @@ -197,6 +197,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at y: Float, select: (relativePage: Int, lineIndex: Int, charIndex: Int) -> Unit ) { + if (!selectAble) return if (!visibleRect.contains(x, y)) return var relativeOffset = relativeOffset(0) for ((lineIndex, textLine) in textPage.textLines.withIndex()) { 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 52acc8195..1482d309a 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 @@ -132,11 +132,6 @@ class PageView(context: Context, attrs: AttributeSet) : } } - fun upSelectAble(selectAble: Boolean) { - pageDelegate?.upSelectAble(selectAble) - curPage.upSelectAble(selectAble) - } - fun upStyle() { ChapterProvider.upStyle() curPage.upStyle() 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 c710367c7..2b26714c4 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 @@ -101,10 +101,6 @@ abstract class PageDelegate(protected val pageView: PageView) : onScroll() } - fun upSelectAble(selectAble: Boolean) { - detector.setIsLongpressEnabled(selectAble) - } - open fun fling( startX: Int, startY: Int, velocityX: Int, velocityY: Int, minX: Int, maxX: Int, minY: Int, maxY: Int From c380d1e7e7f621d136960048eef9ac8e12095b33 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 15:12:45 +0800 Subject: [PATCH 160/169] =?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/App.kt | 7 ++++++- app/src/main/java/io/legado/app/utils/ContextExtensions.kt | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 7310dcef8..24ebd1270 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -5,6 +5,7 @@ import android.app.Application import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context +import android.content.res.Configuration import android.os.Build import android.os.Bundle import androidx.annotation.RequiresApi @@ -62,6 +63,11 @@ class App : Application() { registerActivityLife() } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + initNightMode() + } + /** * 更新主题 */ @@ -91,7 +97,6 @@ class App : Application() { ) .apply() } -// ChapterProvider.upReadAloudSpan() } fun applyDayNight() { 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 febb0989a..3436c9d94 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -133,6 +133,9 @@ fun Context.sendToClip(text: String) { } } +/** + * 系统是否暗色主题 + */ fun Context.sysIsDarkMode(): Boolean { val mode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK return mode == Configuration.UI_MODE_NIGHT_YES From 9e4fd23fb6431b95cf00028751428cab1dfc6ddc Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 15:17:40 +0800 Subject: [PATCH 161/169] =?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 63b59278f..57ccd5f14 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -34,7 +34,7 @@ object ReadBookConfig { var shareLayout = App.INSTANCE.getPrefBoolean(PreferKey.shareLayout) set(value) { field = value - App.INSTANCE.putPrefBoolean(PreferKey.shareLayout) + App.INSTANCE.putPrefBoolean(PreferKey.shareLayout, value) } var pageAnim = App.INSTANCE.getPrefInt(PreferKey.pageAnim) set(value) { From ffb8ed4b66bf57e743a3ab09b6b02be6f78d1b1e Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 15:27:08 +0800 Subject: [PATCH 162/169] =?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/storage/Restore.kt | 4 ++++ 1 file changed, 4 insertions(+) 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 9fd939f74..dd48d6472 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 @@ -12,6 +12,8 @@ import io.legado.app.constant.PreferKey import io.legado.app.data.entities.* import io.legado.app.help.LauncherIconHelp import io.legado.app.help.ReadBookConfig +import io.legado.app.service.help.ReadBook +import io.legado.app.ui.book.read.page.ChapterProvider import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext @@ -113,6 +115,8 @@ object Restore { hideStatusBar = App.INSTANCE.getPrefBoolean(PreferKey.hideStatusBar) hideNavigationBar = App.INSTANCE.getPrefBoolean(PreferKey.hideNavigationBar) } + ChapterProvider.upStyle() + ReadBook.loadContent() } LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon)) } From ecd221930a7850a434ebc38b248978e6cbfdfcac Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 15:31:53 +0800 Subject: [PATCH 163/169] =?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/App.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 24ebd1270..996f449d7 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -65,7 +65,9 @@ class App : Application() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) - initNightMode() + when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) { + Configuration.UI_MODE_NIGHT_YES, Configuration.UI_MODE_NIGHT_NO -> initNightMode() + } } /** From eb1af6df3b48d548a2fd74e037cfb10655da9d02 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 15:34:17 +0800 Subject: [PATCH 164/169] =?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/App.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 996f449d7..cf0f4cf43 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -66,7 +66,7 @@ class App : Application() { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) when (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) { - Configuration.UI_MODE_NIGHT_YES, Configuration.UI_MODE_NIGHT_NO -> initNightMode() + Configuration.UI_MODE_NIGHT_YES, Configuration.UI_MODE_NIGHT_NO -> applyDayNight() } } From acc9b0738e21d4d828e636c190d06f44c02466c0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 16:12:38 +0800 Subject: [PATCH 165/169] =?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 6401e565f..3e30d56af 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -7,6 +7,7 @@ * 修复背景切换有时空白的bug * 修复滚动翻页问题 * 添加书源一键导入 +* 修复主题模式跟随系统 **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了 From 46081225e93de05e7114e8b0e48ea5a0d9529e4c Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 17:10:24 +0800 Subject: [PATCH 166/169] =?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/widget/prefs/IconListPreference.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index ff3fa801c..b295e5ad3 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -167,8 +167,14 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference dialogIconNames?.let { val resId = context.resources .getIdentifier(it[index].toString(), "mipmap", context.packageName) - val d = context.getCompatDrawable(resId) - icon.setImageDrawable(d) + val d = try { + context.getCompatDrawable(resId) + } catch (e: Exception) { + null + } + d?.let { + icon.setImageDrawable(d) + } } label.isChecked = item.toString() == dialogValue onClick { From e49ff9567724b23c37125fc68f7535d59b9a5233 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 17:28:50 +0800 Subject: [PATCH 167/169] =?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/qrcode/QrCodeActivity.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt b/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt index bfd4d23a1..6ea1d85bd 100644 --- a/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.qrcode import android.app.Activity import android.content.Intent +import android.graphics.BitmapFactory import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -11,7 +12,7 @@ import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat -import io.legado.app.utils.RealPathUtil +import io.legado.app.utils.readBytes import kotlinx.android.synthetic.main.activity_qrcode_capture.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.toast @@ -98,9 +99,11 @@ class QrCodeActivity : BaseActivity(R.layout.activity_qrcode_capture), QRCodeVie zxingview.startSpotAndShowRect() // 显示扫描框,并开始识别 if (resultCode == Activity.RESULT_OK && requestCode == requestQrImage) { - val picturePath = RealPathUtil.getPath(this, it) // 本来就用到 QRCodeView 时可直接调 QRCodeView 的方法,走通用的回调 - zxingview.decodeQRCode(picturePath) + it.readBytes(this)?.let { bytes -> + val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size) + zxingview.decodeQRCode(bitmap) + } } } } From f9c1183580307f582f3557c874e178cd3971d2da Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 19:24:16 +0800 Subject: [PATCH 168/169] =?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/service/CheckSourceService.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 67874f9e4..d94b3a6d1 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -21,8 +21,8 @@ class CheckSourceService : BaseService() { private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null - private var idsCount = 0 - private val unCheckIds = LinkedHashSet() + private val allIds = LinkedHashSet() + private val checkedIds = LinkedHashSet() override fun onCreate() { super.onCreate() @@ -47,12 +47,12 @@ class CheckSourceService : BaseService() { private fun check(ids: List) { task?.cancel() - unCheckIds.clear() - idsCount = ids.size - unCheckIds.addAll(ids) - updateNotification(0, getString(R.string.progress_show, 0, idsCount)) - task = execute { - unCheckIds.forEach { sourceUrl -> + allIds.clear() + checkedIds.clear() + allIds.addAll(ids) + updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + task = execute(context = searchPool) { + allIds.forEach { sourceUrl -> App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> val webBook = WebBook(source) webBook.searchBook("我的", scope = this, context = searchPool) @@ -60,11 +60,10 @@ class CheckSourceService : BaseService() { source.addGroup("失效") App.db.bookSourceDao().update(source) }.onFinally { - unCheckIds.remove(sourceUrl) - val checkedCount = idsCount - unCheckIds.size + checkedIds.add(sourceUrl) updateNotification( - checkedCount, - getString(R.string.progress_show, checkedCount, idsCount) + checkedIds.size, + getString(R.string.progress_show, checkedIds.size, allIds.size) ) } } @@ -95,7 +94,7 @@ class CheckSourceService : BaseService() { getString(R.string.cancel), IntentHelp.servicePendingIntent(this, IntentAction.stop) ) - builder.setProgress(idsCount, state, false) + builder.setProgress(allIds.size, state, false) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() startForeground(112202, notification) From d7017bd39a948c589b2341a5c777a8577bc55d9f Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 19:29:22 +0800 Subject: [PATCH 169/169] =?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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 3e30d56af..9bf7bcd87 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,12 +2,15 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/02/29** +* 添加书源一键导入 +* 修复主题模式跟随系统 +* 修复书源校验 + **2020/02/28** * 解决阅读界面部分字体超出范围的问题 * 修复背景切换有时空白的bug * 修复滚动翻页问题 -* 添加书源一键导入 -* 修复主题模式跟随系统 **2020/02/27** * 修复bug,边距调节,换源等一些bug,记不清了