From 76fec52adb0b9089fd0ed301f87a458ed2040738 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 10:46:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/localBook/AnalyzeTxtFile.kt | 10 ++++------ .../io/legado/app/ui/book/read/TextActionMenu.kt | 13 ++++++++++++- app/src/main/res/menu/content_select_action.xml | 4 ++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 99b6b95d3..93e1c8e4a 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -226,12 +226,10 @@ object AnalyzeTxtFile { private fun getTocRules(): List { val rules = App.db.txtTocRule().all - if (rules.isEmpty()) { - App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> - GSON.fromJsonArray(String(byteArray))?.let { - App.db.txtTocRule().insert(*it.toTypedArray()) - return it - } + App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> + GSON.fromJsonArray(String(byteArray))?.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + return it } } return rules diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index 42506132c..1b29cb097 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.pm.ResolveInfo +import android.net.Uri import android.os.Build import android.view.LayoutInflater import android.view.Menu @@ -22,6 +23,7 @@ import io.legado.app.utils.sendToClip import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.popup_action_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.toast class TextActionMenu(private val context: Context, private val callBack: CallBack) : @@ -77,7 +79,16 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac private fun onMenuItemSelected(item: MenuItemImpl) { when (item.itemId) { R.id.menu_copy -> context.sendToClip(callBack.selectedText) - else -> item.intent.let { + R.id.menu_browser -> { + try { + val intent = Intent(Intent.ACTION_VIEW) + intent.data = Uri.parse(callBack.selectedText) + context.startActivity(intent) + } catch (e: Exception) { + context.toast(R.string.can_not_open) + } + } + else -> item.intent?.let { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { it.putExtra(Intent.EXTRA_PROCESS_TEXT, callBack.selectedText) context.startActivity(it) diff --git a/app/src/main/res/menu/content_select_action.xml b/app/src/main/res/menu/content_select_action.xml index b9bdf7b40..52ac3e0f6 100644 --- a/app/src/main/res/menu/content_select_action.xml +++ b/app/src/main/res/menu/content_select_action.xml @@ -9,4 +9,8 @@ android:id="@+id/menu_copy" android:title="@android:string/copy" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f1e0c46b..a19395ca8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -619,4 +619,5 @@ 文本选择开始位置 共用布局 标题居中 + 浏览器