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.core:core-ktx:1.8.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
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.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.1'
|
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.1'
|
||||||
implementation 'androidx.navigation:navigation-ui-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'
|
implementation 'com.github.TeamNewPipe:NewPipeExtractor:master-SNAPSHOT'
|
||||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
|
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) {
|
task androidSourcesJar(type: Jar) {
|
||||||
|
@ -195,8 +199,9 @@ task androidSourcesJar(type: Jar) {
|
||||||
}
|
}
|
||||||
|
|
||||||
task makeJar(type: Copy) {
|
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
|
||||||
into('build') // output location
|
from('build/intermediates/compile_app_classes_jar/debug')
|
||||||
include('classes.jar') // the classes file of the imported rack package
|
into('build') // output location
|
||||||
dependsOn build
|
include('classes.jar') // the classes file of the imported rack package
|
||||||
|
dependsOn build
|
||||||
}
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
package com.lagradost.cloudstream3.ui.settings.extensions
|
package com.lagradost.cloudstream3.ui.settings.extensions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import androidx.appcompat.view.menu.MenuBuilder
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
@ -49,6 +49,40 @@ class PluginsFragment : Fragment() {
|
||||||
return@setOnMenuItemClickListener true
|
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 =
|
plugin_recycler_view?.adapter =
|
||||||
PluginAdapter {
|
PluginAdapter {
|
||||||
pluginViewModel.handlePluginAction(activity, url, it, isLocal)
|
pluginViewModel.handlePluginAction(activity, url, it, isLocal)
|
||||||
|
@ -56,11 +90,12 @@ class PluginsFragment : Fragment() {
|
||||||
|
|
||||||
observe(pluginViewModel.plugins) {
|
observe(pluginViewModel.plugins) {
|
||||||
(plugin_recycler_view?.adapter as? PluginAdapter?)?.updateList(it)
|
(plugin_recycler_view?.adapter as? PluginAdapter?)?.updateList(it)
|
||||||
|
plugin_recycler_view?.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocal) {
|
if (isLocal) {
|
||||||
// No download button
|
// No download button
|
||||||
settings_toolbar?.menu?.clear()
|
settings_toolbar?.menu?.findItem(R.id.download_all)?.isVisible = false
|
||||||
pluginViewModel.updatePluginListLocal()
|
pluginViewModel.updatePluginListLocal()
|
||||||
} else {
|
} else {
|
||||||
pluginViewModel.updatePluginList(url)
|
pluginViewModel.updatePluginList(url)
|
||||||
|
@ -75,5 +110,14 @@ class PluginsFragment : Fragment() {
|
||||||
putBoolean(PLUGINS_BUNDLE_LOCAL, isLocal)
|
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.main
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
|
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import me.xdrop.fuzzywuzzy.FuzzySearch
|
||||||
|
|
||||||
typealias Plugin = Pair<String, SitePlugin>
|
typealias Plugin = Pair<String, SitePlugin>
|
||||||
|
|
||||||
|
@ -168,6 +169,20 @@ class PluginsViewModel : ViewModel() {
|
||||||
updatePluginListPrivate(repositoryUrl)
|
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.
|
* Update the list but only with the local data. Used for file management.
|
||||||
|
|
|
@ -1,9 +1,16 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<item
|
<item
|
||||||
app:showAsAction="always"
|
android:id="@+id/search_button"
|
||||||
android:id="@+id/download_all"
|
android:icon="@drawable/search_icon"
|
||||||
android:icon="@drawable/netflix_download"
|
android:title="@string/title_search"
|
||||||
android:title="@string/batch_download" />
|
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"
|
||||||
|
app:showAsAction="collapseActionView|ifRoom" />
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in a new issue