mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 18:38:23 +01:00
Add intent filter for external queries
This commit is contained in:
parent
ba2194f435
commit
56195434e7
@ -33,6 +33,10 @@
|
|||||||
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
|
<action android:name="com.google.android.gms.actions.SEARCH_ACTION"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="eu.kanade.tachiyomi.SEARCH" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
</intent-filter>
|
||||||
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
|
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
|
||||||
<!--suppress AndroidDomInspection -->
|
<!--suppress AndroidDomInspection -->
|
||||||
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
|
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
|
||||||
|
@ -18,8 +18,10 @@ import kotlinx.android.synthetic.main.catalogue_global_search_controller.*
|
|||||||
* This controller should only handle UI actions, IO actions should be done by [CatalogueSearchPresenter]
|
* This controller should only handle UI actions, IO actions should be done by [CatalogueSearchPresenter]
|
||||||
* [CatalogueSearchCardAdapter.OnMangaClickListener] called when manga is clicked in global search
|
* [CatalogueSearchCardAdapter.OnMangaClickListener] called when manga is clicked in global search
|
||||||
*/
|
*/
|
||||||
open class CatalogueSearchController(protected val initialQuery: String? = null) :
|
open class CatalogueSearchController(
|
||||||
NucleusController<CatalogueSearchPresenter>(),
|
protected val initialQuery: String? = null,
|
||||||
|
protected val extensionFilter: String? = null
|
||||||
|
) : NucleusController<CatalogueSearchPresenter>(),
|
||||||
CatalogueSearchCardAdapter.OnMangaClickListener {
|
CatalogueSearchCardAdapter.OnMangaClickListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,7 +62,7 @@ open class CatalogueSearchController(protected val initialQuery: String? = null)
|
|||||||
* @return instance of [CatalogueSearchPresenter]
|
* @return instance of [CatalogueSearchPresenter]
|
||||||
*/
|
*/
|
||||||
override fun createPresenter(): CatalogueSearchPresenter {
|
override fun createPresenter(): CatalogueSearchPresenter {
|
||||||
return CatalogueSearchPresenter(initialQuery)
|
return CatalogueSearchPresenter(initialQuery, extensionFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
@ -21,6 +22,7 @@ import rx.subjects.PublishSubject
|
|||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presenter of [CatalogueSearchController]
|
* Presenter of [CatalogueSearchController]
|
||||||
@ -32,6 +34,7 @@ import uy.kohesive.injekt.api.get
|
|||||||
*/
|
*/
|
||||||
open class CatalogueSearchPresenter(
|
open class CatalogueSearchPresenter(
|
||||||
val initialQuery: String? = "",
|
val initialQuery: String? = "",
|
||||||
|
val initialExtensionFilter: String? = null,
|
||||||
val sourceManager: SourceManager = Injekt.get(),
|
val sourceManager: SourceManager = Injekt.get(),
|
||||||
val db: DatabaseHelper = Injekt.get(),
|
val db: DatabaseHelper = Injekt.get(),
|
||||||
val preferencesHelper: PreferencesHelper = Injekt.get()
|
val preferencesHelper: PreferencesHelper = Injekt.get()
|
||||||
@ -40,7 +43,7 @@ open class CatalogueSearchPresenter(
|
|||||||
/**
|
/**
|
||||||
* Enabled sources.
|
* Enabled sources.
|
||||||
*/
|
*/
|
||||||
val sources by lazy { getEnabledSources() }
|
val sources by lazy { getSourcesToQuery() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query from the view.
|
* Query from the view.
|
||||||
@ -63,9 +66,16 @@ open class CatalogueSearchPresenter(
|
|||||||
*/
|
*/
|
||||||
private var fetchImageSubscription: Subscription? = null
|
private var fetchImageSubscription: Subscription? = null
|
||||||
|
|
||||||
|
private val extensionManager by injectLazy<ExtensionManager>()
|
||||||
|
|
||||||
|
private var extensionFilter: String? = null
|
||||||
|
|
||||||
override fun onCreate(savedState: Bundle?) {
|
override fun onCreate(savedState: Bundle?) {
|
||||||
super.onCreate(savedState)
|
super.onCreate(savedState)
|
||||||
|
|
||||||
|
extensionFilter = savedState?.getString(CatalogueSearchPresenter::extensionFilter.name) ?:
|
||||||
|
initialExtensionFilter
|
||||||
|
|
||||||
// Perform a search with previous or initial state
|
// Perform a search with previous or initial state
|
||||||
search(savedState?.getString(BrowseCataloguePresenter::query.name) ?: initialQuery.orEmpty())
|
search(savedState?.getString(BrowseCataloguePresenter::query.name) ?: initialQuery.orEmpty())
|
||||||
}
|
}
|
||||||
@ -78,6 +88,7 @@ open class CatalogueSearchPresenter(
|
|||||||
|
|
||||||
override fun onSave(state: Bundle) {
|
override fun onSave(state: Bundle) {
|
||||||
state.putString(BrowseCataloguePresenter::query.name, query)
|
state.putString(BrowseCataloguePresenter::query.name, query)
|
||||||
|
state.putString(CatalogueSearchPresenter::extensionFilter.name, extensionFilter)
|
||||||
super.onSave(state)
|
super.onSave(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +108,26 @@ open class CatalogueSearchPresenter(
|
|||||||
.sortedBy { "(${it.lang}) ${it.name}" }
|
.sortedBy { "(${it.lang}) ${it.name}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getSourcesToQuery(): List<CatalogueSource> {
|
||||||
|
val filter = extensionFilter
|
||||||
|
val enabledSources = getEnabledSources()
|
||||||
|
if (filter.isNullOrEmpty()) {
|
||||||
|
return enabledSources
|
||||||
|
}
|
||||||
|
|
||||||
|
val filterSources = extensionManager.installedExtensions
|
||||||
|
.filter { it.pkgName == filter }
|
||||||
|
.flatMap { it.sources }
|
||||||
|
.filter { it in enabledSources }
|
||||||
|
.filterIsInstance<CatalogueSource>()
|
||||||
|
|
||||||
|
if (filterSources.isEmpty()) {
|
||||||
|
return enabledSources
|
||||||
|
}
|
||||||
|
|
||||||
|
return filterSources
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a catalogue search item
|
* Creates a catalogue search item
|
||||||
*/
|
*/
|
||||||
|
@ -164,12 +164,21 @@ class MainActivity : BaseActivity() {
|
|||||||
//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)
|
||||||
|
|
||||||
setSelectedDrawerItem(R.id.nav_drawer_catalogues)
|
|
||||||
//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.
|
||||||
intent.getStringExtra(SearchManager.QUERY)?.also { query ->
|
val query = intent.getStringExtra(SearchManager.QUERY)
|
||||||
|
if (query != null && !query.isEmpty()) {
|
||||||
|
setSelectedDrawerItem(R.id.nav_drawer_catalogues)
|
||||||
router.pushController(CatalogueSearchController(query).withFadeTransaction())
|
router.pushController(CatalogueSearchController(query).withFadeTransaction())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
INTENT_SEARCH -> {
|
||||||
|
val query = intent.getStringExtra(INTENT_SEARCH_QUERY)
|
||||||
|
val filter = intent.getStringExtra(INTENT_SEARCH_FILTER)
|
||||||
|
if (query != null && !query.isEmpty()) {
|
||||||
|
setSelectedDrawerItem(R.id.nav_drawer_catalogues)
|
||||||
|
router.pushController(CatalogueSearchController(query, filter).withFadeTransaction())
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> return false
|
else -> return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -254,6 +263,10 @@ class MainActivity : BaseActivity() {
|
|||||||
const val SHORTCUT_CATALOGUES = "eu.kanade.tachiyomi.SHOW_CATALOGUES"
|
const val SHORTCUT_CATALOGUES = "eu.kanade.tachiyomi.SHOW_CATALOGUES"
|
||||||
const val SHORTCUT_DOWNLOADS = "eu.kanade.tachiyomi.SHOW_DOWNLOADS"
|
const val SHORTCUT_DOWNLOADS = "eu.kanade.tachiyomi.SHOW_DOWNLOADS"
|
||||||
const val SHORTCUT_MANGA = "eu.kanade.tachiyomi.SHOW_MANGA"
|
const val SHORTCUT_MANGA = "eu.kanade.tachiyomi.SHOW_MANGA"
|
||||||
|
|
||||||
|
const val INTENT_SEARCH = "eu.kanade.tachiyomi.SEARCH"
|
||||||
|
const val INTENT_SEARCH_QUERY = "query"
|
||||||
|
const val INTENT_SEARCH_FILTER = "filter"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user