From d2dab7f43bc8856ecdd3137ac67c0f8644b09de5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 14:46:21 +0800 Subject: [PATCH 01/21] =?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 304df9997..b7b45baea 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -300,6 +300,8 @@ object BookHelp { 1 -> c = ZhConvertBootstrap.newInstance().toSimple(c) 2 -> c = ZhConvertBootstrap.newInstance().toTraditional(c) } - return c.replace("\\s*\\n+\\s*".toRegex(), "\n${ReadBookConfig.bodyIndent}") + return c + .replace("\\s*\\n+\\s*".toRegex(), "\n${ReadBookConfig.bodyIndent}") + .replace("[\\n\\s]+$".toRegex(), "") //移除尾部空行 } } \ No newline at end of file From 16b7ea73476281a3b1c099763d82793cf0eef2f6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 18:48:41 +0800 Subject: [PATCH 02/21] =?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 3503f19ef..fe74ee832 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,6 +4,7 @@ **2020/03/09** * 底部文字对齐 +* 主题添加阴影调节 by yangyxd **2020/03/08** * 订阅长按保存图片 From 23a718a795ed8bad2320d771b34dc9fe473814d3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 19:41:34 +0800 Subject: [PATCH 03/21] =?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/TTSReadAloudService.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 6fd32219d..e54900db7 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -175,9 +175,7 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener } override fun onError(s: String) { - launch { - toast(s) - } + pauseReadAloud(true) } } From 5d7716ecef441faa4c7635dcfebbee48109bc592 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 19:48:54 +0800 Subject: [PATCH 04/21] =?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/widget/TitleBar.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 8df952849..10cd4191f 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 @@ -144,10 +144,10 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a backgroundColor = context.primaryColor // targetElevation = context.elevation stateListAnimator = null - if (AppConfig.elevation < 0) { - elevation = context.elevation + elevation = if (AppConfig.elevation < 0) { + context.elevation } else { - elevation = AppConfig.elevation.toFloat() + AppConfig.elevation.toFloat() } a.recycle() From cb568cbeb6aa8745a0bea91d53a0aa01f22865fe Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 19:49:35 +0800 Subject: [PATCH 05/21] =?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/widget/TitleBar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 10cd4191f..663bb55a8 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 @@ -142,7 +142,7 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a } backgroundColor = context.primaryColor - // targetElevation = context.elevation + stateListAnimator = null elevation = if (AppConfig.elevation < 0) { context.elevation From 37e399d8e49ad840970ed8d1d20e5eb22ae20ed8 Mon Sep 17 00:00:00 2001 From: fisher Date: Mon, 9 Mar 2020 20:28:36 +0800 Subject: [PATCH 06/21] update all rules --- app/src/main/assets/txtTocRule.json | 54 +++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/app/src/main/assets/txtTocRule.json b/app/src/main/assets/txtTocRule.json index fc5469653..cce871125 100644 --- a/app/src/main/assets/txtTocRule.json +++ b/app/src/main/assets/txtTocRule.json @@ -2,25 +2,25 @@ { "enable": true, "name": "目录", - "rule": "^[  \\t]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$", + "rule": "^[  \\t]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$", "serialNumber": 0 }, { "enable": false, - "name": "目录(不匹配行前空白)", - "rule": "^(?<= |\\s)(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$", + "name": "目录(去空白)", + "rule": "(?<=[ \\s])(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|篇(?!张))).{0,30}$", "serialNumber": 1 }, { "enable": false, "name": "目录(去简介)", - "rule": "^(?<= |\\s)(?:前言|序章|楔子|正文(?!完)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", + "rule": "(?<=[ \\s])(?:前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", "serialNumber": 2 }, { "enable": false, "name": "目录(古典、轻小说备用)", - "rule": "^[  \\t]{0,4}(?:前言|序章|楔子|正文(?!完)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", + "rule": "^[  \\t]{0,4}(?:前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", "serialNumber": 3 }, { @@ -32,43 +32,61 @@ { "enable": true, "name": "正文 标题/序号", - "rule": "^[  \\t]{0,4}正文\\s{1,4}.{0,20}$", + "rule": "^[  \\t]{0,4}正文[  ]{1,4}.{0,20}$", "serialNumber": 5 }, { "enable": true, "name": "Chapter/Section/Part/Episode 序号 标题", - "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode)\\s{0,4}\\d{1,4}.{0,30}$", + "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)\\s{0,4}\\d{1,4}.{0,30}$", "serialNumber": 6 }, { - "enable": true, - "name": "特殊符号 序号 标题", - "rule": "^[  \\t]{0,4}[〈〖〔【][第卷][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,10}[章节][\\.:: \f\t].{0,30}$", + "enable": false, + "name": "Chapter(去简介)", + "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode)\\s{0,4}\\d{1,4}.{0,30}$", "serialNumber": 7 }, { "enable": true, - "name": "特殊符号 标题", - "rule": "^[  \\t]{0,4}[\\[〈「『〖〔《(【\\(☆★].{1,30}[\\)】)》〕〗』」〉\\]]?\\s{0,4}$", + "name": "特殊符号 序号 标题", + "rule": "(?<=[\\s ]{0,4}).{1,3}(?:第|卷|[Cc]hapter)[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,10}[章节]?[\\.:: \f\t].{0,20}$", "serialNumber": 8 }, { - "enable":false, - "name": "特殊符号 标题(不匹配空白字符)", - "rule": "^(?<= |\\s)[\\[〈「『〖〔《(【\\(☆★].{1,30}[\\)】)》〕〗』」〉\\]]?\\s{0,4}$", + "enable": false, + "name": "特殊符号 标题(成对)", + "rule": "(?<=[\\s ]{0,4})(?:[\\[〈「『〖〔《(【\\(].{1,30}[\\)】)》〕〗』」〉\\]]?|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$", "serialNumber": 9 }, + { + "enable":true, + "name": "特殊符号 标题(单个)", + "rule": "(?<=[\\s ]{0,4})(?:[☆★✦✧].{1,30}|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$", + "serialNumber": 10 + }, { "enable": true, "name": "章/卷 序号 标题", - "rule": "^[  \\t]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完)|终章|后记|尾声|番外|[卷章][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8})\\s{0,4}.{0,30}$", - "serialNumber": 10 + "rule": "^[ \\t ]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|[卷章][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8})[  ]{0,4}.{0,30}$", + "serialNumber": 11 }, { "enable":false, "name": "顶格标题", "rule": "^\\S.{1,20}$", - "serialNumber": 11 + "serialNumber": 12 + }, + { + "enable":false, + "name": "双标题(前向)", + "rule": "(?m)(?<=[ \\t ]{0,4})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$(?=[\\s ]{0,8}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章)", + "serialNumber": 13 + }, + { + "enable":false, + "name": "双标题(后向)", + "rule": "(?m)(?<=[ \\t ]{0,4}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$[\\s ]{0,8})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$", + "serialNumber": 14 } ] From e05a451314686b7d786ec1766dade79610c0acad Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 21:04:12 +0800 Subject: [PATCH 07/21] =?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 - .../main/java/io/legado/app/help/AppConfig.kt | 2 +- app/src/main/java/io/legado/app/help/BookHelp.kt | 4 ++-- .../legado/app/ui/config/OtherConfigFragment.kt | 16 ++++++++++------ .../io/legado/app/ui/welcome/WelcomeActivity.kt | 2 +- .../io/legado/app/utils/ContextExtensions.kt | 7 +++++++ 6 files changed, 21 insertions(+), 11 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 1ba9ba6cf..e14ec42f6 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -3,7 +3,6 @@ package io.legado.app.constant object PreferKey { const val versionCode = "versionCode" const val themeMode = "themeMode" - const val downloadPath = "downloadPath" const val hideStatusBar = "hideStatusBar" const val clickTurnPage = "clickTurnPage" const val clickAllNext = "clickAllNext" 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 7e9c05834..9d6f87d61 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -49,7 +49,7 @@ object AppConfig { } val autoRefreshBook: Boolean - get() = App.INSTANCE.getPrefBoolean(App.INSTANCE.getString(R.string.pk_auto_refresh)) + get() = App.INSTANCE.getPrefBoolean(R.string.pk_auto_refresh) var threadCount: Int get() = App.INSTANCE.getPrefInt(PreferKey.threadCount, 16) 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 b7b45baea..b6e3ec000 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -4,8 +4,8 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import com.github.houbb.opencc4j.core.impl.ZhConvertBootstrap import io.legado.app.App +import io.legado.app.R import io.legado.app.constant.EventBus -import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.ReplaceRule @@ -21,7 +21,7 @@ import kotlin.math.min object BookHelp { private const val cacheFolderName = "book_cache" val downloadPath: String - get() = App.INSTANCE.getPrefString(PreferKey.downloadPath) + get() = App.INSTANCE.getPrefString(R.string.pk_download_path) ?: App.INSTANCE.getExternalFilesDir(null)?.absolutePath ?: App.INSTANCE.cacheDir.absolutePath diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 58caa351d..a010428fd 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -40,7 +40,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { putPrefBoolean(PreferKey.processText, isProcessTextEnabled()) addPreferencesFromResource(R.xml.pref_config_other) - upPreferenceSummary(PreferKey.downloadPath, BookHelp.downloadPath) + upPreferenceSummary(getString(R.string.pk_download_path), BookHelp.downloadPath) upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString()) upPreferenceSummary(PreferKey.webPort, webPort.toString()) } @@ -74,7 +74,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), .show { putPrefInt(PreferKey.webPort, it) } - PreferKey.downloadPath -> selectDownloadPath() + getString(R.string.pk_download_path) -> selectDownloadPath() PreferKey.cleanCache -> { BookHelp.clearCache() toast(R.string.clear_cache_success) @@ -85,7 +85,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { - PreferKey.downloadPath -> { + getString(R.string.pk_download_path) -> { upPreferenceSummary(key, BookHelp.downloadPath) } PreferKey.threadCount -> upPreferenceSummary( @@ -141,13 +141,17 @@ class OtherConfigFragment : PreferenceFragmentCompat(), private fun selectDownloadPath() { FilePicker.selectFolder(this, requestCodeDownloadPath) { - removePref(PreferKey.downloadPath) + removePref(getString(R.string.pk_download_path)) } } + private fun putDownloadPath(path: String) { + putPrefString(getString(R.string.pk_download_path), path) + } + override fun onFilePicked(requestCode: Int, currentPath: String) { if (requestCode == requestCodeDownloadPath) { - putPrefString(PreferKey.downloadPath, currentPath) + putDownloadPath(currentPath) } } @@ -160,7 +164,7 @@ class OtherConfigFragment : PreferenceFragmentCompat(), uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION ) - putPrefString(PreferKey.downloadPath, uri.toString()) + putDownloadPath(uri.toString()) } } } diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 5c84aa679..46e1e446e 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -48,7 +48,7 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { private fun startMainActivity() { startActivity() - if (getPrefBoolean(getString(R.string.pk_default_read))) { + if (getPrefBoolean(R.string.pk_default_read)) { startActivity() } finish() 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 3436c9d94..bc3f6f9fa 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -12,6 +12,7 @@ import android.os.BatteryManager import android.provider.Settings import androidx.annotation.ColorRes import androidx.annotation.DrawableRes +import androidx.annotation.StringRes import androidx.core.content.ContextCompat import androidx.core.content.FileProvider import androidx.core.content.edit @@ -28,6 +29,9 @@ import java.io.FileOutputStream fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) +fun Context.getPrefBoolean(@StringRes keyId: Int, defValue: Boolean = false) = + defaultSharedPreferences.getBoolean(getString(keyId), defValue) + fun Context.putPrefBoolean(key: String, value: Boolean = false) = defaultSharedPreferences.edit { putBoolean(key, value) } @@ -46,6 +50,9 @@ fun Context.putPrefLong(key: String, value: Long) = fun Context.getPrefString(key: String, defValue: String? = null) = defaultSharedPreferences.getString(key, defValue) +fun Context.getPrefString(@StringRes keyId: Int, defValue: String? = null) = + defaultSharedPreferences.getString(getString(keyId), defValue) + fun Context.putPrefString(key: String, value: String) = defaultSharedPreferences.edit { putString(key, value) } From e9e483ac0ab4050f32cd8303e329ae5207e111cd Mon Sep 17 00:00:00 2001 From: fisher Date: Mon, 9 Mar 2020 21:25:05 +0800 Subject: [PATCH 08/21] added numerical format --- app/src/main/assets/txtTocRule.json | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/assets/txtTocRule.json b/app/src/main/assets/txtTocRule.json index cce871125..b4f6f5b28 100644 --- a/app/src/main/assets/txtTocRule.json +++ b/app/src/main/assets/txtTocRule.json @@ -23,70 +23,76 @@ "rule": "^[  \\t]{0,4}(?:前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|第?\\s{0,4}[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]+?\\s{0,4}(?:章|节(?!课)|卷|集(?![合和])|部(?!分)|回(?![合来事去])|场(?![和合比电是])|篇(?!张))).{0,30}$", "serialNumber": 3 }, + { + "enable": false, + "name": "数字(纯数字标题)", + "rule": "^\\d+$", + "serialNumber": 4 + }, { "enable": true, "name": "数字 分隔符 标题名称", "rule": "^[  \\t]{0,4}\\d{1,5}[\\,\\., 、\\-].{1,30}$", - "serialNumber": 4 + "serialNumber": 5 }, { "enable": true, "name": "正文 标题/序号", "rule": "^[  \\t]{0,4}正文[  ]{1,4}.{0,20}$", - "serialNumber": 5 + "serialNumber": 6 }, { "enable": true, "name": "Chapter/Section/Part/Episode 序号 标题", "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)\\s{0,4}\\d{1,4}.{0,30}$", - "serialNumber": 6 + "serialNumber": 7 }, { "enable": false, "name": "Chapter(去简介)", "rule": "^[  \\t]{0,4}(?:[Cc]hapter|[Ss]ection|[Pp]art|PART|[Ee]pisode)\\s{0,4}\\d{1,4}.{0,30}$", - "serialNumber": 7 + "serialNumber": 8 }, { "enable": true, "name": "特殊符号 序号 标题", "rule": "(?<=[\\s ]{0,4}).{1,3}(?:第|卷|[Cc]hapter)[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,10}[章节]?[\\.:: \f\t].{0,20}$", - "serialNumber": 8 + "serialNumber": 9 }, { "enable": false, "name": "特殊符号 标题(成对)", "rule": "(?<=[\\s ]{0,4})(?:[\\[〈「『〖〔《(【\\(].{1,30}[\\)】)》〕〗』」〉\\]]?|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$", - "serialNumber": 9 + "serialNumber": 10 }, { "enable":true, "name": "特殊符号 标题(单个)", "rule": "(?<=[\\s ]{0,4})(?:[☆★✦✧].{1,30}|(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外)[  ]{0,4}$", - "serialNumber": 10 + "serialNumber": 11 }, { "enable": true, "name": "章/卷 序号 标题", "rule": "^[ \\t ]{0,4}(?:(?:内容|文章)?简介|文案|前言|序章|楔子|正文(?!完|结)|终章|后记|尾声|番外|[卷章][\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8})[  ]{0,4}.{0,30}$", - "serialNumber": 11 + "serialNumber": 12 }, { "enable":false, "name": "顶格标题", "rule": "^\\S.{1,20}$", - "serialNumber": 12 + "serialNumber": 13 }, { "enable":false, "name": "双标题(前向)", "rule": "(?m)(?<=[ \\t ]{0,4})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$(?=[\\s ]{0,8}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章)", - "serialNumber": 13 + "serialNumber": 14 }, { "enable":false, "name": "双标题(后向)", "rule": "(?m)(?<=[ \\t ]{0,4}第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$[\\s ]{0,8})第[\\d零一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟]{1,8}章.{0,30}$", - "serialNumber": 14 + "serialNumber": 15 } ] From 7f1add2b31493bf8002938b7ec94e6426cc2f5bd Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 21:29:07 +0800 Subject: [PATCH 09/21] =?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/AppConfig.kt | 3 +++ .../java/io/legado/app/ui/config/OtherConfigFragment.kt | 7 +++++++ app/src/main/res/values/arrays.xml | 2 +- app/src/main/res/values/pref_key_value.xml | 2 +- app/src/main/res/xml/pref_config_other.xml | 8 ++++++++ 5 files changed, 20 insertions(+), 2 deletions(-) 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 9d6f87d61..4b768b9e7 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -32,6 +32,9 @@ object AppConfig { App.INSTANCE.putPrefBoolean("transparentStatusBar", value) } + val requestedDirection: String? + get() = App.INSTANCE.getPrefString(R.string.pk_requested_direction) + var backupPath: String? get() = App.INSTANCE.getPrefString(PreferKey.backupPath) set(value) { diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index a010428fd..c6633461a 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -43,6 +43,10 @@ class OtherConfigFragment : PreferenceFragmentCompat(), upPreferenceSummary(getString(R.string.pk_download_path), BookHelp.downloadPath) upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString()) upPreferenceSummary(PreferKey.webPort, webPort.toString()) + upPreferenceSummary( + getString(R.string.pk_requested_direction), + AppConfig.requestedDirection + ) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -103,6 +107,9 @@ class OtherConfigFragment : PreferenceFragmentCompat(), setProcessTextEnable(it.getBoolean(key, true)) } PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused") + getString(R.string.pk_requested_direction) -> { + upPreferenceSummary(key, AppConfig.requestedDirection) + } } } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 104febad6..a53546e7f 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -67,7 +67,7 @@ @string/app_folder_picker - + @string/screen_unspecified @string/screen_portrait @string/screen_landscape diff --git a/app/src/main/res/values/pref_key_value.xml b/app/src/main/res/values/pref_key_value.xml index 7bcded4da..0c535ad67 100644 --- a/app/src/main/res/values/pref_key_value.xml +++ b/app/src/main/res/values/pref_key_value.xml @@ -1,7 +1,7 @@ auto_refresh - list_screen_direction + list_screen_direction full_screen threads_num user_agent diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index b049bcf22..bc241370e 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -6,6 +6,14 @@ android:title="@string/main_activity" app:iconSpaceReserved="false"> + + Date: Mon, 9 Mar 2020 21:58:39 +0800 Subject: [PATCH 10/21] =?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/array_values.xml | 6 ++++++ app/src/main/res/xml/pref_config_other.xml | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/array_values.xml b/app/src/main/res/values/array_values.xml index 2aa918837..c517c46ce 100644 --- a/app/src/main/res/values/array_values.xml +++ b/app/src/main/res/values/array_values.xml @@ -38,5 +38,11 @@ 9 + + 0 + 1 + 2 + 3 + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index bc241370e..6bf712292 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -8,10 +8,10 @@ Date: Mon, 9 Mar 2020 22:20:33 +0800 Subject: [PATCH 11/21] =?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 + .../main/java/io/legado/app/ui/book/read/Help.kt | 13 +++++++++++++ .../io/legado/app/ui/book/read/ReadBookActivity.kt | 5 +++++ .../app/ui/book/read/config/MoreConfigDialog.kt | 5 +++++ .../io/legado/app/ui/config/OtherConfigFragment.kt | 7 ------- app/src/main/res/xml/pref_config_other.xml | 8 -------- app/src/main/res/xml/pref_config_read.xml | 8 ++++++++ 7 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 67af4688e..543c13f6c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -185,6 +185,7 @@ android:launchMode="singleTop" /> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + "1" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + "2" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + "3" -> requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR + } + } + + /** * 返回NavigationBar是否存在 * 该方法需要在View完全被绘制出来之后调用,否则判断不了 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 2ca4555a3..3696ccbab 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 @@ -88,6 +88,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override val pageFactory: TextPageFactory get() = page_view.pageFactory override val headerHeight: Int get() = page_view.curPage.headerHeight + override fun onCreate(savedInstanceState: Bundle?) { + Help.setOrientation(this) + super.onCreate(savedInstanceState) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { Help.upLayoutInDisplayCutoutMode(window) initView() 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 6f472f270..a23725143 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 @@ -104,6 +104,11 @@ class MoreConfigDialog : DialogFragment() { } PreferKey.keepLight -> postEvent(key, true) PreferKey.textSelectAble -> postEvent(key, getPrefBoolean(key)) + getString(R.string.pk_requested_direction) -> { + activity?.let { + Help.setOrientation(it) + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index c6633461a..a010428fd 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -43,10 +43,6 @@ class OtherConfigFragment : PreferenceFragmentCompat(), upPreferenceSummary(getString(R.string.pk_download_path), BookHelp.downloadPath) upPreferenceSummary(PreferKey.threadCount, AppConfig.threadCount.toString()) upPreferenceSummary(PreferKey.webPort, webPort.toString()) - upPreferenceSummary( - getString(R.string.pk_requested_direction), - AppConfig.requestedDirection - ) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -107,9 +103,6 @@ class OtherConfigFragment : PreferenceFragmentCompat(), setProcessTextEnable(it.getBoolean(key, true)) } PreferKey.showRss -> postEvent(EventBus.SHOW_RSS, "unused") - getString(R.string.pk_requested_direction) -> { - upPreferenceSummary(key, AppConfig.requestedDirection) - } } } diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 6bf712292..b049bcf22 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -6,14 +6,6 @@ android:title="@string/main_activity" app:iconSpaceReserved="false"> - - + + Date: Mon, 9 Mar 2020 22:37:17 +0800 Subject: [PATCH 12/21] =?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, 6 insertions(+) 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 3696ccbab..3ac7715e6 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 @@ -3,6 +3,7 @@ package io.legado.app.ui.book.read import android.annotation.SuppressLint import android.app.Activity import android.content.Intent +import android.content.res.Configuration import android.net.Uri import android.os.Bundle import android.os.Handler @@ -111,6 +112,11 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo upSystemUiVisibility() } + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + ReadBook.loadContent() + } + override fun onResume() { super.onResume() upSystemUiVisibility() From ef3049c8d3f22022f186018c3856b287e9741b91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 9 Mar 2020 22:54:35 +0800 Subject: [PATCH 13/21] =?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 | 8 ++++---- .../io/legado/app/ui/book/read/page/PageView.kt | 16 ++++++---------- .../ui/book/read/page/delegate/PageDelegate.kt | 13 +++++++++---- 3 files changed, 19 insertions(+), 18 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 3ac7715e6..ffdcfcbfc 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 @@ -349,7 +349,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo @SuppressLint("ClickableViewAccessibility") override fun onTouch(v: View, event: MotionEvent): Boolean { when (event.action) { - MotionEvent.ACTION_MOVE, MotionEvent.ACTION_UP -> { + MotionEvent.ACTION_DOWN -> textActionMenu?.dismiss() + MotionEvent.ACTION_MOVE -> { when (v.id) { R.id.cursor_left -> page_view.curPage.selectStartMove( event.rawX + cursor_left.width, @@ -361,6 +362,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ) } } + MotionEvent.ACTION_UP -> showTextActionMenu() } return true } @@ -372,7 +374,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo cursor_left.x = x - cursor_left.width cursor_left.y = y cursor_left.visible(true) - showTextActionMenu() } /** @@ -382,7 +383,6 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo cursor_right.x = x cursor_right.y = y cursor_right.visible(true) - showTextActionMenu() } /** @@ -397,7 +397,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 显示文本操作菜单 */ - private fun showTextActionMenu() { + override fun showTextActionMenu() { textActionMenu ?: let { textActionMenu = TextActionMenu(this, this) } 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 dbde99c7e..1b7b71b07 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,25 +16,20 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), DataSource { - var callBack: CallBack - var pageFactory: TextPageFactory + val callBack: CallBack get() = activity as CallBack + var pageFactory: TextPageFactory = TextPageFactory(this) var pageDelegate: PageDelegate? = null - var prevPage: ContentView - var curPage: ContentView - var nextPage: ContentView + var prevPage: ContentView = ContentView(context) + var curPage: ContentView = ContentView(context) + var nextPage: ContentView = ContentView(context) init { - callBack = activity as CallBack - nextPage = ContentView(context) addView(nextPage) - curPage = ContentView(context) addView(curPage) - prevPage = ContentView(context) addView(prevPage) upBg() setWillNotDraw(false) - pageFactory = TextPageFactory(this) upPageAnim() } @@ -170,5 +165,6 @@ class PageView(context: Context, attrs: AttributeSet) : val isInitFinish: Boolean fun clickCenter() fun screenOffTimerStart() + fun showTextActionMenu() } } 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 4173ffb09..d83f60edb 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 @@ -200,11 +200,16 @@ abstract class PageDelegate(protected val pageView: PageView) : //GestureDetector.onFling小幅移动不会触发,所以要自己判断 when (event.action) { MotionEvent.ACTION_UP, - MotionEvent.ACTION_CANCEL -> if (isMoved) { - if (selectedOnDown) { - selectedOnDown = false + MotionEvent.ACTION_CANCEL -> { + if (isTextSelected) { + pageView.callBack.showTextActionMenu() + } + if (isMoved) { + if (selectedOnDown) { + selectedOnDown = false + } + if (!noNext) onAnimStart() } - if (!noNext) onAnimStart() } } } From e4865324b19e5a49564cf189c09d0efc5605f885 Mon Sep 17 00:00:00 2001 From: fisher Date: Tue, 10 Mar 2020 00:35:02 +0800 Subject: [PATCH 14/21] update rules --- app/src/main/assets/txtTocRule.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/txtTocRule.json b/app/src/main/assets/txtTocRule.json index b4f6f5b28..ececb6800 100644 --- a/app/src/main/assets/txtTocRule.json +++ b/app/src/main/assets/txtTocRule.json @@ -26,7 +26,7 @@ { "enable": false, "name": "数字(纯数字标题)", - "rule": "^\\d+$", + "rule": "(?<=[ \\s])\\d+[  \\t]{0,4}$", "serialNumber": 4 }, { From ce7142222cdd4cee1cd9283d15cc652c5cabf9a5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 09:10:35 +0800 Subject: [PATCH 15/21] =?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/LocalBook.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 9a893b8a3..fc94613d8 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -4,6 +4,7 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.data.entities.Book +import io.legado.app.help.BookHelp import io.legado.app.utils.FileUtils @@ -12,8 +13,17 @@ object LocalBook { fun importFile(doc: DocumentFile) { doc.name?.let { fileName -> val str = fileName.substringBeforeLast(".") - var name = str.substringBefore("作者") - val author = str.substringAfter("作者", "") + val authorIndex = str.indexOf("作者") + var name: String + var author: String + if (authorIndex == -1) { + name = str + author = "" + } else { + name = str.substring(0, authorIndex) + author = str.substring(authorIndex) + author = BookHelp.formatAuthor(author) + } val smhStart = name.indexOf("《") val smhEnd = name.indexOf("》") if (smhStart != -1 && smhEnd != -1) { From ec362af975810c7452a7000fcc12a9f3a7f3be23 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 10:34:47 +0800 Subject: [PATCH 16/21] =?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 | 18 +++---- .../app/ui/book/read/page/ContentTextView.kt | 53 ++++++++++++++----- .../main/res/layout/activity_book_read.xml | 6 +++ 3 files changed, 56 insertions(+), 21 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 ffdcfcbfc..c6294c290 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 @@ -370,10 +370,12 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 更新文字选择开始位置 */ - override fun upSelectedStart(x: Float, y: Float) { + override fun upSelectedStart(x: Float, y: Float, top: Float) { cursor_left.x = x - cursor_left.width cursor_left.y = y cursor_left.visible(true) + text_menu_position.x = x + text_menu_position.y = top } /** @@ -399,17 +401,15 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo */ override fun showTextActionMenu() { textActionMenu ?: let { - textActionMenu = TextActionMenu(this, this) - } - val x = cursor_left.x.toInt() + cursor_left.width - 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 = TextActionMenu(this, this).apply { + contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) + } } textActionMenu?.let { popup -> + val x = text_menu_position.x.toInt() + val y = text_menu_position.y.toInt() - popup.contentView.measuredHeight if (!popup.isShowing) { - popup.showAtLocation(cursor_left, Gravity.BOTTOM or Gravity.START, x, y) + popup.showAtLocation(text_menu_position, Gravity.TOP or Gravity.START, x, y) } else { popup.update(x, y, WRAP_CONTENT, WRAP_CONTENT) } 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 44baa68f6..53f03462f 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 @@ -31,6 +31,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at 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 private val maxScrollOffset = 100f @@ -210,7 +211,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[0] = 0 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(0, lineIndex, charIndex) return @@ -236,7 +241,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[0] = 1 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(1, lineIndex, charIndex) return @@ -259,7 +268,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectEnd[0] = 2 selectEnd[1] = lineIndex selectEnd[2] = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) upSelectedEnd(textChar.end, textLine.lineBottom + relativeOffset) select(2, lineIndex, charIndex) return @@ -287,7 +300,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[0] = 0 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) upSelectChars() } return @@ -311,7 +328,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[0] = 1 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) upSelectChars() } return @@ -333,7 +354,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[0] = 2 selectStart[1] = lineIndex selectStart[2] = charIndex - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset, + textLine.lineTop + relativeOffset + ) upSelectChars() } return @@ -427,7 +452,11 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at selectStart[2] = charIndex val textLine = relativePage(relativePage).textLines[lineIndex] val textChar = textLine.textChars[charIndex] - upSelectedStart(textChar.start, textLine.lineBottom + relativeOffset(relativePage)) + upSelectedStart( + textChar.start, + textLine.lineBottom + relativeOffset(relativePage), + textLine.lineTop + ) upSelectChars() } @@ -475,12 +504,12 @@ 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 upSelectedStart(x: Float, y: Float, top: Float) = callBack.apply { + upSelectedStart(x, y + headerHeight, top + headerHeight) } - private fun upSelectedEnd(x: Float, y: Float) { - callBack.upSelectedEnd(x, y + callBack.headerHeight) + private fun upSelectedEnd(x: Float, y: Float) = callBack.apply { + upSelectedEnd(x, y + headerHeight) } fun cancelSelect() { @@ -580,7 +609,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at } interface CallBack { - fun upSelectedStart(x: Float, y: Float) + fun upSelectedStart(x: Float, y: Float, top: Float) fun upSelectedEnd(x: Float, y: Float) fun onCancelSelect() val headerHeight: Int diff --git a/app/src/main/res/layout/activity_book_read.xml b/app/src/main/res/layout/activity_book_read.xml index 35d8d5f45..3fc498716 100644 --- a/app/src/main/res/layout/activity_book_read.xml +++ b/app/src/main/res/layout/activity_book_read.xml @@ -9,6 +9,12 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> + + Date: Tue, 10 Mar 2020 10:51:52 +0800 Subject: [PATCH 17/21] =?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 | 9 ++++++++- 1 file changed, 8 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 c6294c290..43c6ef541 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 @@ -406,8 +406,15 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } } textActionMenu?.let { popup -> + val popupHeight = popup.contentView.measuredHeight val x = text_menu_position.x.toInt() - val y = text_menu_position.y.toInt() - popup.contentView.measuredHeight + var y = text_menu_position.y.toInt() - popupHeight + if (y < statusBarHeight) { + y = (cursor_left.y + cursor_left.height).toInt() + } + if (cursor_right.y > y && cursor_right.y < y + popupHeight) { + y = (cursor_right.y + cursor_right.height).toInt() + } if (!popup.isShowing) { popup.showAtLocation(text_menu_position, Gravity.TOP or Gravity.START, x, y) } else { From 853d970642013f66128b2d9b87bd1f84382e6e4b Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 10:58:08 +0800 Subject: [PATCH 18/21] =?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 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 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 7e90c7ad1..9d7046f6e 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 @@ -151,15 +151,16 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac */ @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) + try { + var menuItemOrder = 100 + for (resolveInfo in getSupportedActivities()) { + menu.add( + Menu.NONE, Menu.NONE, + menuItemOrder++, resolveInfo.loadLabel(context.packageManager) + ).intent = createProcessTextIntentForResolveInfo(resolveInfo) + } + } catch (e: Exception) { + context.toast("获取文字操作菜单出错:${e.localizedMessage}") } } From 664813061ec231a7d021fd881a96a6c3b52b5efb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 11:01:50 +0800 Subject: [PATCH 19/21] =?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 fe74ee832..7cfdcfb4c 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,6 +2,10 @@ * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 请关注[开源阅读软件]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 +**2020/03/10** +* 优化文字选择菜单弹出位置 +* 添加屏幕方向控制 + **2020/03/09** * 底部文字对齐 * 主题添加阴影调节 by yangyxd From 838bc6f034b8a4b752f1f2ffad3121a305732866 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 11:04:42 +0800 Subject: [PATCH 20/21] =?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/popup_action_menu.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/popup_action_menu.xml b/app/src/main/res/layout/popup_action_menu.xml index c6b9067d7..98cceb33c 100644 --- a/app/src/main/res/layout/popup_action_menu.xml +++ b/app/src/main/res/layout/popup_action_menu.xml @@ -16,7 +16,7 @@ android:id="@+id/iv_menu_more" android:layout_width="24dp" android:layout_height="24dp" - android:background="?attr/selectableItemBackground" + android:background="?attr/selectableItemBackgroundBorderless" android:src="@drawable/ic_more_vert" android:tint="@color/tv_text_default" android:visibility="gone" From 339ab4c2705bfa89a1eb20f8fb64f58ce0684cbb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Mar 2020 11:46:16 +0800 Subject: [PATCH 21/21] =?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 | 5 ++++- 1 file changed, 4 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 43c6ef541..3de366ec3 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 @@ -14,6 +14,7 @@ import androidx.core.view.isVisible import androidx.core.view.size import androidx.lifecycle.Observer import com.jaredrummler.android.colorpicker.ColorPickerDialogListener +import io.legado.app.BuildConfig import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.EventBus @@ -681,7 +682,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo mHandler.removeCallbacks(keepScreenRunnable) textActionMenu?.dismiss() page_view.onDestroy() - SyncBookProgress.uploadBookProgress() + if (!BuildConfig.DEBUG) { + SyncBookProgress.uploadBookProgress() + } } override fun observeLiveBus() {