Skip to content

Commit

Permalink
Migrate dashboard and overview to descriptor format
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Nov 26, 2023
1 parent c51ebb0 commit d2dd31b
Show file tree
Hide file tree
Showing 53 changed files with 946 additions and 1,051 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
android:name=".activity.OverviewActivity"
android:launchMode="singleTop"
android:parentActivityName=".activity.MainActivity"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar"
android:screenOrientation="userPortrait" />
<activity
android:name=".activity.ResultDetailActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;

import androidx.annotation.Nullable;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.TestDescriptorManager;
import org.openobservatory.ooniprobe.databinding.ActivityCustomwebsiteBinding;
import org.openobservatory.ooniprobe.model.database.Url;
import org.openobservatory.ooniprobe.test.suite.WebsitesSuite;
import org.openobservatory.ooniprobe.test.suite.DynamicTestSuite;

import javax.inject.Inject;
import java.io.Serializable;
import java.util.ArrayList;

import javax.inject.Inject;

import localhost.toolkit.app.fragment.ConfirmDialogFragment;

public class CustomWebsiteActivity extends AbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
private ArrayList<EditText> editTexts;
private ArrayList<ImageButton> deletes;

@Inject
PreferenceManager preferenceManager;

@Inject
TestDescriptorManager descriptorManager;
private ActivityCustomwebsiteBinding binding;

@Override
Expand All @@ -47,11 +56,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
if (Patterns.WEB_URL.matcher(sanitizedUrl).matches() && sanitizedUrl.length() < 2084)
urls.add(Url.checkExistingUrl(sanitizedUrl).toString());
}
WebsitesSuite suite = new WebsitesSuite();
suite.getTestList(preferenceManager)[0].setInputs(urls);
DynamicTestSuite suite = descriptorManager.getTestByDescriptorName(OONITests.WEBSITES.getLabel());
if (suite != null) {
suite.getTestList(preferenceManager)[0].setInputs(urls);

RunningActivity.runAsForegroundService(CustomWebsiteActivity.this, suite.asArray(), this::finish, preferenceManager);
return true;
RunningActivity.runAsForegroundService(CustomWebsiteActivity.this, suite.asArray(), this::finish, preferenceManager);
return true;
}
return false;
});
binding.add.setOnClickListener(v -> add());
add();
Expand All @@ -74,7 +86,7 @@ public void onBackPressed() {
super.onBackPressed();
}

public boolean checkPrefix(){
public boolean checkPrefix() {
boolean prefix = true;
for (EditText editText : editTexts)
if (!editText.getText().toString().contains("http://")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.gson.Gson;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ResubmitTask;
import org.openobservatory.ooniprobe.databinding.ActivityMeasurementDetailBinding;
Expand All @@ -25,7 +26,6 @@
import org.openobservatory.ooniprobe.fragment.resultHeader.ResultHeaderDetailFragment;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.database.Network;
import org.openobservatory.ooniprobe.test.suite.PerformanceSuite;
import org.openobservatory.ooniprobe.test.test.*;
import io.noties.markwon.Markwon;

Expand Down Expand Up @@ -70,8 +70,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
measurement.result.load();
setTheme(measurement.is_failed ?
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failed :
measurement.result.test_group_name.equals(PerformanceSuite.NAME) ?
measurement.result.getTestSuite().getThemeLight() :
measurement.result.test_group_name.equals(OONITests.PERFORMANCE.getLabel()) ?
measurement.result.getTestSuite(this).getThemeLight() :
measurement.is_anomaly ?
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failure :
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.View;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.text.TextUtilsCompat;
import androidx.core.view.ViewCompat;

import org.openobservatory.engine.BaseNettest;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.OONIDescriptor;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ReadMorePlugin;
import org.openobservatory.ooniprobe.databinding.ActivityOverviewBinding;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;
import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite;
import org.openobservatory.ooniprobe.test.suite.WebsitesSuite;
import org.openobservatory.ooniprobe.test.test.AbstractTest;

import java.util.Locale;

Expand All @@ -27,77 +28,75 @@
import io.noties.markwon.Markwon;

public class OverviewActivity extends AbstractActivity {
private static final String TEST = "test";

ActivityOverviewBinding binding;
private AbstractSuite testSuite;

@Inject
PreferenceManager preferenceManager;

public static Intent newIntent(Context context, AbstractSuite testSuite) {
return new Intent(context, OverviewActivity.class).putExtra(TEST, testSuite);
}

@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
testSuite = (AbstractSuite) getIntent().getSerializableExtra(TEST);
setTheme(testSuite.getThemeLight());
binding = ActivityOverviewBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(testSuite.getTitle());
binding.icon.setImageResource(testSuite.getIcon());
binding.customUrl.setVisibility(testSuite.getName().equals(WebsitesSuite.NAME) ? View.VISIBLE : View.GONE);
Markwon markwon = Markwon.builder(this)
.usePlugin(new ReadMorePlugin(
getString(R.string.OONIRun_ReadMore),
getString(R.string.OONIRun_ReadLess))
).build();
if (testSuite.getName().equals(ExperimentalSuite.NAME)) {
String experimentalLinks =
"\n\n* [STUN Reachability](https://github.com/ooni/spec/blob/master/nettests/ts-025-stun-reachability.md)" +
"\n\n* [DNS Check](https://github.com/ooni/spec/blob/master/nettests/ts-028-dnscheck.md)" +
"\n\n* [ECH Check](https://github.com/ooni/spec/blob/master/nettests/ts-039-echcheck.md)" +
"\n\n* [Tor Snowflake](https://ooni.org/nettest/tor-snowflake/) "+ String.format(" ( %s )",getString(R.string.Settings_TestOptions_LongRunningTest))+
"\n\n* [Vanilla Tor](https://github.com/ooni/spec/blob/master/nettests/ts-016-vanilla-tor.md) " + String.format(" ( %s )",getString(R.string.Settings_TestOptions_LongRunningTest));
markwon.setMarkdown(binding.desc, getString(testSuite.getDesc1(), experimentalLinks));
if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL) {
private static final String TEST = "test";

ActivityOverviewBinding binding;

@Inject
PreferenceManager preferenceManager;
private OONIDescriptor<BaseNettest> descriptor;

public static Intent newIntent(Context context, OONIDescriptor<BaseNettest> descriptor) {
return new Intent(context, OverviewActivity.class).putExtra(TEST, descriptor);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
descriptor = (OONIDescriptor) getIntent().getSerializableExtra(TEST);
binding = ActivityOverviewBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle(descriptor.getTitle());
setThemeColor(ContextCompat.getColor(this, descriptor.getColor()));
binding.icon.setImageResource(descriptor.getDisplayIcon(this));
binding.customUrl.setVisibility(descriptor.getName().equals(OONITests.WEBSITES.name()) ? View.VISIBLE : View.GONE);
Markwon markwon = Markwon.builder(this).usePlugin(new ReadMorePlugin(getString(R.string.OONIRun_ReadMore), getString(R.string.OONIRun_ReadLess))).build();
if (descriptor.getName().equals(OONITests.EXPERIMENTAL.name())) {
markwon.setMarkdown(binding.desc, descriptor.getDescription());
if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL) {
binding.desc.setTextDirection(View.TEXT_DIRECTION_RTL);
}
}
else {
markwon.setMarkdown(binding.desc, getString(testSuite.getDesc1()));
} else {
markwon.setMarkdown(binding.desc, descriptor.getDescription());
}
Result lastResult = Result.getLastResult(testSuite.getName());
if (lastResult == null)
binding.lastTime.setText(R.string.Dashboard_Overview_LastRun_Never);
else
binding.lastTime.setText(DateUtils.getRelativeTimeSpanString(lastResult.start_time.getTime()));

setUpOnCLickListeners();
}

private void setUpOnCLickListeners() {
binding.customUrl.setOnClickListener(view -> customUrlClick());
}

@Override protected void onResume() {
super.onResume();
testSuite.setTestList((AbstractTest[]) null);
testSuite.getTestList(preferenceManager);
binding.runtime.setText(getString(R.string.twoParam, getString(testSuite.getDataUsage()), getString(R.string.Dashboard_Card_Seconds, testSuite.getRuntime(preferenceManager).toString())));
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

void customUrlClick() {
startActivity(new Intent(this, CustomWebsiteActivity.class));
}
Result lastResult = Result.getLastResult(descriptor.getName());
if (lastResult == null) {
binding.lastTime.setText(R.string.Dashboard_Overview_LastRun_Never);
} else {
binding.lastTime.setText(DateUtils.getRelativeTimeSpanString(lastResult.start_time.getTime()));
}

setUpOnCLickListeners();
}

public void setThemeColor(int color) {
Window window = getWindow();
window.setStatusBarColor(color);
binding.toolbar.setBackgroundColor(color);
binding.appbarLayout.setBackgroundColor(color);
binding.collapsingToolbar.setBackgroundColor(color);
}

private void setUpOnCLickListeners() {
binding.customUrl.setOnClickListener(view -> customUrlClick());
}

@Override
protected void onResume() {
super.onResume();
binding.runtime.setText(getString(R.string.twoParam, getString(descriptor.getDataUsage()), getString(R.string.Dashboard_Card_Seconds, String.valueOf(descriptor.getRuntime(this, preferenceManager)))));
}

@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

void customUrlClick() {
startActivity(new Intent(this, CustomWebsiteActivity.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ResubmitTask;
import org.openobservatory.ooniprobe.databinding.ActivityResultDetailBinding;
Expand Down Expand Up @@ -71,14 +72,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
getActivityComponent().inject(this);
result = getResults.get(getIntent().getIntExtra(ID, 0));
assert result != null;
setTheme(result.getTestSuite().getThemeLight());
setTheme(result.getTestSuite(this).getThemeLight());
ActivityResultDetailBinding binding = ActivityResultDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
bar.setTitle(result.getTestSuite().getTitle());
bar.setTitle(result.getTestSuite(this).getTitle());
}
binding.pager.setAdapter(new ResultHeaderAdapter(this));
new TabLayoutMediator(binding.tabLayout, binding.pager, (tab, position) ->
Expand Down Expand Up @@ -111,7 +112,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
invalidateOptionsMenu();
if (!result.test_group_name.equals(WebsitesSuite.NAME))
if (!result.test_group_name.equals(OONITests.WEBSITES.getLabel()))
menu.findItem(R.id.reRun).setVisible(false);
return super.onPrepareOptionsMenu(menu);
}
Expand Down Expand Up @@ -142,7 +143,7 @@ private void runAsyncTask() {
private void load() {
result = getResults.get(result.id);
assert result != null;
boolean isPerf = result.test_group_name.equals(PerformanceSuite.NAME);
boolean isPerf = result.test_group_name.equals(OONITests.PERFORMANCE.getLabel());
items.clear();
List<Measurement> measurements = result.getMeasurementsSorted();
for (Measurement measurement : measurements)
Expand All @@ -159,7 +160,7 @@ private void load() {
@Override
public void onClick(View v) {
Measurement measurement = (Measurement) v.getTag();
if (result.test_group_name.equals(ExperimentalSuite.NAME))
if (result.test_group_name.equals(OONITests.EXPERIMENTAL.getLabel()))
startActivity(TextActivity.newIntent(this, TextActivity.TYPE_JSON, measurement));
else
ActivityCompat.startActivity(this, MeasurementDetailActivity.newIntent(this, measurement.id), null);
Expand Down Expand Up @@ -206,7 +207,7 @@ private class ResultHeaderAdapter extends FragmentStateAdapter {

@Override
public Fragment createFragment(int position) {
if (result.test_group_name.equals(ExperimentalSuite.NAME)){
if (result.test_group_name.equals(OONITests.EXPERIMENTAL.getLabel())){
if (position == 0)
return ResultHeaderDetailFragment.newInstance(false, result.getFormattedDataUsageUp(), result.getFormattedDataUsageDown(), result.start_time, result.getRuntime(), true, null, null);
else if (position == 1)
Expand All @@ -216,26 +217,22 @@ else if (position == 1)
return ResultHeaderDetailFragment.newInstance(false, result.getFormattedDataUsageUp(), result.getFormattedDataUsageDown(), result.start_time, result.getRuntime(), true, null, null);
else if (position == 2)
return ResultHeaderDetailFragment.newInstance(false, null, null, null, null, null, Network.getCountry(ResultDetailActivity.this, result.network), result.network);
else switch (result.test_group_name) {
default: //Default can no longer be null, so we have to default to something...
// NOTE: Perhaps set up a test page?
case WebsitesSuite.NAME:
return ResultHeaderTBAFragment.newInstance(result);
case InstantMessagingSuite.NAME:
return ResultHeaderTBAFragment.newInstance(result);
case MiddleBoxesSuite.NAME:
return ResultHeaderMiddleboxFragment.newInstance(result.countAnomalousMeasurements() > 0);
case PerformanceSuite.NAME:
return ResultHeaderPerformanceFragment.newInstance(result);
case CircumventionSuite.NAME:
return ResultHeaderTBAFragment.newInstance(result);
else {
if (result.test_group_name.equals(OONITests.INSTANT_MESSAGING.getLabel())) {
return ResultHeaderTBAFragment.newInstance(result);
} else if (result.test_group_name.equals(OONITests.PERFORMANCE.getLabel())) {
return ResultHeaderPerformanceFragment.newInstance(result);
} else if (result.test_group_name.equals(OONITests.CIRCUMVENTION.getLabel())) {
return ResultHeaderTBAFragment.newInstance(result);
}
return ResultHeaderTBAFragment.newInstance(result);
}
}


@Override
public int getItemCount() {
if (result.test_group_name.equals(ExperimentalSuite.NAME))
if (result.test_group_name.equals(OONITests.EXPERIMENTAL.getLabel()))
return 2;
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.OONITests;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ReachabilityManager;
import org.openobservatory.ooniprobe.common.TestProgressRepository;
Expand All @@ -28,7 +29,6 @@
import org.openobservatory.ooniprobe.databinding.ActivityRunningBinding;
import org.openobservatory.ooniprobe.receiver.TestRunBroadRequestReceiver;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;
import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite;

import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -169,7 +169,7 @@ private void applyUIChanges(RunTestService service) {
binding.eta.setText(R.string.Dashboard_Running_CalculatingETA);
}

if (service.task.currentSuite.getName().equals(ExperimentalSuite.NAME))
if (service.task.currentSuite.getName().equals(OONITests.EXPERIMENTAL.name()))
binding.name.setText(service.task.currentTest.getName());
else
binding.name.setText(getString(service.task.currentTest.getLabelResId()));
Expand Down
Loading

0 comments on commit d2dd31b

Please sign in to comment.