Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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

Rev Autor Línea Nro. Línea
9 gabriel 1
package com.cesams.twogetskills.fragment;
2
 
39 gabriel 3
import android.content.Intent;
25 gabriel 4
import android.graphics.Color;
39 gabriel 5
import android.net.Uri;
9 gabriel 6
import android.os.Bundle;
7
 
25 gabriel 8
import androidx.cardview.widget.CardView;
9 gabriel 9
import androidx.fragment.app.Fragment;
11 gabriel 10
import androidx.recyclerview.widget.GridLayoutManager;
39 gabriel 11
import androidx.recyclerview.widget.LinearLayoutManager;
11 gabriel 12
import androidx.recyclerview.widget.RecyclerView;
9 gabriel 13
 
39 gabriel 14
import android.os.Handler;
25 gabriel 15
import android.text.format.DateFormat;
11 gabriel 16
import android.util.Log;
9 gabriel 17
import android.view.LayoutInflater;
18
import android.view.View;
19
import android.view.ViewGroup;
11 gabriel 20
import android.widget.TextView;
9 gabriel 21
 
25 gabriel 22
import com.cesams.twogetskills.Constants;
9 gabriel 23
import com.cesams.twogetskills.R;
11 gabriel 24
import com.cesams.twogetskills.adapter.CardViewAdapter;
25
import com.cesams.twogetskills.dao.NotificationCenterDao;
26
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
9 gabriel 27
 
25 gabriel 28
import java.text.SimpleDateFormat;
11 gabriel 29
import java.util.ArrayList;
25 gabriel 30
import java.util.Calendar;
39 gabriel 31
import java.util.Collections;
25 gabriel 32
import java.util.Date;
11 gabriel 33
import java.util.HashMap;
34
import java.util.List;
35
 
9 gabriel 36
/**
37
 * A simple {@link Fragment} subclass.
38
 * Use the {@link NotificationCenter#newInstance} factory method to
39
 * create an instance of this fragment.
40
 */
25 gabriel 41
public class NotificationCenter extends Fragment implements CardViewAdapter.ClickListener {
9 gabriel 42
 
11 gabriel 43
   RecyclerView notificaciones;
44
   CardViewAdapter notificacionadapter;
45
   private ITwoGetSkills iTwoGetSkills;
46
   TextView notienenuevas;
9 gabriel 47
 
11 gabriel 48
    ArrayList<HashMap<String, String>> notificacionList;
9 gabriel 49
 
11 gabriel 50
 
9 gabriel 51
    public NotificationCenter() {
52
        // Required empty public constructor
53
    }
54
 
11 gabriel 55
    public static NotificationCenter newInstance() {
9 gabriel 56
        NotificationCenter fragment = new NotificationCenter();
57
        return fragment;
58
    }
59
 
60
    @Override
61
    public void onCreate(Bundle savedInstanceState) {
62
        super.onCreate(savedInstanceState);
11 gabriel 63
 
9 gabriel 64
    }
65
 
66
    @Override
67
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
68
                             Bundle savedInstanceState) {
11 gabriel 69
        View view =inflater.inflate(R.layout.fragment_notification_center, container, false);
70
 
71
        iTwoGetSkills = (ITwoGetSkills) getActivity();
72
 
73
        notificaciones = view.findViewById(R.id.notificacioneslista);
74
 
75
        notificacionList= new ArrayList<>();
76
        notienenuevas= view.findViewById(R.id.textView18);
77
        notienenuevas.setVisibility(View.VISIBLE);
78
 
79
        notificacionadapter = new CardViewAdapter(getContext(),notificacionList);
80
 
39 gabriel 81
        LinearLayoutManager layoutnotifi = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL, true);
82
        layoutnotifi.setStackFromEnd(true);
83
 
11 gabriel 84
        notificaciones.setLayoutManager(layoutnotifi);
85
        notificaciones.setAdapter(notificacionadapter);
86
 
25 gabriel 87
        notificacionadapter.setClickListener(this);
34 gabriel 88
 
39 gabriel 89
       // loaddata();
34 gabriel 90
 
91
 
92
        return view;
93
    }
94
 
95
    private void loaddata(){
96
 
97
        notificacionList.clear();
11 gabriel 98
        NotificationCenterDao notificacionDao;
99
 
100
        notificacionDao =iTwoGetSkills.getDatabase().getNotificationCenterDao();
101
 
25 gabriel 102
        //Log.e("Notificaciones","estas:"+notificacionDao.selectAllNotification().toString());
11 gabriel 103
 
104
        List<com.cesams.twogetskills.entity.NotificationCenter> lista;
105
        lista=notificacionDao.selectAllNotification();
106
 
107
        HashMap<String, String> m_li;
108
 
109
        for(com.cesams.twogetskills.entity.NotificationCenter notificacion: lista)
110
        {
43 gabriel 111
            Log.e("Esto",""+notificacion.getTitle());
11 gabriel 112
            m_li = new HashMap<>();
113
 
114
            m_li.put("titulo",notificacion.getTitle());
115
            m_li.put("date",notificacion.getDate());
116
            m_li.put("descripcion",notificacion.getDescription());
39 gabriel 117
           // Log.e("Viewer: ",notificacion.getViewed());
118
            m_li.put("color",notificacion.getViewed());
119
            m_li.put("url",notificacion.getUrl());
11 gabriel 120
 
121
            notificacionList.add(m_li);
122
            notienenuevas.setVisibility(View.GONE);
123
 
39 gabriel 124
            //Agregar notificacion a la lista de vista
125
            com.cesams.twogetskills.entity.NotificationCenter notificacionupdate = new com.cesams.twogetskills.entity.NotificationCenter();
126
            notificacionupdate.setId(notificacion.getId());
127
            notificacionupdate.setDescription(notificacion.getDescription());
128
            notificacionupdate.setDate(notificacion.getDate());
129
            notificacionupdate.setTitle(notificacion.getTitle());
130
            notificacionupdate.setUrl(notificacion.getUrl());
131
            notificacionupdate.setViewed("white");
132
            notificacionDao.update(notificacionupdate);
11 gabriel 133
 
134
            notificacionadapter.notifyDataSetChanged();
135
 
25 gabriel 136
 
11 gabriel 137
        }
34 gabriel 138
    }
11 gabriel 139
 
34 gabriel 140
    @Override
141
    public void onResume() {
142
        super.onResume();
39 gabriel 143
 
41 gabriel 144
        loaddata();
43 gabriel 145
        notificaciones.scrollTo(0, getView().getBottom());
39 gabriel 146
 
9 gabriel 147
    }
11 gabriel 148
 
25 gabriel 149
    @Override
39 gabriel 150
    public void onHiddenChanged(boolean hidden) {
151
        super.onHiddenChanged(hidden);
41 gabriel 152
        if(!hidden) {
153
            loaddata();
43 gabriel 154
            notificaciones.scrollTo(0, getView().getBottom());
155
 
41 gabriel 156
        }
39 gabriel 157
    }
158
 
159
    @Override
25 gabriel 160
    public void onItemClick(int position, View v) {
161
        Log.e("Aqui", "pise en el fragment"+position);
34 gabriel 162
        //        notificacionList.get(position).put("color","white");
39 gabriel 163
       // loaddata();
25 gabriel 164
 
43 gabriel 165
        if(!notificacionList.get(position).get("url").isEmpty())
39 gabriel 166
        {
167
            Log.e("Tiene url", "vamos alla");
168
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notificacionList.get(position).get("url")));
169
            startActivity(browserIntent);
170
        }
171
        else
172
        {
173
            Log.e("No hay url", "no hago nada");
174
        }
25 gabriel 175
    }
9 gabriel 176
}