Skip to content

Commit

Permalink
Merge branch 'chore/upgdate-ooni-run-activity-to-viewbinding' of gith…
Browse files Browse the repository at this point in the history
…ub.com:ooni/probe-android into xoonirun
  • Loading branch information
aanorbel committed Aug 3, 2023
2 parents a94376f + 36b1bef commit 4d7c065
Showing 1 changed file with 33 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
import android.util.Patterns;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentTransaction;

Expand All @@ -22,37 +18,24 @@
import org.openobservatory.ooniprobe.BuildConfig;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.StringUtils;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.databinding.ActivityOonirunBinding;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
import org.openobservatory.ooniprobe.domain.TestDescriptorManager;
import org.openobservatory.ooniprobe.domain.TestDescriptorManager.FetchTestDescriptorResponse;
import org.openobservatory.ooniprobe.domain.VersionCompare;
import org.openobservatory.ooniprobe.domain.models.Attribute;
import org.openobservatory.ooniprobe.fragment.OoniRunListFragment;
import org.openobservatory.ooniprobe.item.TextItem;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;
import org.openobservatory.ooniprobe.test.suite.OONIRunSuite;
import org.openobservatory.ooniprobe.test.test.AbstractTest;

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

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;

public class OoniRunActivity extends AbstractActivity {
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.icon) ImageView icon;
@BindView(R.id.iconBig) ImageView iconBig;
@BindView(R.id.title) TextView title;
@BindView(R.id.desc) TextView desc;
@BindView(R.id.run) Button run;
ActivityOonirunBinding binding;
private ArrayList<OONIRunNettest> items;

@Inject
Expand All @@ -71,9 +54,9 @@ public class OoniRunActivity extends AbstractActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
setContentView(R.layout.activity_oonirun);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
binding = ActivityOonirunBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
items = new ArrayList<>();
Expand Down Expand Up @@ -135,11 +118,11 @@ else if (Intent.ACTION_SEND.equals(intent.getAction())) {

private void loadScreen(FetchTestDescriptorResponse response) {

icon.setImageResource(response.suite.getIconGradient());
icon.setColorFilter(getResources().getColor(R.color.color_gray7));
binding.icon.setImageResource(response.suite.getIconGradient());
binding.icon.setColorFilter(getResources().getColor(R.color.color_gray7));

title.setText(response.suite.getTitle());
desc.setText(response.suite.getCardDesc());
binding.title.setText(response.suite.getTitle());
binding.desc.setText(response.suite.getCardDesc());


items.addAll(
Expand All @@ -157,10 +140,10 @@ private void loadScreen(FetchTestDescriptorResponse response) {
mTransactiont.replace(R.id.items, OoniRunListFragment.newInstance(), OoniRunListFragment.class.getName());
mTransactiont.commit();

iconBig.setVisibility(View.GONE);
binding.iconBig.setVisibility(View.GONE);
// TODO: 18/07/2023 (aanorbel) Add translation
run.setText("Install");
run.setOnClickListener(
binding.run.setText("Install");
binding.run.setOnClickListener(
v -> {
response.descriptor.save();
ActivityCompat.startActivity(this, OverviewActivity.newIntent(this, response.suite), null);
Expand Down Expand Up @@ -194,53 +177,53 @@ private void loadScreen(String mv, String tn, String ta){
}

private void loadOutOfDate() {
title.setText(R.string.OONIRun_OONIProbeOutOfDate);
desc.setText(R.string.OONIRun_OONIProbeNewerVersion);
run.setText(R.string.OONIRun_Update);
icon.setImageResource(R.drawable.update);
iconBig.setImageResource(R.drawable.update);
iconBig.setVisibility(View.VISIBLE);
run.setOnClickListener(v -> {
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) {
icon.setImageResource(suite.getIcon());
title.setText(suite.getTestList(preferenceManager)[0].getLabelResId());
desc.setText(getString(R.string.OONIRun_YouAreAboutToRun));
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 OONIRunNettest(url,new ArrayList<>()));
}
}
iconBig.setVisibility(View.GONE);
binding.iconBig.setVisibility(View.GONE);
} else {
iconBig.setImageResource(suite.getIcon());
iconBig.setVisibility(View.VISIBLE);
binding.iconBig.setImageResource(suite.getIcon());
binding.iconBig.setVisibility(View.VISIBLE);
}
FragmentTransaction mTransactiont = getSupportFragmentManager().beginTransaction();

mTransactiont.replace(R.id.items, OoniRunListFragment.newInstance(), OoniRunListFragment.class.getName());
mTransactiont.commit();

run.setOnClickListener(v -> {
binding.run.setOnClickListener(v -> {

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

});
}

private void loadInvalidAttributes() {
title.setText(R.string.OONIRun_InvalidParameter);
desc.setText(R.string.OONIRun_InvalidParameter_Msg);
run.setText(R.string.OONIRun_Close);
icon.setImageResource(R.drawable.question_mark);
iconBig.setImageResource(R.drawable.question_mark);
iconBig.setVisibility(View.VISIBLE);
run.setOnClickListener(v -> finish());
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());
}

public ArrayList<OONIRunNettest> getItems() {
Expand Down

0 comments on commit 4d7c065

Please sign in to comment.