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)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2020/01/11
* RSS阅读界面添加朗读功能
* 其它一些优化
**2020/01/10
* 合并KKL369提交的代码

@ -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<ReadRssViewModel>(R.layout.activity_rss_read),
ReadRssViewModel.CallBack {
@ -100,6 +104,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
}
override fun upTtsMenu(isPlaying: Boolean) {
launch {
if (isPlaying) {
ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp)
ttsMenuItem?.setTitle(R.string.aloud_stop)
@ -109,6 +114,7 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
}
DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor)
}
}
override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
@ -134,9 +140,17 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
return super.onKeyUp(keyCode, event)
}
@SuppressLint("SetJavaScriptEnabled")
private fun readAloud() {
if (viewModel.textToSpeech.isSpeaking) {
viewModel.textToSpeech.stop()
upTtsMenu(false)
} else {
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())
}
}
}

@ -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()

@ -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,20 +166,20 @@ class FontSelectDialog : DialogFragment(),
}
override fun onClick(file: File) {
file.absolutePath.let { path ->
(parentFragment as? CallBack)?.let {
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)
}
}
(activity as? CallBack)?.let {
if (it.curFontPath != path) {
it.selectFile(path)
}
}
}
dialog?.dismiss()
}
}
override fun curFilePath(): String {
return (parentFragment as? CallBack)?.curFontPath

Loading…
Cancel
Save