From 06f9735d3efb88d0e71348a11074d5bbd967f67f Mon Sep 17 00:00:00 2001 From: Norbel Ambanumben Date: Sun, 27 Aug 2023 10:14:42 +0100 Subject: [PATCH] Update `ResultListFragment` and components to `ViewBinding` --- .../fragment/ResultListFragment.java | 113 +++++++----------- .../ooniprobe/item/CircumventionItem.java | 43 +++---- .../ooniprobe/item/ExperimentalItem.java | 28 ++--- .../ooniprobe/item/InstantMessagingItem.java | 38 +++--- .../ooniprobe/item/MiddleboxesItem.java | 47 ++++---- .../ooniprobe/item/PerformanceItem.java | 43 +++---- .../ooniprobe/item/WebsiteItem.java | 44 +++---- 7 files changed, 139 insertions(+), 217 deletions(-) diff --git a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java index c0835739d..8b881c25e 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/fragment/ResultListFragment.java @@ -3,30 +3,21 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Spinner; -import android.widget.TextView; - +import android.view.*; +import android.widget.AdapterView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import com.google.android.material.snackbar.Snackbar; import com.raizlabs.android.dbflow.sql.language.Method; import com.raizlabs.android.dbflow.sql.language.SQLite; - +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.activity.AbstractActivity; import org.openobservatory.ooniprobe.activity.ResultDetailActivity; @@ -34,60 +25,25 @@ import org.openobservatory.ooniprobe.common.Application; import org.openobservatory.ooniprobe.common.PreferenceManager; import org.openobservatory.ooniprobe.common.ResubmitTask; +import org.openobservatory.ooniprobe.databinding.FragmentResultListBinding; import org.openobservatory.ooniprobe.domain.GetResults; import org.openobservatory.ooniprobe.domain.MeasurementsManager; import org.openobservatory.ooniprobe.domain.models.DatedResults; -import org.openobservatory.ooniprobe.item.CircumventionItem; -import org.openobservatory.ooniprobe.item.DateItem; -import org.openobservatory.ooniprobe.item.ExperimentalItem; -import org.openobservatory.ooniprobe.item.FailedItem; -import org.openobservatory.ooniprobe.item.InstantMessagingItem; -import org.openobservatory.ooniprobe.item.MiddleboxesItem; -import org.openobservatory.ooniprobe.item.PerformanceItem; -import org.openobservatory.ooniprobe.item.WebsiteItem; +import org.openobservatory.ooniprobe.item.*; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; import org.openobservatory.ooniprobe.model.database.Result_Table; -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.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnItemSelected; -import localhost.toolkit.app.fragment.ConfirmDialogFragment; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - public class ResultListFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, ConfirmDialogFragment.OnConfirmedListener { - @BindView(R.id.coordinatorLayout) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.tests) - TextView tests; - @BindView(R.id.networks) - TextView networks; - @BindView(R.id.upload) - TextView upload; - @BindView(R.id.download) - TextView download; - @BindView(R.id.filterTests) - Spinner filterTests; - @BindView(R.id.recycler) - RecyclerView recycler; - @BindView(R.id.emptyState) - TextView emptyState; + private FragmentResultListBinding binding; + private ArrayList items; private HeterogeneousRecyclerAdapter adapter; private boolean refresh; @@ -105,20 +61,32 @@ public class ResultListFragment extends Fragment implements View.OnClickListener @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_result_list, container, false); - ButterKnife.bind(this, v); + binding = FragmentResultListBinding.inflate(inflater, container, false); ((Application) getActivity().getApplication()).getFragmentComponent().inject(this); - ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); + ((AppCompatActivity) getActivity()).setSupportActionBar(binding.toolbar); setHasOptionsMenu(true); getActivity().setTitle(R.string.TestResults_Overview_Title); reloadHeader(); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); - recycler.setLayoutManager(layoutManager); - recycler.addItemDecoration(new DividerItemDecoration(getActivity(), layoutManager.getOrientation())); + binding.recycler.setLayoutManager(layoutManager); + binding.recycler.addItemDecoration(new DividerItemDecoration(getActivity(), layoutManager.getOrientation())); items = new ArrayList<>(); adapter = new HeterogeneousRecyclerAdapter<>(getActivity(), items); - recycler.setAdapter(adapter); - snackbar = Snackbar.make(coordinatorLayout, R.string.Snackbar_ResultsSomeNotUploaded_Text, Snackbar.LENGTH_INDEFINITE) + binding.recycler.setAdapter(adapter); + + binding.filterTests.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + queryList(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + queryList(); + } + }); + + snackbar = Snackbar.make(binding.coordinatorLayout, R.string.Snackbar_ResultsSomeNotUploaded_Text, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.Snackbar_ResultsSomeNotUploaded_UploadAll, v1 -> new ConfirmDialogFragment.Builder() .withExtra(R.string.Modal_ResultsNotUploaded_Title) @@ -127,14 +95,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c .withPositiveButton(getString(R.string.Modal_ResultsNotUploaded_Button_Upload)) .build().show(getChildFragmentManager(), null) ); - return v; + return binding.getRoot(); } public void reloadHeader() { - tests.setText(getString(R.string.d, SQLite.selectCountOf().from(Result.class).longValue())); - networks.setText(getString(R.string.d, SQLite.selectCountOf().from(Network.class).longValue())); - upload.setText(Result.readableFileSize(SQLite.select(Method.sum(Result_Table.data_usage_up)).from(Result.class).longValue())); - download.setText(Result.readableFileSize(SQLite.select(Method.sum(Result_Table.data_usage_down)).from(Result.class).longValue())); + binding.tests.setText(getString(R.string.d, SQLite.selectCountOf().from(Result.class).longValue())); + binding.networks.setText(getString(R.string.d, SQLite.selectCountOf().from(Network.class).longValue())); + binding.upload.setText(Result.readableFileSize(SQLite.select(Method.sum(Result_Table.data_usage_up)).from(Result.class).longValue())); + binding.download.setText(Result.readableFileSize(SQLite.select(Method.sum(Result_Table.data_usage_down)).from(Result.class).longValue())); } @Override @@ -173,7 +141,6 @@ public boolean onOptionsItemSelected(MenuItem item) { } } - @OnItemSelected(R.id.filterTests) void queryList() { if (measurementsManager.hasUploadables()) { snackbar.show(); @@ -183,15 +150,15 @@ void queryList() { items.clear(); - String filter = getResources().getStringArray(R.array.filterTestValues)[filterTests.getSelectedItemPosition()]; + String filter = getResources().getStringArray(R.array.filterTestValues)[binding.filterTests.getSelectedItemPosition()]; List list = getResults.getGroupedByMonth(filter); if (list.isEmpty()) { - emptyState.setVisibility(View.VISIBLE); - recycler.setVisibility(View.GONE); + binding.emptyState.setVisibility(View.VISIBLE); + binding.recycler.setVisibility(View.GONE); } else { - emptyState.setVisibility(View.GONE); - recycler.setVisibility(View.VISIBLE); + binding.emptyState.setVisibility(View.GONE); + binding.recycler.setVisibility(View.VISIBLE); for (DatedResults group : list) { items.add(new DateItem(group.getGroupedDate())); for (Result result : group.getResultsList()) { diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/CircumventionItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/CircumventionItem.java index f4e8fbc6e..2d54bc237 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/CircumventionItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/CircumventionItem.java @@ -4,23 +4,18 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; - import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.recyclerview.widget.RecyclerView; - +import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.databinding.ItemCircumventionBinding; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - public class CircumventionItem extends HeterogeneousRecyclerItem { private final View.OnClickListener onClickListener; private final View.OnLongClickListener onLongClickListener; @@ -31,39 +26,35 @@ public CircumventionItem(Result extra, View.OnClickListener onClickListener, Vie this.onLongClickListener = onLongClickListener; } - @Override public CircumventionItem.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { - return new CircumventionItem.ViewHolder(layoutInflater.inflate(R.layout.item_circumvention, viewGroup, false)); + @Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return new ViewHolder(ItemCircumventionBinding.inflate(layoutInflater, viewGroup, false)); } - @Override public void onBindViewHolder(CircumventionItem.ViewHolder viewHolder) { + @Override public void onBindViewHolder(ViewHolder viewHolder) { viewHolder.itemView.setTag(extra); viewHolder.itemView.setOnClickListener(onClickListener); viewHolder.itemView.setOnLongClickListener(onLongClickListener); viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(viewHolder.itemView.getContext(), extra.is_viewed ? android.R.color.transparent : R.color.color_yellow0)); - viewHolder.asnName.setText(Network.toString(viewHolder.asnName.getContext(), extra.network)); - viewHolder.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); + viewHolder.binding.asnName.setText(Network.toString(viewHolder.binding.asnName.getContext(), extra.network)); + viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); Long blocked = extra.countAnomalousMeasurements(); Long available = extra.countOkMeasurements(); - viewHolder.failedMeasurements.setText(viewHolder.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Circumvention_Blocked, blocked.intValue(), blocked.toString())); - viewHolder.okMeasurements.setText(viewHolder.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Circumvention_Available, available.intValue(), available.toString())); - viewHolder.failedMeasurements.setTextColor(ContextCompat.getColor(viewHolder.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); - DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.failedMeasurements.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); + viewHolder.binding.failedMeasurements.setText(viewHolder.binding.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Circumvention_Blocked, blocked.intValue(), blocked.toString())); + viewHolder.binding.okMeasurements.setText(viewHolder.binding.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Circumvention_Available, available.intValue(), available.toString())); + viewHolder.binding.failedMeasurements.setTextColor(ContextCompat.getColor(viewHolder.binding.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); + DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.binding.failedMeasurements.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.binding.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); boolean allUploaded = true; for (Measurement m : extra.getMeasurements()) allUploaded = allUploaded && (m.isUploaded() || m.is_failed); - viewHolder.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); + viewHolder.binding.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); } - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.asnName) - TextView asnName; - @BindView(R.id.startTime) TextView startTime; - @BindView(R.id.failedMeasurements) TextView failedMeasurements; - @BindView(R.id.okMeasurements) TextView okMeasurements; + public static class ViewHolder extends RecyclerView.ViewHolder { + ItemCircumventionBinding binding; - ViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ViewHolder(ItemCircumventionBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/ExperimentalItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/ExperimentalItem.java index d3df87b6e..c4f9688b5 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/ExperimentalItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/ExperimentalItem.java @@ -4,22 +4,17 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; - import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; - +import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.databinding.ItemExperimentalBinding; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - public class ExperimentalItem extends HeterogeneousRecyclerItem { private final View.OnClickListener onClickListener; private final View.OnLongClickListener onLongClickListener; @@ -31,7 +26,7 @@ public ExperimentalItem(Result extra, View.OnClickListener onClickListener, View } @Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { - return new ViewHolder(layoutInflater.inflate(R.layout.item_experimental, viewGroup, false)); + return new ViewHolder(ItemExperimentalBinding.inflate(layoutInflater, viewGroup, false)); } @Override public void onBindViewHolder(ViewHolder viewHolder) { @@ -39,21 +34,20 @@ public ExperimentalItem(Result extra, View.OnClickListener onClickListener, View viewHolder.itemView.setOnClickListener(onClickListener); viewHolder.itemView.setOnLongClickListener(onLongClickListener); viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(viewHolder.itemView.getContext(), extra.is_viewed ? android.R.color.transparent : R.color.color_yellow0)); - viewHolder.asnName.setText(Network.toString(viewHolder.asnName.getContext(), extra.network)); - viewHolder.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); + viewHolder.binding.asnName.setText(Network.toString(viewHolder.binding.asnName.getContext(), extra.network)); + viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); boolean allUploaded = true; for (Measurement m : extra.getMeasurements()) allUploaded = allUploaded && (m.isUploaded() || m.is_failed); - viewHolder.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); + viewHolder.binding.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); } - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.asnName) TextView asnName; - @BindView(R.id.startTime) TextView startTime; + public static class ViewHolder extends RecyclerView.ViewHolder { + ItemExperimentalBinding binding; - ViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ViewHolder(ItemExperimentalBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/InstantMessagingItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/InstantMessagingItem.java index 86fab7fa5..799a7fc3d 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/InstantMessagingItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/InstantMessagingItem.java @@ -4,23 +4,18 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; - import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.recyclerview.widget.RecyclerView; - +import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.databinding.ItemInstantmessagingBinding; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - public class InstantMessagingItem extends HeterogeneousRecyclerItem { private final View.OnClickListener onClickListener; private final View.OnLongClickListener onLongClickListener; @@ -32,7 +27,7 @@ public InstantMessagingItem(Result extra, View.OnClickListener onClickListener, } @Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { - return new ViewHolder(layoutInflater.inflate(R.layout.item_instantmessaging, viewGroup, false)); + return new ViewHolder(ItemInstantmessagingBinding.inflate(layoutInflater, viewGroup, false)); } @Override public void onBindViewHolder(ViewHolder viewHolder) { @@ -40,29 +35,26 @@ public InstantMessagingItem(Result extra, View.OnClickListener onClickListener, viewHolder.itemView.setOnClickListener(onClickListener); viewHolder.itemView.setOnLongClickListener(onLongClickListener); viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(viewHolder.itemView.getContext(), extra.is_viewed ? android.R.color.transparent : R.color.color_yellow0)); - viewHolder.asnName.setText(Network.toString(viewHolder.asnName.getContext(), extra.network)); - viewHolder.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); + viewHolder.binding.asnName.setText(Network.toString(viewHolder.binding.asnName.getContext(), extra.network)); + viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); Long blocked = extra.countAnomalousMeasurements(); Long available = extra.countOkMeasurements(); - viewHolder.failedMeasurements.setText(viewHolder.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_InstantMessaging_Blocked, blocked.intValue(), blocked.toString())); - viewHolder.okMeasurements.setText(viewHolder.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_InstantMessaging_Available, available.intValue(), available.toString())); - viewHolder.failedMeasurements.setTextColor(ContextCompat.getColor(viewHolder.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); - DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.failedMeasurements.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); + viewHolder.binding.failedMeasurements.setText(viewHolder.binding.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_InstantMessaging_Blocked, blocked.intValue(), blocked.toString())); + viewHolder.binding.okMeasurements.setText(viewHolder.binding.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_InstantMessaging_Available, available.intValue(), available.toString())); + viewHolder.binding.failedMeasurements.setTextColor(ContextCompat.getColor(viewHolder.binding.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); + DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.binding.failedMeasurements.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.binding.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); boolean allUploaded = true; for (Measurement m : extra.getMeasurements()) allUploaded = allUploaded && (m.isUploaded() || m.is_failed); - viewHolder.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); + viewHolder.binding.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); } - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.asnName) TextView asnName; - @BindView(R.id.startTime) TextView startTime; - @BindView(R.id.failedMeasurements) TextView failedMeasurements; - @BindView(R.id.okMeasurements) TextView okMeasurements; + public static class ViewHolder extends RecyclerView.ViewHolder { + ItemInstantmessagingBinding binding; - ViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ViewHolder(ItemInstantmessagingBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/MiddleboxesItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/MiddleboxesItem.java index f776347cb..df9aeefc8 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/MiddleboxesItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/MiddleboxesItem.java @@ -4,23 +4,18 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; - import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.recyclerview.widget.RecyclerView; - +import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.databinding.ItemMiddleboxesBinding; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - /** * @deprecated * It is not possible to run a MiddleBoxesSuite anymore @@ -38,7 +33,7 @@ public MiddleboxesItem(Result extra, View.OnClickListener onClickListener, View. } @Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { - return new ViewHolder(layoutInflater.inflate(R.layout.item_middleboxes, viewGroup, false)); + return new ViewHolder(ItemMiddleboxesBinding.inflate(layoutInflater, viewGroup, false)); } @Override public void onBindViewHolder(ViewHolder viewHolder) { @@ -46,35 +41,33 @@ public MiddleboxesItem(Result extra, View.OnClickListener onClickListener, View. viewHolder.itemView.setOnClickListener(onClickListener); viewHolder.itemView.setOnLongClickListener(onLongClickListener); viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(viewHolder.itemView.getContext(), extra.is_viewed ? android.R.color.transparent : R.color.color_yellow0)); - viewHolder.asnName.setText(Network.toString(viewHolder.asnName.getContext(), extra.network)); - viewHolder.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); + viewHolder.binding.asnName.setText(Network.toString(viewHolder.binding.asnName.getContext(), extra.network)); + viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); if (extra.countAnomalousMeasurements() > 0) { - viewHolder.status.setText(R.string.TestResults_Overview_MiddleBoxes_Found); - viewHolder.status.setTextColor(ContextCompat.getColor(viewHolder.status.getContext(), R.color.color_yellow9)); - DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.status.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.status.getContext(), R.color.color_yellow9)); + viewHolder.binding.status.setText(R.string.TestResults_Overview_MiddleBoxes_Found); + viewHolder.binding.status.setTextColor(ContextCompat.getColor(viewHolder.binding.status.getContext(), R.color.color_yellow9)); + DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.binding.status.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.binding.status.getContext(), R.color.color_yellow9)); } else if (extra.countCompletedMeasurements() == 0) { - viewHolder.status.setText(R.string.TestResults_Overview_MiddleBoxes_Failed); - viewHolder.status.setTextColor(ContextCompat.getColor(viewHolder.status.getContext(), R.color.color_gray9)); - DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.status.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.status.getContext(), R.color.color_gray9)); + viewHolder.binding.status.setText(R.string.TestResults_Overview_MiddleBoxes_Failed); + viewHolder.binding.status.setTextColor(ContextCompat.getColor(viewHolder.binding.status.getContext(), R.color.color_gray9)); + DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.binding.status.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.binding.status.getContext(), R.color.color_gray9)); } else { - viewHolder.status.setText(R.string.TestResults_Overview_MiddleBoxes_NotFound); - viewHolder.status.setTextColor(ContextCompat.getColor(viewHolder.status.getContext(), R.color.color_gray9)); - DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.status.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.status.getContext(), R.color.color_gray9)); + viewHolder.binding.status.setText(R.string.TestResults_Overview_MiddleBoxes_NotFound); + viewHolder.binding.status.setTextColor(ContextCompat.getColor(viewHolder.binding.status.getContext(), R.color.color_gray9)); + DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.binding.status.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.binding.status.getContext(), R.color.color_gray9)); } boolean allUploaded = true; for (Measurement m : extra.getMeasurements()) allUploaded = allUploaded && (m.isUploaded() || m.is_failed); - viewHolder.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); + viewHolder.binding.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); } - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.asnName) TextView asnName; - @BindView(R.id.startTime) TextView startTime; - @BindView(R.id.status) TextView status; + public static class ViewHolder extends RecyclerView.ViewHolder { + ItemMiddleboxesBinding binding; - ViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ViewHolder(ItemMiddleboxesBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/PerformanceItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/PerformanceItem.java index af9d6dff2..ac29d1292 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/PerformanceItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/PerformanceItem.java @@ -5,12 +5,11 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; - import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; - +import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.databinding.ItemPerformanceBinding; import org.openobservatory.ooniprobe.fragment.resultHeader.ResultHeaderPerformanceFragment; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Network; @@ -20,10 +19,6 @@ import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - public class PerformanceItem extends HeterogeneousRecyclerItem { private final View.OnClickListener onClickListener; private final View.OnLongClickListener onLongClickListener; @@ -35,7 +30,7 @@ public PerformanceItem(Result extra, View.OnClickListener onClickListener, View. } @Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { - return new ViewHolder(layoutInflater.inflate(R.layout.item_performance, viewGroup, false)); + return new ViewHolder(ItemPerformanceBinding.inflate(layoutInflater, viewGroup, false)); } @Override public void onBindViewHolder(ViewHolder viewHolder) { @@ -44,32 +39,28 @@ public PerformanceItem(Result extra, View.OnClickListener onClickListener, View. viewHolder.itemView.setOnClickListener(onClickListener); viewHolder.itemView.setOnLongClickListener(onLongClickListener); viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(c, extra.is_viewed ? android.R.color.transparent : R.color.color_yellow0)); - viewHolder.asnName.setText(Network.toString(viewHolder.asnName.getContext(), extra.network)); - viewHolder.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); + viewHolder.binding.asnName.setText(Network.toString(viewHolder.binding.asnName.getContext(), extra.network)); + viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); Measurement dashM = extra.getMeasurement(Dash.NAME); Measurement ndtM = extra.getMeasurement(Ndt.NAME); - viewHolder.quality.setText(dashM == null ? R.string.TestResults_NotAvailable : dashM.getTestKeys().getVideoQuality(false)); - viewHolder.upload.setText(ndtM == null ? c.getString(R.string.TestResults_NotAvailable) : c.getString(R.string.twoParam, ndtM.getTestKeys().getUpload(c), c.getString(ndtM.getTestKeys().getUploadUnit()))); - viewHolder.download.setText(ndtM == null ? c.getString(R.string.TestResults_NotAvailable) : c.getString(R.string.twoParam, ndtM.getTestKeys().getDownload(c), c.getString(ndtM.getTestKeys().getDownloadUnit()))); - viewHolder.quality.setAlpha(dashM == null ? ResultHeaderPerformanceFragment.ALPHA_DIS : ResultHeaderPerformanceFragment.ALPHA_ENA); - viewHolder.upload.setAlpha(ndtM == null ? ResultHeaderPerformanceFragment.ALPHA_DIS : ResultHeaderPerformanceFragment.ALPHA_ENA); - viewHolder.download.setAlpha(ndtM == null ? ResultHeaderPerformanceFragment.ALPHA_DIS : ResultHeaderPerformanceFragment.ALPHA_ENA); + viewHolder.binding.quality.setText(dashM == null ? R.string.TestResults_NotAvailable : dashM.getTestKeys().getVideoQuality(false)); + viewHolder.binding.upload.setText(ndtM == null ? c.getString(R.string.TestResults_NotAvailable) : c.getString(R.string.twoParam, ndtM.getTestKeys().getUpload(c), c.getString(ndtM.getTestKeys().getUploadUnit()))); + viewHolder.binding.download.setText(ndtM == null ? c.getString(R.string.TestResults_NotAvailable) : c.getString(R.string.twoParam, ndtM.getTestKeys().getDownload(c), c.getString(ndtM.getTestKeys().getDownloadUnit()))); + viewHolder.binding.quality.setAlpha(dashM == null ? ResultHeaderPerformanceFragment.ALPHA_DIS : ResultHeaderPerformanceFragment.ALPHA_ENA); + viewHolder.binding.upload.setAlpha(ndtM == null ? ResultHeaderPerformanceFragment.ALPHA_DIS : ResultHeaderPerformanceFragment.ALPHA_ENA); + viewHolder.binding.download.setAlpha(ndtM == null ? ResultHeaderPerformanceFragment.ALPHA_DIS : ResultHeaderPerformanceFragment.ALPHA_ENA); boolean allUploaded = true; for (Measurement m : extra.getMeasurements()) allUploaded = allUploaded && (m.isUploaded() || m.is_failed); - viewHolder.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); + viewHolder.binding.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); } - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.asnName) TextView asnName; - @BindView(R.id.startTime) TextView startTime; - @BindView(R.id.upload) TextView upload; - @BindView(R.id.download) TextView download; - @BindView(R.id.quality) TextView quality; + public static class ViewHolder extends RecyclerView.ViewHolder { + ItemPerformanceBinding binding; - ViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ViewHolder(ItemPerformanceBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } diff --git a/app/src/main/java/org/openobservatory/ooniprobe/item/WebsiteItem.java b/app/src/main/java/org/openobservatory/ooniprobe/item/WebsiteItem.java index 572f00c24..60d9f0589 100644 --- a/app/src/main/java/org/openobservatory/ooniprobe/item/WebsiteItem.java +++ b/app/src/main/java/org/openobservatory/ooniprobe/item/WebsiteItem.java @@ -4,23 +4,18 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; - import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.recyclerview.widget.RecyclerView; - +import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; import org.openobservatory.ooniprobe.R; +import org.openobservatory.ooniprobe.databinding.ItemWebsitesBinding; import org.openobservatory.ooniprobe.model.database.Measurement; import org.openobservatory.ooniprobe.model.database.Network; import org.openobservatory.ooniprobe.model.database.Result; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem; - public class WebsiteItem extends HeterogeneousRecyclerItem { private final View.OnClickListener onClickListener; private final View.OnLongClickListener onLongClickListener; @@ -31,38 +26,37 @@ public WebsiteItem(Result extra, View.OnClickListener onClickListener, View.OnLo this.onLongClickListener = onLongClickListener; } - @Override public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { - return new ViewHolder(layoutInflater.inflate(R.layout.item_websites, viewGroup, false)); + @Override + public ViewHolder onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) { + return new ViewHolder(ItemWebsitesBinding.inflate(layoutInflater, viewGroup, false)); } - @Override public void onBindViewHolder(ViewHolder viewHolder) { + @Override + public void onBindViewHolder(ViewHolder viewHolder) { viewHolder.itemView.setTag(extra); viewHolder.itemView.setOnClickListener(onClickListener); viewHolder.itemView.setOnLongClickListener(onLongClickListener); viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(viewHolder.itemView.getContext(), extra.is_viewed ? android.R.color.transparent : R.color.color_yellow0)); - viewHolder.asnName.setText(Network.toString(viewHolder.asnName.getContext(), extra.network)); - viewHolder.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); + viewHolder.binding.asnName.setText(Network.toString(viewHolder.binding.asnName.getContext(), extra.network)); + viewHolder.binding.startTime.setText(DateFormat.format(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yMdHm"), extra.start_time)); Long blocked = extra.countAnomalousMeasurements(); Long tested = extra.countTotalMeasurements(); - viewHolder.failedMeasurements.setText(viewHolder.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Websites_Blocked, blocked.intValue(), blocked.toString())); - viewHolder.testedMeasurements.setText(viewHolder.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Websites_Tested, tested.intValue(), tested.toString())); - viewHolder.failedMeasurements.setTextColor(ContextCompat.getColor(viewHolder.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); - DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.failedMeasurements.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); + viewHolder.binding.failedMeasurements.setText(viewHolder.binding.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Websites_Blocked, blocked.intValue(), blocked.toString())); + viewHolder.binding.testedMeasurements.setText(viewHolder.binding.failedMeasurements.getContext().getResources().getQuantityString(R.plurals.TestResults_Overview_Websites_Tested, tested.intValue(), tested.toString())); + viewHolder.binding.failedMeasurements.setTextColor(ContextCompat.getColor(viewHolder.binding.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); + DrawableCompat.setTint(DrawableCompat.wrap(viewHolder.binding.failedMeasurements.getCompoundDrawablesRelative()[0]).mutate(), ContextCompat.getColor(viewHolder.binding.failedMeasurements.getContext(), blocked == 0 ? R.color.color_gray9 : R.color.color_yellow9)); boolean allUploaded = true; for (Measurement m : extra.getMeasurements()) allUploaded = allUploaded && (m.isUploaded() || m.is_failed); - viewHolder.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); + viewHolder.binding.startTime.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, allUploaded ? 0 : R.drawable.cloudoff, 0); } - class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.asnName) TextView asnName; - @BindView(R.id.startTime) TextView startTime; - @BindView(R.id.failedMeasurements) TextView failedMeasurements; - @BindView(R.id.testedMeasurements) TextView testedMeasurements; + public static class ViewHolder extends RecyclerView.ViewHolder { + ItemWebsitesBinding binding; - ViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + ViewHolder(ItemWebsitesBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } \ No newline at end of file