Skip to content

Commit

Permalink
readAllPushMessages parameter change
Browse files Browse the repository at this point in the history
  • Loading branch information
FatihUtkuKara committed May 10, 2024
1 parent 02f979e commit 7cecef8
Showing 1 changed file with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

import euromsg.com.euromobileandroid.Constants;
import euromsg.com.euromobileandroid.EuroMobileManager;
Expand Down Expand Up @@ -360,7 +358,7 @@ public static void updatePayload(Context context, String pushId) {
Log.e(LOG_TAG, e.getMessage());
}
}
public static void readAllPushMessages(Context context, String pushId) {
public static boolean readAllPushMessages(Context context) {
try {
String jsonString = SharedPreference.getString(context, Constants.PAYLOAD_SP_KEY);
JSONObject jsonObject = new JSONObject(jsonString);
Expand All @@ -370,28 +368,17 @@ public static void readAllPushMessages(Context context, String pushId) {
if (payloadsArray != null) {
for (int i = 0; i < payloadsArray.length(); i++) {
JSONObject payloadObject = payloadsArray.getJSONObject(i);
String existingPushId = payloadObject.optString("pushId", "");

if (pushId != null && !pushId.isEmpty()) {
if (existingPushId.equals(pushId)) {
payloadObject.put("status", "O");
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));

SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
return;
}
} else {
payloadObject.put("status", "O");
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));

SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
return;
}
}
jsonObject.put(Constants.PAYLOAD_SP_ARRAY_KEY, payloadsArray);
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
return true;

Log.e(LOG_TAG, "Payload with pushId " + pushId + " not found!");
} else {
Log.e(LOG_TAG, "Payload array is null or empty!");
return false;
}
} catch (Exception e) {
StackTraceElement element = new Throwable().getStackTrace()[0];
Expand All @@ -404,9 +391,11 @@ public static void readAllPushMessages(Context context, String pushId) {
Log.e(LOG_TAG, "Could not update the push message!");
Log.e(LOG_TAG, e.getMessage());
}
return false;
}

public static void readPushMessagesWithPushId(Context context, String pushId) {
public boolean readPushMessagesWithPushId(Context context, String pushId) {
boolean isUpdated = false;
try {
String jsonString = SharedPreference.getString(context, Constants.PAYLOAD_SP_KEY);
JSONObject jsonObject = new JSONObject(jsonString);
Expand All @@ -417,20 +406,20 @@ public static void readPushMessagesWithPushId(Context context, String pushId) {
for (int i = 0; i < payloadsArray.length(); i++) {
JSONObject payloadObject = payloadsArray.getJSONObject(i);
String existingPushId = payloadObject.optString("pushId", "");
if (pushId != null && !pushId.isEmpty()) {
if (existingPushId.equals(pushId)) {
payloadObject.put("status", "O");
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));

SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
return;
}
if (pushId != null && !pushId.isEmpty() && existingPushId.equals(pushId)) {
payloadObject.put("status", "O");
payloadObject.put("openDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(new Date()));
isUpdated = true;
}
}

Log.e(LOG_TAG, "Payload with pushId " + pushId + " not found!");
if (isUpdated) {
jsonObject.put(Constants.PAYLOAD_SP_ARRAY_KEY, payloadsArray);
SharedPreference.saveString(context, Constants.PAYLOAD_SP_KEY, jsonObject.toString());
}
return isUpdated;
} else {
Log.e(LOG_TAG, "Payload array is null or empty!");
return false;
}
} catch (Exception e) {
StackTraceElement element = new Throwable().getStackTrace()[0];
Expand All @@ -442,6 +431,7 @@ public static void readPushMessagesWithPushId(Context context, String pushId) {
);
Log.e(LOG_TAG, "Could not update the push message!");
Log.e(LOG_TAG, e.getMessage());
return false;
}
}

Expand Down

0 comments on commit 7cecef8

Please sign in to comment.