From 67c1ac3da4388a6f89e6dfa63bac0deab605e9d5 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 14 Oct 2023 15:38:41 -0600 Subject: [PATCH] Add option to replace current entry --- .../ui/result/ResultViewModel2.kt | 32 ++++++++++++++++--- app/src/main/res/values/strings.xml | 3 +- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index 93ea5f29..fc7d87aa 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -75,6 +75,8 @@ import java.util.concurrent.TimeUnit interface AlertDialogResponseCallback { fun onUserResponse(response: Boolean) + + fun onUserResponseReplace(duplicateId: Int) } /** This starts at 1 */ @@ -871,6 +873,10 @@ class ResultViewModel2 : ViewModel() { response.name, getAllSubscriptions(), object : AlertDialogResponseCallback { + override fun onUserResponseReplace(duplicateId: Int) { + removeSubscribedData(duplicateId) + } + override fun onUserResponse(action: Boolean) { if (!action) { _subscribeStatus.postValue(false) @@ -932,6 +938,10 @@ class ResultViewModel2 : ViewModel() { response.name, getAllFavorites(), object : AlertDialogResponseCallback { + override fun onUserResponseReplace(duplicateId: Int) { + removeFavoritesData(duplicateId) + } + override fun onUserResponse(action: Boolean) { if (!action) { _favoriteStatus.postValue(false) @@ -974,10 +984,10 @@ class ResultViewModel2 : ViewModel() { message: Int, name: String, data: List, - callback: AlertDialogResponseCallback) - { - val isDuplicate = data.any { it.name == name } - if (!isDuplicate || context == null) { + callback: AlertDialogResponseCallback + ) { + val duplicateEntry = data.find { it.name == name } + if (duplicateEntry == null || context == null) { callback.onUserResponse(true) return } @@ -987,11 +997,23 @@ class ResultViewModel2 : ViewModel() { builder.setTitle(title) builder.setMessage(message) + builder.setNeutralButton(R.string.replace) { _, _ -> + // Replace current entry with new one + val duplicateId = duplicateEntry.id + if (duplicateId != null) { + callback.onUserResponseReplace(duplicateId) + } + + callback.onUserResponse(true) + } + builder.setNegativeButton(R.string.cancel) { _, _ -> + // Don't add duplicate callback.onUserResponse(false) } - builder.setPositiveButton(R.string.ignore) { _, _ -> + builder.setPositiveButton(R.string.add_anyway) { _, _ -> + // Add anyway callback.onUserResponse(true) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49e43593..dbab0e73 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -699,5 +699,6 @@ A possible duplicate with the same name already exists in your subscrptions. Possible Duplicate Found A possible duplicate with the same name already exists in your favorites. - Ignore + Add Anyway + Replace