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 {
|
interface AlertDialogResponseCallback {
|
||||||
fun onUserResponse(response: Boolean)
|
fun onUserResponse(response: Boolean)
|
||||||
|
|
||||||
|
fun onUserResponseReplace(duplicateId: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This starts at 1 */
|
/** This starts at 1 */
|
||||||
|
@ -871,6 +873,10 @@ class ResultViewModel2 : ViewModel() {
|
||||||
response.name,
|
response.name,
|
||||||
getAllSubscriptions(),
|
getAllSubscriptions(),
|
||||||
object : AlertDialogResponseCallback {
|
object : AlertDialogResponseCallback {
|
||||||
|
override fun onUserResponseReplace(duplicateId: Int) {
|
||||||
|
removeSubscribedData(duplicateId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onUserResponse(action: Boolean) {
|
override fun onUserResponse(action: Boolean) {
|
||||||
if (!action) {
|
if (!action) {
|
||||||
_subscribeStatus.postValue(false)
|
_subscribeStatus.postValue(false)
|
||||||
|
@ -932,6 +938,10 @@ class ResultViewModel2 : ViewModel() {
|
||||||
response.name,
|
response.name,
|
||||||
getAllFavorites(),
|
getAllFavorites(),
|
||||||
object : AlertDialogResponseCallback {
|
object : AlertDialogResponseCallback {
|
||||||
|
override fun onUserResponseReplace(duplicateId: Int) {
|
||||||
|
removeFavoritesData(duplicateId)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onUserResponse(action: Boolean) {
|
override fun onUserResponse(action: Boolean) {
|
||||||
if (!action) {
|
if (!action) {
|
||||||
_favoriteStatus.postValue(false)
|
_favoriteStatus.postValue(false)
|
||||||
|
@ -974,10 +984,10 @@ class ResultViewModel2 : ViewModel() {
|
||||||
message: Int,
|
message: Int,
|
||||||
name: String,
|
name: String,
|
||||||
data: List<DataStoreHelper.BaseSearchResponse>,
|
data: List<DataStoreHelper.BaseSearchResponse>,
|
||||||
callback: AlertDialogResponseCallback)
|
callback: AlertDialogResponseCallback
|
||||||
{
|
) {
|
||||||
val isDuplicate = data.any { it.name == name }
|
val duplicateEntry = data.find { it.name == name }
|
||||||
if (!isDuplicate || context == null) {
|
if (duplicateEntry == null || context == null) {
|
||||||
callback.onUserResponse(true)
|
callback.onUserResponse(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -987,11 +997,23 @@ class ResultViewModel2 : ViewModel() {
|
||||||
builder.setTitle(title)
|
builder.setTitle(title)
|
||||||
builder.setMessage(message)
|
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) { _, _ ->
|
builder.setNegativeButton(R.string.cancel) { _, _ ->
|
||||||
|
// Don't add duplicate
|
||||||
callback.onUserResponse(false)
|
callback.onUserResponse(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setPositiveButton(R.string.ignore) { _, _ ->
|
builder.setPositiveButton(R.string.add_anyway) { _, _ ->
|
||||||
|
// Add anyway
|
||||||
callback.onUserResponse(true)
|
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="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_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="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>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue