Skip to content

Commit

Permalink
Merge branch 'dev/design-update' of github.com:ooni/probe-android int…
Browse files Browse the repository at this point in the history
…o issues/2589
  • Loading branch information
aanorbel committed Dec 5, 2023
2 parents 294e968 + 706eef1 commit 778b593
Show file tree
Hide file tree
Showing 51 changed files with 1,778 additions and 969 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: dev-apk
path: app/build/outputs/apk/devFull/release
path: app/build/outputs/apk/devFull/release
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId 'org.openobservatory.ooniprobe'
minSdk libs.versions.minSdk.get().toInteger()
targetSdk libs.versions.targetSdk.get().toInteger()
versionName '3.8.4'
versionCode 106
versionName '3.8.5'
versionCode 107
testInstrumentationRunner "org.openobservatory.ooniprobe.TestAndroidJUnitRunner"
buildConfigField 'String', 'OONI_API_BASE_URL', '"https://api.ooni.io/"'
buildConfigField 'String', 'NOTIFICATION_SERVER', '"https://countly.ooni.io"'
Expand Down Expand Up @@ -149,7 +149,7 @@ dependencies {
// Unit Testing
testImplementation project(':shared-test')
testImplementation libs.junit4
testImplementation libs.androidx.core
testImplementation libs.androidx.test.core
testImplementation libs.androidx.runner
testImplementation libs.androidx.rules
testImplementation libs.mockito.core
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
</intent-filter>
</activity>
<activity
android:name=".activity.CustomWebsiteActivity"
android:name=".activity.customwebsites.CustomWebsiteActivity"
android:label="@string/Settings_Websites_CustomURL_Title"
android:exported="false"
android:parentActivityName=".activity.PreferenceActivity"
android:screenOrientation="userPortrait">
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar.App.NoActionBar">
<intent-filter>
<action android:name="${applicationId}.activity.CustomWebsiteActivity" />

Expand All @@ -114,7 +114,7 @@
</activity>
<activity
android:name=".activity.OoniRunActivity"
android:label="@string/APP_NAME"
android:label=""
android:exported="true"
android:launchMode="singleTop"
android:parentActivityName=".activity.MainActivity"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

public class MainActivity extends AbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
private static final String RES_ITEM = "resItem";
private static final String RES_SNACKBAR_MESSAGE = "resSnackbarMessage";
public static final String NOTIFICATION_DIALOG = "notification";
public static final String AUTOTEST_DIALOG = "automatic_testing";
public static final String BATTERY_DIALOG = "battery_optimization";
Expand All @@ -59,7 +60,14 @@ public static Intent newIntent(Context context, int resItem) {
return new Intent(context, MainActivity.class).putExtra(RES_ITEM, resItem).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

@Override
public static Intent newIntent(Context context, int resItem, String message) {
return new Intent(context, MainActivity.class)
.putExtra(RES_ITEM, resItem)
.putExtra(RES_SNACKBAR_MESSAGE, message)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
Expand All @@ -85,7 +93,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
return false;
}
});
/* TODO(aanorbel): Fix change in state(theme change from notification) changes the selected item.
The proper fix would be to track the selected item as well as other properties in a `ViewModel`. */
binding.bottomNavigation.setSelectedItemId(getIntent().getIntExtra(RES_ITEM, R.id.dashboard));
/* Check if we are restoring the activity from a saved state first.
* If we have a message to show, show it as a snackbar.
* This is used to show the message from test completion.
*/
if (savedInstanceState == null && getIntent().hasExtra(RES_SNACKBAR_MESSAGE)) {
Snackbar.make(binding.getRoot(), getIntent().getStringExtra(RES_SNACKBAR_MESSAGE), Snackbar.LENGTH_SHORT)
.setAnchorView(binding.bottomNavigation)
.show();
}
if (notificationManager.shouldShowAutoTest()) {
new ConfirmDialogFragment.Builder()
.withTitle(getString(R.string.Modal_Autorun_Modal_Title))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,173 +0,0 @@
package org.openobservatory.ooniprobe.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.Toast;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.gson.Gson;

import org.openobservatory.ooniprobe.BuildConfig;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.databinding.ActivityOonirunBinding;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
import org.openobservatory.ooniprobe.domain.VersionCompare;
import org.openobservatory.ooniprobe.domain.models.Attribute;
import org.openobservatory.ooniprobe.item.TextItem;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;

public class OoniRunActivity extends AbstractActivity {
ActivityOonirunBinding binding;
private ArrayList<HeterogeneousRecyclerItem> items;
private HeterogeneousRecyclerAdapter<HeterogeneousRecyclerItem> adapter;

@Inject
PreferenceManager preferenceManager;

@Inject
VersionCompare versionCompare;

@Inject
GetTestSuite getSuite;

@Inject
Gson gson;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
binding = ActivityOonirunBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
binding.recycler.setLayoutManager(layoutManager);
binding.recycler.addItemDecoration(new DividerItemDecoration(this, layoutManager.getOrientation()));
items = new ArrayList<>();
adapter = new HeterogeneousRecyclerAdapter<>(this, items);
binding.recycler.setAdapter(adapter);
manageIntent(getIntent());
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
manageIntent(intent);
}

private void manageIntent(Intent intent) {
if (isTestRunning()) {
Toast.makeText(this, getString(R.string.OONIRun_TestRunningError), Toast.LENGTH_LONG).show();
finish();
}
else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String mv = uri == null ? null : uri.getQueryParameter("mv");
String tn = uri == null ? null : uri.getQueryParameter("tn");
String ta = uri == null ? null : uri.getQueryParameter("ta");
loadScreen(mv, tn, ta);
}
else if (Intent.ACTION_SEND.equals(intent.getAction())) {
String url = intent.getStringExtra(Intent.EXTRA_TEXT);
if (url != null && Patterns.WEB_URL.matcher(url).matches()) {
List<String> urls = Collections.singletonList(url);
AbstractSuite suite = getSuite.get("web_connectivity", urls);
if (suite != null) {
loadSuite(suite, urls);
} else {
loadInvalidAttributes();
}
} else {
loadInvalidAttributes();
}
}
}

private void loadScreen(String mv, String tn, String ta){
String[] split = BuildConfig.VERSION_NAME.split("-");
String version_name = split[0];
if (mv != null && tn != null) {
if (versionCompare.compare(version_name, mv) >= 0) {
try {
Attribute attribute = gson.fromJson(ta, Attribute.class);
List<String> urls = (attribute!=null && attribute.urls != null) ? attribute.urls : null;
AbstractSuite suite = getSuite.get(tn, urls);
if (suite != null) {
loadSuite(suite, urls);
} else {
loadInvalidAttributes();
}
} catch (Exception e) {
loadInvalidAttributes();
}
} else {
loadOutOfDate();
}
} else {
loadInvalidAttributes();
}
}

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.icon.setImageResource(R.drawable.update);
binding.iconBig.setImageResource(R.drawable.update);
binding.iconBig.setVisibility(View.VISIBLE);
binding.run.setOnClickListener(v -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
finish();
});
}

private void loadSuite(AbstractSuite suite, List<String> urls) {
binding.icon.setImageResource(suite.getIcon());
binding.title.setText(suite.getTestList(preferenceManager)[0].getLabelResId());
binding.desc.setText(getString(R.string.OONIRun_YouAreAboutToRun));
if (urls != null) {
for (String url : urls) {
if (URLUtil.isValidUrl(url))
items.add(new TextItem(url));
}
adapter.notifyTypesChanged();
binding.iconBig.setVisibility(View.GONE);
} else {
binding.iconBig.setImageResource(suite.getIcon());
binding.iconBig.setVisibility(View.VISIBLE);
}
binding.run.setOnClickListener(v -> {

RunningActivity.runAsForegroundService(OoniRunActivity.this, suite.asArray(),this::finish, preferenceManager);

});
}

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.icon.setImageResource(R.drawable.question_mark);
binding.iconBig.setImageResource(R.drawable.question_mark);
binding.iconBig.setVisibility(View.VISIBLE);
binding.run.setOnClickListener(v -> finish());
}
}
Loading

0 comments on commit 778b593

Please sign in to comment.