mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add option to replace current entry
This commit is contained in:
parent
194f1b46fb
commit
67c1ac3da4
2 changed files with 29 additions and 6 deletions
|
@ -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<DataStoreHelper.BaseSearchResponse>,
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -699,5 +699,6 @@
|
|||
<string name="subscription_duplicate_message">A possible duplicate with the same name already exists in your subscrptions.</string>
|
||||
<string name="favorites_duplicate_title">Possible Duplicate Found</string>
|
||||
<string name="favorites_duplicate_message">A possible duplicate with the same name already exists in your favorites.</string>
|
||||
<string name="ignore">Ignore</string>
|
||||
<string name="add_anyway">Add Anyway</string>
|
||||
<string name="replace">Replace</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue