From ede7b0a62b5bfce98794d2ac2a44c586c7ecf972 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 08:57:47 +0800 Subject: [PATCH 1/9] up --- app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 44f4f9974..902a5bfae 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.absolutePath == callBack.curFilePath()) { + if (item.name == callBack.curFilePath().substringAfterLast(File.separator)) { iv_checked.visible() } else { iv_checked.invisible() From a7d157db34c9fd6d432d87260ce5da11819d9c15 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:06:52 +0800 Subject: [PATCH 2/9] up --- .../io/legado/app/ui/widget/font/FontSelectDialog.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 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 6ff51d379..8d3deef08 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 @@ -43,6 +43,8 @@ class FontSelectDialog : DialogFragment(), private val fontFolderRequestCode = 35485 private val fontFolder = App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator + private val fontCacheFolder = + App.INSTANCE.cacheDir.absolutePath + File.separator + "Fonts" + File.separator override val coroutineContext: CoroutineContext get() = job + Main private var adapter: FontAdapter? = null @@ -129,15 +131,16 @@ class FontSelectDialog : DialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) { + FileHelp.deleteFile(fontCacheFolder) DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file -> if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { - FileHelp.getFile(fontFolder + file.name).writeBytes(it) + FileHelp.getFile(fontCacheFolder + file.name).writeBytes(it) } } } try { - val file = File(fontFolder) + val file = File(fontCacheFolder) file.listFiles { pathName -> pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) }?.let { @@ -167,7 +170,7 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.absolutePath.let { path -> + file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> (parentFragment as? CallBack)?.let { if (it.curFontPath != path) { it.selectFile(path) From b032acca6ab083d1d66ecdcc7b94a91c55808cea Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:20:37 +0800 Subject: [PATCH 3/9] up --- .../app/ui/widget/font/FontSelectDialog.kt | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 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 8d3deef08..0f5ce1e32 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 @@ -90,12 +90,8 @@ class FontSelectDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - (parentFragment as? CallBack)?.let { - if (it.curFontPath != "") { - it.selectFile("") - } - } - (activity as? CallBack)?.let { + val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) + cb?.let { if (it.curFontPath != "") { it.selectFile("") } @@ -170,19 +166,19 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> - (parentFragment as? CallBack)?.let { - if (it.curFontPath != path) { - it.selectFile(path) - } - } - (activity as? CallBack)?.let { - if (it.curFontPath != path) { - it.selectFile(path) + launch(IO) { + file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> + val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) + cb?.let { + if (it.curFontPath != path) { + withContext(Main) { + it.selectFile(path) + } + } } } + dialog?.dismiss() } - dialog?.dismiss() } override fun curFilePath(): String { From 3fdcdec074cf6572b71b63d066383caebf6f4ac3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 09:28:38 +0800 Subject: [PATCH 4/9] up --- .../main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0f5ce1e32..420bc9233 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 @@ -167,7 +167,7 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { launch(IO) { - file.copyTo(FileHelp.getFile(fontFolder + file.name)).absolutePath.let { path -> + file.copyTo(FileHelp.getFile(fontFolder + file.name), true).absolutePath.let { path -> val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) cb?.let { if (it.curFontPath != path) { From 39ce729ac283e0edb12f6538116aa7e4f47d0a91 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:08:56 +0800 Subject: [PATCH 5/9] up --- .../java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 24b49a5c6..9296537e4 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,8 +14,11 @@ 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.htmlFormat import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_read.* +import org.apache.commons.text.StringEscapeUtils +import org.jsoup.Jsoup class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -134,9 +137,12 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r return super.onKeyUp(keyCode, event) } + @SuppressLint("SetJavaScriptEnabled") private fun readAloud() { + webView.settings.javaScriptEnabled = true webView.evaluateJavascript("document.documentElement.outerHTML") { - viewModel.readAloud(it) + val html = StringEscapeUtils.unescapeJson(it) + viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) } } From 1eef27eba962ad2220675992ede9d5ec88a0e1a7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:15:38 +0800 Subject: [PATCH 6/9] up --- .../legado/app/ui/rss/read/ReadRssActivity.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 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 9296537e4..26ede2867 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 @@ -17,6 +17,7 @@ import io.legado.app.utils.getViewModel import io.legado.app.utils.htmlFormat 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.jsoup.Jsoup @@ -103,14 +104,16 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } override fun upTtsMenu(isPlaying: Boolean) { - if (isPlaying) { - ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) - ttsMenuItem?.setTitle(R.string.aloud_stop) - } else { - ttsMenuItem?.setIcon(R.drawable.ic_volume_up) - ttsMenuItem?.setTitle(R.string.read_aloud) + launch { + if (isPlaying) { + ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) + ttsMenuItem?.setTitle(R.string.aloud_stop) + } else { + ttsMenuItem?.setIcon(R.drawable.ic_volume_up) + ttsMenuItem?.setTitle(R.string.read_aloud) + } + DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) } - DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) } override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { From f3564f86d06c17b88f65760fff46a121f5a10f14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:26:29 +0800 Subject: [PATCH 7/9] up --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 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 26ede2867..2caf40524 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 @@ -142,10 +142,15 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r @SuppressLint("SetJavaScriptEnabled") private fun readAloud() { - webView.settings.javaScriptEnabled = true - webView.evaluateJavascript("document.documentElement.outerHTML") { - val html = StringEscapeUtils.unescapeJson(it) - viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) + if (viewModel.textToSpeech.isSpeaking) { + viewModel.textToSpeech.stop() + upTtsMenu(false) + } else { + webView.settings.javaScriptEnabled = true + webView.evaluateJavascript("document.documentElement.outerHTML") { + val html = StringEscapeUtils.unescapeJson(it) + viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat()) + } } } From 225e1ee005abdcac2a91bd4feb1395b26b8085ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:31:21 +0800 Subject: [PATCH 8/9] up --- 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 a067a90e9..633759c8c 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/11 +* RSS阅读界面添加朗读功能 + **2020/01/10 * 合并KKL369提交的代码 From 641e751edf3217a367c2678afd23e370cb3b07fb Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 11 Jan 2020 10:32:24 +0800 Subject: [PATCH 9/9] up --- 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 633759c8c..847d2c5cd 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/01/11 * RSS阅读界面添加朗读功能 +* 其它一些优化 **2020/01/10 * 合并KKL369提交的代码