Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

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