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

View file

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