Rev 1 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
package com.cesams.twogetskills.inconcert.adapter;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.cesams.twogetskills.inconcert.Constants;
import com.cesams.twogetskills.inconcert.R;
import com.cesams.twogetskills.inconcert.entity.Topic;
import com.cesams.twogetskills.inconcert.library.ImageService;
import com.cesams.twogetskills.inconcert.library.MD5;
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
import java.text.DecimalFormat;
import java.util.List;
public class TopicListViewAdapter extends RecyclerView.Adapter<TopicListViewAdapter.ViewHolder> {
private final static String TAG = "C2GS - TopicAdapter";
private List<Topic> mData;
private LayoutInflater mInflater;
private ItemClickListener mClickListener;
private Context mContext;
private ITwoGetSkills iTwoGetSkills;
private DecimalFormat mDecimalFormat;
private final int imageWidthPixels = 1024;
private final int imageHeightPixels = 768;
// data is passed into the constructor
public TopicListViewAdapter(Context context, List<Topic> data) {
this.mData = data;
this.mContext = context;
this.iTwoGetSkills = (ITwoGetSkills) context;
this.mInflater = LayoutInflater.from(context);
this.mDecimalFormat = new DecimalFormat("#.##");
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d(TAG, "onCreateViewHolder");
View view = mInflater.inflate(R.layout.fragment_topic_listitem, parent, false);
//View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_topic_listitem,parent,false);
return new ViewHolder(view);
}
// binds the data to the TextView in each row
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Log.d(TAG, "onBindViewHolder");
Topic mItem = mData.get(position);
holder.mName.setText(mItem.getName());
holder.mProgressbar.setMax(mItem.getTotalSlides());
holder.mProgressbar.setProgress(mItem.getViewSlides());
holder.mProgress.setText(mDecimalFormat.format(mItem.getProgress()) + " %");
ImageService.retrieve(mContext, mItem.getImage(), holder.mImage);
}
// total number of rows
@Override
public int getItemCount() {
return mData.size();
}
// stores and recycles views as they are scrolled off screen
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView mName;
ImageView mImage;
ProgressBar mProgressbar;
TextView mProgress;
ViewHolder(View itemView) {
super(itemView);
mName = (TextView) itemView.findViewById(R.id.fragment_topic_listitem_name);
mImage = (ImageView) itemView.findViewById(R.id.fragment_topic_listitem_image);
mProgress = (TextView) itemView.findViewById(R.id.fragment_topic_listitem_progress);
mProgressbar = (ProgressBar) itemView.findViewById(R.id.fragment_topic_listitem_progressbar);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (mClickListener != null) {
mClickListener.onItemClick(view, getAdapterPosition());
}
}
}
// convenience method for getting data at click position
public Topic getItem(int id) {
return mData.get(id);
}
// allows clicks events to be caught
public void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}
// parent activity will implement this method to respond to click events
public interface ItemClickListener {
public void onItemClick(View view, int position);
}
}