Proyectos de Subversion Android Microlearning - Inconcert

Rev

Rev 5 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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