2016-08-20 17:26:49 +02:00
|
|
|
package com.topjohnwu.magisk.rv;
|
|
|
|
|
2016-08-21 15:29:42 +02:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
2016-08-20 17:26:49 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-08-21 16:08:45 +02:00
|
|
|
import android.widget.ImageView;
|
2016-08-20 17:26:49 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.topjohnwu.magisk.R;
|
|
|
|
import com.topjohnwu.magisk.model.Module;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-08-21 15:29:42 +02:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2016-08-20 17:26:49 +02:00
|
|
|
|
2016-08-21 15:29:42 +02:00
|
|
|
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
|
|
|
|
|
|
|
private final List<Module> mList;
|
2016-08-21 16:08:45 +02:00
|
|
|
private final ItemClickListener mListener;
|
2016-08-21 15:29:42 +02:00
|
|
|
|
2016-08-21 16:08:45 +02:00
|
|
|
public ModulesAdapter(List<Module> list, ItemClickListener listener) {
|
|
|
|
this.mList = list;
|
|
|
|
this.mListener = listener;
|
2016-08-20 17:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-21 15:29:42 +02:00
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2016-08-21 17:21:37 +02:00
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
|
2016-08-21 15:29:42 +02:00
|
|
|
|
|
|
|
return new ViewHolder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-21 16:08:45 +02:00
|
|
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
2016-08-21 15:29:42 +02:00
|
|
|
Module module = mList.get(position);
|
2016-08-20 17:26:49 +02:00
|
|
|
|
2016-08-21 15:29:42 +02:00
|
|
|
holder.title.setText(module.getName());
|
|
|
|
holder.versionName.setText(module.getVersion());
|
|
|
|
holder.description.setText(module.getDescription());
|
2016-08-20 17:26:49 +02:00
|
|
|
|
2016-08-21 16:08:45 +02:00
|
|
|
holder.overflowButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
mListener.onItemClick(holder.overflowButton, holder.getAdapterPosition());
|
|
|
|
}
|
|
|
|
});
|
2016-08-21 15:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return mList.size();
|
2016-08-20 17:26:49 +02:00
|
|
|
}
|
|
|
|
|
2016-08-21 15:29:42 +02:00
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
@BindView(R.id.title) TextView title;
|
|
|
|
@BindView(R.id.version_name) TextView versionName;
|
|
|
|
@BindView(R.id.description) TextView description;
|
2016-08-21 16:08:45 +02:00
|
|
|
@BindView(R.id.overflow) ImageView overflowButton;
|
2016-08-21 15:29:42 +02:00
|
|
|
|
|
|
|
public ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
ButterKnife.bind(this, itemView);
|
|
|
|
}
|
2016-08-20 17:26:49 +02:00
|
|
|
}
|
|
|
|
}
|