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;
18 efrain 4
import android.media.Image;
1 gabriel 5
import android.util.Log;
6
import android.view.LayoutInflater;
7
import android.view.View;
8
import android.view.ViewGroup;
9
import android.widget.ImageView;
10
import android.widget.ProgressBar;
11
import android.widget.TextView;
12
 
13
import androidx.recyclerview.widget.RecyclerView;
14
 
18 efrain 15
 
1 gabriel 16
import com.cesams.twogetskills.inconcert.Constants;
17
import com.cesams.twogetskills.inconcert.R;
18
import com.cesams.twogetskills.inconcert.entity.Capsule;
18 efrain 19
import com.cesams.twogetskills.inconcert.library.ImageService;
1 gabriel 20
import com.cesams.twogetskills.inconcert.library.MD5;
21
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;
22
 
23
import java.text.DecimalFormat;
24
import java.util.List;
25
 
18 efrain 26
 
1 gabriel 27
public class CapsuleListViewAdapter extends RecyclerView.Adapter<CapsuleListViewAdapter.ViewHolder> {
28
    private final static String TAG = "C2GS - CapsuleAdapter";
29
    private List<Capsule> mData;
30
    private LayoutInflater mInflater;
31
    private ItemClickListener mClickListener;
32
    private Context mContext;
33
    private ITwoGetSkills iTwoGetSkills;
34
    private DecimalFormat mDecimalFormat;
35
 
36
 
37
    // data is passed into the constructor
38
    public CapsuleListViewAdapter(Context context, List<Capsule> data) {
39
        this.mContext = context;
40
        this.iTwoGetSkills = (ITwoGetSkills) context;
41
        this.mInflater = LayoutInflater.from(context);
42
        this.mData = data;
43
        this.mDecimalFormat = new DecimalFormat("#.##");
44
    }
45
 
46
    // inflates the row layout from xml when needed
47
    @Override
48
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
49
        View view = mInflater.inflate(R.layout.fragment_capsule_listitem, parent, false);
50
        return new ViewHolder(view);
51
    }
52
 
53
    /*
54
    public void updateCapsuleList(final List<Capsule> mData) {
55
        this.mData.clear();
56
        this.mData = mData;
57
 
58
        Log.d(TAG, "Notificando el cambio al adaptador");
59
        notifyDataSetChanged();
60
    }
61
    */
62
 
63
 
64
    // binds the data to the TextView in each row
65
    @Override
66
    public void onBindViewHolder(ViewHolder holder, int position) {
67
        Capsule mItem = mData.get(position);
68
        holder.mName.setText(mItem.getName());
69
 
70
        /*
71
        ProgressDao progressDao = new ProgressDao(mContext);
72
        Progress progress = progressDao.selectByCapsuleUuid(mItem.uuid);
73
        progressDao.close();
74
 
75
        if(progress == null) {
76
            holder.mProgressbar.setMax(100);
77
            holder.mProgressbar.setProgress(0);
78
            holder.mProgreess.setText("0 %");
79
        } else {
80
            holder.mProgressbar.setMax(progress.totalSlides);
81
            holder.mProgressbar.setProgress(progress.viewSlides);
82
            holder.mProgreess.setText(mDecimalFormat.format(progress.progress) + " %");
83
        }*/
84
 
85
        holder.mProgressbar.setMax(mItem.getTotalSlides());
86
        holder.mProgressbar.setProgress(mItem.getViewSlides());
87
        holder.mProgreess.setText(mDecimalFormat.format(mItem.getProgress()) + " %");
88
 
18 efrain 89
        ImageService.retrieve(mContext, mItem.getImage(), holder.mImage);
1 gabriel 90
 
91
 
92
    }
93
 
94
    // total number of rows
95
    @Override
96
    public int getItemCount() {
97
        return mData.size();
98
    }
99
 
100
 
101
    // stores and recycles views as they are scrolled off screen
102
    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
103
        TextView mName;
104
        //TextView mDescription;
105
        //JustifyTextView mDescription;
106
        ImageView mImage;
107
        ProgressBar mProgressbar;
108
        TextView mProgreess;
109
 
110
 
111
        ViewHolder(View itemView) {
112
            super(itemView);
113
            mName = (TextView) itemView.findViewById(R.id.fragment_capsule_listitem_name);
114
            mImage = (ImageView) itemView.findViewById(R.id.fragment_capsule_listitem_image);
115
            mProgreess = (TextView) itemView.findViewById(R.id.fragment_capsule_listitem_progress);
116
            mProgressbar = (ProgressBar) itemView.findViewById(R.id.fragment_capsule_listitem_progressbar);
117
            itemView.setOnClickListener(this);
118
        }
119
 
120
        @Override
121
        public void onClick(View view) {
122
            if (mClickListener != null) {
19 efrain 123
                mClickListener.onItemClick(view, getAbsoluteAdapterPosition());
1 gabriel 124
            }
125
        }
126
    }
127
 
128
    // convenience method for getting data at click position
129
    public Capsule getItem(int id) {
130
        return mData.get(id);
131
    }
132
 
133
    // allows clicks events to be caught
134
    public void setClickListener(ItemClickListener itemClickListener) {
135
        this.mClickListener = itemClickListener;
136
    }
137
 
138
    // parent activity will implement this method to respond to click events
139
    public interface ItemClickListener {
140
        public void onItemClick(View view, int position);
141
    }
142
}