Skip to content

Commit

Permalink
Merge pull request #606 from ooni/issues/1709/measurement-detail-acti…
Browse files Browse the repository at this point in the history
…vity

Chore: Update `MeasurementDetailActivity` and component fragment to use `ViewBinding`
  • Loading branch information
aanorbel authored Sep 11, 2023
2 parents fe7c897 + 1f2cbab commit ed9b2bb
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,87 +8,41 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;

import com.google.android.material.snackbar.Snackbar;
import com.google.gson.Gson;

import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ResubmitTask;
import org.openobservatory.ooniprobe.databinding.ActivityMeasurementDetailBinding;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
import org.openobservatory.ooniprobe.domain.MeasurementsManager;
import org.openobservatory.ooniprobe.domain.callback.DomainCallback;
import org.openobservatory.ooniprobe.fragment.measurement.DashFragment;
import org.openobservatory.ooniprobe.fragment.measurement.FacebookMessengerFragment;
import org.openobservatory.ooniprobe.fragment.measurement.FailedFragment;
import org.openobservatory.ooniprobe.fragment.measurement.HeaderNdtFragment;
import org.openobservatory.ooniprobe.fragment.measurement.HeaderOutcomeFragment;
import org.openobservatory.ooniprobe.fragment.measurement.HttpHeaderFieldManipulationFragment;
import org.openobservatory.ooniprobe.fragment.measurement.HttpInvalidRequestLineFragment;
import org.openobservatory.ooniprobe.fragment.measurement.NdtFragment;
import org.openobservatory.ooniprobe.fragment.measurement.PsiphonFragment;
import org.openobservatory.ooniprobe.fragment.measurement.RiseupVPNFragment;
import org.openobservatory.ooniprobe.fragment.measurement.SignalFragment;
import org.openobservatory.ooniprobe.fragment.measurement.TelegramFragment;
import org.openobservatory.ooniprobe.fragment.measurement.TorFragment;
import org.openobservatory.ooniprobe.fragment.measurement.WebConnectivityFragment;
import org.openobservatory.ooniprobe.fragment.measurement.WhatsappFragment;
import org.openobservatory.ooniprobe.fragment.measurement.*;
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.Dash;
import org.openobservatory.ooniprobe.test.test.FacebookMessenger;
import org.openobservatory.ooniprobe.test.test.HttpHeaderFieldManipulation;
import org.openobservatory.ooniprobe.test.test.HttpInvalidRequestLine;
import org.openobservatory.ooniprobe.test.test.Ndt;
import org.openobservatory.ooniprobe.test.test.Psiphon;
import org.openobservatory.ooniprobe.test.test.RiseupVPN;
import org.openobservatory.ooniprobe.test.test.Signal;
import org.openobservatory.ooniprobe.test.test.Telegram;
import org.openobservatory.ooniprobe.test.test.Tor;
import org.openobservatory.ooniprobe.test.test.WebConnectivity;
import org.openobservatory.ooniprobe.test.test.Whatsapp;
import org.openobservatory.ooniprobe.test.test.*;
import ru.noties.markwon.Markwon;

import javax.inject.Inject;
import java.io.Serializable;
import java.util.Collections;
import java.util.Objects;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import ru.noties.markwon.Markwon;

public class MeasurementDetailActivity extends AbstractActivity implements ConfirmDialogFragment.OnConfirmedListener {
private static final String ID = "id";
private static final String RERUN_KEY = "rerun";

@BindView(R.id.coordinatorLayout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.toolbar)
Toolbar toolbar;
private Boolean isInExplorer;

private Measurement measurement;

private Snackbar snackbar;
private Boolean isInExplorer;
@BindView(R.id.log)
Button log;
@BindView(R.id.explorer)
Button explorer;
@BindView(R.id.data)
Button data;
@BindView(R.id.methodology)
TextView methodology;

@Inject
MeasurementsManager measurementsManager;
Expand Down Expand Up @@ -121,9 +75,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
measurement.is_anomaly ?
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Failure :
R.style.Theme_MaterialComponents_Light_DarkActionBar_App_NoActionBar_Success);
setContentView(R.layout.activity_measurement_detail);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
ActivityMeasurementDetailBinding binding = ActivityMeasurementDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
ActionBar bar = getSupportActionBar();
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
Expand Down Expand Up @@ -237,7 +191,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.replace(R.id.body, detail)
.replace(R.id.head, head)
.commit();
snackbar = Snackbar.make(coordinatorLayout, R.string.Snackbar_ResultsNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
snackbar = Snackbar.make(binding.coordinatorLayout, R.string.Snackbar_ResultsNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.Snackbar_ResultsNotUploaded_Upload, v1 -> runAsyncTask());
Context c = this;
isInExplorer = !measurement.hasReportFile(c);
Expand All @@ -255,11 +209,14 @@ public void onError(String msg) {
});

if (!measurement.hasLogFile(this))
log.setVisibility(View.GONE);
binding.log.setVisibility(View.GONE);
if (!measurementsManager.hasReportId(measurement))
explorer.setVisibility(View.GONE);
Markwon.setMarkdown(methodology, getString(R.string.TestResults_Details_Methodology_Paragraph, getString(measurement.getTest().getUrlResId())));
binding.explorer.setVisibility(View.GONE);
Markwon.setMarkdown(binding.methodology, getString(R.string.TestResults_Details_Methodology_Paragraph, getString(measurement.getTest().getUrlResId())));
load();
binding.log.setOnClickListener(v -> logClick());
binding.data.setOnClickListener(v -> dataClick());
binding.explorer.setOnClickListener(v -> explorerClick());
}

private void runAsyncTask() {
Expand Down Expand Up @@ -305,17 +262,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

@OnClick(R.id.log)
void logClick() {
startActivity(TextActivity.newIntent(this, TextActivity.TYPE_LOG, measurement));
}

@OnClick(R.id.data)
void dataClick() {
startActivity(TextActivity.newIntent(this, TextActivity.TYPE_JSON, measurement));
}

@OnClick(R.id.explorer)
void explorerClick() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(measurementsManager.getExplorerUrl(measurement))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.databinding.FragmentMeasurementDashBinding;
import org.openobservatory.ooniprobe.model.database.Measurement;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DashFragment extends Fragment {
private static final String MEASUREMENT = "measurement";
@BindView(R.id.medianBitrate) TextView medianBitrate;
@BindView(R.id.playoutDelay) TextView playoutDelay;

public static DashFragment newInstance(Measurement measurement) {
Bundle args = new Bundle();
Expand All @@ -30,14 +23,15 @@ public static DashFragment newInstance(Measurement measurement) {
return fragment;
}

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
assert getArguments() != null;
Measurement measurement = (Measurement) getArguments().getSerializable(MEASUREMENT);
assert measurement != null;
View v = inflater.inflate(R.layout.fragment_measurement_dash, container, false);
ButterKnife.bind(this, v);
medianBitrate.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getMedianBitrate(getActivity()), getString(measurement.getTestKeys().getMedianBitrateUnit()))));
playoutDelay.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getPlayoutDelay(getActivity()), "s")));
return v;
FragmentMeasurementDashBinding binding = FragmentMeasurementDashBinding.inflate(inflater,container,false);
binding.medianBitrate.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getMedianBitrate(getActivity()), getString(measurement.getTestKeys().getMedianBitrateUnit()))));
binding.playoutDelay.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getPlayoutDelay(getActivity()), "s")));
return binding.getRoot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.databinding.FragmentMeasurementFacebookmessengerBinding;
import org.openobservatory.ooniprobe.model.database.Measurement;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FacebookMessengerFragment extends Fragment {
private static final String MEASUREMENT = "measurement";
@BindView(R.id.tcp) TextView tcp;
@BindView(R.id.dns) TextView dns;
@BindView(R.id.desc) TextView desc;

public static FacebookMessengerFragment newInstance(Measurement measurement) {
Bundle args = new Bundle();
args.putSerializable(MEASUREMENT, measurement);
Expand All @@ -31,19 +22,20 @@ public static FacebookMessengerFragment newInstance(Measurement measurement) {
return fragment;
}

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
assert getArguments() != null;
Measurement measurement = (Measurement) getArguments().getSerializable(MEASUREMENT);
assert measurement != null;
View v = inflater.inflate(R.layout.fragment_measurement_facebookmessenger, container, false);
ButterKnife.bind(this, v);
desc.setText(measurement.is_anomaly ? R.string.TestResults_Details_InstantMessaging_FacebookMessenger_LikelyBlocked_Content_Paragraph : R.string.TestResults_Details_InstantMessaging_FacebookMessenger_Reachable_Content_Paragraph);
dns.setText(measurement.getTestKeys().getFacebookMessengerDns());
FragmentMeasurementFacebookmessengerBinding binding = FragmentMeasurementFacebookmessengerBinding.inflate(inflater,container,false);
binding.desc.setText(measurement.is_anomaly ? R.string.TestResults_Details_InstantMessaging_FacebookMessenger_LikelyBlocked_Content_Paragraph : R.string.TestResults_Details_InstantMessaging_FacebookMessenger_Reachable_Content_Paragraph);
binding.dns.setText(measurement.getTestKeys().getFacebookMessengerDns());
if (Boolean.TRUE.equals(measurement.getTestKeys().facebook_dns_blocking))
dns.setTextColor(ContextCompat.getColor(getActivity(), R.color.color_yellow9));
tcp.setText(measurement.getTestKeys().getFacebookMessengerTcp());
binding.dns.setTextColor(ContextCompat.getColor(getActivity(), R.color.color_yellow9));
binding.tcp.setText(measurement.getTestKeys().getFacebookMessengerTcp());
if (Boolean.TRUE.equals(measurement.getTestKeys().facebook_tcp_blocking))
tcp.setTextColor(ContextCompat.getColor(getActivity(), R.color.color_yellow9));
return v;
binding.tcp.setTextColor(ContextCompat.getColor(getActivity(), R.color.color_yellow9));
return binding.getRoot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ public static FailedFragment newInstance(Measurement measurement) {
return fragment;
}

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
binding = FragmentMeasurementFailedBinding.inflate(inflater,container,false);
binding.tryAgain.setOnClickListener(this::tryAgainClick);
return binding.getRoot();
}

void tryAgainClick(View view) {
void tryAgainClick(View view) {
assert getArguments() != null;
Measurement failedMeasurement = (Measurement) getArguments().getSerializable(MEASUREMENT);
assert failedMeasurement != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.databinding.FragmentMeasurementHeaderNdtBinding;
import org.openobservatory.ooniprobe.model.database.Measurement;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HeaderNdtFragment extends Fragment {
private static final String MEASUREMENT = "measurement";
@BindView(R.id.download) TextView download;
@BindView(R.id.upload) TextView upload;
@BindView(R.id.ping) TextView ping;
@BindView(R.id.server) TextView server;

public static HeaderNdtFragment newInstance(Measurement measurement) {
Bundle args = new Bundle();
Expand All @@ -32,16 +23,17 @@ public static HeaderNdtFragment newInstance(Measurement measurement) {
return fragment;
}

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
assert getArguments() != null;
Measurement measurement = (Measurement) getArguments().getSerializable(MEASUREMENT);
assert measurement != null;
View v = inflater.inflate(R.layout.fragment_measurement_header_ndt, container, false);
ButterKnife.bind(this, v);
download.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getDownload(getActivity()), getString(measurement.getTestKeys().getDownloadUnit()))));
upload.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getUpload(getActivity()), getString(measurement.getTestKeys().getUploadUnit()))));
ping.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getPing(getActivity()), "ms")));
server.setText(measurement.getTestKeys().getServerDetails(getActivity()));
return v;
FragmentMeasurementHeaderNdtBinding binding = FragmentMeasurementHeaderNdtBinding.inflate(inflater,container,false);
binding.download.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getDownload(getActivity()), getString(measurement.getTestKeys().getDownloadUnit()))));
binding.upload.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getUpload(getActivity()), getString(measurement.getTestKeys().getUploadUnit()))));
binding.ping.setText(Html.fromHtml(getString(R.string.bigNormal, measurement.getTestKeys().getPing(getActivity()), "ms")));
binding.server.setText(measurement.getTestKeys().getServerDetails(getActivity()));
return binding.getRoot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.openobservatory.ooniprobe.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import org.openobservatory.ooniprobe.databinding.FragmentMeasurementHeaderOutcomeBinding;

public class HeaderOutcomeFragment extends Fragment {
public static final String ICON_RES = "iconRes";
private static final String DESC = "desc";
@BindView(R.id.outcome) TextView outcome;

public static HeaderOutcomeFragment newInstance(Integer iconRes, String desc) {
Bundle args = new Bundle();
Expand All @@ -31,13 +24,14 @@ public static HeaderOutcomeFragment newInstance(Integer iconRes, String desc) {
return fragment;
}

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
assert getArguments() != null;
View v = inflater.inflate(R.layout.fragment_measurement_header_outcome, container, false);
ButterKnife.bind(this, v);
outcome.setText(Html.fromHtml(getArguments().getString(DESC)));
FragmentMeasurementHeaderOutcomeBinding binding = FragmentMeasurementHeaderOutcomeBinding.inflate(inflater,container,false);
binding.outcome.setText(Html.fromHtml(getArguments().getString(DESC)));
if (getArguments().containsKey(ICON_RES))
outcome.setCompoundDrawablesRelativeWithIntrinsicBounds(0, getArguments().getInt(ICON_RES), 0, 0);
return v;
binding.outcome.setCompoundDrawablesRelativeWithIntrinsicBounds(0, getArguments().getInt(ICON_RES), 0, 0);
return binding.getRoot();
}
}
Loading

0 comments on commit ed9b2bb

Please sign in to comment.