Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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

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