From 4aa7ae7e4c9dfead197f58b22793c5255314ba8c Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sat, 28 Mar 2020 18:45:37 +0100 Subject: [PATCH] Fix synchronization between feeds notifications permissions switches and enables all feeds notifications switch --- .../NotificationPermissionActivity.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/readrops/app/activities/NotificationPermissionActivity.kt b/app/src/main/java/com/readrops/app/activities/NotificationPermissionActivity.kt index 917607c6..c2823ea5 100644 --- a/app/src/main/java/com/readrops/app/activities/NotificationPermissionActivity.kt +++ b/app/src/main/java/com/readrops/app/activities/NotificationPermissionActivity.kt @@ -34,6 +34,7 @@ class NotificationPermissionActivity : AppCompatActivity() { val accountId = intent.getIntExtra(ACCOUNT_ID, 0) val viewModel by viewModels() var adapter: NotificationPermissionListAdapter? = null + var feedStateChanged = false viewModel.getAccount(accountId).observe(this, Observer { account -> viewModel.account = account @@ -59,14 +60,20 @@ class NotificationPermissionActivity : AppCompatActivity() { binding.notifPermissionFeedsSwitch.isEnabled = account.isNotificationsEnabled binding.notifPermissionFeedsSwitch.setOnCheckedChangeListener { _, isChecked -> - viewModel.setAllFeedsNotificationState(isChecked) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .doOnError { Utils.showSnackbar(binding.root, it.message) } - .subscribe() + if (!feedStateChanged) { + viewModel.setAllFeedsNotificationState(isChecked) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .doOnError { Utils.showSnackbar(binding.root, it.message) } + .subscribe() + } + + feedStateChanged = false } adapter = NotificationPermissionListAdapter(account.isNotificationsEnabled) { feed -> + feedStateChanged = true + viewModel.setFeedNotificationState(feed) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread())