Completed notifications background processing
git-svn-id: https://forja.rediris.es/svn/cusl6-swadroid/trunk@106 5bc14d19-1e4b-4ba2-aa50-860af135f48c
This commit is contained in:
parent
612a69ddf9
commit
874a9a0c77
|
@ -17,9 +17,10 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".modules.Login"
|
android:name=".modules.Login"
|
||||||
android:label="@string/loginModuleLabel" android:configChanges="keyboard|keyboardHidden|orientation" android:theme="@android:style/Theme.Dialog">
|
android:label="@string/loginModuleLabel" android:configChanges="keyboard|keyboardHidden|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar">
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".modules.Courses" android:theme="@android:style/Theme.Dialog"></activity>
|
<activity android:name=".modules.Courses"><activity android:name=".modules.Courses" android:theme="@android:style/Theme.Dialog"></activity></activity>
|
||||||
|
<activity android:name=".modules.Notifications" android:label="@string/notificationsModuleLabel" android:icon="@drawable/ic_launcher_swadroid"></activity>
|
||||||
</application>
|
</application>
|
||||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||||
|
|
||||||
|
|
|
@ -29,35 +29,37 @@ public final class R {
|
||||||
}
|
}
|
||||||
public static final class string {
|
public static final class string {
|
||||||
public static final int app_name=0x7f060000;
|
public static final int app_name=0x7f060000;
|
||||||
public static final int close_dialog=0x7f060004;
|
public static final int close_dialog=0x7f060005;
|
||||||
public static final int coursesModuleLabel=0x7f060002;
|
public static final int coursesModuleLabel=0x7f060003;
|
||||||
public static final int coursesProgressDescription=0x7f060017;
|
public static final int coursesProgressDescription=0x7f060018;
|
||||||
public static final int coursesProgressTitle=0x7f060016;
|
public static final int coursesProgressTitle=0x7f060017;
|
||||||
public static final int errorCopyMsg_DB=0x7f06001a;
|
public static final int errorCopyMsg_DB=0x7f06001b;
|
||||||
public static final int errorMsgLaunchingActivity=0x7f060018;
|
public static final int errorMsgLaunchingActivity=0x7f060019;
|
||||||
public static final int errorMsgNoConnection=0x7f06001b;
|
public static final int errorMsgNoConnection=0x7f06001c;
|
||||||
public static final int errorMsgWorkaroundEmulator=0x7f060019;
|
public static final int errorMsgWorkaroundEmulator=0x7f06001a;
|
||||||
public static final int loginModuleLabel=0x7f060001;
|
public static final int loginModuleLabel=0x7f060001;
|
||||||
public static final int loginProgressDescription=0x7f060013;
|
public static final int loginProgressDescription=0x7f060014;
|
||||||
public static final int loginProgressTitle=0x7f060012;
|
public static final int loginProgressTitle=0x7f060013;
|
||||||
public static final int loginSuccessfulMsg=0x7f06001d;
|
public static final int loginSuccessfulMsg=0x7f06001e;
|
||||||
public static final int loginTitle_menu=0x7f060011;
|
public static final int loginTitle_menu=0x7f060012;
|
||||||
public static final int notificationsProgressDescription=0x7f060015;
|
public static final int notificationsModuleLabel=0x7f060002;
|
||||||
public static final int notificationsProgressTitle=0x7f060014;
|
public static final int notificationsProgressDescription=0x7f060016;
|
||||||
public static final int preferencesTitle_menu=0x7f060010;
|
public static final int notificationsProgressTitle=0x7f060015;
|
||||||
public static final int saveMsg_preferences=0x7f06000d;
|
public static final int notificationsSuccessfulMsg=0x7f06001f;
|
||||||
public static final int saveSummary_preferences=0x7f06000e;
|
public static final int preferencesTitle_menu=0x7f060011;
|
||||||
public static final int saveTitle_preferences=0x7f06000f;
|
public static final int saveMsg_preferences=0x7f06000e;
|
||||||
public static final int set_preferences=0x7f060005;
|
public static final int saveSummary_preferences=0x7f06000f;
|
||||||
public static final int title_error_dialog=0x7f060003;
|
public static final int saveTitle_preferences=0x7f060010;
|
||||||
public static final int upgradeMsg_DB=0x7f06001c;
|
public static final int set_preferences=0x7f060006;
|
||||||
public static final int userIDName_preferences=0x7f060007;
|
public static final int title_error_dialog=0x7f060004;
|
||||||
public static final int userIDSummary_preferences=0x7f060008;
|
public static final int upgradeMsg_DB=0x7f06001d;
|
||||||
public static final int userIDTitle_preferences=0x7f060009;
|
public static final int userIDName_preferences=0x7f060008;
|
||||||
public static final int userPasswordName_preferences=0x7f06000a;
|
public static final int userIDSummary_preferences=0x7f060009;
|
||||||
public static final int userPasswordSummary_preferences=0x7f06000b;
|
public static final int userIDTitle_preferences=0x7f06000a;
|
||||||
public static final int userPasswordTitle_preferences=0x7f06000c;
|
public static final int userPasswordName_preferences=0x7f06000b;
|
||||||
public static final int user_preferences=0x7f060006;
|
public static final int userPasswordSummary_preferences=0x7f06000c;
|
||||||
|
public static final int userPasswordTitle_preferences=0x7f06000d;
|
||||||
|
public static final int user_preferences=0x7f060007;
|
||||||
}
|
}
|
||||||
public static final class xml {
|
public static final class xml {
|
||||||
public static final int preferences=0x7f040000;
|
public static final int preferences=0x7f040000;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">SWADroid</string>
|
<string name="app_name">SWADroid</string>
|
||||||
<string name="loginModuleLabel">Conectar</string><string name="coursesModuleLabel">Asignaturas</string>
|
<string name="loginModuleLabel">Conectar</string><string name="notificationsModuleLabel">Notificaciones</string><string name="coursesModuleLabel">Asignaturas</string>
|
||||||
<string name="title_error_dialog">ERROR</string>
|
<string name="title_error_dialog">ERROR</string>
|
||||||
<string name="close_dialog">Cerrar</string>
|
<string name="close_dialog">Cerrar</string>
|
||||||
<string name="set_preferences">Configuración</string>
|
<string name="set_preferences">Configuración</string>
|
||||||
|
@ -22,5 +22,5 @@
|
||||||
<string name="coursesProgressTitle">Asignaturas</string><string name="coursesProgressDescription">Obteniendo asignaturas...</string><string name="notificationsProgressTitle">Notificaciones</string><string name="notificationsProgressDescription">Obteniendo nuevas notificaciones</string><string name="errorMsgWorkaroundEmulator">Mierda. Ese bug del emulador de Android ha vuelto a aparecer. Reintentando...</string>
|
<string name="coursesProgressTitle">Asignaturas</string><string name="coursesProgressDescription">Obteniendo asignaturas...</string><string name="notificationsProgressTitle">Notificaciones</string><string name="notificationsProgressDescription">Obteniendo nuevas notificaciones</string><string name="errorMsgWorkaroundEmulator">Mierda. Ese bug del emulador de Android ha vuelto a aparecer. Reintentando...</string>
|
||||||
<string name="errorMsgLaunchingActivity">Ha ocurrido un error durante la ejecución de la operación</string><string name="errorMsgNoConnection">No hay conexión</string>
|
<string name="errorMsgLaunchingActivity">Ha ocurrido un error durante la ejecución de la operación</string><string name="errorMsgNoConnection">No hay conexión</string>
|
||||||
<string name="errorCopyMsg_DB">Error copiando base de datos</string><string name="upgradeMsg_DB">Actualizando base de datos...</string>
|
<string name="errorCopyMsg_DB">Error copiando base de datos</string><string name="upgradeMsg_DB">Actualizando base de datos...</string>
|
||||||
<string name="loginSuccessfulMsg">Conectado</string>
|
<string name="loginSuccessfulMsg">Conectado</string><string name="notificationsSuccessfulMsg">Notificaciones descargadas</string>
|
||||||
</resources>
|
</resources>
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">SWADroid</string>
|
<string name="app_name">SWADroid</string>
|
||||||
<string name="loginModuleLabel">Login</string><string name="coursesModuleLabel">Courses</string>
|
<string name="loginModuleLabel">Login</string><string name="notificationsModuleLabel">Notifications</string><string name="coursesModuleLabel">Courses</string>
|
||||||
<string name="title_error_dialog">ERROR</string>
|
<string name="title_error_dialog">ERROR</string>
|
||||||
<string name="close_dialog">Close</string>
|
<string name="close_dialog">Close</string>
|
||||||
<string name="set_preferences">Preferences</string>
|
<string name="set_preferences">Preferences</string>
|
||||||
|
@ -19,11 +19,13 @@
|
||||||
<string name="loginTitle_menu">Login</string>
|
<string name="loginTitle_menu">Login</string>
|
||||||
<string name="loginProgressTitle">Login</string>
|
<string name="loginProgressTitle">Login</string>
|
||||||
<string name="loginProgressDescription">Connecting...</string>
|
<string name="loginProgressDescription">Connecting...</string>
|
||||||
<string name="notificationsProgressTitle">Notifications</string><string name="notificationsProgressDescription">Getting new notifications</string><string name="coursesProgressTitle">Courses</string><string name="coursesProgressDescription">Getting courses...</string><string name="errorMsgLaunchingActivity">An error occurred during the execution of the operation</string>
|
<string name="notificationsProgressTitle">Notifications</string><string name="notificationsProgressDescription">Fetching new notifications</string><string name="coursesProgressTitle">Courses</string><string name="coursesProgressDescription">Getting courses...</string><string name="errorMsgLaunchingActivity">An error occurred during the execution of the operation</string>
|
||||||
<string name="errorMsgWorkaroundEmulator">Damn. That Android emulator bug appeared again. Retrying...</string>
|
<string name="errorMsgWorkaroundEmulator">Damn. That Android emulator bug appeared again. Retrying...</string>
|
||||||
|
|
||||||
<string name="errorCopyMsg_DB">Error copying database</string>
|
<string name="errorCopyMsg_DB">Error copying database</string>
|
||||||
<string name="errorMsgNoConnection">No connection found</string><string name="upgradeMsg_DB">Upgrading database...</string><string name="loginSuccessfulMsg">Login successful</string>
|
<string name="errorMsgNoConnection">No connection found</string><string name="upgradeMsg_DB">Upgrading database...</string><string name="loginSuccessfulMsg">Login successful</string>
|
||||||
|
<string name="notificationsSuccessfulMsg">Notifications fetched</string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<database name="swadroid_db" version="2">
|
<database name="swadroid_db" version="4">
|
||||||
<table name="courses" to-string="%name%">
|
<table name="courses" to-string="%name%">
|
||||||
<field name="id" obligatory="true" type="integer"/>
|
<field name="id" obligatory="true" type="integer"/>
|
||||||
<field name="name" obligatory="true" type="text"/>
|
<field name="name" obligatory="true" type="text"/>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<table name="notifications" to-string="%name%">
|
<table name="notifications" to-string="%name%" new-in-version="3">
|
||||||
<field name="id" obligatory="true" type="integer"/>
|
<field name="id" obligatory="true" type="integer"/>
|
||||||
<field name="eventType" obligatory="true" type="text"/>
|
<field name="eventType" obligatory="true" type="text"/>
|
||||||
<field name="eventTime" obligatory="true" type="integer"/>
|
<field name="eventTime" obligatory="true" type="text"/>
|
||||||
<field name="userSurname1" obligatory="true" type="text"/>
|
<field name="userSurname1" obligatory="true" type="text"/>
|
||||||
<field name="userSurname2" obligatory="true" type="text"/>
|
<field name="userSurname2" obligatory="true" type="text"/>
|
||||||
<field name="userFirstname" obligatory="true" type="text"/>
|
<field name="userFirstname" obligatory="true" type="text"/>
|
||||||
<field name="location" obligatory="true" type="text"/>
|
<field name="location" obligatory="true" type="text"/>
|
||||||
<field name="summary" obligatory="true" type="text"/>
|
<field name="summary" obligatory="true" type="text"/>
|
||||||
|
<field name="status" obligatory="true" type="text" new-in-version="4"/>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</database>
|
</database>
|
|
@ -27,7 +27,7 @@ public class Global {
|
||||||
/**
|
/**
|
||||||
* SWAD application key
|
* SWAD application key
|
||||||
*/
|
*/
|
||||||
private static final String AppKey = "HTC-Desire";
|
private static final String AppKey = "";
|
||||||
/**
|
/**
|
||||||
* User logged flag
|
* User logged flag
|
||||||
*/
|
*/
|
||||||
|
@ -64,6 +64,10 @@ public class Global {
|
||||||
* Login tag name for Logcat
|
* Login tag name for Logcat
|
||||||
*/
|
*/
|
||||||
public static final String LOGIN_TAG = "Login";
|
public static final String LOGIN_TAG = "Login";
|
||||||
|
/**
|
||||||
|
* Notifications tag name for Logcat
|
||||||
|
*/
|
||||||
|
public static final String NOTIFICATIONS_TAG = "Notifications";
|
||||||
/*
|
/*
|
||||||
* Table name for courses
|
* Table name for courses
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,7 +35,7 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import es.ugr.swad.swadroid.model.DataBaseHelper;
|
import es.ugr.swad.swadroid.model.DataBaseHelper;
|
||||||
import es.ugr.swad.swadroid.model.Notification;
|
import es.ugr.swad.swadroid.modules.Notifications;
|
||||||
import es.ugr.swad.swadroid.ssl.SecureConnection;
|
import es.ugr.swad.swadroid.ssl.SecureConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,10 +118,13 @@ public class SWADMain extends ListActivity {
|
||||||
if (resultCode == ListActivity.RESULT_OK) {
|
if (resultCode == ListActivity.RESULT_OK) {
|
||||||
//Bundle extras = data.getExtras();
|
//Bundle extras = data.getExtras();
|
||||||
|
|
||||||
/*switch(requestCode) {
|
switch(requestCode) {
|
||||||
case Global.LOGIN_REQUEST_CODE:
|
case Global.NOTIFICATIONS_REQUEST_CODE:
|
||||||
break;
|
Toast.makeText(getBaseContext(),
|
||||||
}*/
|
R.string.notificationsSuccessfulMsg,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
Log.d(Global.NOTIFICATIONS_TAG, getString(R.string.notificationsSuccessfulMsg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,15 +135,19 @@ public class SWADMain extends ListActivity {
|
||||||
Object o = this.getListAdapter().getItem(position);
|
Object o = this.getListAdapter().getItem(position);
|
||||||
String keyword = o.toString();
|
String keyword = o.toString();
|
||||||
|
|
||||||
|
Intent activity;
|
||||||
switch(position)
|
switch(position)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
Intent notificationsActivity = new Intent(getBaseContext(),
|
activity = new Intent(getBaseContext(),
|
||||||
Notification.class);
|
Notifications.class);
|
||||||
startActivityForResult(notificationsActivity, Global.NOTIFICATIONS_REQUEST_CODE);
|
startActivityForResult(activity, Global.NOTIFICATIONS_REQUEST_CODE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
|
/*activity = new Intent(getBaseContext(),
|
||||||
|
Tests.class);
|
||||||
|
startActivityForResult(activity, Global.TESTS_REQUEST_CODE);*/
|
||||||
Toast.makeText(this, keyword + " aún no implementado", Toast.LENGTH_LONG)
|
Toast.makeText(this, keyword + " aún no implementado", Toast.LENGTH_LONG)
|
||||||
.show();
|
.show();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -159,14 +159,19 @@ public class DataBaseHelper {
|
||||||
public void insertNotification(Notification n)
|
public void insertNotification(Notification n)
|
||||||
{
|
{
|
||||||
Entity ent = new Entity(Global.DB_TABLE_NOTIFICATIONS);
|
Entity ent = new Entity(Global.DB_TABLE_NOTIFICATIONS);
|
||||||
|
|
||||||
|
String eventTime = String.valueOf(n.getEventTime());
|
||||||
|
String status = String.valueOf(n.getStatus());
|
||||||
|
|
||||||
ent.setValue("id", n.getId());
|
ent.setValue("id", n.getId());
|
||||||
ent.setValue("eventType", n.getEventType());
|
ent.setValue("eventType", n.getEventType());
|
||||||
ent.setValue("eventTime", n.getEventTime());
|
ent.setValue("eventTime", eventTime);
|
||||||
ent.setValue("userSurname1", n.getUserSurname1());
|
ent.setValue("userSurname1", n.getUserSurname1());
|
||||||
ent.setValue("userSurname2", n.getUserSurname2());
|
ent.setValue("userSurname2", n.getUserSurname2());
|
||||||
ent.setValue("userFirstName", n.getUserFirstName());
|
ent.setValue("userFirstName", n.getUserFirstName());
|
||||||
ent.setValue("location", n.getLocation());
|
ent.setValue("location", n.getLocation());
|
||||||
ent.setValue("summary", n.getSummary());
|
ent.setValue("summary", n.getSummary());
|
||||||
|
ent.setValue("status", status);
|
||||||
ent.save();
|
ent.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,13 +213,19 @@ public class DataBaseHelper {
|
||||||
{
|
{
|
||||||
List<Entity> rows = db.getEntityList(Global.DB_TABLE_NOTIFICATIONS, "id = " + prev.getId());
|
List<Entity> rows = db.getEntityList(Global.DB_TABLE_NOTIFICATIONS, "id = " + prev.getId());
|
||||||
Entity ent = rows.get(0);
|
Entity ent = rows.get(0);
|
||||||
|
|
||||||
|
String eventTime = String.valueOf(actual.getEventTime());
|
||||||
|
String status = String.valueOf(actual.getStatus());
|
||||||
|
|
||||||
ent.setValue("id", actual.getId());
|
ent.setValue("id", actual.getId());
|
||||||
ent.setValue("eventType", actual.getEventType());
|
ent.setValue("eventType", actual.getEventType());
|
||||||
ent.setValue("eventTime", actual.getEventTime());
|
ent.setValue("eventTime", eventTime);
|
||||||
ent.setValue("userSurname1", actual.getUserSurname1());
|
ent.setValue("userSurname1", actual.getUserSurname1());
|
||||||
ent.setValue("userSurname2", actual.getUserSurname2());
|
ent.setValue("userSurname2", actual.getUserSurname2());
|
||||||
ent.setValue("userFirstName", actual.getUserFirstName());
|
ent.setValue("userFirstName", actual.getUserFirstName());
|
||||||
ent.setValue("location", actual.getSummary());
|
ent.setValue("location", actual.getLocation());
|
||||||
|
ent.setValue("summary", actual.getSummary());
|
||||||
|
ent.setValue("status", status);
|
||||||
ent.save();
|
ent.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,42 +311,38 @@ public class DataBaseHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets timestamp of last notification
|
* Gets a field of last notification
|
||||||
* @return Timestamp of last notification
|
* @param field A field of last notification
|
||||||
|
* @return The field of last notification
|
||||||
*/
|
*/
|
||||||
public int getLastNotificationTimestamp()
|
public String getFieldOfLastNotification(String field)
|
||||||
{
|
{
|
||||||
List<Entity> rows = db.getEntityList(Global.DB_TABLE_NOTIFICATIONS);
|
String orderby = "eventTime desc";
|
||||||
int timestamp;
|
List<Entity> rows = db.getEntityList(Global.DB_TABLE_NOTIFICATIONS, null, orderby);
|
||||||
|
String f = "0";
|
||||||
|
|
||||||
if(rows.size() > 0)
|
if(rows.size() > 0)
|
||||||
{
|
{
|
||||||
Entity ent = rows.get(rows.size()-1);
|
Entity ent = rows.get(rows.size()-1);
|
||||||
timestamp = (Integer) ent.getValue("eventTime");
|
f = (String) ent.getValue(field);
|
||||||
} else {
|
|
||||||
timestamp = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return timestamp;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets id of last notification
|
* Clear old notifications
|
||||||
* @return Id of last notification
|
* @param timestamp Newest timestamp to clear
|
||||||
*/
|
*/
|
||||||
public int getLastNotificationId()
|
public void clearOldNotifications(long timestamp)
|
||||||
{
|
{
|
||||||
List<Entity> rows = db.getEntityList(Global.DB_TABLE_NOTIFICATIONS);
|
String where = "eventTime < " + timestamp;
|
||||||
int id;
|
List<Entity> rows = db.getEntityList(Global.DB_TABLE_NOTIFICATIONS, where);
|
||||||
|
Iterator<Entity> iter = rows.iterator();
|
||||||
|
|
||||||
if(rows.size() > 0)
|
while (iter.hasNext()) {
|
||||||
{
|
Entity ent = iter.next();
|
||||||
Entity ent = rows.get(rows.size()-1);
|
ent.delete();
|
||||||
id = (Integer) ent.getValue("id");
|
|
||||||
} else {
|
|
||||||
id = 0;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class Notification extends Model {
|
||||||
/**
|
/**
|
||||||
* Notification timestamp
|
* Notification timestamp
|
||||||
*/
|
*/
|
||||||
private int eventTime;
|
private long eventTime;
|
||||||
/**
|
/**
|
||||||
* Sender first surname
|
* Sender first surname
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,10 @@ public class Notification extends Model {
|
||||||
* Notification summary
|
* Notification summary
|
||||||
*/
|
*/
|
||||||
private String summary;
|
private String summary;
|
||||||
|
/**
|
||||||
|
* Notification status
|
||||||
|
*/
|
||||||
|
private int status;
|
||||||
private static PropertyInfo PI_id = new PropertyInfo();
|
private static PropertyInfo PI_id = new PropertyInfo();
|
||||||
private static PropertyInfo PI_eventType = new PropertyInfo();
|
private static PropertyInfo PI_eventType = new PropertyInfo();
|
||||||
private static PropertyInfo PI_eventTime = new PropertyInfo();
|
private static PropertyInfo PI_eventTime = new PropertyInfo();
|
||||||
|
@ -63,6 +67,7 @@ public class Notification extends Model {
|
||||||
private static PropertyInfo PI_userFirstName = new PropertyInfo();
|
private static PropertyInfo PI_userFirstName = new PropertyInfo();
|
||||||
private static PropertyInfo PI_location = new PropertyInfo();
|
private static PropertyInfo PI_location = new PropertyInfo();
|
||||||
private static PropertyInfo PI_summary = new PropertyInfo();
|
private static PropertyInfo PI_summary = new PropertyInfo();
|
||||||
|
private static PropertyInfo PI_status = new PropertyInfo();
|
||||||
private static PropertyInfo[] PI_PROP_ARRAY =
|
private static PropertyInfo[] PI_PROP_ARRAY =
|
||||||
{
|
{
|
||||||
PI_id,
|
PI_id,
|
||||||
|
@ -72,7 +77,8 @@ public class Notification extends Model {
|
||||||
PI_userSurname2,
|
PI_userSurname2,
|
||||||
PI_userFirstName,
|
PI_userFirstName,
|
||||||
PI_location,
|
PI_location,
|
||||||
PI_summary
|
PI_summary,
|
||||||
|
PI_status
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,10 +90,11 @@ public class Notification extends Model {
|
||||||
* @param userFirstName Sender first name
|
* @param userFirstName Sender first name
|
||||||
* @param location Notification location
|
* @param location Notification location
|
||||||
* @param summary Notification summary
|
* @param summary Notification summary
|
||||||
|
* @param status Notification summary
|
||||||
*/
|
*/
|
||||||
public Notification(int id, String eventType, int eventTime,
|
public Notification(int id, String eventType, long eventTime,
|
||||||
String userSurname1, String userSurname2, String userFirstName,
|
String userSurname1, String userSurname2, String userFirstName,
|
||||||
String location, String summary) {
|
String location, String summary, int status) {
|
||||||
|
|
||||||
super(id);
|
super(id);
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
|
@ -97,6 +104,7 @@ public class Notification extends Model {
|
||||||
this.userFirstName = userFirstName;
|
this.userFirstName = userFirstName;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +127,7 @@ public class Notification extends Model {
|
||||||
* Gets notification timestamp
|
* Gets notification timestamp
|
||||||
* @return Notification timestamp
|
* @return Notification timestamp
|
||||||
*/
|
*/
|
||||||
public int getEventTime() {
|
public long getEventTime() {
|
||||||
return eventTime;
|
return eventTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,6 +219,22 @@ public class Notification extends Model {
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets notification status
|
||||||
|
* @return Notification status
|
||||||
|
*/
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets notification status
|
||||||
|
* @param status Notification status
|
||||||
|
*/
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
|
@ -218,11 +242,12 @@ public class Notification extends Model {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = super.hashCode();
|
int result = super.hashCode();
|
||||||
result = prime * result + eventTime;
|
result = prime * result + (int) (eventTime ^ (eventTime >>> 32));
|
||||||
result = prime * result
|
result = prime * result
|
||||||
+ ((eventType == null) ? 0 : eventType.hashCode());
|
+ ((eventType == null) ? 0 : eventType.hashCode());
|
||||||
result = prime * result
|
result = prime * result
|
||||||
+ ((location == null) ? 0 : location.hashCode());
|
+ ((location == null) ? 0 : location.hashCode());
|
||||||
|
result = prime * result + status;
|
||||||
result = prime * result + ((summary == null) ? 0 : summary.hashCode());
|
result = prime * result + ((summary == null) ? 0 : summary.hashCode());
|
||||||
result = prime * result
|
result = prime * result
|
||||||
+ ((userFirstName == null) ? 0 : userFirstName.hashCode());
|
+ ((userFirstName == null) ? 0 : userFirstName.hashCode());
|
||||||
|
@ -257,6 +282,8 @@ public class Notification extends Model {
|
||||||
return false;
|
return false;
|
||||||
} else if (!location.equals(other.location))
|
} else if (!location.equals(other.location))
|
||||||
return false;
|
return false;
|
||||||
|
if (status != other.status)
|
||||||
|
return false;
|
||||||
if (summary == null) {
|
if (summary == null) {
|
||||||
if (other.summary != null)
|
if (other.summary != null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -278,7 +305,7 @@ public class Notification extends Model {
|
||||||
} else if (!userSurname2.equals(other.userSurname2))
|
} else if (!userSurname2.equals(other.userSurname2))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
|
@ -289,7 +316,7 @@ public class Notification extends Model {
|
||||||
+ eventTime + ", userSurname1=" + userSurname1
|
+ eventTime + ", userSurname1=" + userSurname1
|
||||||
+ ", userSurname2=" + userSurname2 + ", userFirstName="
|
+ ", userSurname2=" + userSurname2 + ", userFirstName="
|
||||||
+ userFirstName + ", location=" + location + ", summary="
|
+ userFirstName + ", location=" + location + ", summary="
|
||||||
+ summary + ", getId()=" + getId() + "]";
|
+ summary + ", status=" + status + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -307,6 +334,7 @@ public class Notification extends Model {
|
||||||
case 5 : object = userFirstName;break;
|
case 5 : object = userFirstName;break;
|
||||||
case 6 : object = location;break;
|
case 6 : object = location;break;
|
||||||
case 7 : object = summary;break;
|
case 7 : object = summary;break;
|
||||||
|
case 8 : object = status;break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
|
@ -316,7 +344,7 @@ public class Notification extends Model {
|
||||||
* @see org.ksoap2.serialization.KvmSerializable#getPropertyCount()
|
* @see org.ksoap2.serialization.KvmSerializable#getPropertyCount()
|
||||||
*/
|
*/
|
||||||
public int getPropertyCount() {
|
public int getPropertyCount() {
|
||||||
return 8;
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -333,7 +361,7 @@ public class Notification extends Model {
|
||||||
propertyInfo.name = "eventType";
|
propertyInfo.name = "eventType";
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
propertyInfo.type = PropertyInfo.INTEGER_CLASS;
|
propertyInfo.type = PropertyInfo.LONG_CLASS;
|
||||||
propertyInfo.name = "eventTime";
|
propertyInfo.name = "eventTime";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -356,6 +384,10 @@ public class Notification extends Model {
|
||||||
propertyInfo.type = PropertyInfo.STRING_CLASS;
|
propertyInfo.type = PropertyInfo.STRING_CLASS;
|
||||||
propertyInfo.name = "summary";
|
propertyInfo.name = "summary";
|
||||||
break;
|
break;
|
||||||
|
case 8:
|
||||||
|
propertyInfo.type = PropertyInfo.INTEGER_CLASS;
|
||||||
|
propertyInfo.name = "status";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,13 +399,13 @@ public class Notification extends Model {
|
||||||
{
|
{
|
||||||
case 0 : this.setId((Integer)obj); break;
|
case 0 : this.setId((Integer)obj); break;
|
||||||
case 1 : eventType = (String)obj; break;
|
case 1 : eventType = (String)obj; break;
|
||||||
case 2 : eventTime = (Integer)obj; break;
|
case 2 : eventTime = (Long)obj; break;
|
||||||
case 3 : userSurname1 = (String)obj; break;
|
case 3 : userSurname1 = (String)obj; break;
|
||||||
case 4 : userSurname2 = (String)obj; break;
|
case 4 : userSurname2 = (String)obj; break;
|
||||||
case 5 : userFirstName = (String)obj; break;
|
case 5 : userFirstName = (String)obj; break;
|
||||||
case 6 : location = (String)obj; break;
|
case 6 : location = (String)obj; break;
|
||||||
case 7 : summary = (String)obj; break;
|
case 7 : summary = (String)obj; break;
|
||||||
|
case 8 : status = (Integer)obj; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@ import android.net.NetworkInfo;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.Window;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import es.ugr.swad.swadroid.Global;
|
import es.ugr.swad.swadroid.Global;
|
||||||
import es.ugr.swad.swadroid.Preferences;
|
import es.ugr.swad.swadroid.Preferences;
|
||||||
|
@ -52,10 +56,6 @@ import com.android.dataframework.DataFramework;
|
||||||
* Superclass for encapsulate common behavior of all modules.
|
* Superclass for encapsulate common behavior of all modules.
|
||||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
||||||
*/
|
*/
|
||||||
/**
|
|
||||||
* @author Juan Miguel Boyero Corral <juanmi1982@gmail.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class Module extends Activity {
|
public abstract class Module extends Activity {
|
||||||
/**
|
/**
|
||||||
* SOAP_ACTION param for webservice request.
|
* SOAP_ACTION param for webservice request.
|
||||||
|
@ -97,6 +97,10 @@ public abstract class Module extends Activity {
|
||||||
* Database Framework.
|
* Database Framework.
|
||||||
*/
|
*/
|
||||||
private static DataFramework db;
|
private static DataFramework db;
|
||||||
|
/**
|
||||||
|
* Connection available flag
|
||||||
|
*/
|
||||||
|
protected static boolean isConnected;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to SWAD and gets user data.
|
* Connects to SWAD and gets user data.
|
||||||
|
@ -227,6 +231,24 @@ public abstract class Module extends Activity {
|
||||||
public void setResult(Object result) {
|
public void setResult(Object result) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch login activity when required
|
||||||
|
*/
|
||||||
|
private void runLogin()
|
||||||
|
{
|
||||||
|
isConnected = connectionAvailable(this);
|
||||||
|
if (!isConnected) {
|
||||||
|
Toast.makeText(this, R.string.errorMsgNoConnection, Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
//If not logged and this is not the Login module, launch login
|
||||||
|
if(!Global.isLogged() && !(this instanceof Login)) {
|
||||||
|
Intent loginActivity = new Intent(getBaseContext(),
|
||||||
|
Login.class);
|
||||||
|
startActivityForResult(loginActivity, Global.LOGIN_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see android.app.Activity#onCreate()
|
* @see android.app.Activity#onCreate()
|
||||||
|
@ -236,6 +258,10 @@ public abstract class Module extends Activity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
prefs.getPreferences(getBaseContext());
|
prefs.getPreferences(getBaseContext());
|
||||||
|
|
||||||
|
Window w = getWindow();
|
||||||
|
w.requestFeature(Window.FEATURE_LEFT_ICON);
|
||||||
|
w.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher_swadroid);
|
||||||
|
|
||||||
//If not connected to database, connect now
|
//If not connected to database, connect now
|
||||||
if(dbHelper == null) {
|
if(dbHelper == null) {
|
||||||
try {
|
try {
|
||||||
|
@ -246,13 +272,8 @@ public abstract class Module extends Activity {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//If not logged and this is not the Login module, launch login
|
runLogin();
|
||||||
if(!Global.isLogged() && !(this instanceof Login)) {
|
|
||||||
Intent loginActivity = new Intent(getBaseContext(),
|
|
||||||
Login.class);
|
|
||||||
startActivityForResult(loginActivity, Global.LOGIN_REQUEST_CODE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -374,6 +395,39 @@ public abstract class Module extends Activity {
|
||||||
})
|
})
|
||||||
.setIcon(R.drawable.erroricon).show();
|
.setIcon(R.drawable.erroricon).show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows Preferences screen
|
||||||
|
*/
|
||||||
|
protected void viewPreferences() {
|
||||||
|
Intent settingsActivity = new Intent(getBaseContext(),
|
||||||
|
Preferences.class);
|
||||||
|
startActivity(settingsActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onCreateOptionsMenu()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.menu_main, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onOptionsItemSelected()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.preferences_menu:
|
||||||
|
viewPreferences();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.ksoap2.SoapFault;
|
||||||
import org.ksoap2.serialization.SoapObject;
|
import org.ksoap2.serialization.SoapObject;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import es.ugr.swad.swadroid.Global;
|
||||||
import es.ugr.swad.swadroid.R;
|
import es.ugr.swad.swadroid.R;
|
||||||
import es.ugr.swad.swadroid.model.User;
|
import es.ugr.swad.swadroid.model.User;
|
||||||
import es.ugr.swad.swadroid.model.Notification;
|
import es.ugr.swad.swadroid.model.Notification;
|
||||||
|
@ -37,12 +38,18 @@ import android.util.Log;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Notifications extends Module {
|
public class Notifications extends Module {
|
||||||
|
/**
|
||||||
|
* Time period to store notifications
|
||||||
|
*/
|
||||||
|
private static final long TIMESTAMP_LIMIT = 2629743; //A month
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see es.ugr.swad.swadroid.modules.Module#onCreate(android.os.Bundle)
|
* @see es.ugr.swad.swadroid.modules.Module#onCreate(android.os.Bundle)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
//setContentView(R.layout.notifications);
|
||||||
setMETHOD_NAME("getNotifications");
|
setMETHOD_NAME("getNotifications");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,41 +60,46 @@ public class Notifications extends Module {
|
||||||
protected void requestService() throws NoSuchAlgorithmException,
|
protected void requestService() throws NoSuchAlgorithmException,
|
||||||
IOException, XmlPullParserException, SoapFault,
|
IOException, XmlPullParserException, SoapFault,
|
||||||
IllegalAccessException, InstantiationException {
|
IllegalAccessException, InstantiationException {
|
||||||
|
|
||||||
//Calculates next timestamp to be requested
|
//Calculates next timestamp to be requested
|
||||||
int timestamp = dbHelper.getLastNotificationTimestamp() + 1;
|
Long timestamp = new Long(dbHelper.getFieldOfLastNotification("eventTime"));
|
||||||
|
timestamp++;
|
||||||
|
|
||||||
|
//Clear old notifications to control database size
|
||||||
|
dbHelper.clearOldNotifications(timestamp - TIMESTAMP_LIMIT);
|
||||||
|
|
||||||
//Creates webservice request, adds required params and sends request to webservice
|
//Creates webservice request, adds required params and sends request to webservice
|
||||||
createRequest();
|
createRequest();
|
||||||
addParam("wsKey", User.getWsKey());
|
addParam("wsKey", User.getWsKey());
|
||||||
addParam("beginTime", timestamp);
|
addParam("beginTime", timestamp);
|
||||||
sendRequest(Notification.class, false);
|
sendRequest(Notification.class, false);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
//Stores notifications data returned by webservice response
|
//Stores notifications data returned by webservice response
|
||||||
Vector res = (Vector) result;
|
Vector res = (Vector) result;
|
||||||
SoapObject soap = (SoapObject) res.get(1);
|
SoapObject soap = (SoapObject) res.get(1);
|
||||||
int csSize = soap.getPropertyCount();
|
int csSize = soap.getPropertyCount();
|
||||||
int lastId = dbHelper.getLastNotificationId();
|
Integer lastId = new Integer(dbHelper.getFieldOfLastNotification("id"));
|
||||||
for (int i = 0; i < csSize; i++) {
|
for (int i = 0; i < csSize; i++) {
|
||||||
SoapObject pii = (SoapObject)soap.getProperty(i);
|
SoapObject pii = (SoapObject)soap.getProperty(i);
|
||||||
String eventType = pii.getProperty(1).toString();
|
String eventType = pii.getProperty("eventType").toString();
|
||||||
int eventTime = Integer.parseInt(pii.getProperty(0).toString());
|
Long eventTime = new Long(pii.getProperty("eventTime").toString());
|
||||||
String userSurname1 = pii.getProperty(1).toString();
|
String userSurname1 = pii.getProperty("userSurname1").toString();
|
||||||
String userSurname2 = pii.getProperty(1).toString();
|
String userSurname2 = pii.getProperty("userSurname2").toString();
|
||||||
String userFirstName = pii.getProperty(1).toString();
|
String userFirstName = pii.getProperty("userFirstname").toString();
|
||||||
String location = pii.getProperty(1).toString();
|
String location = pii.getProperty("location").toString();
|
||||||
String summary = pii.getProperty(1).toString();
|
String summary = pii.getProperty("summary").toString();
|
||||||
Notification n = new Notification(lastId+i, eventType, eventTime, userSurname1, userSurname2, userFirstName, location, summary);
|
Integer status = new Integer(pii.getProperty("status").toString());
|
||||||
dbHelper.insertNotification(n);
|
Notification n = new Notification(lastId+i, eventType, eventTime, userSurname1, userSurname2, userFirstName, location, summary, status);
|
||||||
Log.d("Notifications", n.toString());
|
dbHelper.insertNotification(n);
|
||||||
}
|
Log.d(Global.NOTIFICATIONS_TAG, n.toString());
|
||||||
|
}
|
||||||
|
|
||||||
//Request finalized without errors
|
//Request finalized without errors
|
||||||
setResult(RESULT_OK);
|
//setResult(RESULT_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
finish();
|
//finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user