diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt index b5f97bf12..3307c2078 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt @@ -27,7 +27,7 @@ import org.schabi.newpipe.R import org.schabi.newpipe.database.feed.model.FeedGroupEntity import org.schabi.newpipe.database.subscription.SubscriptionEntity import org.schabi.newpipe.local.subscription.FeedGroupIcon -import org.schabi.newpipe.local.subscription.dialog.FeedGroupDialogViewModel.FeedDialogEvent +import org.schabi.newpipe.local.subscription.dialog.FeedGroupDialogViewModel.DialogEvent.* import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.PickerIconItem import org.schabi.newpipe.local.subscription.item.PickerSubscriptionItem @@ -95,9 +95,10 @@ class FeedGroupDialog : DialogFragment() { viewModel.groupLiveData.observe(viewLifecycleOwner, Observer(::handleGroup)) viewModel.subscriptionsLiveData.observe(viewLifecycleOwner, Observer { setupSubscriptionPicker(it.first, it.second) }) - viewModel.successLiveData.observe(viewLifecycleOwner, Observer { + viewModel.dialogEventLiveData.observe(viewLifecycleOwner, Observer { when (it) { - is FeedDialogEvent.SuccessEvent -> dismiss() + ProcessingEvent -> disableInput() + SuccessEvent -> dismiss() } }) @@ -331,6 +332,15 @@ class FeedGroupDialog : DialogFragment() { group_name_input.clearFocus() } + private fun disableInput() { + delete_button?.isEnabled = false + confirm_button?.isEnabled = false + cancel_button?.isEnabled = false + isCancelable = false + + hideKeyboard() + } + companion object { private const val KEY_GROUP_ID = "KEY_GROUP_ID" private const val NO_GROUP_SELECTED = -1L diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt index 40ed38bd4..07d4003c0 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialogViewModel.kt @@ -4,9 +4,9 @@ import android.content.Context import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider +import io.reactivex.Completable import io.reactivex.Flowable -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.CompositeDisposable +import io.reactivex.disposables.Disposable import io.reactivex.functions.BiFunction import io.reactivex.schedulers.Schedulers import org.schabi.newpipe.database.feed.model.FeedGroupEntity @@ -29,9 +29,9 @@ class FeedGroupDialogViewModel(applicationContext: Context, val groupId: Long = val groupLiveData = MutableLiveData() val subscriptionsLiveData = MutableLiveData, Set>>() - val successLiveData = MutableLiveData() + val dialogEventLiveData = MutableLiveData() - private val disposables = CompositeDisposable() + private var actionProcessingDisposable: Disposable? = null private var feedGroupDisposable = feedDatabaseManager.getGroup(groupId) .subscribeOn(Schedulers.io()) @@ -45,35 +45,39 @@ class FeedGroupDialogViewModel(applicationContext: Context, val groupId: Long = override fun onCleared() { super.onCleared() + actionProcessingDisposable?.dispose() subscriptionsDisposable.dispose() feedGroupDisposable.dispose() - disposables.dispose() } fun createGroup(name: String, selectedIcon: FeedGroupIcon, selectedSubscriptions: Set) { - disposables.add(feedDatabaseManager.createGroup(name, selectedIcon) - .flatMapCompletable { feedDatabaseManager.updateSubscriptionsForGroup(it, selectedSubscriptions.toList()) } - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { successLiveData.postValue(FeedDialogEvent.SuccessEvent) }) + doAction(feedDatabaseManager.createGroup(name, selectedIcon) + .flatMapCompletable { + feedDatabaseManager.updateSubscriptionsForGroup(it, selectedSubscriptions.toList()) + }) } fun updateGroup(name: String, selectedIcon: FeedGroupIcon, selectedSubscriptions: Set, sortOrder: Long) { - disposables.add(feedDatabaseManager.updateSubscriptionsForGroup(groupId, selectedSubscriptions.toList()) - .andThen(feedDatabaseManager.updateGroup(FeedGroupEntity(groupId, name, selectedIcon, sortOrder))) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { successLiveData.postValue(FeedDialogEvent.SuccessEvent) }) + doAction(feedDatabaseManager.updateSubscriptionsForGroup(groupId, selectedSubscriptions.toList()) + .andThen(feedDatabaseManager.updateGroup(FeedGroupEntity(groupId, name, selectedIcon, sortOrder)))) } fun deleteGroup() { - disposables.add(feedDatabaseManager.deleteGroup(groupId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { successLiveData.postValue(FeedDialogEvent.SuccessEvent) }) + doAction(feedDatabaseManager.deleteGroup(groupId)) } - sealed class FeedDialogEvent { - object SuccessEvent : FeedDialogEvent() + private fun doAction(completable: Completable) { + if (actionProcessingDisposable == null) { + dialogEventLiveData.value = DialogEvent.ProcessingEvent + + actionProcessingDisposable = completable + .subscribeOn(Schedulers.io()) + .subscribe { dialogEventLiveData.postValue(DialogEvent.SuccessEvent) } + } + } + + sealed class DialogEvent { + object ProcessingEvent : DialogEvent() + object SuccessEvent : DialogEvent() } } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt index 6313b3c10..17ee89c87 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt @@ -19,7 +19,7 @@ import icepick.State import kotlinx.android.synthetic.main.dialog_feed_group_reorder.* import org.schabi.newpipe.R import org.schabi.newpipe.database.feed.model.FeedGroupEntity -import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewModel.DialogEvent.SuccessEvent +import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialogViewModel.DialogEvent.* import org.schabi.newpipe.local.subscription.item.FeedGroupReorderItem import org.schabi.newpipe.util.ThemeHelper import java.util.* @@ -50,7 +50,8 @@ class FeedGroupReorderDialog : DialogFragment() { viewModel.groupsLiveData.observe(viewLifecycleOwner, Observer(::handleGroups)) viewModel.dialogEventLiveData.observe(viewLifecycleOwner, Observer { when (it) { - is SuccessEvent -> dismiss() + ProcessingEvent -> disableInput() + SuccessEvent -> dismiss() } }) @@ -81,6 +82,11 @@ class FeedGroupReorderDialog : DialogFragment() { groupAdapter.update(groupList.map { FeedGroupReorderItem(it, itemTouchHelper) }) } + private fun disableInput() { + confirm_button?.isEnabled = false + isCancelable = false + } + private fun getItemTouchCallback(): SimpleCallback { return object : TouchCallback() { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialogViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialogViewModel.kt index 21828ee04..ec738eed6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialogViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialogViewModel.kt @@ -3,8 +3,8 @@ package org.schabi.newpipe.local.subscription.dialog import android.app.Application import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData -import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.CompositeDisposable +import io.reactivex.Completable +import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import org.schabi.newpipe.database.feed.model.FeedGroupEntity import org.schabi.newpipe.local.feed.FeedDatabaseManager @@ -15,7 +15,7 @@ class FeedGroupReorderDialogViewModel(application: Application) : AndroidViewMod val groupsLiveData = MutableLiveData>() val dialogEventLiveData = MutableLiveData() - private val disposables = CompositeDisposable() + private var actionProcessingDisposable: Disposable? = null private var groupsDisposable = feedDatabaseManager.groups() .limit(1) @@ -24,18 +24,26 @@ class FeedGroupReorderDialogViewModel(application: Application) : AndroidViewMod override fun onCleared() { super.onCleared() + actionProcessingDisposable?.dispose() groupsDisposable.dispose() - disposables.dispose() } fun updateOrder(groupIdList: List) { - disposables.add(feedDatabaseManager.updateGroupsOrder(groupIdList) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { dialogEventLiveData.postValue(DialogEvent.SuccessEvent) }) + doAction(feedDatabaseManager.updateGroupsOrder(groupIdList)) + } + + private fun doAction(completable: Completable) { + if (actionProcessingDisposable == null) { + dialogEventLiveData.value = DialogEvent.ProcessingEvent + + actionProcessingDisposable = completable + .subscribeOn(Schedulers.io()) + .subscribe { dialogEventLiveData.postValue(DialogEvent.SuccessEvent) } + } } sealed class DialogEvent { + object ProcessingEvent : DialogEvent() object SuccessEvent : DialogEvent() } } \ No newline at end of file