Skip to content

Commit

Permalink
Updated app to display disabled dashboard items based on build config
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Dec 5, 2023
1 parent 38d85b5 commit a16dd05
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package org.openobservatory.ooniprobe.fragment.dashboard
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.openobservatory.ooniprobe.BuildConfig
import org.openobservatory.ooniprobe.common.PreferenceManager
import org.openobservatory.ooniprobe.test.TestAsyncTask
import org.openobservatory.ooniprobe.test.suite.AbstractSuite
import javax.inject.Inject

class DashboardViewModel @Inject constructor(private val preferenceManager: PreferenceManager) : ViewModel() {
private val enabledTitle: String = "Enabled"
private val enabledTitle: String = "Enabled"
private val groupedItemList = MutableLiveData<List<Any>>()
val items = MutableLiveData<List<AbstractSuite>>(TestAsyncTask.getSuites())

Expand All @@ -22,18 +23,20 @@ class DashboardViewModel @Inject constructor(private val preferenceManager: Pref

private fun fetchItemList() {

val groupedItems = items.value!!.sortedBy { it.getTestList(preferenceManager).isEmpty() }
val groupedItems = items.value!!.filter {testSuite ->
return@filter testSuite.getTestList(preferenceManager).isNotEmpty() || BuildConfig.SHOW_DISABLED_CARDS
}.sortedBy { it.getTestList(preferenceManager).isEmpty() }
.groupBy {
return@groupBy if ((it.getTestList(preferenceManager).isNotEmpty())) {
enabledTitle
enabledTitle
} else {
""
}
}

val groupedItemList = mutableListOf<Any>()
groupedItems.forEach { (status, itemList) ->
if (status != enabledTitle){
if (status != enabledTitle) {
groupedItemList.add(status)
}
groupedItemList.addAll(itemList)
Expand Down

0 comments on commit a16dd05

Please sign in to comment.