Skip to content

Commit

Permalink
Merge branch 'dev/ooni-run-v2' of github.com:ooni/probe-android into …
Browse files Browse the repository at this point in the history
…issues/2594
  • Loading branch information
aanorbel committed Feb 19, 2024
2 parents 4e59a6c + f81263c commit 8962eb3
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 33 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 @@ -33,6 +33,7 @@

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

import javax.inject.Inject;

Expand Down Expand Up @@ -170,10 +171,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().setBackgroundDrawable(new ColorDrawable(service.task.currentSuite.getColor()));
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
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package org.openobservatory.ooniprobe.di;


import org.openobservatory.ooniprobe.activity.adddescriptor.AddDescriptorActivity;
import org.openobservatory.ooniprobe.activity.customwebsites.CustomWebsiteActivity;
import org.openobservatory.ooniprobe.activity.LogActivity;
import org.openobservatory.ooniprobe.activity.MainActivity;
import org.openobservatory.ooniprobe.activity.MeasurementDetailActivity;
import org.openobservatory.ooniprobe.activity.OoniRunActivity;
import org.openobservatory.ooniprobe.activity.OverviewActivity;
import org.openobservatory.ooniprobe.activity.ProxyActivity;
import org.openobservatory.ooniprobe.activity.ResultDetailActivity;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity;
import org.openobservatory.ooniprobe.activity.oonirun.OoniRunV2Activity;
import org.openobservatory.ooniprobe.activity.runtests.RunTestsActivity;
import org.openobservatory.ooniprobe.activity.RunningActivity;
import org.openobservatory.ooniprobe.activity.TextActivity;
import org.openobservatory.ooniprobe.activity.adddescriptor.AddDescriptorActivity;
import org.openobservatory.ooniprobe.activity.customwebsites.CustomWebsiteActivity;
import org.openobservatory.ooniprobe.activity.oonirun.OoniRunV2Activity;
import org.openobservatory.ooniprobe.activity.reviewdescriptorupdates.ReviewDescriptorUpdatesActivity;
import org.openobservatory.ooniprobe.activity.runtests.RunTestsActivity;
import org.openobservatory.ooniprobe.di.annotations.PerActivity;

import dagger.Subcomponent;

@PerActivity
@Subcomponent()
public interface ActivityComponent {
void inject(ReviewDescriptorUpdatesActivity activity);
void inject(OoniRunV2Activity activity);
void inject(AddDescriptorActivity activity);
void inject(ReviewDescriptorUpdatesActivity activity);
void inject(CustomWebsiteActivity activity);
void inject(MainActivity activity);
void inject(ProxyActivity activity);
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
android:layout_height="?attr/actionBarSize"
android:visibility="gone" />

<FrameLayout
android:id="@+id/dynamic_progress_fragment"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:visibility="gone" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
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 8962eb3

Please sign in to comment.