Commit f897e962 authored by Toni Beier's avatar Toni Beier

Feature: Timetable is refreshable by pull-down gesture

parent c9b720eb
......@@ -25,7 +25,22 @@ public class ASiSTModuleManager {
public void register(AbstractAsistModule module){
modules.add(module);
}
public <T extends AbstractAsistModule> T getModule( Class<T> moduleClass, T defaultValue ) {
T resultModule = defaultValue;
for ( AbstractAsistModule registeredModule: this.modules ) {
if( moduleClass.isInstance( registeredModule ) ) {
defaultValue = (T)registeredModule;
break;
}
}
return resultModule;
}
public <T extends AbstractAsistModule> T getModule( Class<T> moduleClass) {
return this.getModule(moduleClass, null);
}
public List<AbstractAsistModule> getModules() {
return modules;
}
......
......@@ -75,6 +75,10 @@ public class EnvironmentManager {
setEnvironmentString(context, TimetableModule.PREF_KEY_SHORTCODE, code);
}
public boolean containsCourseShortCode(Context context) {
return containsEnvironmentKey(context, TimetableModule.PREF_KEY_SHORTCODE);
}
public static boolean updateOnStartUp(Context context){
return getEnvironmentBoolean(context, KEY_UPDATE_ON_STARTUP, true);
}
......@@ -83,6 +87,18 @@ public class EnvironmentManager {
setEnvironmentBoolean(context, KEY_UPDATE_ON_STARTUP, value);
}
/**
* Return if a environment variable key exists
*
* @param context The context
* @param key The key that is search
* @return Is the key available
*/
public static boolean containsEnvironmentKey(final Context context, final String key) {
final SharedPreferences environment = context.getSharedPreferences(SHAREDPREFERENCE_ENVIRONMENT, Context.MODE_PRIVATE);
return environment.contains(key);
}
/**
* Speichert einen String in den Umgebungsvariablen 'key'
* @param context
......
......@@ -8,7 +8,11 @@ import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -19,6 +23,7 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;
import java.util.List;
......@@ -30,6 +35,7 @@ import de.bps.asist.gui.AbstractASiSTFragment;
import de.bps.asist.gui.code.GenericAddActivity;
import de.bps.asist.gui.dialog.ASiSTDialog;
import de.bps.asist.module.timetable.model.Course;
import de.bps.asist.module.timetable.model.CourseList;
import de.bps.asist.module.timetable.model.SelectionTreeNode;
/**
......@@ -83,6 +89,62 @@ public class TimetableFragment extends AbstractASiSTFragment {
DatabaseManager<SelectionTreeNode> selectionDB = new DatabaseManager<>(getActivity(), SelectionTreeNode.class);
hasSelectionTree = selectionDB.hasItems();
final SwipeRefreshLayout refreshTimeTableSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_timetable_swipe_layout);
refreshTimeTableSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
if (EnvironmentManager.getInstance().containsCourseShortCode(getContext())) {
TimetableModule.updateByShortCode(getContext(), EnvironmentManager.getInstance().getCourseShortCode(getContext()), new CourseParseCallback() {
@Override
public void onError(Exception e) {
Log.d("timetable_update", "Error while Downloading/Parsing timetable", e);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), R.string.module_timetable_course_update_failure, Toast.LENGTH_LONG).show();
}
});
refreshTimeTableSwipeLayout.setRefreshing(false);
}
@Override
public void onSuccess() {
refreshTimeTableSwipeLayout.setRefreshing(false);
}
@Override
public void onManagedError(CourseList parsed) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), R.string.module_timetable_course_update_failure, Toast.LENGTH_LONG).show();
}
});
refreshTimeTableSwipeLayout.setRefreshing(false);
}
}, null);
} else {
TextView toastContent = new TextView(getContext());
toastContent.setText(R.string.module_timetable_course_code_not_found);
toastContent.setGravity(Gravity.CENTER);
Toast courseCodeNotFoundToast = new Toast(getContext());
courseCodeNotFoundToast.setView(toastContent);
courseCodeNotFoundToast.setDuration(Toast.LENGTH_LONG);
courseCodeNotFoundToast.show();
refreshTimeTableSwipeLayout.setRefreshing(false);
}
}
});
}
});
return view;
}
......
......@@ -46,10 +46,15 @@
/>
</LinearLayout>
<ListView
android:id="@+id/courses_overview"
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh_timetable_swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">
<ListView
android:id="@+id/courses_overview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
\ No newline at end of file
......@@ -198,6 +198,8 @@
<string name="generic_list_showmore">Mehr anzeigen</string>
<!-- timetable -->
<string name="module_timetable_course_code_not_found" formatted="false">Aktualisierung konnte nicht durchgeführt werden.\nImportieren Sie zuerst Ihren Stundenplan.</string>
<string name="module_timetable_course_update_failure" formatted="false">Während der Aktualisierung des Stundplanes ist ein Fehler aufgetreten</string>
<!-- Feedback Module -->
<string name="module_feedback_name">Vorlesungs-Feedback</string>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment