diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index a067a90e9..847d2c5cd 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 旧版数据导入教程: * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/01/11 +* RSS阅读界面添加朗读功能 +* 其它一些优化 + **2020/01/10 * 合并KKL369提交的代码 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..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 @@ -14,8 +14,12 @@ 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 kotlinx.coroutines.launch +import org.apache.commons.text.StringEscapeUtils +import org.jsoup.Jsoup class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -100,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 { @@ -134,9 +140,17 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r return super.onKeyUp(keyCode, event) } + @SuppressLint("SetJavaScriptEnabled") private fun readAloud() { - webView.evaluateJavascript("document.documentElement.outerHTML") { - viewModel.readAloud(it) + 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()) + } } } 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() 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..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 @@ -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 @@ -88,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("") } @@ -129,15 +127,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,19 +166,19 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.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), true).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 {