| 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 |
{
|
| 25 |
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();
|
| 39 |
gabriel |
145 |
|
| 9 |
gabriel |
146 |
}
|
| 11 |
gabriel |
147 |
|
| 25 |
gabriel |
148 |
@Override
|
| 39 |
gabriel |
149 |
public void onHiddenChanged(boolean hidden) {
|
|
|
150 |
super.onHiddenChanged(hidden);
|
| 41 |
gabriel |
151 |
if(!hidden) {
|
|
|
152 |
loaddata();
|
|
|
153 |
}
|
| 39 |
gabriel |
154 |
}
|
|
|
155 |
|
|
|
156 |
@Override
|
| 25 |
gabriel |
157 |
public void onItemClick(int position, View v) {
|
|
|
158 |
Log.e("Aqui", "pise en el fragment"+position);
|
| 34 |
gabriel |
159 |
// notificacionList.get(position).put("color","white");
|
| 39 |
gabriel |
160 |
// loaddata();
|
| 25 |
gabriel |
161 |
|
| 39 |
gabriel |
162 |
if(!notificacionList.get(position).get("url").equals(""))
|
|
|
163 |
{
|
|
|
164 |
Log.e("Tiene url", "vamos alla");
|
|
|
165 |
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notificacionList.get(position).get("url")));
|
|
|
166 |
startActivity(browserIntent);
|
|
|
167 |
}
|
|
|
168 |
else
|
|
|
169 |
{
|
|
|
170 |
Log.e("No hay url", "no hago nada");
|
|
|
171 |
}
|
| 25 |
gabriel |
172 |
}
|
| 9 |
gabriel |
173 |
}
|