Skip to content

Commit

Permalink
feat: update OverviewActivity UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed May 24, 2024
1 parent 6f13727 commit 553a1da
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import org.openobservatory.ooniprobe.common.disableTest
import org.openobservatory.ooniprobe.common.enableTest
import org.openobservatory.ooniprobe.model.database.InstalledDescriptor
import org.openobservatory.ooniprobe.model.database.Result
import org.openobservatory.ooniprobe.model.database.getNettests
import java.text.SimpleDateFormat
import java.util.Locale
import javax.inject.Inject

class TestGroupItem(
var selected: Boolean, override var name: String, override var inputs: List<String>?,
var selected: Boolean, override var name: String, override var inputs: List<String>?,
) : BaseNettest(name = name, inputs = inputs)


Expand Down Expand Up @@ -82,19 +83,19 @@ class OverviewViewModel @Inject constructor(var application: Application, var pr
fun disableTest(name: String) {
descriptor.value?.let {
preferenceManager.disableTest(
name = name,
prefix = it.preferencePrefix(),
autoRun = true
name = name,
prefix = it.preferencePrefix(),
autoRun = true
)
}
}

fun enableTest(name: String) {
descriptor.value?.let {
preferenceManager.enableTest(
name = name,
prefix = it.preferencePrefix(),
autoRun = true
name = name,
prefix = it.preferencePrefix(),
autoRun = true
)
}
}
Expand All @@ -119,6 +120,7 @@ class OverviewViewModel @Inject constructor(var application: Application, var pr
fun getIcon(): Int {
return descriptor.value?.getDisplayIcon(application) ?: 0
}

fun getRunTime(): String? {
return descriptor.value?.getRuntime(application, preferenceManager)?.toString()
}
Expand All @@ -129,13 +131,13 @@ class OverviewViewModel @Inject constructor(var application: Application, var pr
DateUtils.getRelativeTimeSpanString(
time
).toString()
}?: application.getString(R.string.Dashboard_Overview_LastRun_Never)
} ?: application.getString(R.string.Dashboard_Overview_LastRun_Never)
}
}

fun getDescription(): String? {
return descriptor.value?.let {
if (it is InstalledDescriptor){
if (it is InstalledDescriptor) {
return String.format(
"Created by %s on %s\n\n%s",
it.descriptor?.author,
Expand All @@ -148,6 +150,18 @@ class OverviewViewModel @Inject constructor(var application: Application, var pr
}
}

fun getAutomaticRunSwitchVisibility(): Int {
return descriptor.value?.let {
it.descriptor?.getNettests()?.let { nettests ->
if (nettests.count() > 1) {
View.VISIBLE // if there are multiple tests, the switch should be visible.
} else {
View.GONE // if there is only one test, the switch should be gone.
}
} ?: View.VISIBLE // if descriptor is not installed, it should be visible.
} ?: View.GONE // if descriptor is null, it should be gone
}

companion object {
const val SELECT_ALL = "SELECT_ALL"
const val SELECT_SOME = "SELECT_SOME"
Expand Down
26 changes: 14 additions & 12 deletions app/src/main/res/layout/activity_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,20 @@
app:richText="@{viewmodel.description}"
app:testName="@{viewmodel.descriptor.name}"/>

<TextView
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Settings"
android:layout_below="@+id/desc"
style="?attr/textAppearanceHeadline6"
android:paddingBottom="@dimen/item_padding_large"/>

<LinearLayout
android:id="@+id/automatic_updates_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/desc"
android:layout_below="@+id/settings"
android:paddingBottom="16dp">

<TextView
Expand All @@ -202,24 +211,16 @@
android:layout_height="wrap_content" />
</LinearLayout>

<TextView
android:id="@+id/run_automatically"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/automatic_updates_container"
android:layout_alignBottom="@id/automatic_updates_container"
android:text="Run automatically" />

<LinearLayout
android:id="@+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/run_automatically">
android:layout_below="@+id/automatic_updates_container">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tests" />
android:text="Run Tests automatically" />

<View
android:layout_width="0dp"
Expand All @@ -231,7 +232,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/check_box_custom_button"
app:checkedState="indeterminate" />
app:checkedState="indeterminate"
android:visibility="@{viewmodel.automaticRunSwitchVisibility ,default = visible}"/>
</LinearLayout>
</RelativeLayout>

Expand Down

0 comments on commit 553a1da

Please sign in to comment.