Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make search history account specific #638

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.DataStore.getKey
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.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
Expand Down Expand Up @@ -398,7 +399,7 @@ class SearchFragment : Fragment() {
DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_POSITIVE -> {
removeKeys(SEARCH_HISTORY_KEY)
removeKeys("$currentAccount/$SEARCH_HISTORY_KEY")
searchViewModel.updateHistory()
}
DialogInterface.BUTTON_NEGATIVE -> {
Expand Down Expand Up @@ -510,7 +511,7 @@ class SearchFragment : Fragment() {
binding?.mainSearch?.setQuery(searchItem.searchText, true)
}
SEARCH_HISTORY_REMOVE -> {
removeKey(SEARCH_HISTORY_KEY, searchItem.key)
removeKey("$currentAccount/$SEARCH_HISTORY_KEY", searchItem.key)
searchViewModel.updateHistory()
}
else -> {
Expand Down Expand Up @@ -559,4 +560,4 @@ class SearchFragment : Fragment() {
.commit()*/
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.DataStoreHelper.currentAccount
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -64,7 +65,7 @@ class SearchViewModel : ViewModel() {

fun updateHistory() = viewModelScope.launch {
ioSafe {
val items = getKeys(SEARCH_HISTORY_KEY)?.mapNotNull {
val items = getKeys("$currentAccount/$SEARCH_HISTORY_KEY")?.mapNotNull {
getKey<SearchHistoryItem>(it)
}?.sortedByDescending { it.searchedAt } ?: emptyList()
_currentHistory.postValue(items)
Expand All @@ -87,7 +88,7 @@ class SearchViewModel : ViewModel() {
if (!isQuickSearch) {
val key = query.hashCode().toString()
setKey(
SEARCH_HISTORY_KEY,
"$currentAccount/$SEARCH_HISTORY_KEY",
key,
SearchHistoryItem(
searchedAt = System.currentTimeMillis(),
Expand Down Expand Up @@ -140,4 +141,4 @@ class SearchViewModel : ViewModel() {
_searchResponse.postValue(Resource.Success(list))
}
}
}
}
Loading