Commit d5e070c6 authored by Jan Lippert's avatar Jan Lippert
Browse files

Status and meeting date are displayed again.

Merge branch 'master' into develop

Conflicts:
	gradle/wrapper/gradle-wrapper.properties
	src/main/java/de/upb/fsmi/fsdroid/db/DatabaseHelper.java
	src/main/java/de/upb/fsmi/fsdroid/sync/FSDroidContentProvider.java
parent e23edc53
package de.upb.fsmi.fsdroid.cards.views;
import android.database.*;
import android.os.*;
import android.support.v4.app.*;
import android.widget.*;
import org.androidannotations.annotations.*;
import org.slf4j.*;
import de.upb.fsmi.fsdroid.*;
import de.upb.fsmi.fsdroid.sync.*;
import de.upb.fsmi.fsdroid.sync.entities.*;
@EFragment(R.layout.card_meeting)
public class MeetingCardFragment extends Fragment implements
LoaderManager.LoaderCallbacks<Cursor> {
@ViewById
TextView txtMeetingDate;
private static final int MEETING_LOADER = 0x01;
@Override
public android.support.v4.content.Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
if (BuildConfig.DEBUG) LOGGER.debug("onCreateLoader({},{})", i, bundle);
String[] projection = {MeetingDate.COLUMN_VALUE, MeetingDate.COLUMN_ID};
android.support.v4.content.CursorLoader cursorLoader = new android.support.v4.content.CursorLoader(getActivity(),
FSDroidContentProvider.MEETING_DATE_URI, projection, null, null, MeetingDate.COLUMN_LAST_UPDATE + " DESC");
if (BuildConfig.DEBUG) LOGGER.debug("onCreateLoader({},{}) done", i, bundle);
return cursorLoader;
}
@Override
public void onLoadFinished(android.support.v4.content.Loader<Cursor> cursorLoader, Cursor cursor) {
if (BuildConfig.DEBUG) LOGGER.debug("onLoadFinished({},{})", cursor, cursorLoader);
if (cursor.moveToFirst()) {
if (BuildConfig.DEBUG) LOGGER.debug("moved to first");
if (cursor.getColumnCount() > 0) {
bind(cursor.getString(0));
}
}
if (BuildConfig.DEBUG) LOGGER.debug("onLoadFinished({},{}) done", cursor, cursorLoader);
}
@Override
public void onLoaderReset(android.support.v4.content.Loader<Cursor> cursorLoader) {
// do nothing
if (BuildConfig.DEBUG) LOGGER.debug("onLoaderReset({}) done", cursorLoader);
}
private final static Logger LOGGER = LoggerFactory
.getLogger(MeetingCardFragment.class.getSimpleName());
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLoaderManager().initLoader(MEETING_LOADER, null, this);
if (BuildConfig.DEBUG) LOGGER.debug("onCreate({}) done", savedInstanceState);
}
public void bind(String dateString) {
LOGGER.debug("Binding date = {}", dateString);
if (dateString != null) {
txtMeetingDate.setText(dateString);
LOGGER.trace("Displayed date");
} else {
txtMeetingDate.setText("Datum ist unbekannt...");
LOGGER.trace("date was null");
}
}
}
package de.upb.fsmi.fsdroid.cards.views;
import android.content.*;
import android.util.*;
import android.widget.*;
import org.androidannotations.annotations.*;
import org.slf4j.*;
import java.text.*;
import java.util.*;
import de.upb.fsmi.fsdroid.*;
@EViewGroup(R.layout.card_meeting)
public class MeetingCardView extends RelativeLayout implements CustomView<Date> {
@ViewById
TextView txtMeetingDate;
private final static Logger LOGGER = LoggerFactory
.getLogger(MeetingCardView.class);
public MeetingCardView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//
@Override
public void bind(Date t) {
LOGGER.debug("Binding date = {}", t);
if (t != null) {
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy");
txtMeetingDate.setText(sdf.format(t));
LOGGER.trace("Displayed date");
} else {
txtMeetingDate.setText("Datum ist unbekannt...");
LOGGER.trace("date was null");
}
invalidate();
}
}
package de.upb.fsmi.fsdroid.cards.views;
import android.accounts.*;
import android.content.*;
import android.database.*;
import android.os.*;
import android.support.v4.app.*;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.util.*;
import android.widget.*;
import org.androidannotations.annotations.*;
import org.androidannotations.annotations.res.*;
import org.slf4j.*;
import de.upb.fsmi.fsdroid.*;
import de.upb.fsmi.fsdroid.sync.*;
import de.upb.fsmi.fsdroid.sync.entities.*;
@EFragment(R.layout.card_status)
public class StatusCardFragment extends Fragment implements
LoaderManager.LoaderCallbacks<Cursor> {
private static final int STATUS_LOADER = 0x01;
private final Logger LOGGER = LoggerFactory.getLogger(StatusCardFragment.class.getSimpleName());
@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
if (BuildConfig.DEBUG) LOGGER.debug("onCreateLoader({},{})", i, bundle);
String[] projection = {Status.COLUMN_VALUE, Status.COLUMN_ID};
CursorLoader cursorLoader = new CursorLoader(getActivity(),
FSDroidContentProvider.STATUS_URI, projection, null, null, Status.COLUMN_LAST_UPDATE + " DESC");
if (BuildConfig.DEBUG) LOGGER.debug("onCreateLoader({},{}) done", i, bundle);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
if (BuildConfig.DEBUG) LOGGER.debug("onLoadFinished({},{})", cursor, cursorLoader);
if (cursor.moveToFirst()) {
if (BuildConfig.DEBUG) LOGGER.debug("moved to first");
if (cursor.getColumnCount() > 0) {
bind(cursor.getInt(0));
}
}
if (BuildConfig.DEBUG) LOGGER.debug("onLoadFinished({},{}) done", cursor, cursorLoader);
}
@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
// do nothing
if (BuildConfig.DEBUG) LOGGER.debug("onLoaderReset({}) done", cursorLoader);
}
@ViewById(R.id.txtStatus)
TextView txtStatus;
@ViewById(R.id.txtDescriptionStatus)
TextView txtDescriptionStatus;
@ViewById(R.id.imgStatus)
ImageView imgStatus;
@StringArrayRes
String[] stati, statiDescriptions;
@Bean
AccountCreator mAccountCreator;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLoaderManager().initLoader(STATUS_LOADER, null, this);
if (BuildConfig.DEBUG) LOGGER.debug("onCreate({}) done", savedInstanceState);
}
public void bind(Integer status) {
Log.v(StatusCardFragment.class.getSimpleName(), "Binding status=" + status);
final int statusInt = status.intValue();
imgStatus.setImageLevel(statusInt);
txtStatus.setText(stati[statusInt]);
txtDescriptionStatus.setText(statiDescriptions[statusInt]);
}
@Override
public void onResume() {
super.onResume();
Account account = mAccountCreator.getAccountRegisterAccount();
String authority = AccountCreator.getAuthority();
ContentResolver resolver = getActivity().getContentResolver();
// Turn on automatic syncing for the default account and authority
resolver.setSyncAutomatically(account, authority, true);
}
@Override
public void onPause() {
super.onPause();
}
}
package de.upb.fsmi.fsdroid.cards.views;
import android.content.*;
import android.content.res.*;
import android.util.*;
import android.widget.*;
import org.androidannotations.annotations.*;
import de.upb.fsmi.fsdroid.*;
@EViewGroup(R.layout.card_status)
public class StatusCardView extends RelativeLayout implements
CustomView<Integer> {
@ViewById(R.id.txtStatus)
TextView txtStatus;
@ViewById(R.id.txtDescriptionStatus)
TextView txtDescriptionStatus;
@ViewById(R.id.imgStatus)
ImageView imgStatus;
String[] stati, statiDescriptions;
public StatusCardView(Context context, AttributeSet attrs) {
super(context, attrs);
if (!isInEditMode()) {
Resources resources = getContext().getResources();
stati = resources.getStringArray(R.array.stati);
statiDescriptions = resources.getStringArray(R.array.statiDescriptions);
}
}
@Override
public void bind(Integer status) {
Log.v(StatusCardView.class.getSimpleName(), "Binding status=" + status);
final int statusInt = status.intValue();
imgStatus.setImageLevel(statusInt);
txtStatus.setText(stati[statusInt]);
txtDescriptionStatus.setText(statiDescriptions[statusInt]);
invalidate();
}
}
......@@ -21,7 +21,7 @@ import de.upb.fsmi.fsdroid.sync.*;
@EFragment(R.layout.fragment_news)
@OptionsMenu(R.menu.menu_main)
public class NewsFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>, SyncStatusObserver {
private static final int TUTORIAL_LIST_LOADER = 0x01;
private static final int NEWS_LOADER = 0x01;
private SimpleCursorAdapter adapter;
private final Logger LOGGER = LoggerFactory.getLogger(NewsFragment.TAG);
......@@ -49,6 +49,7 @@ public class NewsFragment extends ListFragment implements LoaderManager.LoaderCa
@Bean
AccountCreator mAccountCreator;
@StringRes
String news;
......@@ -65,7 +66,7 @@ public class NewsFragment extends ListFragment implements LoaderManager.LoaderCa
String[] uiBindFrom = NewsItemContract.NEWS_LIST_PROJECTION;
int[] uiBindTo = {R.id.newsHeadline, R.id.newsText};
getLoaderManager().initLoader(TUTORIAL_LIST_LOADER, null, this);
getLoaderManager().initLoader(NEWS_LOADER, null, this);
adapter = new SimpleCursorAdapter(
getActivity().getApplicationContext(), R.layout.card_news_item,
null, uiBindFrom, uiBindTo, 0);
......
package de.upb.fsmi.fsdroid.fragments;
import android.content.*;
import android.os.*;
import android.support.v4.app.*;
import android.support.v7.app.*;
import android.util.*;
import android.widget.*;
import org.androidannotations.annotations.*;
import org.androidannotations.annotations.res.*;
import org.slf4j.*;
import java.util.*;
import de.upb.fsmi.fsdroid.*;
import de.upb.fsmi.fsdroid.cards.views.*;
import de.upb.fsmi.fsdroid.helper.*;
import de.upb.fsmi.fsdroid.sync.*;
@EFragment(R.layout.fragment_overview)
@OptionsMenu(R.menu.menu_main)
......@@ -22,12 +19,10 @@ public class OverviewFragment extends Fragment {
@StringRes
String misc;
private static final String TAG = OverviewFragment.class.getSimpleName();
@ViewById
StatusCardView statusCard;
@ViewById
MeetingCardView meetingCard;
@FragmentById
StatusCardFragment statusCard;
@FragmentById
MeetingCardFragment meetingCard;
@AfterViews
void updateTitle() {
......@@ -36,50 +31,18 @@ public class OverviewFragment extends Fragment {
}
@Bean
DataKeeper dataKeeper;
@AfterViews
@UiThread
@Trace
protected void initCardView() {
refreshData();
}
@Background
void refreshData() {
try {
dataKeeper.refresh(false);
} catch (NoAvailableNetworkException e) {
Log.e(TAG, e.getMessage(), e);
}
refreshCards();
}
@UiThread
protected void refreshCards() {
refreshStatusCard();
refreshMeetingCard();
}
void refreshStatusCard() {
statusCard.bind(dataKeeper.getFsmiState());
}
void refreshMeetingCard() {
Date nextMeetingDate = dataKeeper.getNextMeetingDate();
if (nextMeetingDate != null) {
meetingCard.bind(dataKeeper.getNextMeetingDate());
}
}
AccountCreator mAccountCreator;
@OptionsItem(R.id.ab_refresh)
void refresh() {
Toast.makeText(getActivity(), "Refresh started", Toast.LENGTH_SHORT)
.show();
refreshData();
Bundle settingsBundle = new Bundle();
settingsBundle.putBoolean(
ContentResolver.SYNC_EXTRAS_MANUAL, true);
settingsBundle.putBoolean(
ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
ContentResolver.requestSync(mAccountCreator.getAccountRegisterAccount(), AccountCreator.getAuthority(), settingsBundle);
}
}
......@@ -12,7 +12,7 @@ import de.upb.fsmi.fsdroid.*;
/**
* Created by ljan on 10.01.14.
*/
@EBean
@EBean(scope = EBean.Scope.Singleton)
public class AccountCreator {
private static final String TAG = AccountCreator.class.getSimpleName();
Logger LOGGER = LoggerFactory.getLogger(TAG);
......@@ -22,6 +22,9 @@ public class AccountCreator {
@SystemService
AccountManager mAccountManager;
public AccountCreator() {
}
/**
* Neded for synchroniztation initialization
*/
......
......@@ -15,7 +15,7 @@ import de.upb.fsmi.fsdroid.sync.entities.*;
/**
* ContentProvider for fsmi data. Following uris are supported:
*
* <p/>
* content://de.fsmi.fsdroid.provider/news
* content://de.fsmi.fsdroid.provider/news/{newsId}
* content://de.fsmi.fsdroid.provider/status
......@@ -82,15 +82,10 @@ public class FSDroidContentProvider extends ContentProvider {
private Cursor queryStatus(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
NewsItemContract.checkNewsItemColumnsProjection(projection);
queryBuilder.setTables(Status.TABLE);
SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
queryBuilder.appendWhere(NewsItemContract.NewsItemColumns.COLUMN_ID + "="
+ uri.getLastPathSegment());
Cursor cursor = queryBuilder.query(db, projection, selection,
selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
......@@ -100,15 +95,10 @@ public class FSDroidContentProvider extends ContentProvider {
private Cursor queryMeetingDate(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
NewsItemContract.checkNewsItemColumnsProjection(projection);
queryBuilder.setTables(MeetingDate.TABLE);
SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
queryBuilder.appendWhere(NewsItemContract.NewsItemColumns.COLUMN_ID + "="
+ uri.getLastPathSegment());
Cursor cursor = queryBuilder.query(db, projection, selection,
selectionArgs, null, null, sortOrder);
cursor.setNotificationUri(getContext().getContentResolver(), uri);
......
......@@ -4,20 +4,14 @@ import android.accounts.*;
import android.annotation.*;
import android.content.*;
import android.os.*;
import android.util.*;
import org.slf4j.*;
import org.xmlpull.v1.*;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import de.upb.fsmi.fsdroid.*;
import de.upb.fsmi.fsdroid.sync.synchronizators.*;
import de.upb.fsmi.fsdroid.db.*;
import de.upb.fsmi.fsdroid.sync.entities.*;
/**
......@@ -86,10 +80,10 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
final int syncMask = bundle.getInt(SyncTypes.KEY);
try {
if ((syncMask & SyncTypes.STATUS) == SyncTypes.NEWS) {
if ((syncMask & SyncTypes.STATUS) == SyncTypes.STATUS) {
StatusSynchronizator.getInstance(mContext).executeSync();
}
if ((syncMask & SyncTypes.MEETING) == SyncTypes.NEWS) {
if ((syncMask & SyncTypes.MEETING) == SyncTypes.MEETING) {
MeetingSynchronizator.getInstance(mContext).executeSync();
}
if ((syncMask & SyncTypes.NEWS) == SyncTypes.NEWS) {
......
......@@ -17,6 +17,8 @@ import javax.xml.parsers.*;
import javax.xml.xpath.*;
import de.upb.fsmi.fsdroid.helper.*;
import de.upb.fsmi.fsdroid.sync.*;
import de.upb.fsmi.fsdroid.sync.entities.*;
/**
* Created by ljan on 03.03.14.
......@@ -31,6 +33,7 @@ public class MeetingSynchronizator implements Synchronizator {
public static final SimpleDateFormat API_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
public static final String MEETING_DATE_URL = "https://fsmi.uni-paderborn.de/?eID=fsmi_sitzung";
private final SimpleDateFormat germanFormat = new SimpleDateFormat("dd.MM.yyyy");
MeetingPrefs_ meetingPrefs;
......@@ -52,9 +55,13 @@ public class MeetingSynchronizator implements Synchronizator {
downloadedDate = parseDate(file);
if (downloadedDate != null) {
long currentTime = System.currentTimeMillis();
meetingPrefs.edit().lastMeetingUpdateInMillis()
.put(currentTime).nextMeetingInMillis()
.put(downloadedDate.getTime()).apply();
ContentValues cvs = new ContentValues();
cvs.put(MeetingDate.COLUMN_LAST_UPDATE, currentTime);
cvs.put(MeetingDate.COLUMN_VALUE, germanFormat.format(downloadedDate));
context.getContentResolver().insert(FSDroidContentProvider.MEETING_DATE_URI, cvs);
context.getContentResolver().notifyChange(FSDroidContentProvider.MEETING_DATE_URI, null);
}
file.deleteOnExit();
} catch (MalformedURLException e) {
......@@ -73,7 +80,7 @@ public class MeetingSynchronizator implements Synchronizator {
@SuppressWarnings("nls")
@SuppressLint("SimpleDateFormat")
private static Date parseDate(File file) throws SAXException, IOException,
ParserConfigurationException, FileNotFoundException,
ParserConfigurationException,
XPathExpressionException {
Date parsedDate = null;
......
......@@ -9,7 +9,10 @@ import java.io.*;
import java.net.*;
import java.util.*;
import de.upb.fsmi.fsdroid.*;
import de.upb.fsmi.fsdroid.helper.*;
import de.upb.fsmi.fsdroid.sync.*;
import de.upb.fsmi.fsdroid.sync.entities.*;
public class StatusSynchronizator implements Synchronizator {
@SuppressWarnings("nls")
......@@ -33,6 +36,8 @@ public class StatusSynchronizator implements Synchronizator {
@Override
public void executeSync() throws IOException, XmlPullParserException {
if (BuildConfig.DEBUG) LOGGER.debug("executeSync()");
File file = null;
try {
final String statusURL = STATUS_URL;
......@@ -40,9 +45,12 @@ public class StatusSynchronizator implements Synchronizator {
this.status = parseStatus(file) + 1;
final long currentTime = System.currentTimeMillis();
meetingPrefs.edit().lastStatus().put(status)
.lastStatusUpdateInMillis().put(currentTime).apply();
ContentValues cvs = new ContentValues();
cvs.put(Status.COLUMN_LAST_UPDATE, currentTime);
cvs.put(Status.COLUMN_VALUE, status);
context.getContentResolver().insert(FSDroidContentProvider.STATUS_URI, cvs);
context.getContentResolver().notifyChange(FSDroidContentProvider.STATUS_URI, null);
LOGGER.debug("Status refreshed, new status: {} ", status);
} catch (MalformedURLException e) {
LOGGER.error(e.getMessage(), e);
......@@ -50,17 +58,26 @@ public class StatusSynchronizator implements Synchronizator {
if (file != null) {
file.delete();
}