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