Skip to content

Commit

Permalink
Replace Butterknife in TestsuiteItem
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Aug 26, 2023
1 parent 9a7bd4f commit 0182e61
Showing 1 changed file with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package org.openobservatory.ooniprobe.item;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.databinding.ItemTestsuiteBinding;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;

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

public class TestsuiteItem extends HeterogeneousRecyclerItem<AbstractSuite, TestsuiteItem.ViewHolderImpl> {
private final View.OnClickListener onClickListener;
private final PreferenceManager preferenceManager;
Expand All @@ -33,36 +24,34 @@ public TestsuiteItem(AbstractSuite extra, View.OnClickListener onClickListener,
}

@Override public ViewHolderImpl onCreateViewHolder(LayoutInflater layoutInflater, ViewGroup viewGroup) {
return new ViewHolderImpl(layoutInflater.inflate(R.layout.item_testsuite, viewGroup, false));
return new ViewHolderImpl(ItemTestsuiteBinding.inflate(layoutInflater, viewGroup, false));
}

@Override public void onBindViewHolder(ViewHolderImpl holder) {
holder.title.setText(extra.getTitle());
holder.desc.setText(extra.getCardDesc());
holder.icon.setImageResource(extra.getIconGradient());
holder.binding.title.setText(extra.getTitle());
holder.binding.desc.setText(extra.getCardDesc());
holder.binding.icon.setImageResource(extra.getIconGradient());
holder.itemView.setTag(extra);
if(extra.isTestEmpty(preferenceManager)) {
((CardView)holder.itemView).setElevation(0);
Resources resources = holder.itemView.getContext().getResources();
((CardView)holder.itemView).setCardBackgroundColor(resources.getColor(R.color.disabled_test_background));
holder.title.setTextColor(resources.getColor(R.color.disabled_test_text));
holder.desc.setTextColor(resources.getColor(R.color.disabled_test_text));
holder.icon.setColorFilter(resources.getColor(R.color.disabled_test_text), PorterDuff.Mode.SRC_IN);
holder.binding.title.setTextColor(resources.getColor(R.color.disabled_test_text));
holder.binding.desc.setTextColor(resources.getColor(R.color.disabled_test_text));
holder.binding.icon.setColorFilter(resources.getColor(R.color.disabled_test_text), PorterDuff.Mode.SRC_IN);
holder.setIsRecyclable(false);
holder.itemView.setClickable(false);
} else {
holder.itemView.setOnClickListener(onClickListener);
}
}

class ViewHolderImpl extends RecyclerView.ViewHolder {
@BindView(R.id.title) TextView title;
@BindView(R.id.desc) TextView desc;
@BindView(R.id.icon) ImageView icon;
static class ViewHolderImpl extends RecyclerView.ViewHolder {
ItemTestsuiteBinding binding;

ViewHolderImpl(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
ViewHolderImpl(ItemTestsuiteBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}

0 comments on commit 0182e61

Please sign in to comment.