Skip to content

Commit

Permalink
new downloader got a new design
Browse files Browse the repository at this point in the history
new downloder supports the personal plan
  • Loading branch information
GoneUp committed Dec 7, 2015
1 parent 6f6ebb9 commit 3ca556a
Show file tree
Hide file tree
Showing 15 changed files with 344 additions and 58 deletions.
14 changes: 8 additions & 6 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-ads/8.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-appindexing/8.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-basement/8.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
Expand All @@ -81,18 +82,19 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="commons-codec-1.8" level="project" />
<orderEntry type="library" exported="" name="play-services-ads-8.3.0" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="backport-util-concurrent-3.1" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.7.3" level="project" />
<orderEntry type="library" exported="" name="play-services-ads-8.3.0" level="project" />
<orderEntry type="library" exported="" name="ical4j-1.0.6" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.7.3" level="project" />
<orderEntry type="library" exported="" name="commons-lang-2.6" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="play-services-appindexing-8.3.0" level="project" />
<orderEntry type="library" exported="" name="play-services-basement-8.3.0" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
compile 'org.mnode.ical4j:ical4j:1.0.6'
compile 'commons-io:commons-io:2.4'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.google.android.gms:play-services-appindexing:8.3.0'
}


3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.hstrobel.lsfplan.MainActivity" />
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>

</manifest>
134 changes: 117 additions & 17 deletions app/src/main/java/com/hstrobel/lsfplan/HtmlWebSelector.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package com.hstrobel.lsfplan;

import android.graphics.Color;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.Toolbar;
import android.util.Base64;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.hstrobel.lsfplan.classes.Globals;
import com.hstrobel.lsfplan.classes.ICSLoader;
import com.hstrobel.lsfplan.classes.LoginProcess;
import com.hstrobel.lsfplan.classes.PlanGroup;
import com.hstrobel.lsfplan.frags.AbstractWebSelector;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand All @@ -33,11 +41,14 @@ public class HtmlWebSelector extends AbstractWebSelector {

PlanExportLoader exportLoader = null;
PlanOverviewLoader overviewLoader = null;
LoginProcess loginProcess = null;
private HtmlWebSelector local;
private ExpandableListView mList;
private PlanListAdapter mAdapter;
private ProgressBar spinner;
private PlanGroup.PlanItem lastItem = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -54,18 +65,24 @@ public void onClick(View view) {
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

local = this;
mList = (ExpandableListView) findViewById(R.id.listView);
mAdapter = new PlanListAdapter(this);
mList.setAdapter(mAdapter);

spinner = (ProgressBar) findViewById(R.id.progressBarHtml);

loadOverview();

mList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
private View lastHighlight = null;

public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.background, typedValue, true);

v.setBackgroundResource(R.color.orange);
if (lastHighlight != null) lastHighlight.setBackgroundColor(Color.WHITE);
if (lastHighlight != null) lastHighlight.setBackgroundColor(typedValue.data);
lastHighlight = v;

int index = parent.getFlatListPosition(ExpandableListView
Expand All @@ -81,6 +98,9 @@ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition
protected void onStop() {
super.onStop();

if (exportLoader != null) exportLoader.cancel(true);
if (overviewLoader != null) overviewLoader.cancel(true);
if (loginProcess != null) loginProcess.cancel(true);
}

@Override
Expand All @@ -105,21 +125,39 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}


private void loadExportUrl() {
Log.d("LSF", "loadExportUrl");
if (lastItem == null) return;
String planURL = "";

if (lastItem.URL.equals("#LOGIN#")) {
showLoginForm();
} else {
spinner.setVisibility(View.VISIBLE);
mList.setEnabled(false);
planURL = lastItem.URL;

exportLoader = new PlanExportLoader();
exportLoader.execute(planURL);
}
}

public void loginCallback(String loginCookie) {
if (loginCookie == null) {
Toast.makeText(this, "Login failed. Check your username/password.", Toast.LENGTH_LONG).show();
spinner.setVisibility(View.GONE);
mList.setEnabled(true);
return;
}

spinner = (ProgressBar) findViewById(R.id.progressBarHtml);
spinner.setVisibility(View.VISIBLE);
mList.setEnabled(false);
String planURL = lastItem.URL;
exportLoader = new PlanExportLoader();
exportLoader.execute(planURL);
exportLoader.execute(getString(R.string.misc_personalPlanURL), loginCookie);
}

private void exportCallback(String url) {
if (url == 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", "exportCallback");
Expand All @@ -129,7 +167,6 @@ private void exportCallback(String url) {

private void loadOverview() {
Log.d("LSF", "loadOverview");
spinner = (ProgressBar) findViewById(R.id.progressBarHtml);
spinner.setVisibility(View.VISIBLE);
mList.setEnabled(false);

Expand Down Expand Up @@ -160,13 +197,72 @@ private void overviewCallback(List<PlanGroup> results) {
spinner.setVisibility(View.GONE);
}

/* <tr >
<td class="mod_n_odd">
<a class="regular" href="https://lsf.htwg-konstanz.de/qisserver/rds?state=verpublish&amp;publishContainer=stgContainer&amp;publishid=4511">Angewandte Informatik (Bachelor) </a>
</td>
<td class="mod_n_odd">
<a class="normal" href="https://lsf.htwg-konstanz.de/qisserver/rds?state=wplan&amp;act=stg&amp;pool=stg&amp;show=plan&amp;P.vx=kurz&amp;r_zuordabstgv.semvonint=1&amp;r_zuordabstgv.sembisint=1&amp;missing=allTerms&amp;k_parallel.parallelid=&amp;k_abstgv.abstgvnr=4511&amp;r_zuordabstgv.phaseid=">1. Semester</a>
*/

private void showLoginForm() {
// Create Object of Dialog class
final Dialog login = new Dialog(this);
// Set GUI of login screen
login.setContentView(R.layout.login_dialog);
login.setTitle("Enter HTWG Login Data");

// Init button of login GUI
final CheckBox box = (CheckBox) login.findViewById(R.id.checkSave);
final Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
final Button btnCancel = (Button) login.findViewById(R.id.btnCancel);
final EditText txtUsername = (EditText) login.findViewById(R.id.txtUsername);
final EditText txtPassword = (EditText) login.findViewById(R.id.txtPassword);

boolean autoSave = Globals.mSettings.getBoolean("loginAutoSave", true);
box.setChecked(autoSave);
if (autoSave) {
String user = Globals.mSettings.getString("loginUser", "");
String pw = Globals.mSettings.getString("loginPassword", "");
if (!user.equals("")) {
user = new String(Base64.decode(user, Base64.DEFAULT));
pw = new String(Base64.decode(pw, Base64.DEFAULT));
}

txtUsername.setText(user);
txtPassword.setText(pw);
}


// Attached listener for login GUI button
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = txtUsername.getText().toString().trim();
String pw = txtPassword.getText().toString().trim();

if ((user.length() > 0) && (pw.length() > 0)) {
login.dismiss();
//login
spinner.setVisibility(View.VISIBLE);
mList.setEnabled(false);

loginProcess = new LoginProcess(local, new Handler());
loginProcess.execute(user, pw);
}

SharedPreferences.Editor editor = Globals.mSettings.edit();
editor.putBoolean("loginAutoSave", box.isChecked());
if (box.isChecked()) {
editor.putString("loginUser", Base64.encodeToString(user.getBytes(), Base64.DEFAULT));
editor.putString("loginPassword", Base64.encodeToString(pw.getBytes(), Base64.DEFAULT));
}
editor.apply();
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login.dismiss();
}
});

// Make dialog box visible.
login.show();
}

public class PlanOverviewLoader extends AsyncTask<String, String, List<PlanGroup>> {
public PlanOverviewLoader() {
Expand Down Expand Up @@ -236,7 +332,11 @@ protected String doInBackground(String... params) {
// Making HTTP request
String url = null;
try {
Document doc = Jsoup.parse(new URL(params[0]), 5000);
Connection con = Jsoup.connect(params[0]);
if (params.length > 1) con.cookie("JSESSIONID", params[1]);
con.userAgent("LSF APP");
Document doc = con.get();


Elements images = doc.select("img");
for (Element imgs : images) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hstrobel/lsfplan/PlanListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public boolean hasStableIds() {
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.planview_item, parent, false);
convertView = inflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false);

TextView text = (TextView) convertView.findViewById(R.id.planText);
TextView text = (TextView) convertView.findViewById(android.R.id.text1);
text.setTypeface(null, Typeface.BOLD);
PlanGroup group = list.get(groupPosition);
text.setText(group.name);
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/hstrobel/lsfplan/UserSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.hstrobel.lsfplan.classes.Globals;

Expand Down Expand Up @@ -48,7 +45,7 @@ public boolean onPreferenceClick(Preference preference) {
editor.clear();
editor.commit();
PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.settings, true);
Globals.initalized = false;
Globals.initialized = false;
NavUtils.navigateUpFromSameTask(getActivity());
return true;
}
Expand Down
39 changes: 21 additions & 18 deletions app/src/main/java/com/hstrobel/lsfplan/classes/AlarmReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@
import org.apache.commons.lang.exception.ExceptionUtils;

public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("LSF", "onReceive");
try {
//Process could be killed in the meantime, setup our calender, but NOT init the notifications to prevent duplicates loops etc
if (!Globals.initalized) Globals.InitCalender(context, false);
VEvent[] events = (VEvent[]) intent.getSerializableExtra("event");
for (VEvent e : events) {
CalenderUtils.showNotfication(e, context);
}
ScheduleNextEventNot(context);
} catch (Exception ex) {
Log.e("LSF", "FAIL onReceive:\n " + ExceptionUtils.getCause(ex));
Log.e("LSF", "FAIL onReceive ST:\n " + ExceptionUtils.getFullStackTrace(ex));
}
}

public static void ScheduleNextEventNot(Context c) {
//cancel for all cases
CancelNextEventNot(c);
Expand All @@ -50,7 +33,7 @@ public static void ScheduleNextEventNot(Context c) {

Date start = CalenderUtils.getNextRecuringStartDate(events[0]); //all should have the same start time
int minutesBefore = Integer.parseInt(Globals.mSettings.getString("notfiyTime", "15"));
start.setTime(start.getTime() - minutesBefore * 60 * 1000);
start.setTime(start.getTime() - (minutesBefore) * 60 * 1000);

//DEBUG DEBUG REMOVE IT
//start.setTime(new DateTime().getTime() + 30 * 1000);
Expand All @@ -69,9 +52,29 @@ public static void ScheduleNextEventNot(Context c) {
}

public static void CancelNextEventNot(Context c) {
Log.i("LSF", "cancel sched");
AlarmManager alarmManager = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
Intent intentAlarm = new Intent(c, AlarmReceiver.class);
alarmManager.cancel(PendingIntent.getBroadcast(c, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));

}

@Override
public void onReceive(Context context, Intent intent) {
Log.i("LSF", "onReceive");
try {
//Process could be killed in the meantime, setup our calender, but NOT init the notifications to prevent duplicates loops etc
if (!Globals.initialized) Globals.InitCalender(context, false);


VEvent[] events = (VEvent[]) intent.getSerializableExtra("event");
for (VEvent e : events) {
CalenderUtils.showNotfication(e, context);
}
ScheduleNextEventNot(context);
} catch (Exception ex) {
Log.e("LSF", "FAIL onReceive:\n " + ExceptionUtils.getCause(ex));
Log.e("LSF", "FAIL onReceive ST:\n " + ExceptionUtils.getFullStackTrace(ex));
}
}
}
Loading

0 comments on commit 3ca556a

Please sign in to comment.