mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add search button
This commit is contained in:
parent
34131bdf62
commit
b7a11048f0
4 changed files with 83 additions and 12 deletions
|
@ -100,7 +100,9 @@ dependencies {
|
|||
|
||||
implementation 'androidx.core:core-ktx:1.8.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
||||
implementation 'com.google.android.material:material:1.5.0' // dont change this to 1.6.0 it looks ugly af
|
||||
|
||||
// dont change this to 1.6.0 it looks ugly af
|
||||
implementation 'com.google.android.material:material:1.5.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.1'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.1'
|
||||
|
@ -187,6 +189,8 @@ dependencies {
|
|||
implementation 'com.github.TeamNewPipe:NewPipeExtractor:master-SNAPSHOT'
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
||||
|
||||
// Library/extensions searching with Levenshtein distance
|
||||
implementation 'me.xdrop:fuzzywuzzy:1.4.0'
|
||||
}
|
||||
|
||||
task androidSourcesJar(type: Jar) {
|
||||
|
@ -195,7 +199,8 @@ task androidSourcesJar(type: Jar) {
|
|||
}
|
||||
|
||||
task makeJar(type: Copy) {
|
||||
from('build/intermediates/compile_app_classes_jar/debug') // after modifying here, you can export. Jar
|
||||
// after modifying here, you can export. Jar
|
||||
from('build/intermediates/compile_app_classes_jar/debug')
|
||||
into('build') // output location
|
||||
include('classes.jar') // the classes file of the imported rack package
|
||||
dependsOn build
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.lagradost.cloudstream3.ui.settings.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.appcompat.view.menu.MenuBuilder
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.lagradost.cloudstream3.R
|
||||
|
@ -49,6 +49,40 @@ class PluginsFragment : Fragment() {
|
|||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
|
||||
val searchView =
|
||||
settings_toolbar?.menu?.findItem(R.id.search_button)?.actionView as? RepoSearchView
|
||||
|
||||
// Don't go back if active query
|
||||
settings_toolbar?.setNavigationOnClickListener {
|
||||
if (searchView?.isIconified == false) {
|
||||
searchView?.isIconified = true
|
||||
} else {
|
||||
activity?.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
// searchView?.onActionViewCollapsed = {
|
||||
// pluginViewModel.search(null)
|
||||
// }
|
||||
|
||||
// Because onActionViewCollapsed doesn't wanna work we need this workaround :(
|
||||
searchView?.setOnQueryTextFocusChangeListener { _, hasFocus ->
|
||||
if (!hasFocus) pluginViewModel.search(null)
|
||||
}
|
||||
|
||||
searchView?.setOnQueryTextListener(object : android.widget.SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
pluginViewModel.search(query)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
pluginViewModel.search(newText)
|
||||
return true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
plugin_recycler_view?.adapter =
|
||||
PluginAdapter {
|
||||
pluginViewModel.handlePluginAction(activity, url, it, isLocal)
|
||||
|
@ -56,11 +90,12 @@ class PluginsFragment : Fragment() {
|
|||
|
||||
observe(pluginViewModel.plugins) {
|
||||
(plugin_recycler_view?.adapter as? PluginAdapter?)?.updateList(it)
|
||||
plugin_recycler_view?.scrollToPosition(0)
|
||||
}
|
||||
|
||||
if (isLocal) {
|
||||
// No download button
|
||||
settings_toolbar?.menu?.clear()
|
||||
settings_toolbar?.menu?.findItem(R.id.download_all)?.isVisible = false
|
||||
pluginViewModel.updatePluginListLocal()
|
||||
} else {
|
||||
pluginViewModel.updatePluginList(url)
|
||||
|
@ -75,5 +110,14 @@ class PluginsFragment : Fragment() {
|
|||
putBoolean(PLUGINS_BUNDLE_LOCAL, isLocal)
|
||||
}
|
||||
}
|
||||
|
||||
class RepoSearchView(context: Context) : android.widget.SearchView(context) {
|
||||
// var onActionViewCollapsed = {}
|
||||
//
|
||||
// override fun onActionViewCollapsed() {
|
||||
// onActionViewCollapsed()
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
|||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
|
||||
import kotlinx.coroutines.launch
|
||||
import me.xdrop.fuzzywuzzy.FuzzySearch
|
||||
|
||||
typealias Plugin = Pair<String, SitePlugin>
|
||||
|
||||
|
@ -168,6 +169,20 @@ class PluginsViewModel : ViewModel() {
|
|||
updatePluginListPrivate(repositoryUrl)
|
||||
}
|
||||
|
||||
fun search(query: String?) {
|
||||
val currentPlugins = plugins.value ?: return
|
||||
|
||||
// Return list to base state if no query
|
||||
val newValue = if (query == null) {
|
||||
currentPlugins.sortedBy { it.plugin.second.name }
|
||||
} else {
|
||||
currentPlugins.sortedBy {
|
||||
-FuzzySearch.ratio(it.plugin.second.name, query)
|
||||
}
|
||||
}
|
||||
_plugins.postValue(newValue)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the list but only with the local data. Used for file management.
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
app:showAsAction="always"
|
||||
android:id="@+id/search_button"
|
||||
android:icon="@drawable/search_icon"
|
||||
android:title="@string/title_search"
|
||||
app:actionViewClass="com.lagradost.cloudstream3.ui.settings.extensions.PluginsFragment$Companion$RepoSearchView"
|
||||
app:searchHintIcon="@drawable/search_icon"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/download_all"
|
||||
android:icon="@drawable/netflix_download"
|
||||
android:title="@string/batch_download" />
|
||||
android:title="@string/batch_download"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
</menu>
|
Loading…
Reference in a new issue