From 3a79bc8bff4f7bd8c17cf613e3902e7986c0cf93 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 23 Feb 2020 11:27:58 +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/ui/book/read/TextActionMenu.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 c7044b2ae..bcc815ee6 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 @@ -1,6 +1,7 @@ package io.legado.app.ui.book.read import android.annotation.SuppressLint +import android.app.SearchManager import android.content.Context import android.content.Intent import android.content.pm.ResolveInfo @@ -19,6 +20,7 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.utils.isAbsUrl import io.legado.app.utils.sendToClip import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.popup_action_menu.view.* @@ -81,8 +83,15 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac R.id.menu_copy -> context.sendToClip(callBack.selectedText) R.id.menu_browser -> { try { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = Uri.parse(callBack.selectedText) + val intent = if (callBack.selectedText.isAbsUrl()) { + Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse(callBack.selectedText) + } + } else { + Intent(Intent.ACTION_WEB_SEARCH).apply { + putExtra(SearchManager.QUERY, callBack.selectedText) + } + } context.startActivity(intent) } catch (e: Exception) { e.printStackTrace()