Skip to content

Commit

Permalink
downloader is choosable over the settings menu now
Browse files Browse the repository at this point in the history
  • Loading branch information
GoneUp committed Dec 7, 2015
1 parent 3ca556a commit ef47c2b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
28 changes: 17 additions & 11 deletions app/src/main/java/com/hstrobel/lsfplan/HtmlWebSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

//noinspection SimplifiableIfStatement
if (id == R.id.action_refresh) {
Globals.cachedPlans = null;
loadOverview();
}

Expand Down Expand Up @@ -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<PlanGroup> 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));
Expand Down Expand Up @@ -286,21 +294,19 @@ protected List<PlanGroup> 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);

Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/com/hstrobel/lsfplan/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<VEvent> evs = CalenderUtils.getNextEvent(Globals.myCal);
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/hstrobel/lsfplan/classes/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<PlanGroup> cachedPlans = null;

public static void InitCalender(Context c, boolean initNotification) throws IOException, ParserException {
if (!initialized) {
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
android:orderInCategory="100"
android:title="@string/action_setCalender"
app:showAsAction="never" />
<item
android:id="@+id/action_setCalenderNew"
android:orderInCategory="100"
android:title="DL NEW"
app:showAsAction="never" />
<item
android:id="@+id/action_testNotfication"
android:orderInCategory="100"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<string name="pref_description_refresh">Du bekommst eine Warnmeldung wenn der Plan älter als vier Wochen ist</string>
<string name="pref_cat_notify">Benachrichtigungen</string>
<string name="action_refesh">Refresh</string>
<string name="html_login_cancel"></string>
<string name="html_login_head">Persönlicher Stundenplan</string>
<string name="html_login_save"></string>
<string name="pref_title_dl">Benutze alten Downloader</string>
<string name="pref_description_dl">Wenn der Download des Planes nicht korrekt funktioniert...</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
<string name="html_login_save" translatable="false">Save login details</string>
<string name="html_login_cancel" translatable="false">Cancel</string>
<string name="html_login_login" translatable="false">Login</string>
<string name="pref_title_dl">Use old Downloader</string>
<string name="pref_description_dl">In case download plan is not working, check this</string>


</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
android:key="enableAds"
android:summary="@string/pref_description_ads"
android:title="@string/pref_title_ads" />
<CheckBoxPreference
android:defaultValue="false"
android:key="enableOldDL"
android:summary="@string/pref_description_dl"
android:title="@string/pref_title_dl" />
<Preference
android:key="reset"
android:title="@string/pref_reset"></Preference>
android:title="@string/pref_reset"/>
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_cat_notify">
Expand Down

0 comments on commit ef47c2b

Please sign in to comment.