Check year also to have more accuracy

This commit is contained in:
Luna712 2023-10-14 20:48:21 -06:00
parent e1f833ad3a
commit 15ef933fec
2 changed files with 28 additions and 18 deletions

View file

@ -60,10 +60,12 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.getAllSubscriptions
import com.lagradost.cloudstream3.utils.DataStoreHelper.getBookmarkedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getDub
import com.lagradost.cloudstream3.utils.DataStoreHelper.getFavoritesData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getLastWatched
import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultEpisode
import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultSeason
import com.lagradost.cloudstream3.utils.DataStoreHelper.getResultWatchState
import com.lagradost.cloudstream3.utils.DataStoreHelper.getSubscribedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.getVideoWatchState
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeFavoritesData
import com.lagradost.cloudstream3.utils.DataStoreHelper.removeSubscribedData
@ -73,6 +75,8 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.setFavoritesData
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultEpisode
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultSeason
import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultWatchState
import com.lagradost.cloudstream3.utils.DataStoreHelper.setSubscribedData
import com.lagradost.cloudstream3.utils.DataStoreHelper.setVideoWatchState
import com.lagradost.cloudstream3.utils.DataStoreHelper.updateSubscribedData
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import kotlinx.coroutines.*
@ -472,9 +476,9 @@ class ResultViewModel2 : ViewModel() {
DataStoreHelper.BookmarkedData(
current?.bookmarkedTime ?: currentTime,
currentTime,
currentResponse.year,
currentId,
currentResponse.name,
currentResponse.year,
currentResponse.url,
currentResponse.apiName,
currentResponse.type,
@ -851,6 +855,7 @@ class ResultViewModel2 : ViewModel() {
R.string.bookmarks_duplicate_title,
R.string.bookmarks_duplicate_message,
response.name,
response.year,
getAllBookmarkedDataByWatchType()[status] ?: emptyList(),
object : AlertDialogResponseCallback {
override fun onUserResponseReplace(duplicateId: Int) {
@ -899,6 +904,7 @@ class ResultViewModel2 : ViewModel() {
R.string.subscriptions_duplicate_title,
R.string.subscriptions_duplicate_message,
response.name,
response.year,
getAllSubscriptions(),
object : AlertDialogResponseCallback {
override fun onUserResponseReplace(duplicateId: Int) {
@ -910,15 +916,15 @@ class ResultViewModel2 : ViewModel() {
val current = getSubscribedData(currentId)
DataStoreHelper.setSubscribedData(
setSubscribedData(
currentId,
DataStoreHelper.SubscribedData(
current?.subscribedTime ?: unixTimeMS,
unixTimeMS,
response.getLatestEpisodes(),
response.year,
currentId,
response.name,
response.year,
response.url,
response.apiName,
response.type,
@ -961,6 +967,7 @@ class ResultViewModel2 : ViewModel() {
R.string.favorites_duplicate_title,
R.string.favorites_duplicate_message,
response.name,
response.year,
getAllFavorites(),
object : AlertDialogResponseCallback {
override fun onUserResponseReplace(duplicateId: Int) {
@ -977,9 +984,9 @@ class ResultViewModel2 : ViewModel() {
DataStoreHelper.FavoritesData(
current?.favoritesTime ?: unixTimeMS,
unixTimeMS,
response.year,
currentId,
response.name,
response.year,
response.url,
response.apiName,
response.type,
@ -1005,10 +1012,12 @@ class ResultViewModel2 : ViewModel() {
title: Int,
message: Int,
name: String,
year: Int?,
data: List<DataStoreHelper.BaseSearchResponse>,
callback: AlertDialogResponseCallback
) {
val duplicateEntry = data.find { it.name == name }
// TODO support checking IMDB ID rather than name + year when available
val duplicateEntry = data.find { it.name == name && it.year == year }
if (duplicateEntry == null || context == null) {
callback.onUserResponse(true)
return
@ -1393,7 +1402,7 @@ class ResultViewModel2 : ViewModel() {
// Do not add mark as watched on movies
if (!listOf(TvType.Movie, TvType.AnimeMovie).contains(click.data.tvType)) {
val isWatched =
DataStoreHelper.getVideoWatchState(click.data.id) == VideoWatchState.Watched
getVideoWatchState(click.data.id) == VideoWatchState.Watched
val watchedText = if (isWatched) R.string.action_remove_from_watched
else R.string.action_mark_as_watched
@ -1642,12 +1651,12 @@ class ResultViewModel2 : ViewModel() {
ACTION_MARK_AS_WATCHED -> {
val isWatched =
DataStoreHelper.getVideoWatchState(click.data.id) == VideoWatchState.Watched
getVideoWatchState(click.data.id) == VideoWatchState.Watched
if (isWatched) {
DataStoreHelper.setVideoWatchState(click.data.id, VideoWatchState.None)
setVideoWatchState(click.data.id, VideoWatchState.None)
} else {
DataStoreHelper.setVideoWatchState(click.data.id, VideoWatchState.Watched)
setVideoWatchState(click.data.id, VideoWatchState.Watched)
}
// Kinda dirty to reload all episodes :(
@ -1856,7 +1865,7 @@ class ResultViewModel2 : ViewModel() {
list.subList(start, end).map {
val posDur = getViewPos(it.id)
val watchState =
DataStoreHelper.getVideoWatchState(it.id) ?: VideoWatchState.None
getVideoWatchState(it.id) ?: VideoWatchState.None
it.copy(
position = posDur?.position ?: 0,
duration = posDur?.duration ?: 0,
@ -2302,7 +2311,7 @@ class ResultViewModel2 : ViewModel() {
private fun resume(): ResumeWatchingStatus? {
val correctId = currentId ?: return null
val resume = DataStoreHelper.getLastWatched(correctId)
val resume = getLastWatched(correctId)
val resumeParentId = resume?.parentId
if (resumeParentId != correctId) return null // is null or smth went wrong with getLastWatched
val resumeId = resume.episodeId ?: return null// invalid episode id

View file

@ -355,6 +355,7 @@ object DataStoreHelper {
abstract class BaseSearchResponse(
@JsonProperty("id") override var id: Int?,
@JsonProperty("name") override val name: String,
@JsonProperty("year") open val year: Int?,
@JsonProperty("url") override val url: String,
@JsonProperty("apiName") override val apiName: String,
@JsonProperty("type") override var type: TvType? = null,
@ -367,16 +368,16 @@ object DataStoreHelper {
@JsonProperty("subscribedTime") val subscribedTime: Long,
@JsonProperty("latestUpdatedTime") val latestUpdatedTime: Long,
@JsonProperty("lastSeenEpisodeCount") val lastSeenEpisodeCount: Map<DubStatus, Int?>,
@JsonProperty("year") val year: Int?,
override var id: Int?,
override val name: String,
override val year: Int?,
override val url: String,
override val apiName: String,
override var type: TvType?,
override var posterUrl: String?,
override var quality: SearchQuality? = null,
override var posterHeaders: Map<String, String>? = null
) : BaseSearchResponse(id, name, url, apiName, type, posterUrl, quality, posterHeaders) {
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, quality, posterHeaders) {
fun toLibraryItem(): SyncAPI.LibraryItem? {
return SyncAPI.LibraryItem(
name,
@ -394,16 +395,16 @@ object DataStoreHelper {
data class BookmarkedData(
@JsonProperty("bookmarkedTime") val bookmarkedTime: Long,
@JsonProperty("latestUpdatedTime") val latestUpdatedTime: Long,
@JsonProperty("year") val year: Int?,
override var id: Int?,
override val name: String,
override val year: Int?,
override val url: String,
override val apiName: String,
override var type: TvType?,
override var posterUrl: String?,
override var quality: SearchQuality? = null,
override var posterHeaders: Map<String, String>? = null
) : BaseSearchResponse(id, name, url, apiName, type, posterUrl, quality, posterHeaders) {
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, quality, posterHeaders) {
fun toLibraryItem(id: String): SyncAPI.LibraryItem {
return SyncAPI.LibraryItem(
name,
@ -421,16 +422,16 @@ object DataStoreHelper {
data class FavoritesData(
@JsonProperty("favoritesTime") val favoritesTime: Long,
@JsonProperty("latestUpdatedTime") val latestUpdatedTime: Long,
@JsonProperty("year") val year: Int?,
override var id: Int?,
override val name: String,
override val year: Int?,
override val url: String,
override val apiName: String,
override var type: TvType?,
override var posterUrl: String?,
override var quality: SearchQuality? = null,
override var posterHeaders: Map<String, String>? = null
) : BaseSearchResponse(id, name, url, apiName, type, posterUrl, quality, posterHeaders) {
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, quality, posterHeaders) {
fun toLibraryItem(): SyncAPI.LibraryItem? {
return SyncAPI.LibraryItem(
name,
@ -459,7 +460,7 @@ object DataStoreHelper {
override var posterUrl: String?,
override var quality: SearchQuality? = null,
override var posterHeaders: Map<String, String>? = null
) : BaseSearchResponse(id, name, url, apiName, type, posterUrl, quality, posterHeaders)
) : BaseSearchResponse(id, name, null, url, apiName, type, posterUrl, quality, posterHeaders)
/**
* A datastore wide account for future implementations of a multiple account system