Added search intent handler and Google Search Action, for the global search (#1787)

* Added search intent handler

* Added support for Google Search actions
This commit is contained in:
Amine A 2019-04-03 10:25:52 +02:00 committed by inorichi
parent 77296348a0
commit 8f2878a841
3 changed files with 23 additions and 1 deletions

View file

@ -28,7 +28,12 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
<!--suppress AndroidDomInspection -->
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
</activity>

View file

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.ui.main
import android.animation.ObjectAnimator
import android.app.SearchManager
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
@ -15,6 +16,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.ui.base.controller.*
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController
import eu.kanade.tachiyomi.ui.download.DownloadController
import eu.kanade.tachiyomi.ui.extension.ExtensionController
import eu.kanade.tachiyomi.ui.library.LibraryController
@ -158,6 +160,16 @@ class MainActivity : BaseActivity() {
setSelectedDrawerItem(R.id.nav_drawer_downloads)
}
}
Intent.ACTION_SEARCH, "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)
setSelectedDrawerItem(R.id.nav_drawer_catalogues)
//Get the search query provided in extras, and if not null, perform a global search with it.
intent.getStringExtra(SearchManager.QUERY)?.also { query ->
router.pushController(CatalogueSearchController(query).withFadeTransaction())
}
}
else -> return false
}
return true

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/action_global_search_hint" >
</searchable>