Skip to content

Commit 6d65ab2

Browse files
committed
Implementada la funcionalidad de "Recientes", ahora la lógica para evaluar si es reciente
reside en CromaNewsAdapter. El límite de recientes es de 7 dias y este valor está en el código y se pasa a la función IsRecent junto con la cadena de texto de la fecha. El constructor ahora permite que cualquier tipo de feed (notas, conferencias, etc) se pueda filtrar por fecha o por algún otro filtro que se implementase.
1 parent a0b6148 commit 6d65ab2

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

Android/src/mx/croma/news/android/ListaNoticias.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public void FinishedDownloadCallback(String categoria, CromaFeedHandler cfh) {
130130
if (categoria.equalsIgnoreCase("Documentos")) {
131131
newsAdapter = new CromaNewsAdapter(Publicacion.class, cfh.getNoticias(), this);
132132
} else if(categoria.equalsIgnoreCase("Recientes")) {
133-
newsAdapter = new CromaNewsAdapter(RecientesCache.getCache().getRecientes(), this);
133+
newsAdapter = new CromaNewsAdapter("", "RECIENTES",cfh.getNoticias(), this);
134134
} else {
135-
newsAdapter = new CromaNewsAdapter(categoria, cfh.getNoticias(), this);
135+
newsAdapter = new CromaNewsAdapter(categoria, "",cfh.getNoticias(), this);
136136
}
137137
lv.setOnItemClickListener(new ListaListener());
138138
lv.setAdapter(newsAdapter);

Android/src/mx/croma/news/android/core/CromaFeedHandler.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,11 @@ public void endElement(String uri, String ln, String qName) {
9090
} else if (ln.endsWith(TAG_DATE)) {
9191
_actual.setFecha(chars);
9292
} else if (ln.endsWith(TAG_ITEM)) {
93-
try {
94-
Date d = formatter.parse(_actual.getFecha());
95-
if(isRecent(d)){
96-
Log.d("BCN", "Reciente: " + _actual.getFecha());
97-
RecientesCache.getCache().getRecientes().add(_actual);
98-
}else{
99-
Log.d("BCN", "No reciente:" + _actual.getFecha());
100-
}
101-
} catch (ParseException e) {
102-
Log.e("BCN", "Error parseando " + _actual.getFecha(), e);
103-
}
93+
Log.v("BCN::", _actual.getFecha()+" "+_actual.getTitulo()+" "+_actual.getCategoria()+ " "+_actual.getClass().toString());
10494
_noticias.add(_actual);
10595
onItem = false;
10696
}
10797
}
10898
}
109-
110-
private boolean isRecent(Date d){
111-
Calendar current = Calendar.getInstance();
112-
current.add(Calendar.DATE, -7);
113-
Calendar target = (Calendar) current.clone();
114-
target.setTimeInMillis(d.getTime());
115-
return target.after(current);
116-
}
11799

118100
}

Android/src/mx/croma/news/android/core/CromaNewsAdapter.java

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package mx.croma.news.android.core;
22

33
import java.util.ArrayList;
4+
import java.util.Calendar;
45
import java.util.List;
56

67
import mx.croma.news.android.object.Publicacion;
78
import mx.croma.news.android.object.PublicacionStorage;
89
import android.content.Context;
10+
import android.util.Log;
911
import android.view.View;
1012
import android.view.ViewGroup;
1113
import android.widget.BaseAdapter;
@@ -21,21 +23,39 @@ public CromaNewsAdapter(ArrayList<Noticia> noticias, Context ctx){
2123
_context = ctx;
2224
}
2325

24-
public CromaNewsAdapter(String category, List<Noticia> noticias, Context ctx){
26+
public CromaNewsAdapter(String category, String filter, List<Noticia> noticias, Context ctx){
27+
Log.v("::::::VIA_CATEGORIA ",category);
2528
_noticias = noticias;
2629
_context = ctx;
27-
if(category != null){
28-
_category = category;
29-
_noticias = new ArrayList<Noticia>();
30-
for(Noticia n : noticias){
31-
if(_category.equals(n.getCategoria())){
30+
_category = category;
31+
_noticias = new ArrayList<Noticia>();
32+
for(Noticia n : noticias){
33+
String n_date = n.getFecha();
34+
Log.v(":::::::::DATE",n_date);
35+
if (filter.equalsIgnoreCase("RECIENTES")) {
36+
if (IsRecent(n_date, 7)) {
37+
if (category!="") {
38+
if(_category.equals(n.getCategoria())){
39+
_noticias.add(n);
40+
}
41+
} else {
42+
_noticias.add(n);
43+
}
44+
}
45+
} else {
46+
if (category!="") {
47+
if(_category.equals(n.getCategoria())){
48+
_noticias.add(n);
49+
}
50+
} else {
3251
_noticias.add(n);
3352
}
3453
}
3554
}
3655
}
3756

3857
public CromaNewsAdapter(Class<?> validClass, List<Noticia> noticias, Context ctx){
58+
Log.v("::::::VIA_CLASS ",validClass.toString());
3959
_context = ctx;
4060
_noticias = new ArrayList<Noticia>();
4161
if(validClass == Publicacion.class){
@@ -55,7 +75,6 @@ public CromaNewsAdapter(Class<?> validClass, List<Noticia> noticias, Context ctx
5575
}
5676
}
5777

58-
5978
private void addToPublicacionStorage(List<Noticia> noticias) {
6079
for(Noticia n : noticias){
6180
if(n instanceof Publicacion){
@@ -87,5 +106,23 @@ public View getView(int arg0, View arg1, ViewGroup arg2) {
87106
nv.update(_noticias.get(arg0));
88107
return nv;
89108
}
109+
110+
public boolean IsRecent(String strdate, int TimeInDays) {
111+
boolean r = false;
112+
long d = TimeInDays * 24 * 60 * 60 * 1000;
113+
Calendar t = Calendar.getInstance();
114+
Calendar h = Calendar.getInstance();
115+
t.set(Calendar.YEAR, Integer.parseInt(strdate.substring(0, 4)));
116+
t.set(Calendar.MONTH, Integer.parseInt(strdate.substring(5, 7)));
117+
t.set(Calendar.DATE, Integer.parseInt(strdate.substring(8, 10)));
118+
long delta = Math.abs(h.getTimeInMillis()-t.getTimeInMillis());
119+
if (delta>=d) {
120+
r = false;
121+
} else {
122+
Log.v("DATE::::::", "IsRecent "+strdate);
123+
r = true;
124+
}
125+
return r;
126+
}
90127

91128
}

0 commit comments

Comments
 (0)