Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 39 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2 gabriel 1
package com.cesams.twogetskills.adapter;
2
 
3
 
4
import android.content.Context;
25 gabriel 5
import android.graphics.Color;
2 gabriel 6
import android.view.LayoutInflater;
7
import android.view.View;
8
import android.view.ViewGroup;
11 gabriel 9
import android.widget.Button;
2 gabriel 10
import android.widget.TextView;
11
import androidx.annotation.NonNull;
25 gabriel 12
import androidx.cardview.widget.CardView;
2 gabriel 13
import androidx.recyclerview.widget.RecyclerView;
14
import com.cesams.twogetskills.R;
15
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
16
import java.util.ArrayList;
17
import java.util.HashMap;
18
 
19
public class CardViewAdapter extends RecyclerView.Adapter<CardViewAdapter.MyViewHolder> {
20
 
21
    private ArrayList<HashMap<String, String>> mDataSet;
22
 
23
    private ClickListener clickListener;
24
    private View.OnFocusChangeListener focusChangeListener;
25
    private Context mContext;
26
    private ITwoGetSkills iTwoGetSkills;
27
 
28
    public CardViewAdapter(Context context, ArrayList<HashMap<String, String>> mDataSet) {
29
        this.mDataSet = mDataSet;
30
        this.mContext = context;
31
        this.iTwoGetSkills = (ITwoGetSkills) context;
32
    }
33
 
34
    @NonNull
35
    @Override
36
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
11 gabriel 37
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.notification_item, parent, false);
2 gabriel 38
        return new MyViewHolder(v);
39
    }
40
 
41
    @Override
42
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
43
        HashMap<String, String> data = mDataSet.get(position);
44
        holder.bindData(data);
45
    }
46
 
47
    @Override
48
    public int getItemCount() {
49
        return (mDataSet != null) ? mDataSet.size() : 0;
50
    }
51
 
52
    public String getItem(int position) {
53
        return (mDataSet != null) ? String.valueOf(mDataSet.get(position)) : null;
54
    }
55
 
56
    void setOnFocusChangeListener(View.OnFocusChangeListener focusChangeListener){
57
        this.focusChangeListener = focusChangeListener;
58
    }
59
 
60
 
61
 
62
    public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
63
 
64
        private TextView titulo;
11 gabriel 65
        private TextView descripcion;
66
        private Button cerrar;
25 gabriel 67
        private CardView card;
2 gabriel 68
 
69
 
70
        public MyViewHolder(@NonNull View itemView) {
71
            super(itemView);
11 gabriel 72
            titulo = itemView.findViewById(R.id.titlenotifi);
73
            descripcion = itemView.findViewById(R.id.description);
74
            cerrar = itemView.findViewById(R.id.button);
25 gabriel 75
            card = itemView.findViewById(R.id.card_notifi);
2 gabriel 76
 
77
            if (clickListener != null) {
25 gabriel 78
                card.setFocusable(true);
79
                card.setOnClickListener(this);
2 gabriel 80
 
81
 
82
            }
83
        }
84
 
85
        public void bindData(final HashMap<String, String> data) {
86
 
87
            data.entrySet();
88
 
53 gabriel 89
            String title, descripciones,color;
2 gabriel 90
 
11 gabriel 91
            title= data.get("titulo");
92
            descripciones=data.get("descripcion");
25 gabriel 93
            color=data.get("color");
2 gabriel 94
 
39 gabriel 95
 
96
 
97
            if (!color.equals(""))
25 gabriel 98
            {
99
                card.setCardBackgroundColor(Color.WHITE);
100
            }
11 gabriel 101
 
25 gabriel 102
 
11 gabriel 103
            if(titulo != null)
2 gabriel 104
            {
11 gabriel 105
                titulo.setText(title);
2 gabriel 106
 
107
            }
108
 
11 gabriel 109
          if(descripciones != null)
110
          {
111
              descripcion.setText(descripciones);
112
          }
2 gabriel 113
 
114
        }
115
 
116
        @Override
117
        public void onClick(View v) {
118
            if (clickListener != null) {
119
                clickListener.onItemClick(getBindingAdapterPosition(), v);
120
            }
121
        }
122
 
123
 
124
 
125
    }
126
 
25 gabriel 127
    // allows clicks events to be caught
128
    public void setClickListener(ClickListener itemClickListener) {
129
        this.clickListener = itemClickListener;
130
    }
131
 
2 gabriel 132
    public interface ClickListener {
133
        void onItemClick(int position, View v);
134
    }
135
 
136
}