mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fix scrolling to top when managing plugins
This commit is contained in:
parent
18f1fba047
commit
a43534417b
3 changed files with 17 additions and 10 deletions
|
@ -90,9 +90,11 @@ class PluginsFragment : Fragment() {
|
|||
pluginViewModel.handlePluginAction(activity, url, it, isLocal)
|
||||
}
|
||||
|
||||
observe(pluginViewModel.filteredPlugins) {
|
||||
(plugin_recycler_view?.adapter as? PluginAdapter?)?.updateList(it)
|
||||
plugin_recycler_view?.scrollToPosition(0)
|
||||
observe(pluginViewModel.filteredPlugins) { (scrollToTop, list) ->
|
||||
(plugin_recycler_view?.adapter as? PluginAdapter?)?.updateList(list)
|
||||
|
||||
if (scrollToTop)
|
||||
plugin_recycler_view?.scrollToPosition(0)
|
||||
}
|
||||
|
||||
if (isLocal) {
|
||||
|
|
|
@ -22,14 +22,19 @@ import kotlinx.coroutines.launch
|
|||
import me.xdrop.fuzzywuzzy.FuzzySearch
|
||||
|
||||
typealias Plugin = Pair<String, SitePlugin>
|
||||
/**
|
||||
* The boolean signifies if the plugin list should be scrolled to the top, used for searching.
|
||||
* */
|
||||
typealias PluginViewDataUpdate = Pair<Boolean, List<PluginViewData>>
|
||||
|
||||
class PluginsViewModel : ViewModel() {
|
||||
|
||||
/** plugins is an unaltered list of plugins */
|
||||
private var plugins: List<PluginViewData> = emptyList()
|
||||
|
||||
/** filteredPlugins is a subset of plugins following the current search query and tv type selection */
|
||||
private var _filteredPlugins = MutableLiveData<List<PluginViewData>>()
|
||||
var filteredPlugins: LiveData<List<PluginViewData>> = _filteredPlugins
|
||||
private var _filteredPlugins = MutableLiveData<PluginViewDataUpdate>()
|
||||
var filteredPlugins: LiveData<PluginViewDataUpdate> = _filteredPlugins
|
||||
|
||||
val tvTypes = mutableListOf<String>()
|
||||
private var currentQuery: String? = null
|
||||
|
@ -169,7 +174,7 @@ class PluginsViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
this.plugins = list
|
||||
_filteredPlugins.postValue(list.filterTvTypes().sortByQuery(currentQuery))
|
||||
_filteredPlugins.postValue(false to list.filterTvTypes().sortByQuery(currentQuery))
|
||||
}
|
||||
|
||||
// Perhaps can be optimized?
|
||||
|
@ -191,7 +196,7 @@ class PluginsViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
fun updateFilteredPlugins() {
|
||||
_filteredPlugins.postValue(plugins.filterTvTypes().sortByQuery(currentQuery))
|
||||
_filteredPlugins.postValue(false to plugins.filterTvTypes().sortByQuery(currentQuery))
|
||||
}
|
||||
|
||||
fun updatePluginList(repositoryUrl: String) = viewModelScope.launch {
|
||||
|
@ -201,7 +206,7 @@ class PluginsViewModel : ViewModel() {
|
|||
|
||||
fun search(query: String?) {
|
||||
currentQuery = query
|
||||
_filteredPlugins.postValue(filteredPlugins.value?.sortByQuery(query))
|
||||
_filteredPlugins.postValue(true to (filteredPlugins.value?.second?.sortByQuery(query) ?: emptyList()))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +222,6 @@ class PluginsViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
plugins = downloadedPlugins
|
||||
_filteredPlugins.postValue(downloadedPlugins.filterTvTypes().sortByQuery(currentQuery))
|
||||
_filteredPlugins.postValue(false to downloadedPlugins.filterTvTypes().sortByQuery(currentQuery))
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent">
|
||||
android:background="?attr/primaryGrayBackground">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/settings_toolbar"
|
||||
|
|
Loading…
Reference in a new issue