Skip to content

Commit

Permalink
Update ResultDetailActivity and component fragment to use `ViewBin…
Browse files Browse the repository at this point in the history
…ding`
  • Loading branch information
aanorbel committed Aug 27, 2023
1 parent 9f033e7 commit 40013a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,23 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import localhost.toolkit.app.fragment.ConfirmDialogFragment;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ResubmitTask;
import org.openobservatory.ooniprobe.databinding.ActivityResultDetailBinding;
import org.openobservatory.ooniprobe.domain.GetResults;
import org.openobservatory.ooniprobe.domain.GetTestSuite;
import org.openobservatory.ooniprobe.fragment.resultHeader.ResultHeaderDetailFragment;
Expand All @@ -39,39 +35,18 @@
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.model.database.Network;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.test.suite.CircumventionSuite;
import org.openobservatory.ooniprobe.test.suite.ExperimentalSuite;
import org.openobservatory.ooniprobe.test.suite.InstantMessagingSuite;
import org.openobservatory.ooniprobe.test.suite.MiddleBoxesSuite;
import org.openobservatory.ooniprobe.test.suite.PerformanceSuite;
import org.openobservatory.ooniprobe.test.suite.WebsitesSuite;
import org.openobservatory.ooniprobe.test.suite.*;

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

import javax.inject.Inject;

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

public class ResultDetailActivity extends AbstractActivity implements View.OnClickListener, ConfirmDialogFragment.OnConfirmedListener {
private static final String ID = "id";
private static final String UPLOAD_KEY = "upload";
private static final String RERUN_KEY = "rerun";
@BindView(R.id.coordinatorLayout)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.tabLayout)
TabLayout tabLayout;
@BindView(R.id.pager)
ViewPager2 pager;
@BindView(R.id.recyclerView)
RecyclerView recycler;

private ArrayList<HeterogeneousRecyclerItem> items;
private HeterogeneousRecyclerAdapter<HeterogeneousRecyclerItem> adapter;
private Result result;
Expand All @@ -97,27 +72,27 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
result = getResults.get(getIntent().getIntExtra(ID, 0));
assert result != null;
setTheme(result.getTestSuite().getThemeLight());
setContentView(R.layout.activity_result_detail);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
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());
}
pager.setAdapter(new ResultHeaderAdapter(this));
new TabLayoutMediator(tabLayout, pager, (tab, position) ->
binding.pager.setAdapter(new ResultHeaderAdapter(this));
new TabLayoutMediator(binding.tabLayout, binding.pager, (tab, position) ->
tab.setText("●")
).attach();
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recycler.setLayoutManager(layoutManager);
recycler.addItemDecoration(new DividerItemDecoration(this, layoutManager.getOrientation()));
binding.recyclerView.setLayoutManager(layoutManager);
binding.recyclerView.addItemDecoration(new DividerItemDecoration(this, layoutManager.getOrientation()));
result.is_viewed = true;
result.save();
items = new ArrayList<>();
adapter = new HeterogeneousRecyclerAdapter<>(this, items);
recycler.setAdapter(adapter);
snackbar = Snackbar.make(coordinatorLayout, R.string.Snackbar_ResultsSomeNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
binding.recyclerView.setAdapter(adapter);
snackbar = Snackbar.make(binding.coordinatorLayout, R.string.Snackbar_ResultsSomeNotUploaded_Text, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.Snackbar_ResultsSomeNotUploaded_UploadAll, v1 -> runAsyncTask());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
import androidx.recyclerview.widget.RecyclerView;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.databinding.ItemMeasurementBinding;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.test.test.AbstractTest;
import org.openobservatory.ooniprobe.test.test.WebConnectivity;

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

public class MeasurementItem extends HeterogeneousRecyclerItem<Measurement, MeasurementItem.ViewHolder> {
Expand All @@ -28,7 +27,7 @@ public MeasurementItem(Measurement extra, View.OnClickListener onClickListener)
}

@Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) {
return new ViewHolder(layoutInflater.inflate(R.layout.item_measurement, viewGroup, false));
return new ViewHolder(ItemMeasurementBinding.inflate(layoutInflater, viewGroup, false));
}

@Override public void onBindViewHolder(ViewHolder viewHolder) {
Expand Down Expand Up @@ -65,12 +64,12 @@ else if (extra.isUploaded())
}

class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.text) TextView text;
TextView text;

ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
text.setOnClickListener(onClickListener);
ViewHolder(ItemMeasurementBinding binding) {
super(binding.getRoot());
this.text = binding.text;
this.text.setOnClickListener(onClickListener);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.databinding.ItemMeasurementPerfBinding;
import org.openobservatory.ooniprobe.model.database.Measurement;
import org.openobservatory.ooniprobe.test.test.Dash;
import org.openobservatory.ooniprobe.test.test.HttpHeaderFieldManipulation;
import org.openobservatory.ooniprobe.test.test.HttpInvalidRequestLine;
import org.openobservatory.ooniprobe.test.test.Ndt;

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

public class MeasurementPerfItem extends HeterogeneousRecyclerItem<Measurement, MeasurementPerfItem.ViewHolder> {
Expand All @@ -28,46 +26,43 @@ public MeasurementPerfItem(Measurement extra, View.OnClickListener onClickListen
}

@Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) {
return new ViewHolder(layoutInflater.inflate(R.layout.item_measurement_perf, viewGroup, false));
return new ViewHolder(ItemMeasurementPerfBinding.inflate(layoutInflater, viewGroup, false));
}

@Override public void onBindViewHolder(ViewHolder viewHolder) {
viewHolder.itemView.setTag(extra);
Context c = viewHolder.text.getContext();
Context c = viewHolder.binding.text.getContext();
if (extra.getTest().getLabelResId() == (R.string.Test_Experimental_Fullname))
viewHolder.text.setText(extra.getTest().getName());
viewHolder.binding.text.setText(extra.getTest().getName());
else
viewHolder.text.setText(extra.getTest().getLabelResId());
viewHolder.text.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, extra.is_failed || extra.isUploaded() ? 0 : R.drawable.cloudoff, 0);
viewHolder.binding.text.setText(extra.getTest().getLabelResId());
viewHolder.binding.text.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, extra.is_failed || extra.isUploaded() ? 0 : R.drawable.cloudoff, 0);
if (extra.test_name.equals(Dash.NAME)) {
viewHolder.data1.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.video_quality, 0, 0, 0);
viewHolder.data1.setText(extra.getTestKeys().getVideoQuality(true));
viewHolder.data2.setVisibility(View.GONE);
viewHolder.binding.data1.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.video_quality, 0, 0, 0);
viewHolder.binding.data1.setText(extra.getTestKeys().getVideoQuality(true));
viewHolder.binding.data2.setVisibility(View.GONE);
} else if (extra.test_name.equals(Ndt.NAME)) {
viewHolder.data1.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.download_black, 0, 0, 0);
viewHolder.data1.setText(c.getString(R.string.twoParam, extra.getTestKeys().getDownload(c), c.getString(extra.getTestKeys().getDownloadUnit())));
viewHolder.data2.setVisibility(View.VISIBLE);
viewHolder.data2.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.upload_black, 0, 0, 0);
viewHolder.data2.setText(c.getString(R.string.twoParam, extra.getTestKeys().getUpload(c), c.getString(extra.getTestKeys().getUploadUnit())));
viewHolder.binding.data1.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.download_black, 0, 0, 0);
viewHolder.binding.data1.setText(c.getString(R.string.twoParam, extra.getTestKeys().getDownload(c), c.getString(extra.getTestKeys().getDownloadUnit())));
viewHolder.binding.data2.setVisibility(View.VISIBLE);
viewHolder.binding.data2.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.upload_black, 0, 0, 0);
viewHolder.binding.data2.setText(c.getString(R.string.twoParam, extra.getTestKeys().getUpload(c), c.getString(extra.getTestKeys().getUploadUnit())));
} else if (extra.test_name.equals(HttpHeaderFieldManipulation.NAME)
|| extra.test_name.equals(HttpInvalidRequestLine.NAME)) {
viewHolder.data1.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.test_middle_boxes_small, 0, 0, 0);
viewHolder.data1.setText(extra.is_anomaly ?
viewHolder.binding.data1.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.test_middle_boxes_small, 0, 0, 0);
viewHolder.binding.data1.setText(extra.is_anomaly ?
c.getString(R.string.TestResults_Overview_MiddleBoxes_Found) :
c.getString(R.string.TestResults_Overview_MiddleBoxes_NotFound));
viewHolder.data2.setVisibility(View.GONE);
viewHolder.binding.data2.setVisibility(View.GONE);
}
}

class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.text) TextView text;
@BindView(R.id.data1) TextView data1;
@BindView(R.id.data2) TextView data2;

ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(onClickListener);
ItemMeasurementPerfBinding binding;
ViewHolder(ItemMeasurementPerfBinding binding) {
super(binding.getRoot());
this.binding = binding;
binding.getRoot().setOnClickListener(onClickListener);
}
}
}

0 comments on commit 40013a3

Please sign in to comment.