Merge remote-tracking branch 'origin/master'

pull/71/head
Administrator 5 years ago
commit 7da314fb7f
  1. 4
      app/src/main/assets/updateLog.md
  2. 16
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt
  4. 27
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -3,6 +3,10 @@
* 旧版数据导入教程: * 旧版数据导入教程:
* 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/01/11
* RSS阅读界面添加朗读功能
* 其它一些优化
**2020/01/10 **2020/01/10
* 合并KKL369提交的代码 * 合并KKL369提交的代码

@ -14,8 +14,12 @@ import io.legado.app.lib.theme.DrawableUtils
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.htmlFormat
import io.legado.app.utils.shareText import io.legado.app.utils.shareText
import kotlinx.android.synthetic.main.activity_rss_read.* 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<ReadRssViewModel>(R.layout.activity_rss_read), class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_read),
ReadRssViewModel.CallBack { ReadRssViewModel.CallBack {
@ -100,6 +104,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
} }
override fun upTtsMenu(isPlaying: Boolean) { override fun upTtsMenu(isPlaying: Boolean) {
launch {
if (isPlaying) { if (isPlaying) {
ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp)
ttsMenuItem?.setTitle(R.string.aloud_stop) ttsMenuItem?.setTitle(R.string.aloud_stop)
@ -109,6 +114,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
} }
DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor)
} }
}
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) { when (keyCode) {
@ -134,9 +140,17 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
return super.onKeyUp(keyCode, event) return super.onKeyUp(keyCode, event)
} }
@SuppressLint("SetJavaScriptEnabled")
private fun readAloud() { private fun readAloud() {
if (viewModel.textToSpeech.isSpeaking) {
viewModel.textToSpeech.stop()
upTtsMenu(false)
} else {
webView.settings.javaScriptEnabled = true
webView.evaluateJavascript("document.documentElement.outerHTML") { webView.evaluateJavascript("document.documentElement.outerHTML") {
viewModel.readAloud(it) val html = StringEscapeUtils.unescapeJson(it)
viewModel.readAloud(Jsoup.parse(html).body().html().htmlFormat())
}
} }
} }

@ -20,7 +20,7 @@ class FontAdapter(context: Context, val callBack: CallBack) :
tv_font.typeface = typeface tv_font.typeface = typeface
tv_font.text = item.name tv_font.text = item.name
this.onClick { callBack.onClick(item) } this.onClick { callBack.onClick(item) }
if (item.absolutePath == callBack.curFilePath()) { if (item.name == callBack.curFilePath().substringAfterLast(File.separator)) {
iv_checked.visible() iv_checked.visible()
} else { } else {
iv_checked.invisible() iv_checked.invisible()

@ -43,6 +43,8 @@ class FontSelectDialog : DialogFragment(),
private val fontFolderRequestCode = 35485 private val fontFolderRequestCode = 35485
private val fontFolder = private val fontFolder =
App.INSTANCE.filesDir.absolutePath + File.separator + "Fonts" + File.separator 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 override val coroutineContext: CoroutineContext
get() = job + Main get() = job + Main
private var adapter: FontAdapter? = null private var adapter: FontAdapter? = null
@ -88,12 +90,8 @@ class FontSelectDialog : DialogFragment(),
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_default -> { R.id.menu_default -> {
(parentFragment as? CallBack)?.let { val cb = (parentFragment as? CallBack) ?: (activity as? CallBack)
if (it.curFontPath != "") { cb?.let {
it.selectFile("")
}
}
(activity as? CallBack)?.let {
if (it.curFontPath != "") { if (it.curFontPath != "") {
it.selectFile("") it.selectFile("")
} }
@ -129,15 +127,16 @@ class FontSelectDialog : DialogFragment(),
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
private fun getFontFiles(uri: Uri) { private fun getFontFiles(uri: Uri) {
launch(IO) { launch(IO) {
FileHelp.deleteFile(fontCacheFolder)
DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file -> DocumentFile.fromTreeUri(App.INSTANCE, uri)?.listFiles()?.forEach { file ->
if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) { if (file.name?.toLowerCase()?.matches(".*\\.[ot]tf".toRegex()) == true) {
DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let { DocumentUtils.readBytes(App.INSTANCE, file.uri)?.let {
FileHelp.getFile(fontFolder + file.name).writeBytes(it) FileHelp.getFile(fontCacheFolder + file.name).writeBytes(it)
} }
} }
} }
try { try {
val file = File(fontFolder) val file = File(fontCacheFolder)
file.listFiles { pathName -> file.listFiles { pathName ->
pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex()) pathName.name.toLowerCase().matches(".*\\.[ot]tf".toRegex())
}?.let { }?.let {
@ -167,20 +166,20 @@ class FontSelectDialog : DialogFragment(),
} }
override fun onClick(file: File) { override fun onClick(file: File) {
file.absolutePath.let { path -> launch(IO) {
(parentFragment as? CallBack)?.let { 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) { if (it.curFontPath != path) {
withContext(Main) {
it.selectFile(path) it.selectFile(path)
} }
} }
(activity as? CallBack)?.let {
if (it.curFontPath != path) {
it.selectFile(path)
}
} }
} }
dialog?.dismiss() dialog?.dismiss()
} }
}
override fun curFilePath(): String { override fun curFilePath(): String {
return (parentFragment as? CallBack)?.curFontPath return (parentFragment as? CallBack)?.curFontPath

Loading…
Cancel
Save