diff --git a/app/src/main/java/com/hstrobel/lsfplan/HtmlWebSelector.java b/app/src/main/java/com/hstrobel/lsfplan/HtmlWebSelector.java index a971289..a6f193c 100644 --- a/app/src/main/java/com/hstrobel/lsfplan/HtmlWebSelector.java +++ b/app/src/main/java/com/hstrobel/lsfplan/HtmlWebSelector.java @@ -119,6 +119,7 @@ public boolean onOptionsItemSelected(MenuItem item) { //noinspection SimplifiableIfStatement if (id == R.id.action_refresh) { + Globals.cachedPlans = null; loadOverview(); } @@ -167,20 +168,27 @@ private void exportCallback(String url) { private void loadOverview() { Log.d("LSF", "loadOverview"); - spinner.setVisibility(View.VISIBLE); - mList.setEnabled(false); - String savedURL = Globals.mSettings.getString("URL", "missing"); - overviewLoader = new PlanOverviewLoader(); - overviewLoader.execute(savedURL); + if (Globals.cachedPlans != null) { + // got a saved version + overviewCallback(Globals.cachedPlans); + } else { + spinner.setVisibility(View.VISIBLE); + mList.setEnabled(false); + + String savedURL = Globals.mSettings.getString("URL", "missing"); + overviewLoader = new PlanOverviewLoader(); + overviewLoader.execute(savedURL); + } } private void overviewCallback(List results) { if (results == null) { - Toast.makeText(this, "Download failed! Check your Connection", Toast.LENGTH_LONG); + Toast.makeText(this, "Download failed! Check your Connection", Toast.LENGTH_LONG).show(); return; } Log.d("LSF", "overviewCallback"); + Globals.cachedPlans = results; mAdapter.clear(); mAdapter.addPlanGroup(getString(R.string.html_login_head)); @@ -286,21 +294,19 @@ protected List doInBackground(String... params) { //course name Element courseURL = columns.get(0).child(0); //row 0 --> a class --> inner text - Log.d("LSF", courseURL.text()); + if (Globals.DEBUG) Log.d("LSF", courseURL.text()); group = new PlanGroup(courseURL.text()); //course semesters for (Element ele : columns.get(1).children()) { if (ele.tagName() != "a") continue; - Log.d("LSF", ele.text()); - Log.d("LSF", ele.attr("href")); + if (Globals.DEBUG) Log.d("LSF", String.format("%s : %s", ele.text(), ele.attr("href"))); item = new PlanGroup.PlanItem(ele.text(), ele.attr("href")); group.items.add(item); } //course everthing Element allURL = columns.get(2).child(0); //row 0 --> a class --> inner text - Log.d("LSF", allURL.text()); - Log.d("LSF", allURL.attr("href")); + if (Globals.DEBUG) Log.d("LSF", String.format("%s : %s", allURL.text(), allURL.attr("href"))); item = new PlanGroup.PlanItem(allURL.text(), allURL.attr("href")); group.items.add(item); diff --git a/app/src/main/java/com/hstrobel/lsfplan/MainActivity.java b/app/src/main/java/com/hstrobel/lsfplan/MainActivity.java index e3a5338..1b376dc 100644 --- a/app/src/main/java/com/hstrobel/lsfplan/MainActivity.java +++ b/app/src/main/java/com/hstrobel/lsfplan/MainActivity.java @@ -104,11 +104,13 @@ public boolean onOptionsItemSelected(MenuItem item) { Intent intent = new Intent(this, UserSettings.class); startActivity(intent); } else if (id == R.id.action_setCalender) { - Intent intent = new Intent(this, WebSelector.class); - startActivity(intent); - } else if (id == R.id.action_setCalenderNew) { - Intent intent = new Intent(this, HtmlWebSelector.class); - startActivity(intent); + if (mSettings.getBoolean("enableOldDL", false)){ + Intent intent = new Intent(this, WebSelector.class); + startActivity(intent); + } else { + Intent intent = new Intent(this, HtmlWebSelector.class); + startActivity(intent); + } } else if (id == R.id.action_testNotfication) { if (Globals.myCal != null) { List evs = CalenderUtils.getNextEvent(Globals.myCal); diff --git a/app/src/main/java/com/hstrobel/lsfplan/classes/Globals.java b/app/src/main/java/com/hstrobel/lsfplan/classes/Globals.java index 90901f4..d157b5e 100644 --- a/app/src/main/java/com/hstrobel/lsfplan/classes/Globals.java +++ b/app/src/main/java/com/hstrobel/lsfplan/classes/Globals.java @@ -19,12 +19,13 @@ import java.io.InputStream; import java.io.StringWriter; import java.io.Writer; +import java.util.List; /** * Created by Henry on 09.11.2015. */ public class Globals { - public static boolean DEBUG = true; + public static boolean DEBUG = false; public static ICSLoader loader = null; @@ -35,6 +36,7 @@ public class Globals { public static String icsFile = null; public static InputStream icsFileStream = null; public static Calendar myCal = null; + public static List cachedPlans = null; public static void InitCalender(Context c, boolean initNotification) throws IOException, ParserException { if (!initialized) { diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml index 05f623b..d4a0059 100644 --- a/app/src/main/res/menu/menu_main.xml +++ b/app/src/main/res/menu/menu_main.xml @@ -12,11 +12,6 @@ android:orderInCategory="100" android:title="@string/action_setCalender" app:showAsAction="never" /> - Du bekommst eine Warnmeldung wenn der Plan älter als vier Wochen ist Benachrichtigungen Refresh - Persönlicher Stundenplan - + Benutze alten Downloader + Wenn der Download des Planes nicht korrekt funktioniert... \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e13b1e1..9e6d9e7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,6 +85,8 @@ Save login details Cancel Login + Use old Downloader + In case download plan is not working, check this diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 642b1bb..638d020 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -15,9 +15,14 @@ android:key="enableAds" android:summary="@string/pref_description_ads" android:title="@string/pref_title_ads" /> + + android:title="@string/pref_reset"/>