Perform a global search via share menu

Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
Jays2Kings 2021-04-24 16:42:46 -04:00
parent a756b40b47
commit fe09262a66
3 changed files with 12 additions and 3 deletions

View File

@ -45,7 +45,8 @@
</activity> </activity>
<activity <activity
android:name=".ui.main.SearchActivity" android:name=".ui.main.SearchActivity"
android:theme="@style/Theme.Splash"> android:theme="@style/Theme.Splash"
android:label="@string/label_global_search">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEARCH" /> <action android:name="android.intent.action.SEARCH" />
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/> <action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
@ -56,6 +57,11 @@
<action android:name="eu.kanade.tachiyomi.SEARCH" /> <action android:name="eu.kanade.tachiyomi.SEARCH" />
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
</activity> </activity>
<activity android:name=".ui.reader.ReaderActivity" <activity android:name=".ui.reader.ReaderActivity"

View File

@ -80,14 +80,16 @@ class SearchActivity : MainActivity() {
intent.getIntExtra("groupId", 0) intent.getIntExtra("groupId", 0)
) )
when (intent.action) { when (intent.action) {
Intent.ACTION_SEARCH, "com.google.android.gms.actions.SEARCH_ACTION" -> { Intent.ACTION_SEARCH, Intent.ACTION_SEND, "com.google.android.gms.actions.SEARCH_ACTION" -> {
// If the intent match the "standard" Android search intent // 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) // 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. // 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.getStringExtra(Intent.EXTRA_TEXT)
if (query != null && query.isNotEmpty()) { if (query != null && query.isNotEmpty()) {
router.replaceTopController(GlobalSearchController(query).withFadeTransaction()) router.replaceTopController(GlobalSearchController(query).withFadeTransaction())
} else {
finish()
} }
} }
INTENT_SEARCH -> { INTENT_SEARCH -> {

View File

@ -255,6 +255,7 @@
<string name="local_source">Local source</string> <string name="local_source">Local source</string>
<string name="other">Other</string> <string name="other">Other</string>
<string name="global_search">Global search…</string> <string name="global_search">Global search…</string>
<string name="label_global_search">Global search</string>
<string name="latest">Latest</string> <string name="latest">Latest</string>
<string name="browse">Browse</string> <string name="browse">Browse</string>
<string name="in_library">In Library</string> <string name="in_library">In Library</string>