mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Global search now does extension filtering for supported urls
so if you disable an extension's app links and share the url to tachij2k, it'll open the correct extension to handle it instead of globally searching a url
This commit is contained in:
parent
397e66e4b3
commit
7e13556e01
3 changed files with 27 additions and 3 deletions
|
@ -208,14 +208,16 @@ internal object ExtensionLoader {
|
|||
return LoadResult.Success(extension)
|
||||
}
|
||||
|
||||
fun isPackageNameAnExtension(packageManager: PackageManager, pkgName: String): Boolean =
|
||||
isPackageAnExtension(packageManager.getPackageInfo(pkgName, PACKAGE_FLAGS))
|
||||
|
||||
/**
|
||||
* Returns true if the given package is an extension.
|
||||
*
|
||||
* @param pkgInfo The package info of the application.
|
||||
*/
|
||||
private fun isPackageAnExtension(pkgInfo: PackageInfo): Boolean {
|
||||
return pkgInfo.reqFeatures.orEmpty().any { it.name == EXTENSION_FEATURE }
|
||||
}
|
||||
private fun isPackageAnExtension(pkgInfo: PackageInfo): Boolean =
|
||||
pkgInfo.reqFeatures.orEmpty().any { it.name == EXTENSION_FEATURE }
|
||||
|
||||
/**
|
||||
* Returns the signature hash of the package or null if it's not signed.
|
||||
|
|
|
@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.ui.setting.SettingsReaderController
|
|||
import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController
|
||||
import eu.kanade.tachiyomi.ui.source.globalsearch.GlobalSearchController
|
||||
import eu.kanade.tachiyomi.util.chapter.ChapterSort
|
||||
import eu.kanade.tachiyomi.util.system.extensionIntentForText
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
@ -128,6 +129,11 @@ class SearchActivity : MainActivity() {
|
|||
// Get the search query provided in extras, and if not null, perform a global search with it.
|
||||
val query = intent.getStringExtra(SearchManager.QUERY) ?: intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||
if (query != null && query.isNotEmpty()) {
|
||||
extensionIntentForText(query)?.let {
|
||||
startActivity(it)
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
router.replaceTopController(GlobalSearchController(query).withFadeTransaction())
|
||||
} else {
|
||||
finish()
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.hippo.unifile.UniFile
|
|||
import com.nononsenseapps.filepicker.FilePickerActivity
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.extension.util.ExtensionLoader
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity
|
||||
import uy.kohesive.injekt.Injekt
|
||||
|
@ -220,6 +221,21 @@ fun Context.withOriginalWidth(): Context {
|
|||
return this
|
||||
}
|
||||
|
||||
fun Context.extensionIntentForText(text: String): Intent? {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(text))
|
||||
val info = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL)
|
||||
.firstOrNull {
|
||||
try {
|
||||
val pkgName = it.activityInfo.packageName
|
||||
ExtensionLoader.isPackageNameAnExtension(packageManager, pkgName)
|
||||
} catch (_: Exception) {
|
||||
false
|
||||
}
|
||||
} ?: return null
|
||||
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun Context.isLandscape(): Boolean {
|
||||
return resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue