Disable buttons when processing actions in the feed dialogs
This commit is contained in:
parent
34082c40d3
commit
597859eb23
|
@ -27,7 +27,7 @@ import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
||||||
import org.schabi.newpipe.local.subscription.FeedGroupIcon
|
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.EmptyPlaceholderItem
|
||||||
import org.schabi.newpipe.local.subscription.item.PickerIconItem
|
import org.schabi.newpipe.local.subscription.item.PickerIconItem
|
||||||
import org.schabi.newpipe.local.subscription.item.PickerSubscriptionItem
|
import org.schabi.newpipe.local.subscription.item.PickerSubscriptionItem
|
||||||
|
@ -95,9 +95,10 @@ class FeedGroupDialog : DialogFragment() {
|
||||||
|
|
||||||
viewModel.groupLiveData.observe(viewLifecycleOwner, Observer(::handleGroup))
|
viewModel.groupLiveData.observe(viewLifecycleOwner, Observer(::handleGroup))
|
||||||
viewModel.subscriptionsLiveData.observe(viewLifecycleOwner, Observer { setupSubscriptionPicker(it.first, it.second) })
|
viewModel.subscriptionsLiveData.observe(viewLifecycleOwner, Observer { setupSubscriptionPicker(it.first, it.second) })
|
||||||
viewModel.successLiveData.observe(viewLifecycleOwner, Observer {
|
viewModel.dialogEventLiveData.observe(viewLifecycleOwner, Observer {
|
||||||
when (it) {
|
when (it) {
|
||||||
is FeedDialogEvent.SuccessEvent -> dismiss()
|
ProcessingEvent -> disableInput()
|
||||||
|
SuccessEvent -> dismiss()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -331,6 +332,15 @@ class FeedGroupDialog : DialogFragment() {
|
||||||
group_name_input.clearFocus()
|
group_name_input.clearFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun disableInput() {
|
||||||
|
delete_button?.isEnabled = false
|
||||||
|
confirm_button?.isEnabled = false
|
||||||
|
cancel_button?.isEnabled = false
|
||||||
|
isCancelable = false
|
||||||
|
|
||||||
|
hideKeyboard()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val KEY_GROUP_ID = "KEY_GROUP_ID"
|
private const val KEY_GROUP_ID = "KEY_GROUP_ID"
|
||||||
private const val NO_GROUP_SELECTED = -1L
|
private const val NO_GROUP_SELECTED = -1L
|
||||||
|
|
|
@ -4,9 +4,9 @@ import android.content.Context
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import io.reactivex.Completable
|
||||||
import io.reactivex.Flowable
|
import io.reactivex.Flowable
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
|
||||||
import io.reactivex.functions.BiFunction
|
import io.reactivex.functions.BiFunction
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
|
@ -29,9 +29,9 @@ class FeedGroupDialogViewModel(applicationContext: Context, val groupId: Long =
|
||||||
|
|
||||||
val groupLiveData = MutableLiveData<FeedGroupEntity>()
|
val groupLiveData = MutableLiveData<FeedGroupEntity>()
|
||||||
val subscriptionsLiveData = MutableLiveData<Pair<List<SubscriptionEntity>, Set<Long>>>()
|
val subscriptionsLiveData = MutableLiveData<Pair<List<SubscriptionEntity>, Set<Long>>>()
|
||||||
val successLiveData = MutableLiveData<FeedDialogEvent>()
|
val dialogEventLiveData = MutableLiveData<DialogEvent>()
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
private var actionProcessingDisposable: Disposable? = null
|
||||||
|
|
||||||
private var feedGroupDisposable = feedDatabaseManager.getGroup(groupId)
|
private var feedGroupDisposable = feedDatabaseManager.getGroup(groupId)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
|
@ -45,35 +45,39 @@ class FeedGroupDialogViewModel(applicationContext: Context, val groupId: Long =
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
actionProcessingDisposable?.dispose()
|
||||||
subscriptionsDisposable.dispose()
|
subscriptionsDisposable.dispose()
|
||||||
feedGroupDisposable.dispose()
|
feedGroupDisposable.dispose()
|
||||||
disposables.dispose()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createGroup(name: String, selectedIcon: FeedGroupIcon, selectedSubscriptions: Set<Long>) {
|
fun createGroup(name: String, selectedIcon: FeedGroupIcon, selectedSubscriptions: Set<Long>) {
|
||||||
disposables.add(feedDatabaseManager.createGroup(name, selectedIcon)
|
doAction(feedDatabaseManager.createGroup(name, selectedIcon)
|
||||||
.flatMapCompletable { feedDatabaseManager.updateSubscriptionsForGroup(it, selectedSubscriptions.toList()) }
|
.flatMapCompletable {
|
||||||
.subscribeOn(Schedulers.io())
|
feedDatabaseManager.updateSubscriptionsForGroup(it, selectedSubscriptions.toList())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
})
|
||||||
.subscribe { successLiveData.postValue(FeedDialogEvent.SuccessEvent) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateGroup(name: String, selectedIcon: FeedGroupIcon, selectedSubscriptions: Set<Long>, sortOrder: Long) {
|
fun updateGroup(name: String, selectedIcon: FeedGroupIcon, selectedSubscriptions: Set<Long>, sortOrder: Long) {
|
||||||
disposables.add(feedDatabaseManager.updateSubscriptionsForGroup(groupId, selectedSubscriptions.toList())
|
doAction(feedDatabaseManager.updateSubscriptionsForGroup(groupId, selectedSubscriptions.toList())
|
||||||
.andThen(feedDatabaseManager.updateGroup(FeedGroupEntity(groupId, name, selectedIcon, sortOrder)))
|
.andThen(feedDatabaseManager.updateGroup(FeedGroupEntity(groupId, name, selectedIcon, sortOrder))))
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { successLiveData.postValue(FeedDialogEvent.SuccessEvent) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteGroup() {
|
fun deleteGroup() {
|
||||||
disposables.add(feedDatabaseManager.deleteGroup(groupId)
|
doAction(feedDatabaseManager.deleteGroup(groupId))
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { successLiveData.postValue(FeedDialogEvent.SuccessEvent) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class FeedDialogEvent {
|
private fun doAction(completable: Completable) {
|
||||||
object SuccessEvent : FeedDialogEvent()
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@ import icepick.State
|
||||||
import kotlinx.android.synthetic.main.dialog_feed_group_reorder.*
|
import kotlinx.android.synthetic.main.dialog_feed_group_reorder.*
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
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.local.subscription.item.FeedGroupReorderItem
|
||||||
import org.schabi.newpipe.util.ThemeHelper
|
import org.schabi.newpipe.util.ThemeHelper
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -50,7 +50,8 @@ class FeedGroupReorderDialog : DialogFragment() {
|
||||||
viewModel.groupsLiveData.observe(viewLifecycleOwner, Observer(::handleGroups))
|
viewModel.groupsLiveData.observe(viewLifecycleOwner, Observer(::handleGroups))
|
||||||
viewModel.dialogEventLiveData.observe(viewLifecycleOwner, Observer {
|
viewModel.dialogEventLiveData.observe(viewLifecycleOwner, Observer {
|
||||||
when (it) {
|
when (it) {
|
||||||
is SuccessEvent -> dismiss()
|
ProcessingEvent -> disableInput()
|
||||||
|
SuccessEvent -> dismiss()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -81,6 +82,11 @@ class FeedGroupReorderDialog : DialogFragment() {
|
||||||
groupAdapter.update(groupList.map { FeedGroupReorderItem(it, itemTouchHelper) })
|
groupAdapter.update(groupList.map { FeedGroupReorderItem(it, itemTouchHelper) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun disableInput() {
|
||||||
|
confirm_button?.isEnabled = false
|
||||||
|
isCancelable = false
|
||||||
|
}
|
||||||
|
|
||||||
private fun getItemTouchCallback(): SimpleCallback {
|
private fun getItemTouchCallback(): SimpleCallback {
|
||||||
return object : TouchCallback() {
|
return object : TouchCallback() {
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ package org.schabi.newpipe.local.subscription.dialog
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import androidx.lifecycle.AndroidViewModel
|
import androidx.lifecycle.AndroidViewModel
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.Completable
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.local.feed.FeedDatabaseManager
|
import org.schabi.newpipe.local.feed.FeedDatabaseManager
|
||||||
|
@ -15,7 +15,7 @@ class FeedGroupReorderDialogViewModel(application: Application) : AndroidViewMod
|
||||||
val groupsLiveData = MutableLiveData<List<FeedGroupEntity>>()
|
val groupsLiveData = MutableLiveData<List<FeedGroupEntity>>()
|
||||||
val dialogEventLiveData = MutableLiveData<DialogEvent>()
|
val dialogEventLiveData = MutableLiveData<DialogEvent>()
|
||||||
|
|
||||||
private val disposables = CompositeDisposable()
|
private var actionProcessingDisposable: Disposable? = null
|
||||||
|
|
||||||
private var groupsDisposable = feedDatabaseManager.groups()
|
private var groupsDisposable = feedDatabaseManager.groups()
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
@ -24,18 +24,26 @@ class FeedGroupReorderDialogViewModel(application: Application) : AndroidViewMod
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
actionProcessingDisposable?.dispose()
|
||||||
groupsDisposable.dispose()
|
groupsDisposable.dispose()
|
||||||
disposables.dispose()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateOrder(groupIdList: List<Long>) {
|
fun updateOrder(groupIdList: List<Long>) {
|
||||||
disposables.add(feedDatabaseManager.updateGroupsOrder(groupIdList)
|
doAction(feedDatabaseManager.updateGroupsOrder(groupIdList))
|
||||||
.subscribeOn(Schedulers.io())
|
}
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { dialogEventLiveData.postValue(DialogEvent.SuccessEvent) })
|
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 {
|
sealed class DialogEvent {
|
||||||
|
object ProcessingEvent : DialogEvent()
|
||||||
object SuccessEvent : DialogEvent()
|
object SuccessEvent : DialogEvent()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue