Simplify disposables handling in notification mode settings
This commit is contained in:
parent
fb1360b72a
commit
b1d9080a0f
1 changed files with 10 additions and 12 deletions
|
@ -27,7 +27,7 @@ class NotificationModeConfigFragment : Fragment() {
|
||||||
private var _binding: FragmentChannelsNotificationsBinding? = null
|
private var _binding: FragmentChannelsNotificationsBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
private val updaters = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
private var loader: Disposable? = null
|
private var loader: Disposable? = null
|
||||||
private lateinit var adapter: NotificationModeConfigAdapter
|
private lateinit var adapter: NotificationModeConfigAdapter
|
||||||
private lateinit var subscriptionManager: SubscriptionManager
|
private lateinit var subscriptionManager: SubscriptionManager
|
||||||
|
@ -56,7 +56,7 @@ class NotificationModeConfigFragment : Fragment() {
|
||||||
adapter = NotificationModeConfigAdapter { position, mode ->
|
adapter = NotificationModeConfigAdapter { position, mode ->
|
||||||
// Notification mode has been changed via the UI.
|
// Notification mode has been changed via the UI.
|
||||||
// Now change it in the database.
|
// Now change it in the database.
|
||||||
updaters.add(updateNotificationMode(adapter.currentList[position], mode))
|
updateNotificationMode(adapter.currentList[position], mode)
|
||||||
}
|
}
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = adapter
|
||||||
loader?.dispose()
|
loader?.dispose()
|
||||||
|
@ -73,7 +73,7 @@ class NotificationModeConfigFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
updaters.dispose()
|
disposables.dispose()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,16 +98,14 @@ class NotificationModeConfigFragment : Fragment() {
|
||||||
NotificationMode.DISABLED -> NotificationMode.ENABLED
|
NotificationMode.DISABLED -> NotificationMode.ENABLED
|
||||||
else -> NotificationMode.DISABLED
|
else -> NotificationMode.DISABLED
|
||||||
}
|
}
|
||||||
val disposables = adapter.currentList.map { updateNotificationMode(it, newMode) }
|
adapter.currentList.forEach { updateNotificationMode(it, newMode) }
|
||||||
updaters.add(CompositeDisposable(disposables))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateNotificationMode(
|
private fun updateNotificationMode(item: SubscriptionItem, @NotificationMode mode: Int) {
|
||||||
item: SubscriptionItem,
|
disposables.add(
|
||||||
@NotificationMode mode: Int
|
subscriptionManager.updateNotificationMode(item.serviceId, item.url, mode)
|
||||||
): Disposable {
|
.subscribeOn(Schedulers.io())
|
||||||
return subscriptionManager.updateNotificationMode(item.serviceId, item.url, mode)
|
.subscribe()
|
||||||
.subscribeOn(Schedulers.io())
|
)
|
||||||
.subscribe()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue