Completed "seen notifications" feature

This commit is contained in:
Juan Miguel Boyero Corral 2013-11-17 10:17:59 +01:00
parent 353ddf7220
commit cd5be67b93
3 changed files with 74 additions and 39 deletions

View File

@ -1209,6 +1209,21 @@ public class DataBaseHelper {
}
}
/**
* Updates a notification in database
*
* @param id Notification code of notification to be updated
* @param field Field to be updated
* @param value New field value
*/
public void updateNotification(long id, String field, String value) {
List<Entity> rows = db.getEntityList(Constants.DB_TABLE_NOTIFICATIONS, "id = " + id);
for(Entity ent : rows) {
ent.setValue(field, value);
ent.save();
}
}
/**
* Updates a notification in database
*
@ -1217,25 +1232,36 @@ public class DataBaseHelper {
*/
public void updateNotification(long id, SWADNotification actual) {
List<Entity> rows = db.getEntityList(Constants.DB_TABLE_NOTIFICATIONS, "id = " + id);
Entity ent = rows.get(0);
long newID = actual.getId();
String eventType = crypto.encrypt(actual.getEventType());
String eventTime = String.valueOf(actual.getEventTime());
String userSurname1 = crypto.encrypt(actual.getUserSurname1());
String userSurname2 = crypto.encrypt(actual.getUserSurname2());
String userFirstname = crypto.encrypt(actual.getUserFirstName());
String userPhoto = crypto.encrypt(actual.getUserPhoto());
String location = crypto.encrypt(actual.getLocation());
String summary = crypto.encrypt(actual.getSummary());
String status = String.valueOf(actual.getStatus());
ent.setValue("id", actual.getId());
ent.setValue("eventType", crypto.encrypt(actual.getEventType()));
ent.setValue("eventTime", eventTime);
ent.setValue("userSurname1", crypto.encrypt(actual.getUserSurname1()));
ent.setValue("userSurname2", crypto.encrypt(actual.getUserSurname2()));
ent.setValue("userFirstname", crypto.encrypt(actual.getUserFirstName()));
ent.setValue("userPhoto", crypto.encrypt(actual.getUserPhoto()));
ent.setValue("location", crypto.encrypt(actual.getLocation()));
ent.setValue("summary", crypto.encrypt(actual.getSummary()));
ent.setValue("status", status);
ent.setValue("content", crypto.encrypt(actual.getContent()));
ent.setValue("seenLocal", Utils.parseBoolString(actual.isSeenLocal()));
ent.setValue("seenRemote", Utils.parseBoolString(actual.isSeenRemote()));
ent.save();
String content = crypto.encrypt(actual.getContent());
String seenLocal = Utils.parseBoolString(actual.isSeenLocal());
String seenRemote = Utils.parseBoolString(actual.isSeenRemote());
for(Entity ent : rows) {
ent.setValue("id", newID);
ent.setValue("eventType", eventType);
ent.setValue("eventTime", eventTime);
ent.setValue("userSurname1", userSurname1);
ent.setValue("userSurname2", userSurname2);
ent.setValue("userFirstname", userFirstname);
ent.setValue("userPhoto", userPhoto);
ent.setValue("location", location);
ent.setValue("summary", summary);
ent.setValue("status", status);
ent.setValue("content", content);
ent.setValue("seenLocal", seenLocal);
ent.setValue("seenRemote", seenRemote);
ent.save();
}
}
/**
@ -1246,25 +1272,36 @@ public class DataBaseHelper {
*/
public void updateNotification(SWADNotification prev, SWADNotification actual) {
List<Entity> rows = db.getEntityList(Constants.DB_TABLE_NOTIFICATIONS, "id = " + prev.getId());
Entity ent = rows.get(0);
long newID = actual.getId();
String eventType = crypto.encrypt(actual.getEventType());
String eventTime = String.valueOf(actual.getEventTime());
String userSurname1 = crypto.encrypt(actual.getUserSurname1());
String userSurname2 = crypto.encrypt(actual.getUserSurname2());
String userFirstname = crypto.encrypt(actual.getUserFirstName());
String userPhoto = crypto.encrypt(actual.getUserPhoto());
String location = crypto.encrypt(actual.getLocation());
String summary = crypto.encrypt(actual.getSummary());
String status = String.valueOf(actual.getStatus());
ent.setValue("id", actual.getId());
ent.setValue("eventType", crypto.encrypt(actual.getEventType()));
ent.setValue("eventTime", eventTime);
ent.setValue("userSurname1", crypto.encrypt(actual.getUserSurname1()));
ent.setValue("userSurname2", crypto.encrypt(actual.getUserSurname2()));
ent.setValue("userFirstname", crypto.encrypt(actual.getUserFirstName()));
ent.setValue("userPhoto", crypto.encrypt(actual.getUserPhoto()));
ent.setValue("location", crypto.encrypt(actual.getLocation()));
ent.setValue("summary", crypto.encrypt(actual.getSummary()));
ent.setValue("status", status);
ent.setValue("content", crypto.encrypt(actual.getContent()));
ent.setValue("seenLocal", Utils.parseBoolString(actual.isSeenLocal()));
ent.setValue("seenRemote", Utils.parseBoolString(actual.isSeenRemote()));
ent.save();
String content = crypto.encrypt(actual.getContent());
String seenLocal = Utils.parseBoolString(actual.isSeenLocal());
String seenRemote = Utils.parseBoolString(actual.isSeenRemote());
for(Entity ent : rows) {
ent.setValue("id", newID);
ent.setValue("eventType", eventType);
ent.setValue("eventTime", eventTime);
ent.setValue("userSurname1", userSurname1);
ent.setValue("userSurname2", userSurname2);
ent.setValue("userFirstname", userFirstname);
ent.setValue("userPhoto", userPhoto);
ent.setValue("location", location);
ent.setValue("summary", summary);
ent.setValue("status", status);
ent.setValue("content", content);
ent.setValue("seenLocal", seenLocal);
ent.setValue("seenRemote", seenRemote);
ent.save();
}
}
/**

View File

@ -30,7 +30,6 @@ import android.widget.TextView;
import es.ugr.swad.swadroid.Constants;
import es.ugr.swad.swadroid.R;
import es.ugr.swad.swadroid.gui.MenuActivity;
import es.ugr.swad.swadroid.model.SWADNotification;
import es.ugr.swad.swadroid.modules.Messages;
import es.ugr.swad.swadroid.utils.DownloadImageTask;
import es.ugr.swad.swadroid.utils.Utils;
@ -58,7 +57,6 @@ public class NotificationItem extends MenuActivity {
ImageButton replyButton;
WebView webview;
String type = this.getIntent().getStringExtra("notificationType");
SWADNotification notif;
super.onCreate(savedInstanceState);
setContentView(R.layout.single_notification_view);
@ -122,9 +120,7 @@ public class NotificationItem extends MenuActivity {
//Set notification as seen locally
notificationCode = Long.valueOf(this.getIntent().getStringExtra("notificationCode"));
notif = (SWADNotification) dbHelper.getRow(Constants.DB_TABLE_NOTIFICATIONS, "id", String.valueOf(notificationCode));
notif.setSeenLocal(true);
dbHelper.updateNotification(notificationCode, notif);
dbHelper.updateNotification(notificationCode, "seenLocal", Utils.parseBoolString(true));
}
/**

View File

@ -114,6 +114,8 @@ public class NotificationsCursorAdapter extends CursorAdapter {
if(!seenLocal) {
view.setBackgroundColor(context.getResources().getColor(R.color.notifications_background_yellow));
} else {
view.setBackgroundColor(context.getResources().getColor(R.color.background));
}
if (contentVisible.length == 0) {