Simplify disposables handling in notification mode settings

This commit is contained in:
Stypox 2023-01-02 14:45:11 +01:00
parent fb1360b72a
commit b1d9080a0f
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 10 additions and 12 deletions

View File

@ -27,7 +27,7 @@ class NotificationModeConfigFragment : Fragment() {
private var _binding: FragmentChannelsNotificationsBinding? = null
private val binding get() = _binding!!
private val updaters = CompositeDisposable()
private val disposables = CompositeDisposable()
private var loader: Disposable? = null
private lateinit var adapter: NotificationModeConfigAdapter
private lateinit var subscriptionManager: SubscriptionManager
@ -56,7 +56,7 @@ class NotificationModeConfigFragment : Fragment() {
adapter = NotificationModeConfigAdapter { position, mode ->
// Notification mode has been changed via the UI.
// Now change it in the database.
updaters.add(updateNotificationMode(adapter.currentList[position], mode))
updateNotificationMode(adapter.currentList[position], mode)
}
binding.recyclerView.adapter = adapter
loader?.dispose()
@ -73,7 +73,7 @@ class NotificationModeConfigFragment : Fragment() {
}
override fun onDestroy() {
updaters.dispose()
disposables.dispose()
super.onDestroy()
}
@ -98,16 +98,14 @@ class NotificationModeConfigFragment : Fragment() {
NotificationMode.DISABLED -> NotificationMode.ENABLED
else -> NotificationMode.DISABLED
}
val disposables = adapter.currentList.map { updateNotificationMode(it, newMode) }
updaters.add(CompositeDisposable(disposables))
adapter.currentList.forEach { updateNotificationMode(it, newMode) }
}
private fun updateNotificationMode(
item: SubscriptionItem,
@NotificationMode mode: Int
): Disposable {
return subscriptionManager.updateNotificationMode(item.serviceId, item.url, mode)
.subscribeOn(Schedulers.io())
.subscribe()
private fun updateNotificationMode(item: SubscriptionItem, @NotificationMode mode: Int) {
disposables.add(
subscriptionManager.updateNotificationMode(item.serviceId, item.url, mode)
.subscribeOn(Schedulers.io())
.subscribe()
)
}
}