Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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