Skip to content
This repository was archived by the owner on May 13, 2021. It is now read-only.

Commit f69f82d

Browse files
committed
pre-patch v0.6
+ check if file from URL does exist & error message if not * bugs that caused the app to display "TextView" instead of the error message or text, because of functions being interrupted by nullpointers. * error messages for empty tree map -- + added - removed * fixed
1 parent 5bdc627 commit f69f82d

File tree

7 files changed

+139
-109
lines changed

7 files changed

+139
-109
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ dependencies {
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
2828
// jsoup HTML parser library @ https://jsoup.org/
29-
compile 'org.jsoup:jsoup:1.11.3'
29+
implementation 'org.jsoup:jsoup:1.11.3'
3030
}

app/release/app-release.apk

1.69 MB
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package de.vp.dennis.vp2018.core;
2+
3+
import java.net.HttpURLConnection;
4+
import java.net.URL;
5+
6+
public class DoesUrlExist {
7+
8+
9+
public static boolean exists(String URLName){
10+
try {
11+
HttpURLConnection.setFollowRedirects(false);
12+
HttpURLConnection con =
13+
(HttpURLConnection) new URL(URLName).openConnection();
14+
con.setRequestMethod("HEAD");
15+
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
16+
}
17+
catch (Exception e) {
18+
e.printStackTrace();
19+
return false;
20+
}
21+
}
22+
23+
}

app/src/main/java/de/vp/dennis/vp2018/core/VertretungsHandle.java

Lines changed: 104 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -17,164 +17,168 @@ public class VertretungsHandle {
1717

1818
public static ArrayList<String> getSource(String klasse, String woche) {
1919

20-
String url = "http://mpg-vertretungsplan.de/w/"+woche+"/"+klasse+".htm";
20+
String url = "http://mpg-vertretungsplan.de/w/" + woche + "/" + klasse + ".htm";
2121

22-
Document doc = null;
23-
try {
24-
doc = Jsoup.connect(url).get();
25-
} catch (IOException e) {
26-
e.printStackTrace();
27-
}
22+
if (DoesUrlExist.exists(url)) {
23+
24+
Document doc = null;
25+
try {
26+
doc = Jsoup.connect(url).get();
27+
} catch (IOException e) {
28+
e.printStackTrace();
29+
}
2830

29-
ArrayList<String> returnment = new ArrayList<>();
30-
for (String s : doc.toString().replace("\"", "").split("\n"))
31-
{
32-
returnment.add(s);
31+
ArrayList<String> returnment = new ArrayList<>();
32+
for (String s : doc.toString().replace("\"", "").split("\n")) {
33+
returnment.add(s);
34+
}
35+
return returnment;
36+
}else{
37+
System.out.println("Achtung! URL "+url.toString()+" wurde nicht gefunden!");
38+
return null;
3339
}
34-
return returnment;
3540
}
3641

42+
3743
public static void sortDays(ArrayList<String> days) {
3844

39-
// Monday
45+
// Monday
4046

41-
int mondayint = 0;
42-
boolean mondaybool = false;
43-
ArrayList<String> monday = new ArrayList<>();
47+
int mondayint = 0;
48+
boolean mondaybool = false;
49+
ArrayList<String> monday = new ArrayList<>();
4450

45-
for (String s : days) {
51+
for (String s : days) {
4652

47-
if (s.contains("<a name=2>")) {
48-
mondaybool = false;
49-
}
53+
if (s.contains("<a name=2>")) {
54+
mondaybool = false;
55+
}
5056

51-
if (mondaybool == true) {
52-
monday.add(days.get(mondayint));
53-
}
57+
if (mondaybool == true) {
58+
monday.add(days.get(mondayint));
59+
}
5460

55-
if (s.contains("<a name=1>")) {
56-
monday.add(days.get(mondayint));
57-
mondaybool = true;
61+
if (s.contains("<a name=1>")) {
62+
monday.add(days.get(mondayint));
63+
mondaybool = true;
64+
}
65+
mondayint++;
5866
}
59-
mondayint++;
60-
}
6167

62-
addVP(monday, "monday");
68+
addVP(monday, "monday");
6369

6470

65-
// Tuesday
71+
// Tuesday
6672

67-
int tuesdayint = 0;
68-
boolean tuesdaybool = false;
69-
ArrayList<String> tuesday = new ArrayList<>();
73+
int tuesdayint = 0;
74+
boolean tuesdaybool = false;
75+
ArrayList<String> tuesday = new ArrayList<>();
7076

71-
for (String s : days) {
77+
for (String s : days) {
7278

73-
if (s.contains("<a name=3>")) {
74-
tuesdaybool = false;
75-
}
79+
if (s.contains("<a name=3>")) {
80+
tuesdaybool = false;
81+
}
7682

77-
if (tuesdaybool == true) {
78-
tuesday.add(days.get(tuesdayint));
79-
}
83+
if (tuesdaybool == true) {
84+
tuesday.add(days.get(tuesdayint));
85+
}
8086

81-
if (s.contains("<a name=2>")) {
82-
tuesday.add(days.get(tuesdayint));
83-
tuesdaybool = true;
87+
if (s.contains("<a name=2>")) {
88+
tuesday.add(days.get(tuesdayint));
89+
tuesdaybool = true;
90+
}
91+
92+
tuesdayint++;
8493
}
8594

86-
tuesdayint++;
87-
}
95+
addVP(tuesday, "tuesday");
8896

89-
addVP(tuesday, "tuesday");
9097

98+
// Wednesday
9199

92-
// Wednesday
100+
int wednesdayint = 0;
101+
boolean wednesdaybool = false;
102+
ArrayList<String> wednesday = new ArrayList<>();
93103

94-
int wednesdayint = 0;
95-
boolean wednesdaybool = false;
96-
ArrayList<String> wednesday = new ArrayList<>();
104+
for (String s : days) {
97105

98-
for (String s : days) {
106+
if (s.contains("<a name=4>")) {
107+
wednesdaybool = false;
108+
}
99109

100-
if (s.contains("<a name=4>")) {
101-
wednesdaybool = false;
102-
}
110+
if (wednesdaybool == true) {
111+
wednesday.add(days.get(wednesdayint));
112+
}
103113

104-
if (wednesdaybool == true) {
105-
wednesday.add(days.get(wednesdayint));
106-
}
114+
if (s.contains("<a name=3>")) {
115+
wednesday.add(days.get(wednesdayint));
116+
wednesdaybool = true;
117+
}
107118

108-
if (s.contains("<a name=3>")) {
109-
wednesday.add(days.get(wednesdayint));
110-
wednesdaybool = true;
119+
wednesdayint++;
111120
}
112121

113-
wednesdayint++;
114-
}
122+
addVP(wednesday, "wednesday");
115123

116-
addVP(wednesday, "wednesday");
117124

125+
// Thursday
118126

119-
// Thursday
127+
int thursdayint = 0;
128+
boolean thursdaybool = false;
129+
ArrayList<String> thursday = new ArrayList<>();
120130

121-
int thursdayint = 0;
122-
boolean thursdaybool = false;
123-
ArrayList<String> thursday = new ArrayList<>();
131+
for (String s : days) {
124132

125-
for (String s : days) {
133+
if (s.contains("<a name=5>")) {
134+
thursdaybool = false;
135+
}
126136

127-
if (s.contains("<a name=5>")) {
128-
thursdaybool = false;
129-
}
137+
if (thursdaybool == true) {
138+
thursday.add(days.get(thursdayint));
139+
}
130140

131-
if (thursdaybool == true) {
132-
thursday.add(days.get(thursdayint));
133-
}
141+
if (s.contains("<a name=4>")) {
142+
thursday.add(days.get(thursdayint));
143+
thursdaybool = true;
144+
}
134145

135-
if (s.contains("<a name=4>")) {
136-
thursday.add(days.get(thursdayint));
137-
thursdaybool = true;
146+
thursdayint++;
138147
}
139148

140-
thursdayint++;
141-
}
149+
addVP(thursday, "thursday");
142150

143-
addVP(thursday, "thursday");
144151

152+
// Friday
145153

146-
// Friday
154+
int fridayint = 0;
155+
boolean fridaybool = false;
156+
ArrayList<String> friday = new ArrayList<>();
147157

148-
int fridayint = 0;
149-
boolean fridaybool = false;
150-
ArrayList<String> friday = new ArrayList<>();
158+
for (String s : days) {
151159

152-
for (String s : days) {
160+
if (s.contains("<a name=6>")) {
161+
fridaybool = false;
162+
}
153163

154-
if (s.contains("<a name=6>")) {
155-
fridaybool = false;
156-
}
164+
if (fridaybool == true) {
165+
friday.add(days.get(fridayint));
166+
}
157167

158-
if (fridaybool == true) {
159-
friday.add(days.get(fridayint));
160-
}
168+
if (s.contains("<a name=5>")) {
169+
friday.add(days.get(fridayint));
170+
fridaybool = true;
171+
}
161172

162-
if (s.contains("<a name=5>")) {
163-
friday.add(days.get(fridayint));
164-
fridaybool = true;
173+
fridayint++;
165174
}
166175

167-
fridayint++;
168-
}
169-
170-
addVP(friday, "friday");
176+
addVP(friday, "friday");
171177

172178
}
173179

174180

175181

176-
177-
178182
public static void addVP(ArrayList<String> strings, String tag ) {
179183

180184
int i = 0;

app/src/main/java/de/vp/dennis/vp2018/main_vp.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
import android.content.Intent;
44
import android.graphics.Color;
5-
import android.support.v4.app.Fragment;
65
import android.support.v7.app.AppCompatActivity;
76
import android.os.Bundle;
87
import android.view.View;
9-
import android.view.WindowManager;
108
import android.widget.Button;
119
import android.widget.ImageView;
1210
import android.widget.TextView;
13-
1411
import java.util.Calendar;
1512
import java.util.Date;
1613
import java.util.Map;
1714
import java.util.TreeMap;
1815

16+
import de.vp.dennis.vp2018.core.DoesUrlExist;
1917
import de.vp.dennis.vp2018.core.InternetCheck;
2018
import de.vp.dennis.vp2018.core.Vertretung;
2119
import de.vp.dennis.vp2018.core.VertretungsHandle;
@@ -165,8 +163,6 @@ public void onSwipeRight(){
165163
}
166164
}
167165
});
168-
169-
170166
}
171167

172168
Thread startup = new Thread(new Runnable() {
@@ -251,6 +247,7 @@ public void run() {
251247
if(InternetCheck.isOnline()) {
252248

253249
VertretungsHandle.sortDays(VertretungsHandle.getSource(klasse, weekNumber));
250+
System.out.println("Suche nach w/"+weekNumber+"/"+klasse+"!");
254251

255252
Map<String, Vertretung> map = new TreeMap<>(VertretungsHandle.vp);
256253
if(!map.isEmpty()) {
@@ -274,9 +271,15 @@ public void run() {
274271
}
275272

276273
}else{
277-
monday = tuesday = wednesday = thursday = friday = "Für diese Woche sind keine Vertretungen eingetragen (Ferien?)";
278-
}
274+
System.out.println("TreeMap ist leer.");
279275

276+
String url = "http://mpg-vertretungsplan.de/w/" + weekNumber + "/" + klasse + ".htm";
277+
if(!DoesUrlExist.exists(url)){
278+
monday = tuesday = wednesday = thursday = friday = "Unter der dynamisch generierten URL wurde kein Vertretungsplan gefunden (Externer Fehler?). (Fehlercode: 404)";
279+
}else {
280+
monday = tuesday = wednesday = thursday = friday = "Für diese Woche wurden entweder keine Vertretungen eingetragen oder es handelt sich um einen Fehler. (Fehlercode: 001)";
281+
}
282+
}
280283
}else{
281284
monday = tuesday = wednesday = thursday = friday = "Derzeit besteht keine Internetverbindung!";
282285
}

0 commit comments

Comments
 (0)