Proyectos de Subversion Android Microlearning - Inconcert

Rev

Rev 18 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 gabriel 1
package com.cesams.twogetskills.inconcert.adapter;
2
 
3
import android.content.Context;
4
import android.util.Log;
5
import android.view.LayoutInflater;
6
import android.view.View;
7
import android.view.ViewGroup;
8
import android.widget.ImageView;
9
import android.widget.ProgressBar;
10
import android.widget.TextView;
11
 
12
import androidx.recyclerview.widget.RecyclerView;
13
 
18 efrain 14
 
1 gabriel 15
import com.cesams.twogetskills.inconcert.Constants;
16
import com.cesams.twogetskills.inconcert.R;
17
import com.cesams.twogetskills.inconcert.entity.Topic;
18 efrain 18
import com.cesams.twogetskills.inconcert.library.ImageService;
1 gabriel 19
import com.cesams.twogetskills.inconcert.library.MD5;
20
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
21
 
22
 
23
 
24
import java.text.DecimalFormat;
25
import java.util.List;
26
 
18 efrain 27
 
1 gabriel 28
public class TopicListViewAdapter extends RecyclerView.Adapter<TopicListViewAdapter.ViewHolder> {
29
    private final static String TAG = "C2GS - TopicAdapter";
30
    private List<Topic> mData;
31
    private LayoutInflater mInflater;
32
    private ItemClickListener mClickListener;
33
    private Context mContext;
34
    private ITwoGetSkills iTwoGetSkills;
35
    private DecimalFormat mDecimalFormat;
36
    private final int imageWidthPixels = 1024;
37
    private final int imageHeightPixels = 768;
38
 
39
 
40
    // data is passed into the constructor
41
    public TopicListViewAdapter(Context context, List<Topic> data) {
42
        this.mData =  data;
43
        this.mContext = context;
44
        this.iTwoGetSkills = (ITwoGetSkills) context;
45
        this.mInflater = LayoutInflater.from(context);
46
        this.mDecimalFormat = new DecimalFormat("#.##");
47
    }
48
 
49
    @Override
50
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
51
        Log.d(TAG, "onCreateViewHolder");
52
       View view = mInflater.inflate(R.layout.fragment_topic_listitem, parent, false);
53
 
54
        //View view =  LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_topic_listitem,parent,false);
55
        return new ViewHolder(view);
56
    }
57
 
58
    // binds the data to the TextView in each row
59
    @Override
60
    public void onBindViewHolder(ViewHolder holder, int position) {
61
        Log.d(TAG, "onBindViewHolder");
62
 
63
        Topic mItem = mData.get(position);
64
        holder.mName.setText(mItem.getName());
65
 
66
 
67
 
68
        holder.mProgressbar.setMax(mItem.getTotalSlides());
69
        holder.mProgressbar.setProgress(mItem.getViewSlides());
70
        holder.mProgress.setText(mDecimalFormat.format(mItem.getProgress()) + " %");
71
 
18 efrain 72
        ImageService.retrieve(mContext, mItem.getImage(), holder.mImage);
1 gabriel 73
    }
74
 
75
    // total number of rows
76
    @Override
77
    public int getItemCount() {
78
        return mData.size();
79
    }
80
 
81
 
82
    // stores and recycles views as they are scrolled off screen
83
    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
84
        TextView mName;
85
        ImageView mImage;
86
        ProgressBar mProgressbar;
87
        TextView mProgress;
88
 
89
 
90
 
91
        ViewHolder(View itemView) {
92
            super(itemView);
93
            mName = (TextView) itemView.findViewById(R.id.fragment_topic_listitem_name);
94
            mImage = (ImageView) itemView.findViewById(R.id.fragment_topic_listitem_image);
95
            mProgress = (TextView) itemView.findViewById(R.id.fragment_topic_listitem_progress);
96
            mProgressbar = (ProgressBar) itemView.findViewById(R.id.fragment_topic_listitem_progressbar);
97
            itemView.setOnClickListener(this);
98
        }
99
 
100
        @Override
101
        public void onClick(View view) {
102
            if (mClickListener != null) {
19 efrain 103
                mClickListener.onItemClick(view, getAbsoluteAdapterPosition());
1 gabriel 104
            }
105
        }
106
    }
107
 
108
    // convenience method for getting data at click position
109
    public Topic getItem(int id) {
110
        return mData.get(id);
111
    }
112
 
113
    // allows clicks events to be caught
114
    public void setClickListener(ItemClickListener itemClickListener) {
115
        this.mClickListener = itemClickListener;
116
    }
117
 
118
    // parent activity will implement this method to respond to click events
119
    public interface ItemClickListener {
120
        public void onItemClick(View view, int position);
121
    }
18 efrain 122
}