Skip to content

Commit

Permalink
Match result colors with descriptor theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Feb 19, 2024
1 parent 0060c85 commit b009d7d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import androidx.fragment.app.Fragment;
import com.google.android.material.snackbar.Snackbar;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;

import org.openobservatory.engine.BaseNettest;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
Expand Down Expand Up @@ -71,15 +74,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
assert measurement != null;
measurement.result.load();
if (measurement.is_failed) {
setTheme((int) R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failed);
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failed);
} else {
if (measurement.result.test_group_name.equals(OONITests.PERFORMANCE.getLabel())) {
Optional<AbstractSuite> optionalSuite = measurement.result.getTestSuite(this);
if (optionalSuite.isPresent()){
setTheme(optionalSuite.get().getThemeLight());
} else {
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Experimental);
}
if (Lists.transform(OONITests.PERFORMANCE.getNettests(), BaseNettest::getName).contains(measurement.test_name)) {
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Performance);
} else {
if (measurement.is_anomaly) {
setTheme(R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
Expand All @@ -19,6 +20,7 @@ import localhost.toolkit.app.fragment.ConfirmDialogFragment.OnConfirmedListener
import org.openobservatory.ooniprobe.R
import org.openobservatory.ooniprobe.adapters.MeasurementGroup
import org.openobservatory.ooniprobe.adapters.ResultDetailExpandableListAdapter
import org.openobservatory.ooniprobe.common.OONIDescriptor
import org.openobservatory.ooniprobe.common.OONITests
import org.openobservatory.ooniprobe.common.PreferenceManager
import org.openobservatory.ooniprobe.common.ResubmitTask
Expand Down Expand Up @@ -160,6 +162,8 @@ class ResultDetailActivity : AbstractActivity(), View.OnClickListener, OnConfirm
private fun load() {
result = getResults[result.id]

setThemeFromDescriptor()

val groupedItemList = mutableListOf<Any>()
val groupedItems = result.getMeasurementsSorted().groupBy { it.test_name }
for ((_, itemList) in groupedItems) {
Expand Down Expand Up @@ -193,19 +197,51 @@ class ResultDetailActivity : AbstractActivity(), View.OnClickListener, OnConfirm
) snackbar.show() else snackbar.dismiss()
}

/**
* Set the theme of the activity from the descriptor of the test suite.
* The color of the toolbar, the app bar, the tab layout and the status bar will be set to the color of the descriptor.
*/
private fun setThemeFromDescriptor() {
result.getDescriptor(this).get().let { desriptor ->
if (desriptor is OONIDescriptor<*>) {
val color = ContextCompat.getColor(this@ResultDetailActivity, desriptor.color)
binding.toolbar.setBackgroundColor(color)
binding.appBar.setBackgroundColor(color)
binding.tabLayout.setBackgroundColor(color)
window.statusBarColor = color
}
}
}

/**
* Open the [TextActivity] or the [MeasurementDetailActivity] based on the test name of the measurement test name.
* If the test name is in the list of [OONITests.EXPERIMENTAL.nettests] or [OONITests.EXPERIMENTAL.longRunningTests],
* the [TextActivity] will be opened otherwise, the [MeasurementDetailActivity] will be opened.
*
* @param v The view that was clicked.
*/
override fun onClick(v: View) {
val measurement = v.tag as Measurement
if (Objects.equals(result.test_group_name, OONITests.EXPERIMENTAL.label)) startActivity(
TextActivity.newIntent(

val textActivityItems = (OONITests.EXPERIMENTAL.nettests).map { it.name }.toMutableList()
(OONITests.EXPERIMENTAL.longRunningTests)?.map { it.name }
?.let { textActivityItems.addAll(it) }

if (textActivityItems.contains(measurement.test_name)) {
startActivity(
TextActivity.newIntent(
this,
TextActivity.TYPE_JSON,
measurement
)
)
} else {
ActivityCompat.startActivity(
this,
TextActivity.TYPE_JSON,
measurement
MeasurementDetailActivity.newIntent(this, measurement.id),
null
)
) else ActivityCompat.startActivity(
this,
MeasurementDetailActivity.newIntent(this, measurement.id),
null
)
}
}

override fun onConfirmation(extra: Serializable, buttonClicked: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Objects;

import javax.inject.Inject;

Expand Down Expand Up @@ -169,10 +170,11 @@ private void applyUIChanges(RunTestService service) {
binding.eta.setText(R.string.Dashboard_Running_CalculatingETA);
}

if (service.task.currentSuite.getName().equals(OONITests.EXPERIMENTAL.name()))
if (Objects.equals(service.task.currentTest.getLabelResId(),R.string.Test_Experimental_Fullname)) {
binding.name.setText(service.task.currentTest.getName());
else
} else {
binding.name.setText(getString(service.task.currentTest.getLabelResId()));
}
getWindow().setBackgroundDrawableResource(service.task.currentSuite.getColor());
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setStatusBarColor(service.task.currentSuite.getColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class RunTestsExpandableListViewAdapter(
val groupItem = getGroup(groupPosition)
val nettest = AbstractTest.getTestByName(childItem.name)
convertView.findViewById<TextView>(R.id.child_name)?.apply {
text = when (groupItem.name) {
OONITests.EXPERIMENTAL.label -> {
text = when (nettest.labelResId) {
R.string.Test_Experimental_Fullname -> {
childItem.name
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_result_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
Expand Down

0 comments on commit b009d7d

Please sign in to comment.