Make duplicate warning if changed to any bookmarks from NONE

This commit is contained in:
Luna712 2023-10-25 11:38:53 -06:00
parent e1141c3a45
commit 8694a13faf
2 changed files with 33 additions and 29 deletions

View file

@ -55,10 +55,10 @@ import com.lagradost.cloudstream3.utils.Coroutines.ioWork
import com.lagradost.cloudstream3.utils.Coroutines.ioWorkSafe
import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.DataStoreHelper.deleteBookmarkedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllBookmarkedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllFavorites
import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllSubscriptions
import com.lagradost.cloudstream3.utils.DataStoreHelper.getBookmarkedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getBookmarkedDataByWatchType
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDub
import com.lagradost.cloudstream3.utils.DataStoreHelper.getFavoritesData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getLastWatched
@ -837,12 +837,13 @@ class ResultViewModel2 : ViewModel() {
val currentStatus = getResultWatchState(currentId)
// If the status is not actually changing, set this to an empty
// list so that we don't show the duplicate warning dialog, but we
// still want to refresh the data anyway
val bookmarkedData = if (status == currentStatus) {
emptyList()
} else getBookmarkedDataByWatchType(status)
// If the current status is "NONE" and the new status is not "NONE",
// fetch the bookmarked data to check for duplicates, otherwise set this
// to an empty list, so that we don't show the duplicate warning dialog,
// but we still want to update the current bookmark and refresh the data anyway.
val bookmarkedData = if (currentStatus == WatchType.NONE && status != WatchType.NONE) {
getAllBookmarkedData()
} else emptyList()
checkAndWarnDuplicates(
context,
@ -864,25 +865,32 @@ class ResultViewModel2 : ViewModel() {
setResultWatchState(currentId, status.internalId)
val current = getBookmarkedData(currentId)
// We don't need to store if WatchType.NONE.
// The key is removed in setResultWatchState, we don't want to
// re-add it again here if it was just removed.
if (status != WatchType.NONE) {
val current = getBookmarkedData(currentId)
setBookmarkedData(
currentId,
DataStoreHelper.BookmarkedData(
current?.bookmarkedTime ?: unixTimeMS,
setBookmarkedData(
currentId,
unixTimeMS,
response.name,
response.url,
response.apiName,
response.type,
response.posterUrl,
response.year,
response.syncData
DataStoreHelper.BookmarkedData(
current?.bookmarkedTime ?: unixTimeMS,
currentId,
unixTimeMS,
response.name,
response.url,
response.apiName,
response.type,
response.posterUrl,
response.year,
response.syncData
)
)
)
}
MainActivity.bookmarksUpdatedEvent(true)
if (currentStatus != status) {
MainActivity.bookmarksUpdatedEvent(true)
}
_watchStatus.postValue(status)

View file

@ -589,14 +589,10 @@ object DataStoreHelper {
return getKey("$currentAccount/$RESULT_WATCH_STATE_DATA", id.toString())
}
fun getBookmarkedDataByWatchType(watchType: WatchType): List<BookmarkedData> {
val allBookmarkedData: List<BookmarkedData> =
getKeys("$currentAccount/$RESULT_WATCH_STATE_DATA")?.mapNotNull {
getKey(it)
fun getAllBookmarkedData(): List<BookmarkedData> {
return getKeys("$currentAccount/$RESULT_WATCH_STATE_DATA")?.mapNotNull {
getKey(it)
} ?: emptyList()
return allBookmarkedData
.filter { getResultWatchState(it.id ?: return emptyList()) == watchType }
}
fun getAllSubscriptions(): List<SubscribedData> {