Skip to content

Commit b1d9080

Browse files
committed
Simplify disposables handling in notification mode settings
1 parent fb1360b commit b1d9080

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

app/src/main/java/org/schabi/newpipe/settings/notifications/NotificationModeConfigFragment.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class NotificationModeConfigFragment : Fragment() {
2727
private var _binding: FragmentChannelsNotificationsBinding? = null
2828
private val binding get() = _binding!!
2929

30-
private val updaters = CompositeDisposable()
30+
private val disposables = CompositeDisposable()
3131
private var loader: Disposable? = null
3232
private lateinit var adapter: NotificationModeConfigAdapter
3333
private lateinit var subscriptionManager: SubscriptionManager
@@ -56,7 +56,7 @@ class NotificationModeConfigFragment : Fragment() {
5656
adapter = NotificationModeConfigAdapter { position, mode ->
5757
// Notification mode has been changed via the UI.
5858
// Now change it in the database.
59-
updaters.add(updateNotificationMode(adapter.currentList[position], mode))
59+
updateNotificationMode(adapter.currentList[position], mode)
6060
}
6161
binding.recyclerView.adapter = adapter
6262
loader?.dispose()
@@ -73,7 +73,7 @@ class NotificationModeConfigFragment : Fragment() {
7373
}
7474

7575
override fun onDestroy() {
76-
updaters.dispose()
76+
disposables.dispose()
7777
super.onDestroy()
7878
}
7979

@@ -98,16 +98,14 @@ class NotificationModeConfigFragment : Fragment() {
9898
NotificationMode.DISABLED -> NotificationMode.ENABLED
9999
else -> NotificationMode.DISABLED
100100
}
101-
val disposables = adapter.currentList.map { updateNotificationMode(it, newMode) }
102-
updaters.add(CompositeDisposable(disposables))
101+
adapter.currentList.forEach { updateNotificationMode(it, newMode) }
103102
}
104103

105-
private fun updateNotificationMode(
106-
item: SubscriptionItem,
107-
@NotificationMode mode: Int
108-
): Disposable {
109-
return subscriptionManager.updateNotificationMode(item.serviceId, item.url, mode)
110-
.subscribeOn(Schedulers.io())
111-
.subscribe()
104+
private fun updateNotificationMode(item: SubscriptionItem, @NotificationMode mode: Int) {
105+
disposables.add(
106+
subscriptionManager.updateNotificationMode(item.serviceId, item.url, mode)
107+
.subscribeOn(Schedulers.io())
108+
.subscribe()
109+
)
112110
}
113111
}

0 commit comments

Comments
 (0)