Skip to content

Commit 7cecef8

Browse files
committed
readAllPushMessages parameter change
1 parent 02f979e commit 7cecef8

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

euromsg/src/main/java/euromsg/com/euromobileandroid/utils/PayloadUtils.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
import java.text.SimpleDateFormat;
1616
import java.util.Date;
17-
import java.util.HashMap;
1817
import java.util.List;
1918
import java.util.Locale;
2019
import java.util.Map;
21-
import java.util.Objects;
2220

2321
import euromsg.com.euromobileandroid.Constants;
2422
import euromsg.com.euromobileandroid.EuroMobileManager;
@@ -360,7 +358,7 @@ public static void updatePayload(Context context, String pushId) {
360358
Log.e(LOG_TAG, e.getMessage());
361359
}
362360
}
363-
public static void readAllPushMessages(Context context, String pushId) {
361+
public static boolean readAllPushMessages(Context context) {
364362
try {
365363
String jsonString = SharedPreference.getString(context, Constants.PAYLOAD_SP_KEY);
366364
JSONObject jsonObject = new JSONObject(jsonString);
@@ -370,28 +368,17 @@ public static void readAllPushMessages(Context context, String pushId) {
370368
if (payloadsArray != null) {
371369
for (int i = 0; i < payloadsArray.length(); i++) {
372370
JSONObject payloadObject = payloadsArray.getJSONObject(i);
373-
String existingPushId = payloadObject.optString("pushId", "");
374-
375-
if (pushId != null && !pushId.isEmpty()) {
376-
if (existingPushId.equals(pushId)) {
377-
payloadObject.put("status", "O");
378-
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
379371

380-
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
381-
return;
382-
}
383-
} else {
384372
payloadObject.put("status", "O");
385373
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
386-
387-
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
388-
return;
389-
}
390374
}
375+
jsonObject.put(Constants.PAYLOAD_SP_ARRAY_KEY, payloadsArray);
376+
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
377+
return true;
391378

392-
Log.e(LOG_TAG, "Payload with pushId " + pushId + " not found!");
393379
} else {
394380
Log.e(LOG_TAG, "Payload array is null or empty!");
381+
return false;
395382
}
396383
} catch (Exception e) {
397384
StackTraceElement element = new Throwable().getStackTrace()[0];
@@ -404,9 +391,11 @@ public static void readAllPushMessages(Context context, String pushId) {
404391
Log.e(LOG_TAG, "Could not update the push message!");
405392
Log.e(LOG_TAG, e.getMessage());
406393
}
394+
return false;
407395
}
408396

409-
public static void readPushMessagesWithPushId(Context context, String pushId) {
397+
public boolean readPushMessagesWithPushId(Context context, String pushId) {
398+
boolean isUpdated = false;
410399
try {
411400
String jsonString = SharedPreference.getString(context, Constants.PAYLOAD_SP_KEY);
412401
JSONObject jsonObject = new JSONObject(jsonString);
@@ -417,20 +406,20 @@ public static void readPushMessagesWithPushId(Context context, String pushId) {
417406
for (int i = 0; i < payloadsArray.length(); i++) {
418407
JSONObject payloadObject = payloadsArray.getJSONObject(i);
419408
String existingPushId = payloadObject.optString("pushId", "");
420-
if (pushId != null && !pushId.isEmpty()) {
421-
if (existingPushId.equals(pushId)) {
422-
payloadObject.put("status", "O");
423-
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
424-
425-
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
426-
return;
427-
}
409+
if (pushId != null && !pushId.isEmpty() && existingPushId.equals(pushId)) {
410+
payloadObject.put("status", "O");
411+
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
412+
isUpdated = true;
428413
}
429414
}
430-
431-
Log.e(LOG_TAG, "Payload with pushId " + pushId + " not found!");
415+
if (isUpdated) {
416+
jsonObject.put(Constants.PAYLOAD_SP_ARRAY_KEY, payloadsArray);
417+
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
418+
}
419+
return isUpdated;
432420
} else {
433421
Log.e(LOG_TAG, "Payload array is null or empty!");
422+
return false;
434423
}
435424
} catch (Exception e) {
436425
StackTraceElement element = new Throwable().getStackTrace()[0];
@@ -442,6 +431,7 @@ public static void readPushMessagesWithPushId(Context context, String pushId) {
442431
);
443432
Log.e(LOG_TAG, "Could not update the push message!");
444433
Log.e(LOG_TAG, e.getMessage());
434+
return false;
445435
}
446436
}
447437

0 commit comments

Comments
 (0)