diff --git a/SWADroid/src/es/ugr/swad/swadroid/model/DataBaseHelper.java b/SWADroid/src/es/ugr/swad/swadroid/model/DataBaseHelper.java index cbf0f806..5c3ea2db 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/model/DataBaseHelper.java +++ b/SWADroid/src/es/ugr/swad/swadroid/model/DataBaseHelper.java @@ -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 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 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 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(); + } } /** diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationItem.java b/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationItem.java index b543eeed..c5487253 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationItem.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationItem.java @@ -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)); } /** diff --git a/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationsCursorAdapter.java b/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationsCursorAdapter.java index dd18390d..0145f0f5 100644 --- a/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationsCursorAdapter.java +++ b/SWADroid/src/es/ugr/swad/swadroid/modules/notifications/NotificationsCursorAdapter.java @@ -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) {