From 5fbc0245db97b7c8ba7ce02448d73fb2650340a4 Mon Sep 17 00:00:00 2001 From: Norbel Ambanumben Date: Fri, 3 Nov 2023 07:14:02 +0100 Subject: [PATCH] Updated rules for storing preferences --- .../activity/runtests/RunTestsViewModel.kt | 8 ++---- .../RunTestsExpandableListViewAdapter.kt | 6 +++++ .../common/PreferenceManagerExtension.kt | 27 ++++++++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsViewModel.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsViewModel.kt index 1b5403aa4..aa9be5488 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsViewModel.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/RunTestsViewModel.kt @@ -58,15 +58,11 @@ class RunTestsViewModel() : ViewModel() { } fun disableTest(name: String) { - if (!ExperimentalSuite().getTestList(preferenceManager).map { it.name }.contains(name)) { - preferenceManager.disableTest(name) - } + preferenceManager.disableTest(name) } fun enableTest(name: String) { - if (!ExperimentalSuite().getTestList(preferenceManager).map { it.name }.contains(name)) { - preferenceManager.enableTest(name) - } + preferenceManager.enableTest(name) } companion object { diff --git a/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/adapter/RunTestsExpandableListViewAdapter.kt b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/adapter/RunTestsExpandableListViewAdapter.kt index b4798ea9b..7415076d8 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/adapter/RunTestsExpandableListViewAdapter.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/activity/runtests/adapter/RunTestsExpandableListViewAdapter.kt @@ -74,9 +74,15 @@ class RunTestsExpandableListViewAdapter( } } else { groupSelectionIndicator.setImageResource(R.drawable.check_box_outline_blank) + if (groupItem.name == ExperimentalSuite.NAME) { + mViewModel.disableTest(ExperimentalSuite.NAME) + } } } else { groupSelectionIndicator.setImageResource(R.drawable.check_box_outline_blank) + if (groupItem.name == ExperimentalSuite.NAME) { + mViewModel.disableTest(ExperimentalSuite.NAME) + } } groupSelectionIndicator.setOnClickListener { if (groupItem.selected && isSelectAllChildItems(groupItem.nettests)) { diff --git a/app/src/main/java/org/openobservatory/ooniprobe/common/PreferenceManagerExtension.kt b/app/src/main/java/org/openobservatory/ooniprobe/common/PreferenceManagerExtension.kt index b9679a940..8564a1801 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/common/PreferenceManagerExtension.kt +++ b/app/src/main/java/org/openobservatory/ooniprobe/common/PreferenceManagerExtension.kt @@ -5,12 +5,31 @@ import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite import org.openobservatory.ooniprobe.test.test.* -fun PreferenceManager.enableTest(name: String) { - this.setValue(name, true) +private fun PreferenceManager.exclusionList(): MutableList { + val exclusionList = mutableListOf() + ExperimentalSuite().run { + exclusionList.addAll(getTestList(this@exclusionList).map { it.name }) + exclusionList.addAll(longRunningTests().map { it.name }) + } + + return exclusionList + } -fun PreferenceManager.disableTest(name: String) { - this.setValue(name, false) +fun PreferenceManager.enableTest(name: String): Boolean { + if (!exclusionList().contains(name)) { + this.setValue(name, true) + return true + } + return false +} + +fun PreferenceManager.disableTest(name: String): Boolean { + if (!exclusionList().contains(name)) { + this.setValue(name, false) + return true + } + return false } fun PreferenceManager.setValue(name: String, value: Boolean) {