| 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 |
|
| 56 |
gabriel |
29 |
import java.text.ParseException;
|
| 25 |
gabriel |
30 |
import java.text.SimpleDateFormat;
|
| 11 |
gabriel |
31 |
import java.util.ArrayList;
|
| 25 |
gabriel |
32 |
import java.util.Calendar;
|
| 39 |
gabriel |
33 |
import java.util.Collections;
|
| 25 |
gabriel |
34 |
import java.util.Date;
|
| 11 |
gabriel |
35 |
import java.util.HashMap;
|
|
|
36 |
import java.util.List;
|
| 56 |
gabriel |
37 |
import java.util.Objects;
|
| 11 |
gabriel |
38 |
|
| 9 |
gabriel |
39 |
/**
|
|
|
40 |
* A simple {@link Fragment} subclass.
|
|
|
41 |
* Use the {@link NotificationCenter#newInstance} factory method to
|
|
|
42 |
* create an instance of this fragment.
|
|
|
43 |
*/
|
| 25 |
gabriel |
44 |
public class NotificationCenter extends Fragment implements CardViewAdapter.ClickListener {
|
| 9 |
gabriel |
45 |
|
| 11 |
gabriel |
46 |
RecyclerView notificaciones;
|
|
|
47 |
CardViewAdapter notificacionadapter;
|
|
|
48 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
49 |
TextView notienenuevas;
|
| 9 |
gabriel |
50 |
|
| 56 |
gabriel |
51 |
ArrayList<HashMap<String, String>> notificacionListToday;
|
| 9 |
gabriel |
52 |
|
| 11 |
gabriel |
53 |
|
| 9 |
gabriel |
54 |
public NotificationCenter() {
|
|
|
55 |
// Required empty public constructor
|
|
|
56 |
}
|
|
|
57 |
|
| 11 |
gabriel |
58 |
public static NotificationCenter newInstance() {
|
| 9 |
gabriel |
59 |
NotificationCenter fragment = new NotificationCenter();
|
|
|
60 |
return fragment;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
@Override
|
|
|
64 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
65 |
super.onCreate(savedInstanceState);
|
| 11 |
gabriel |
66 |
|
| 9 |
gabriel |
67 |
}
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
71 |
Bundle savedInstanceState) {
|
| 11 |
gabriel |
72 |
View view =inflater.inflate(R.layout.fragment_notification_center, container, false);
|
|
|
73 |
|
|
|
74 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
|
|
75 |
|
|
|
76 |
notificaciones = view.findViewById(R.id.notificacioneslista);
|
| 56 |
gabriel |
77 |
notificacionListToday= new ArrayList<>();
|
| 11 |
gabriel |
78 |
notienenuevas= view.findViewById(R.id.textView18);
|
|
|
79 |
notienenuevas.setVisibility(View.VISIBLE);
|
|
|
80 |
|
| 56 |
gabriel |
81 |
notificacionadapter = new CardViewAdapter(getContext(),notificacionListToday);
|
| 11 |
gabriel |
82 |
|
| 56 |
gabriel |
83 |
LinearLayoutManager layoutnotifi = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL, false);
|
|
|
84 |
layoutnotifi.setStackFromEnd(false);
|
| 39 |
gabriel |
85 |
|
| 11 |
gabriel |
86 |
notificaciones.setLayoutManager(layoutnotifi);
|
|
|
87 |
notificaciones.setAdapter(notificacionadapter);
|
|
|
88 |
|
| 25 |
gabriel |
89 |
notificacionadapter.setClickListener(this);
|
| 34 |
gabriel |
90 |
|
| 39 |
gabriel |
91 |
// loaddata();
|
| 34 |
gabriel |
92 |
|
|
|
93 |
|
|
|
94 |
return view;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
private void loaddata(){
|
| 56 |
gabriel |
98 |
iTwoGetSkills.setTitleActionBar("Centro de notificaciones");
|
| 34 |
gabriel |
99 |
|
| 56 |
gabriel |
100 |
notificacionListToday.clear();
|
| 11 |
gabriel |
101 |
NotificationCenterDao notificacionDao;
|
|
|
102 |
|
|
|
103 |
notificacionDao =iTwoGetSkills.getDatabase().getNotificationCenterDao();
|
|
|
104 |
|
| 25 |
gabriel |
105 |
//Log.e("Notificaciones","estas:"+notificacionDao.selectAllNotification().toString());
|
| 11 |
gabriel |
106 |
|
| 56 |
gabriel |
107 |
List<com.cesams.twogetskills.entity.NotificationCenter> grupo;
|
|
|
108 |
grupo=notificacionDao.selectAllNotificationOrderDay();
|
| 11 |
gabriel |
109 |
|
| 56 |
gabriel |
110 |
boolean hoy = false,ayer=false,other=false;
|
| 11 |
gabriel |
111 |
|
| 56 |
gabriel |
112 |
for (com.cesams.twogetskills.entity.NotificationCenter notificaciongrupos: grupo){
|
| 11 |
gabriel |
113 |
|
| 56 |
gabriel |
114 |
String diaactual= notificaciongrupos.getDate();
|
| 11 |
gabriel |
115 |
|
| 56 |
gabriel |
116 |
List<com.cesams.twogetskills.entity.NotificationCenter> lista;
|
|
|
117 |
lista=notificacionDao.selectAllNotificationInDay(diaactual);
|
| 11 |
gabriel |
118 |
|
| 56 |
gabriel |
119 |
HashMap<String, String> m_li,dias;
|
| 11 |
gabriel |
120 |
|
| 56 |
gabriel |
121 |
for(com.cesams.twogetskills.entity.NotificationCenter notificacion: lista)
|
|
|
122 |
{
|
|
|
123 |
m_li = new HashMap<>(); dias = new HashMap<>();
|
| 11 |
gabriel |
124 |
|
| 56 |
gabriel |
125 |
m_li.put("titulo",notificacion.getTitle());
|
|
|
126 |
m_li.put("date",notificacion.getDate());
|
|
|
127 |
m_li.put("descripcion",notificacion.getDescription());
|
|
|
128 |
m_li.put("color",notificacion.getViewed());
|
|
|
129 |
m_li.put("url",notificacion.getUrl());
|
|
|
130 |
dias.put("titulo","");
|
|
|
131 |
dias.put("date",notificacion.getDate());
|
|
|
132 |
dias.put("descripcion","");
|
|
|
133 |
dias.put("color","");
|
|
|
134 |
dias.put("url","");
|
| 25 |
gabriel |
135 |
|
| 56 |
gabriel |
136 |
Calendar calendar = Calendar.getInstance();
|
|
|
137 |
Date date = calendar.getTime();
|
|
|
138 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.FORMAT_DATE_SERVICE);
|
|
|
139 |
String dateOn = simpleDateFormat.format(date);
|
|
|
140 |
|
|
|
141 |
|
|
|
142 |
final Calendar cal = Calendar.getInstance();
|
|
|
143 |
cal.add(Calendar.DATE, -1);
|
|
|
144 |
Date date2 = cal.getTime();
|
|
|
145 |
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat(Constants.FORMAT_DATE_SERVICE);
|
|
|
146 |
String dateOn2 = simpleDateFormat2.format(date2);
|
|
|
147 |
|
|
|
148 |
if(Objects.equals(notificacion.getDate(), dateOn))
|
|
|
149 |
{
|
|
|
150 |
if(!hoy){
|
|
|
151 |
|
|
|
152 |
dias.put("day","today");
|
|
|
153 |
notificacionListToday.add(dias);
|
|
|
154 |
hoy=true;
|
|
|
155 |
}
|
|
|
156 |
m_li.put("day","");
|
|
|
157 |
notificacionListToday.add(m_li);
|
|
|
158 |
|
|
|
159 |
}
|
|
|
160 |
else if (Objects.equals(notificacion.getDate(), dateOn2))
|
|
|
161 |
{
|
|
|
162 |
if(!ayer){
|
|
|
163 |
dias.put("day","yesterday");
|
|
|
164 |
notificacionListToday.add(dias);
|
|
|
165 |
ayer=true;
|
|
|
166 |
}
|
|
|
167 |
m_li.put("day","");
|
|
|
168 |
notificacionListToday.add(m_li);
|
|
|
169 |
|
|
|
170 |
}
|
|
|
171 |
else if(!Objects.equals(notificacion.getDate(), dateOn) || !Objects.equals(notificacion.getDate(), dateOn2)) {
|
|
|
172 |
|
|
|
173 |
if(!other){
|
|
|
174 |
|
|
|
175 |
dias.put("day","other");
|
|
|
176 |
notificacionListToday.add(dias);
|
|
|
177 |
other=true;
|
|
|
178 |
}
|
|
|
179 |
m_li.put("day","");
|
|
|
180 |
notificacionListToday.add(m_li);
|
|
|
181 |
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
notienenuevas.setVisibility(View.GONE);
|
|
|
186 |
|
|
|
187 |
//Agregar notificacion a la lista de vistas
|
|
|
188 |
com.cesams.twogetskills.entity.NotificationCenter notificacionupdate = new com.cesams.twogetskills.entity.NotificationCenter();
|
|
|
189 |
notificacionupdate.setId(notificacion.getId());
|
|
|
190 |
notificacionupdate.setDescription(notificacion.getDescription());
|
|
|
191 |
notificacionupdate.setDate(notificacion.getDate());
|
|
|
192 |
notificacionupdate.setTitle(notificacion.getTitle());
|
|
|
193 |
notificacionupdate.setUrl(notificacion.getUrl());
|
|
|
194 |
notificacionupdate.setViewed("white");
|
|
|
195 |
notificacionDao.update(notificacionupdate);
|
|
|
196 |
|
|
|
197 |
notificacionadapter.notifyItemChanged(notificacionListToday.size()-1);
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
|
| 11 |
gabriel |
203 |
}
|
| 34 |
gabriel |
204 |
}
|
| 11 |
gabriel |
205 |
|
| 34 |
gabriel |
206 |
@Override
|
|
|
207 |
public void onResume() {
|
|
|
208 |
super.onResume();
|
| 39 |
gabriel |
209 |
|
| 53 |
gabriel |
210 |
getActivity().runOnUiThread(new Runnable() {
|
|
|
211 |
@Override
|
|
|
212 |
public void run() {
|
|
|
213 |
loaddata();
|
|
|
214 |
|
|
|
215 |
}
|
|
|
216 |
});
|
| 43 |
gabriel |
217 |
notificaciones.scrollTo(0, getView().getBottom());
|
| 39 |
gabriel |
218 |
|
| 9 |
gabriel |
219 |
}
|
| 11 |
gabriel |
220 |
|
| 25 |
gabriel |
221 |
@Override
|
| 39 |
gabriel |
222 |
public void onHiddenChanged(boolean hidden) {
|
|
|
223 |
super.onHiddenChanged(hidden);
|
| 41 |
gabriel |
224 |
if(!hidden) {
|
| 53 |
gabriel |
225 |
|
|
|
226 |
getActivity().runOnUiThread(new Runnable() {
|
|
|
227 |
@Override
|
|
|
228 |
public void run() {
|
|
|
229 |
loaddata();
|
|
|
230 |
|
|
|
231 |
}
|
|
|
232 |
});
|
| 43 |
gabriel |
233 |
notificaciones.scrollTo(0, getView().getBottom());
|
|
|
234 |
|
| 41 |
gabriel |
235 |
}
|
| 39 |
gabriel |
236 |
}
|
|
|
237 |
|
|
|
238 |
@Override
|
| 25 |
gabriel |
239 |
public void onItemClick(int position, View v) {
|
|
|
240 |
Log.e("Aqui", "pise en el fragment"+position);
|
| 34 |
gabriel |
241 |
// notificacionList.get(position).put("color","white");
|
| 39 |
gabriel |
242 |
// loaddata();
|
| 25 |
gabriel |
243 |
|
| 56 |
gabriel |
244 |
if(!notificacionListToday.get(position).get("url").isEmpty())
|
| 39 |
gabriel |
245 |
{
|
|
|
246 |
Log.e("Tiene url", "vamos alla");
|
| 56 |
gabriel |
247 |
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notificacionListToday.get(position).get("url")));
|
| 54 |
gabriel |
248 |
try{
|
|
|
249 |
startActivity(browserIntent);
|
|
|
250 |
}catch (Exception e)
|
|
|
251 |
{
|
|
|
252 |
Toast.makeText(getContext(), "Necesitas un navegador para ver esta web", Toast.LENGTH_SHORT).show();
|
|
|
253 |
}
|
| 39 |
gabriel |
254 |
}
|
|
|
255 |
else
|
|
|
256 |
{
|
|
|
257 |
Log.e("No hay url", "no hago nada");
|
|
|
258 |
}
|
| 25 |
gabriel |
259 |
}
|
| 56 |
gabriel |
260 |
}
|