From df70ca8f56362cc58f4d39e252bc6106088c55b4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 09:00:08 +0800 Subject: [PATCH 01/13] up --- .../app/ui/widget/font/FontSelectDialog.kt | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 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 a0a4170d8..c16c5d138 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 @@ -88,16 +88,14 @@ class FontSelectDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - val pf = parentFragment - if (pf is CallBack) { - if ("" != pf.curFontPath) { - pf.selectFile("") + parentFragment?.let { + if (it is CallBack && it.curFontPath != "") { + it.selectFile("") } } - val activity = activity - if (activity is CallBack) { - if ("" != activity.curFontPath) { - activity.selectFile("") + activity?.let { + if (it is CallBack && it.curFontPath != "") { + it.selectFile("") } } dismiss() @@ -131,7 +129,7 @@ class FontSelectDialog : DialogFragment(), @SuppressLint("DefaultLocale") private fun getFontFiles(uri: Uri) { launch(IO) { - DocumentFile.fromTreeUri(requireContext(), uri)?.listFiles()?.forEach { file -> + 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) @@ -169,17 +167,15 @@ class FontSelectDialog : DialogFragment(), } override fun onClick(file: File) { - file.absolutePath.let { - val pf = parentFragment - if (pf is CallBack) { - if (it != pf.curFontPath) { - pf.selectFile(it) + file.absolutePath.let { path -> + parentFragment?.let { + if (it is CallBack && it.curFontPath != path) { + it.selectFile(path) } } - val activity = activity - if (activity is CallBack) { - if (it != activity.curFontPath) { - activity.selectFile(it) + activity?.let { + if (it is CallBack && it.curFontPath != path) { + it.selectFile(path) } } } @@ -187,13 +183,15 @@ class FontSelectDialog : DialogFragment(), } override fun curFilePath(): String { - val pf = parentFragment - if (pf is CallBack) { - return pf.curFontPath + parentFragment?.let { + if (it is CallBack) { + return it.curFontPath + } } - val activity = activity - if (activity is CallBack) { - return activity.curFontPath + activity?.let { + if (it is CallBack) { + return it.curFontPath + } } return "" } From 22c17683fdc6faf9a2b41c6edd5e35829ce8d5d9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 09:06:39 +0800 Subject: [PATCH 02/13] up --- .../app/ui/widget/font/FontSelectDialog.kt | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 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 c16c5d138..6ff51d379 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 @@ -88,13 +88,13 @@ class FontSelectDialog : DialogFragment(), override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_default -> { - parentFragment?.let { - if (it is CallBack && it.curFontPath != "") { + (parentFragment as? CallBack)?.let { + if (it.curFontPath != "") { it.selectFile("") } } - activity?.let { - if (it is CallBack && it.curFontPath != "") { + (activity as? CallBack)?.let { + if (it.curFontPath != "") { it.selectFile("") } } @@ -168,13 +168,13 @@ class FontSelectDialog : DialogFragment(), override fun onClick(file: File) { file.absolutePath.let { path -> - parentFragment?.let { - if (it is CallBack && it.curFontPath != path) { + (parentFragment as? CallBack)?.let { + if (it.curFontPath != path) { it.selectFile(path) } } - activity?.let { - if (it is CallBack && it.curFontPath != path) { + (activity as? CallBack)?.let { + if (it.curFontPath != path) { it.selectFile(path) } } @@ -183,17 +183,9 @@ class FontSelectDialog : DialogFragment(), } override fun curFilePath(): String { - parentFragment?.let { - if (it is CallBack) { - return it.curFontPath - } - } - activity?.let { - if (it is CallBack) { - return it.curFontPath - } - } - return "" + return (parentFragment as? CallBack)?.curFontPath + ?: (activity as? CallBack)?.curFontPath + ?: "" } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { From 23b5a47190789d21e1ad78c18fa96e0f4c964dd1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 10:11:18 +0800 Subject: [PATCH 03/13] up --- app/src/main/res/menu/rss_read.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/res/menu/rss_read.xml b/app/src/main/res/menu/rss_read.xml index 15463f64d..f32d01d2e 100644 --- a/app/src/main/res/menu/rss_read.xml +++ b/app/src/main/res/menu/rss_read.xml @@ -14,4 +14,10 @@ android:icon="@drawable/ic_menu_share" app:showAsAction="ifRoom" /> + + \ No newline at end of file From 8218c66cbf6c9f64ed3ec84ccd9f49883848ac86 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 10:53:30 +0800 Subject: [PATCH 04/13] up --- app/src/main/java/io/legado/app/help/BookHelp.kt | 2 +- .../main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt | 5 +++++ 2 files changed, 6 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 1ea320505..c117c61ed 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -86,7 +86,7 @@ object BookHelp { } private fun getBookFolder(book: Book): String { - val bookFolder = formatFolderName(book.name + book.bookUrl) + val bookFolder = formatFolderName(book.name + MD5Utils.md5Encode16(book.bookUrl)) return "${getBookCachePath()}${File.separator}$bookFolder" } 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 037364296..0cab40e01 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 @@ -47,6 +47,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r R.id.menu_share_it -> viewModel.rssArticle?.let { shareText("链接分享", it.link) } + R.id.menu_aloud -> readAloud() } return super.onCompatOptionsItemSelected(item) } @@ -121,6 +122,10 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r return super.onKeyUp(keyCode, event) } + private fun readAloud() { + + } + private fun shareText(title: String, text: String) { try { val textIntent = Intent(Intent.ACTION_SEND) From 4609e87254799f5948e05b9b828f65ee7f44cb20 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 11:01:54 +0800 Subject: [PATCH 05/13] up --- app/src/main/java/io/legado/app/help/BookHelp.kt | 3 +++ 1 file changed, 3 insertions(+) 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 c117c61ed..ff5ee0b7d 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -108,6 +108,9 @@ object BookHelp { ?: "" } + /** + * 找到相似度最高的章节 + */ fun getDurChapterIndexByChapterTitle( title: String?, index: Int, From f7a02cf14193c4190b0414b08fef5fce7b89de3a Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 11:16:53 +0800 Subject: [PATCH 06/13] up --- .../source/edit/BookSourceEditActivity.kt | 14 +++----------- .../legado/app/ui/rss/read/ReadRssActivity.kt | 13 +------------ .../rss/source/edit/RssSourceEditActivity.kt | 4 ++++ .../io/legado/app/utils/ContextExtensions.kt | 19 +++++++++++++++++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index aeb83a093..4bab3e780 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -29,6 +29,7 @@ import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -87,17 +88,8 @@ class BookSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } - R.id.menu_share_str -> { - GSON.toJson(getSource())?.let { sourceStr -> - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, sourceStr) - startActivity(Intent.createChooser(textIntent, "Source Share")) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } + R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr -> + shareText("分享书源", sourceStr) } R.id.menu_rule_summary -> { try { 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 0cab40e01..951d190f7 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 @@ -1,7 +1,6 @@ package io.legado.app.ui.rss.read import android.annotation.SuppressLint -import android.content.Intent import android.os.Bundle import android.view.KeyEvent import android.view.Menu @@ -15,8 +14,8 @@ 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.shareText import kotlinx.android.synthetic.main.activity_rss_read.* -import org.jetbrains.anko.toast class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_read), ReadRssViewModel.CallBack { @@ -126,14 +125,4 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } - private fun shareText(title: String, text: String) { - try { - val textIntent = Intent(Intent.ACTION_SEND) - textIntent.type = "text/plain" - textIntent.putExtra(Intent.EXTRA_TEXT, text) - startActivity(Intent.createChooser(textIntent, title)) - } catch (e: Exception) { - toast(R.string.can_not_share) - } - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index d1704848e..2b5d88b7a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -25,6 +25,7 @@ import io.legado.app.ui.widget.KeyboardToolPop import io.legado.app.utils.GSON import io.legado.app.utils.applyTint import io.legado.app.utils.getViewModel +import io.legado.app.utils.shareText import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -103,6 +104,9 @@ class RssSourceEditActivity : } } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } + R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> + shareText("分享RSS源", sourceStr) + } } return super.onCompatOptionsItemSelected(item) } 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 f47a0a2a8..ff917b09f 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -1,13 +1,16 @@ package io.legado.app.utils import android.content.Context +import android.content.Intent import android.content.res.ColorStateList import android.graphics.drawable.Drawable import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.content.edit +import io.legado.app.R import org.jetbrains.anko.defaultSharedPreferences +import org.jetbrains.anko.toast fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) @@ -48,7 +51,8 @@ fun Context.getCompatColor(@ColorRes id: Int): Int = ContextCompat.getColor(this fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(this, id) -fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = ContextCompat.getColorStateList(this, id) +fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = + ContextCompat.getColorStateList(this, id) fun Context.getStatusBarHeight(): Int { val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") @@ -60,6 +64,17 @@ fun Context.getNavigationBarHeight(): Int { return resources.getDimensionPixelSize(resourceId) } +fun Context.shareText(title: String, text: String) { + try { + val textIntent = Intent(Intent.ACTION_SEND) + textIntent.type = "text/plain" + textIntent.putExtra(Intent.EXTRA_TEXT, text) + startActivity(Intent.createChooser(textIntent, title)) + } catch (e: Exception) { + toast(R.string.can_not_share) + } +} + val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") @@ -67,4 +82,4 @@ val Context.isTransparentStatusBar: Boolean get() = getPrefBoolean("transparentStatusBar", true) val Context.isShowRSS: Boolean - get() = getPrefBoolean("showRss", true) \ No newline at end of file + get() = getPrefBoolean("showRss", true) \ No newline at end of file From 797c6eb9c811177caeb6c6b06a37db0f3f8abe00 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 14:28:15 +0800 Subject: [PATCH 07/13] 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 48dc30c5b..a067a90e9 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/10 +* 合并KKL369提交的代码 + **2020/01/08** * 导入本地源不再需要存储权限 From ec1d335c57623c01d327b6e5951d67b724069ece Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 15:25:00 +0800 Subject: [PATCH 08/13] up --- .../legado/app/ui/rss/read/ReadRssActivity.kt | 4 +- .../app/ui/rss/read/ReadRssViewModel.kt | 53 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 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 951d190f7..138ede020 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 @@ -122,7 +122,9 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } private fun readAloud() { - + webView.evaluateJavascript("document.documentElement.outerHTML") { + viewModel.readAloud(it) + } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 98355d7d8..db9d7bb82 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -2,21 +2,28 @@ package io.legado.app.ui.rss.read import android.app.Application import android.content.Intent +import android.speech.tts.TextToSpeech +import android.speech.tts.UtteranceProgressListener import androidx.lifecycle.MutableLiveData import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.Rss import io.legado.app.model.analyzeRule.AnalyzeUrl +import kotlinx.coroutines.launch +import java.util.* -class ReadRssViewModel(application: Application) : BaseViewModel(application) { +class ReadRssViewModel(application: Application) : BaseViewModel(application), + TextToSpeech.OnInitListener { var callBack: CallBack? = null var rssSource: RssSource? = null var rssArticle: RssArticle? = null val contentLiveData = MutableLiveData() val urlLiveData = MutableLiveData() var star = false + var textToSpeech: TextToSpeech = TextToSpeech(context, this) fun initData(intent: Intent) { execute { @@ -91,6 +98,50 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { } } + override fun onInit(status: Int) { + launch { + if (status == TextToSpeech.SUCCESS) { + textToSpeech.language = Locale.CHINA + textToSpeech.setOnUtteranceProgressListener(TTSUtteranceListener()) + } else { + toast(R.string.tts_init_failed) + } + } + } + + fun readAloud(text: String) { + + } + + override fun onCleared() { + super.onCleared() + textToSpeech.stop() + textToSpeech.shutdown() + } + + /** + * 朗读监听 + */ + private inner class TTSUtteranceListener : UtteranceProgressListener() { + + override fun onStart(s: String) { + + } + + override fun onDone(s: String) { + + } + + override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { + super.onRangeStart(utteranceId, start, end, frame) + + } + + override fun onError(s: String) { + + } + + } interface CallBack { fun upStarMenu() } From 1e3f5ec23bacb139bb5d33aac77ca290f8419e85 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 15:29:48 +0800 Subject: [PATCH 09/13] up --- app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index db9d7bb82..98b79b708 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -110,7 +110,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } fun readAloud(text: String) { - + textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, "rss") } override fun onCleared() { From 528c8b42bbe1769272ccda6eb827118d6a66420b Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 16:55:29 +0800 Subject: [PATCH 10/13] up --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 13 +++++++++++++ .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 11 ++++------- 2 files changed, 17 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 138ede020..24b49a5c6 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 @@ -24,6 +24,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r get() = getViewModel(ReadRssViewModel::class.java) private var starMenuItem: MenuItem? = null + private var ttsMenuItem: MenuItem? = null override fun onActivityCreated(savedInstanceState: Bundle?) { viewModel.callBack = this @@ -36,6 +37,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.rss_read, menu) starMenuItem = menu.findItem(R.id.menu_rss_star) + ttsMenuItem = menu.findItem(R.id.menu_aloud) upStarMenu() return super.onCompatCreateOptionsMenu(menu) } @@ -97,6 +99,17 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r DrawableUtils.setTint(starMenuItem?.icon, primaryTextColor) } + 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) + } + DrawableUtils.setTint(ttsMenuItem?.icon, primaryTextColor) + } + override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_BACK -> { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index 98b79b708..83a88091e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -125,16 +125,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), private inner class TTSUtteranceListener : UtteranceProgressListener() { override fun onStart(s: String) { - + callBack?.upTtsMenu(true) } override fun onDone(s: String) { - - } - - override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) { - super.onRangeStart(utteranceId, start, end, frame) - + callBack?.upTtsMenu(false) } override fun onError(s: String) { @@ -142,7 +137,9 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } } + interface CallBack { fun upStarMenu() + fun upTtsMenu(isPlaying: Boolean) } } \ No newline at end of file From fbe6a6cbc54678ba4b2e36e86a0c74c7e811e62e Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 19:55:56 +0800 Subject: [PATCH 11/13] up --- .../source/edit/BookSourceEditActivity.kt | 10 ++--- .../rss/source/edit/RssSourceEditActivity.kt | 10 ++--- .../io/legado/app/utils/ContextExtensions.kt | 40 +++++++++++++++++++ app/src/main/res/menu/source_edit.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++ 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index 4bab3e780..cc63c93d4 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -26,10 +26,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.GSON -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.shareText +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -89,7 +86,10 @@ class BookSourceEditActivity : } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> GSON.toJson(getSource())?.let { sourceStr -> - shareText("分享书源", sourceStr) + shareText(getString(R.string.share_book_source), sourceStr) + } + R.id.menu_share_qr -> GSON.toJson(getSource())?.let { sourceStr -> + shareWithQr(getString(R.string.share_book_source), sourceStr) } R.id.menu_rule_summary -> { try { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index 2b5d88b7a..1ae70df5d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -22,10 +22,7 @@ import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.ui.rss.source.debug.RssSourceDebugActivity import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.GSON -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.shareText +import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_rss_source_edit.* import org.jetbrains.anko.displayMetrics import org.jetbrains.anko.startActivity @@ -105,7 +102,10 @@ class RssSourceEditActivity : } R.id.menu_paste_source -> viewModel.pasteSource { upRecyclerView(it) } R.id.menu_share_str -> GSON.toJson(getRssSource())?.let { sourceStr -> - shareText("分享RSS源", sourceStr) + shareText(getString(R.string.share_rss_source), sourceStr) + } + R.id.menu_share_qr -> GSON.toJson(getRssSource())?.let { sourceStr -> + shareWithQr(getString(R.string.share_rss_source), sourceStr) } } return super.onCompatOptionsItemSelected(item) 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 ff917b09f..2ab88b481 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -1,16 +1,25 @@ package io.legado.app.utils +import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.res.ColorStateList +import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.annotation.ColorRes import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat +import androidx.core.content.FileProvider import androidx.core.content.edit +import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder +import com.google.zxing.EncodeHintType +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel +import io.legado.app.BuildConfig import io.legado.app.R import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.toast +import java.io.File +import java.io.FileOutputStream fun Context.getPrefBoolean(key: String, defValue: Boolean = false) = defaultSharedPreferences.getBoolean(key, defValue) @@ -75,6 +84,37 @@ fun Context.shareText(title: String, text: String) { } } +@SuppressLint("SetWorldReadable") +fun Context.shareWithQr(title: String, text: String) { + QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L + val bitmap = QRCodeEncoder.syncEncodeQRCode(text, 600) + QRCodeEncoder.HINTS[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H + if (bitmap == null) { + toast(R.string.text_too_long_qr_error) + } else { + try { + val file = File(externalCacheDir, "qr.png") + val fOut = FileOutputStream(file) + bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut) + fOut.flush() + fOut.close() + file.setReadable(true, false) + val contentUri = FileProvider.getUriForFile( + this, + "${BuildConfig.APPLICATION_ID}.fileProvider", + file + ) + val intent = Intent(Intent.ACTION_SEND) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK + intent.putExtra(Intent.EXTRA_STREAM, contentUri) + intent.type = "image/png" + startActivity(Intent.createChooser(intent, title)) + } catch (e: Exception) { + toast(e.localizedMessage ?: "ERROR") + } + } +} + val Context.isNightTheme: Boolean get() = getPrefBoolean("isNightTheme") diff --git a/app/src/main/res/menu/source_edit.xml b/app/src/main/res/menu/source_edit.xml index ec8739c11..2fd9678c4 100644 --- a/app/src/main/res/menu/source_edit.xml +++ b/app/src/main/res/menu/source_edit.xml @@ -35,7 +35,7 @@ app:showAsAction="never" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5036723df..3ceda2af3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -579,5 +579,8 @@ 上一句 下一句 其它目录 + 文字太多,生成二维码失败 + 分享RSS源 + 分享书源 From de10ebca2a154bd0fb566a8b7f1f9dcc9dc84c6d Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 20:15:24 +0800 Subject: [PATCH 12/13] up --- app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt | 2 +- .../main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt index b3605e3e9..5335a6830 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt @@ -15,7 +15,7 @@ import io.legado.app.R * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) */ class ThemeStore @SuppressLint("CommitPrefEdits") -private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeStoreInterface { +private constructor(private val mContext: Context) : ThemeStoreInterface { private val mEditor: SharedPreferences.Editor init { diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt index 4fd4540fc..c934ef176 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStorePrefKeys.kt @@ -3,8 +3,7 @@ package io.legado.app.lib.theme /** * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) */ -internal interface ThemeStorePrefKeys { - companion object { +object ThemeStorePrefKeys { const val CONFIG_PREFS_KEY_DEFAULT = "app_themes" const val IS_CONFIGURED_KEY = "is_configured" @@ -27,5 +26,4 @@ internal interface ThemeStorePrefKeys { const val KEY_APPLY_PRIMARYDARK_STATUSBAR = "apply_primarydark_statusbar" const val KEY_APPLY_PRIMARY_NAVBAR = "apply_primary_navbar" const val KEY_AUTO_GENERATE_PRIMARYDARK = "auto_generate_primarydark" - } } \ No newline at end of file From 91a5def2cc21e59ebb051277cff64d42daa8be33 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 10 Jan 2020 21:09:30 +0800 Subject: [PATCH 13/13] up --- app/src/main/AndroidManifest.xml | 1 + .../app/ui/importbook/ImportBookActivity.kt | 19 +++++++++++++++++++ .../app/ui/importbook/ImportBookViewModel.kt | 10 ++++++++++ .../main/res/layout/activity_import_book.xml | 7 +++++++ 4 files changed, 37 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt create mode 100644 app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt create mode 100644 app/src/main/res/layout/activity_import_book.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bc92ac136..23f5edd36 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -98,6 +98,7 @@ + diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt new file mode 100644 index 000000000..8cbce52f8 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt @@ -0,0 +1,19 @@ +package io.legado.app.ui.importbook + +import android.os.Bundle +import io.legado.app.R +import io.legado.app.base.VMBaseActivity +import io.legado.app.utils.getViewModel + + +class ImportBookActivity : VMBaseActivity(R.layout.activity_import_book) { + + override val viewModel: ImportBookViewModel + get() = getViewModel(ImportBookViewModel::class.java) + + + override fun onActivityCreated(savedInstanceState: Bundle?) { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt new file mode 100644 index 000000000..1865f1be8 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/importbook/ImportBookViewModel.kt @@ -0,0 +1,10 @@ +package io.legado.app.ui.importbook + +import android.app.Application +import io.legado.app.base.BaseViewModel + + +class ImportBookViewModel(application: Application) : BaseViewModel(application) { + + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_import_book.xml b/app/src/main/res/layout/activity_import_book.xml new file mode 100644 index 000000000..d829e291c --- /dev/null +++ b/app/src/main/res/layout/activity_import_book.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file