Skip to content

Commit

Permalink
Merge branch 'xoonirun' of github.com:ooni/probe-android into oonirun…
Browse files Browse the repository at this point in the history
…/add-autorun-and-auto-update-options
  • Loading branch information
aanorbel committed Aug 14, 2023
2 parents ca44991 + ea8c3da commit 0e3dc3c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.openobservatory.ooniprobe.BuildConfig;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.TaskExecutor;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.databinding.ActivityOonirunBinding;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
Expand Down Expand Up @@ -59,7 +60,6 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
items = new ArrayList<>();
manageIntent(getIntent());
}

Expand All @@ -70,21 +70,40 @@ protected void onNewIntent(Intent intent) {
}

private void manageIntent(Intent intent) {
items = new ArrayList<>();

Uri uri = intent.getData();
if (uri == null) return;

String host = uri.getHost();

if ("runv2".equals(host) || "run.test.ooni.org".equals(host)) {
try {

binding.progressIndicator.setVisibility(View.VISIBLE);
long runId = Long.parseLong(uri.getPathSegments().get(0));
FetchTestDescriptorResponse response = TestDescriptorManager.fetchDataFromRunId(runId, this);
loadV2Screen(response);
} catch (Exception exception) {
exception.printStackTrace();
ThirdPartyServices.logException(exception);
loadInvalidAttributes();
}

TaskExecutor executor = new TaskExecutor();
executor.executeTask(
() -> {
try {
return TestDescriptorManager.fetchDataFromRunId(runId, this);
} catch (Exception exception) {
exception.printStackTrace();
ThirdPartyServices.logException(exception);
return null;
}
},
descriptorResponse -> {
if (descriptorResponse!=null) {
binding.progressIndicator.setVisibility(View.GONE);
loadV2Screen(descriptorResponse);
} else {
binding.progressIndicator.setVisibility(View.GONE);
loadInvalidAttributes();
}
return null;
});

} else if (isTestRunning()) {
Toast.makeText(this, getString(R.string.OONIRun_TestRunningError), Toast.LENGTH_LONG).show();
finish();
Expand Down Expand Up @@ -151,6 +170,7 @@ private void loadV2Screen(FetchTestDescriptorResponse response) {
binding.iconBig.setVisibility(View.GONE);
// TODO: 18/07/2023 (aanorbel) Add translation
binding.run.setText("Install");
binding.run.setVisibility(View.VISIBLE);
binding.run.setOnClickListener(
v -> {
response.descriptor.setAutoUpdate(binding.autoUpdates.isChecked());
Expand Down Expand Up @@ -190,6 +210,7 @@ private void loadOutOfDate() {
binding.title.setText(R.string.OONIRun_OONIProbeOutOfDate);
binding.desc.setText(R.string.OONIRun_OONIProbeNewerVersion);
binding.run.setText(R.string.OONIRun_Update);
binding.run.setVisibility(View.VISIBLE);
binding.icon.setImageResource(R.drawable.update);
binding.iconBig.setImageResource(R.drawable.update);
binding.iconBig.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -219,6 +240,8 @@ private void loadSuite(AbstractSuite suite, List<String> urls) {
mTransactiont.replace(R.id.items, OoniRunListFragment.newInstance(), OoniRunListFragment.class.getName());
mTransactiont.commit();

binding.run.setText(R.string.OONIRun_Close);
binding.run.setVisibility(View.VISIBLE);
binding.run.setOnClickListener(v -> {

RunningActivity.runAsForegroundService(OoniRunActivity.this, suite.asArray(),this::finish, preferenceManager);
Expand All @@ -230,6 +253,7 @@ private void loadInvalidAttributes() {
binding.title.setText(R.string.OONIRun_InvalidParameter);
binding.desc.setText(R.string.OONIRun_InvalidParameter_Msg);
binding.run.setText(R.string.OONIRun_Close);
binding.run.setVisibility(View.VISIBLE);
binding.icon.setImageResource(R.drawable.question_mark);
binding.iconBig.setImageResource(R.drawable.question_mark);
binding.iconBig.setVisibility(View.VISIBLE);
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/res/layout/activity_oonirun.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
Expand Down Expand Up @@ -36,7 +37,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/OONIRun_InvalidParameter"
tools:text="@string/OONIRun_InvalidParameter"
android:visibility="gone"/>

<TextView
Expand All @@ -45,7 +46,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/OONIRun_InvalidParameter" />
tools:text="@string/OONIRun_InvalidParameter" />

<TextView
android:id="@+id/short_desc"
Expand All @@ -54,7 +55,7 @@
android:gravity="center_horizontal"
android:maxLines="2"
android:ellipsize="end"
android:text="@string/OONIRun_InvalidParameter"
tools:text="@string/OONIRun_InvalidParameter"
android:visibility="gone"/>

<TextView
Expand All @@ -64,7 +65,14 @@
android:gravity="center_horizontal"
android:maxLines="2"
android:ellipsize="end"
android:text="@string/OONIRun_YouAreAboutToRun" />
tools:text="@string/OONIRun_YouAreAboutToRun" />

<ProgressBar
android:id="@+id/progress_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
</LinearLayout>

<androidx.appcompat.widget.Toolbar
Expand Down Expand Up @@ -129,6 +137,8 @@
android:layout_margin="16dp"
android:text="@string/OONIRun_Run"
android:textAllCaps="false"
android:visibility="gone"
tools:visibility="visible"
android:backgroundTint="@color/color_base"
app:cornerRadius="24dp" />
</androidx.appcompat.widget.LinearLayoutCompat>
Expand Down

0 comments on commit 0e3dc3c

Please sign in to comment.