mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Make search history account specific (#638)
* Make search history account specific * Update for clear history
This commit is contained in:
parent
bd05a67f26
commit
1d90858f64
2 changed files with 8 additions and 6 deletions
|
@ -55,6 +55,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.main
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
|
||||||
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
import com.lagradost.cloudstream3.utils.SubtitleHelper
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
|
||||||
|
@ -398,7 +399,7 @@ class SearchFragment : Fragment() {
|
||||||
DialogInterface.OnClickListener { _, which ->
|
DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_POSITIVE -> {
|
DialogInterface.BUTTON_POSITIVE -> {
|
||||||
removeKeys(SEARCH_HISTORY_KEY)
|
removeKeys("$currentAccount/$SEARCH_HISTORY_KEY")
|
||||||
searchViewModel.updateHistory()
|
searchViewModel.updateHistory()
|
||||||
}
|
}
|
||||||
DialogInterface.BUTTON_NEGATIVE -> {
|
DialogInterface.BUTTON_NEGATIVE -> {
|
||||||
|
@ -510,7 +511,7 @@ class SearchFragment : Fragment() {
|
||||||
binding?.mainSearch?.setQuery(searchItem.searchText, true)
|
binding?.mainSearch?.setQuery(searchItem.searchText, true)
|
||||||
}
|
}
|
||||||
SEARCH_HISTORY_REMOVE -> {
|
SEARCH_HISTORY_REMOVE -> {
|
||||||
removeKey(SEARCH_HISTORY_KEY, searchItem.key)
|
removeKey("$currentAccount/$SEARCH_HISTORY_KEY", searchItem.key)
|
||||||
searchViewModel.updateHistory()
|
searchViewModel.updateHistory()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.lagradost.cloudstream3.mvvm.Resource
|
||||||
import com.lagradost.cloudstream3.mvvm.launchSafe
|
import com.lagradost.cloudstream3.mvvm.launchSafe
|
||||||
import com.lagradost.cloudstream3.ui.APIRepository
|
import com.lagradost.cloudstream3.ui.APIRepository
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -64,7 +65,7 @@ class SearchViewModel : ViewModel() {
|
||||||
|
|
||||||
fun updateHistory() = viewModelScope.launch {
|
fun updateHistory() = viewModelScope.launch {
|
||||||
ioSafe {
|
ioSafe {
|
||||||
val items = getKeys(SEARCH_HISTORY_KEY)?.mapNotNull {
|
val items = getKeys("$currentAccount/$SEARCH_HISTORY_KEY")?.mapNotNull {
|
||||||
getKey<SearchHistoryItem>(it)
|
getKey<SearchHistoryItem>(it)
|
||||||
}?.sortedByDescending { it.searchedAt } ?: emptyList()
|
}?.sortedByDescending { it.searchedAt } ?: emptyList()
|
||||||
_currentHistory.postValue(items)
|
_currentHistory.postValue(items)
|
||||||
|
@ -87,7 +88,7 @@ class SearchViewModel : ViewModel() {
|
||||||
if (!isQuickSearch) {
|
if (!isQuickSearch) {
|
||||||
val key = query.hashCode().toString()
|
val key = query.hashCode().toString()
|
||||||
setKey(
|
setKey(
|
||||||
SEARCH_HISTORY_KEY,
|
"$currentAccount/$SEARCH_HISTORY_KEY",
|
||||||
key,
|
key,
|
||||||
SearchHistoryItem(
|
SearchHistoryItem(
|
||||||
searchedAt = System.currentTimeMillis(),
|
searchedAt = System.currentTimeMillis(),
|
||||||
|
|
Loading…
Reference in a new issue