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