Răsfoiți Sursa

Add text selection shortcut to invoke global search (closes #4058)

arkon 4 ani în urmă
părinte
comite
b6e246c6b2

+ 7 - 1
app/src/main/AndroidManifest.xml

@@ -42,7 +42,8 @@
         <activity
             android:name=".ui.main.DeepLinkActivity"
             android:launchMode="singleTask"
-            android:theme="@android:style/Theme.NoDisplay">
+            android:theme="@android:style/Theme.NoDisplay"
+            android:label="@string/process_text_action_name">
             <intent-filter>
                 <action android:name="android.intent.action.SEARCH" />
                 <action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
@@ -53,6 +54,11 @@
                 <action android:name="eu.kanade.tachiyomi.SEARCH" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.PROCESS_TEXT" />
+                <category android:name="android.intent.category.DEFAULT" />
+                <data android:mimeType="text/plain" />
+            </intent-filter>
 
             <meta-data
                 android:name="android.app.searchable"

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt

@@ -241,12 +241,12 @@ class MainActivity : BaseActivity<MainActivityBinding>() {
                 setSelectedNavItem(R.id.nav_more)
                 router.pushController(RouterTransaction.with(DownloadController()))
             }
-            Intent.ACTION_SEARCH, "com.google.android.gms.actions.SEARCH_ACTION" -> {
+            Intent.ACTION_SEARCH, Intent.ACTION_PROCESS_TEXT, "com.google.android.gms.actions.SEARCH_ACTION" -> {
                 // If the intent match the "standard" Android search intent
                 // or the Google-specific search intent (triggered by saying or typing "search *query* on *Tachiyomi*" in Google Search/Google Assistant)
 
                 // Get the search query provided in extras, and if not null, perform a global search with it.
-                val query = intent.getStringExtra(SearchManager.QUERY)
+                val query = intent.getStringExtra(SearchManager.QUERY) ?: intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT)?.toString()
                 if (query != null && query.isNotEmpty()) {
                     if (router.backstackSize > 1) {
                         router.popToRoot()

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -731,4 +731,7 @@
     <string name="spen_previous_page">Previous page</string>
     <string name="spen_next_page">Next page</string>
 
+    <!-- Android OS text selection menu action -->
+    <string name="process_text_action_name">Search in Tachiyomi</string>
+
 </resources>