Skip to content

Commit 915615e

Browse files
committed
Merge pull request #7 from codeTom/dev
Obed bug fixed
2 parents 2bbada9 + 5fe3507 commit 915615e

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="sk.ayazi.glstnzastupovanie"
4-
android:versionCode="4"
5-
android:versionName="2.1" >
4+
android:versionCode="5"
5+
android:versionName="2.2" >
66

77
<uses-sdk
88
android:minSdkVersion="8"
0 Bytes
Binary file not shown.

src/sk/ayazi/glstnzastupovanie/JedalnyListok.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private Object fromString(String s) throws IOException,ClassNotFoundException {
5151
}
5252

5353
public String[] getObed(Date date) throws ObedNotAvailableException{
54+
5455
if(listok.containsKey(date)){return listok.get(date);}
5556
else{
5657
try {
@@ -64,6 +65,7 @@ public String[] getObed(Date date) throws ObedNotAvailableException{
6465
}
6566

6667
private void update() throws IOException{
68+
6769
TreeMap<Date,String[]> ts= z.getWeekMenu();
6870
if(ts!=null){listok.putAll(ts);}
6971
clean();

src/sk/ayazi/glstnzastupovanie/ObedActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package sk.ayazi.glstnzastupovanie;
22

3+
import java.text.ParseException;
34
import java.text.SimpleDateFormat;
45
import java.util.Date;
56

@@ -85,10 +86,14 @@ protected void onPreExecute (){
8586
@Override
8687
protected String[] doInBackground(Date... param) {
8788
try{
88-
return jl.getObed(param[param.length-1]);
89+
Date date= new SimpleDateFormat("yyyyMMdd").parse(new SimpleDateFormat("yyyyMMdd").format(param[param.length-1]));
90+
return jl.getObed(date);
8991
} catch (ObedNotAvailableException e) {
9092
// TODO Handle the error somehow
9193
e.printStackTrace();
94+
} catch (ParseException e) {
95+
// TODO Auto-generated catch block
96+
e.printStackTrace();
9297
}
9398
return null;
9499
}

src/sk/ayazi/glstnzastupovanie/Zastup.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class Zastup {
2929
//jedlo
3030
private final Pattern menuKomplet=Pattern.compile("<table class=\"obed_menu\" >(.*?)</table>");
3131
private final Pattern menuDateRange=Pattern.compile("<h2>Od (.*?) do (.*?)</h2>");
32-
private final Pattern menuTabulka=Pattern.compile("<th>Hlavné jedlo</th></tr>(.*?)</tbody>");
32+
private final Pattern menuTabulka=Pattern.compile("<th>Hlavné jedlo</th>.*?</tr>(.*?)</tbody>");
3333
private final Pattern tabulkaRow=Pattern.compile("<tr style=\"background-color:.*?\">(.*?)</tr>");
3434
private final Pattern tabulkaDen=Pattern.compile("<th class=\"v_align r_align\">(.*?)</th>");
3535
private final Pattern tabulkaJedlo=Pattern.compile("<td class=\"v_align\">(.*?)</td>\\s*?<td>\\s*?(.*?)\\s*?</td>");
@@ -59,6 +59,7 @@ public String getOznam(){
5959

6060
@SuppressWarnings("deprecation")
6161
public TreeMap<Date,String[]> getWeekMenu() throws IOException{
62+
6263
TreeMap<Date,String[]> ts=new TreeMap<Date,String[]>();
6364
final Hashtable<String,Integer> ht=new Hashtable<String,Integer>();
6465
ht.put("Pondelok",1);
@@ -78,31 +79,35 @@ public TreeMap<Date,String[]> getWeekMenu() throws IOException{
7879
String inputLine;
7980
while ((inputLine = in.readLine()) != null){
8081
page+=inputLine;}
82+
8183
Matcher m=menuDateRange.matcher(page);
8284
if(!m.find()){return null;}
8385
Date datestart = null;
8486
try {
8587
datestart=new SimpleDateFormat("d.M.yyyy", Locale.ENGLISH).parse(m.group(1));
88+
8689
} catch (ParseException e) {
8790
e.printStackTrace();
8891
return null;
8992
}
9093
m=menuTabulka.matcher(page);
91-
if(!m.find()){return null;}
94+
if(!m.find()){return null;}
9295
String tabulka=m.group(1);
9396
m=tabulkaRow.matcher(tabulka);
9497
Matcher m2,m3;
9598
cal.setTime(datestart);
96-
if(!m.find()){return null;}
99+
if(!m.find()){System.err.println("1");return null;}
97100
m2=tabulkaDen.matcher(m.group(1));
98-
if(!m2.find()){return null;}
101+
if(!m2.find()){System.err.println("1");return null;}
99102
m3=tabulkaJedlo.matcher(m.group(1));
103+
100104
if(m3.find()){
105+
101106
jedlo[0]=m3.group(1).trim();
102107
jedlo[1]=m3.group(2).trim();
103108
ts.put(datestart, jedlo);
104109
jedlo=new String[2];
105-
}
110+
}else{throw new RuntimeException();}
106111
while(m.find()){
107112
m2=tabulkaDen.matcher(m.group(1));
108113
if(m2.find()){
@@ -112,8 +117,10 @@ public TreeMap<Date,String[]> getWeekMenu() throws IOException{
112117
if(m3.find()){
113118
jedlo[0]=m3.group(1).trim();
114119
jedlo[1]=m3.group(2).trim();
120+
115121
ts.put(calt.getTime(),jedlo);
116122
jedlo=new String[2];
123+
117124
}
118125
}
119126
}
@@ -354,7 +361,8 @@ private String loadPage(String date) throws IOException{
354361
/**method to get next non-weekend day,from system time
355362
* @return next day(Monday-Friday) date, with 0 time
356363
* */
357-
public Date getNextDay(){
364+
@SuppressLint("SimpleDateFormat")
365+
public Date getNextDay(){
358366
Date d=new Date();
359367
Calendar c=Calendar.getInstance();
360368
c.setTime(d);

0 commit comments

Comments
 (0)