Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Amr Hossam <[email protected]>
  • Loading branch information
amrhossamdev authored and aaronbrethorst committed Oct 28, 2024
1 parent b34eb30 commit f940ff9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import org.onebusaway.android.R;
import org.onebusaway.android.app.Application;
import org.onebusaway.android.database.widealerts.AlertsRepository;
import org.onebusaway.android.database.widealerts.entity.AlertEntity;

import android.content.Context;
import android.content.SharedPreferences;
Expand Down Expand Up @@ -63,12 +61,11 @@ public void fetchAlerts(String regionId, GtfsAlertCallBack callback) {
*/
public void processAlerts(List<GtfsRealtime.FeedEntity> alerts, GtfsAlertCallBack callback) {
for (GtfsRealtime.FeedEntity entity : alerts) {
GtfsRealtime.Alert alert = entity.getAlert();
if (!GtfsAlertsHelper.isValidEntity(mContext, entity)) {
continue;
}
// Store the alert in the database.
AlertsRepository.insertAlert(mContext, new AlertEntity(entity.getId()));
GtfsRealtime.Alert alert = entity.getAlert();
GtfsAlertsHelper.markAlertAsRead(Application.get().getApplicationContext() ,entity);

String id = entity.getId();
String title = GtfsAlertsHelper.getAlertTitle(alert);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.onebusaway.android.R;
import org.onebusaway.android.database.widealerts.AlertsRepository;
import org.onebusaway.android.database.widealerts.entity.AlertEntity;

import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -145,6 +146,16 @@ public static boolean isAlertRead(Context context, GtfsRealtime.FeedEntity entit
return AlertsRepository.isAlertExists(context, entity.getId());
}

/**
* Marks the alert as read by inserting it into the database.
*
* @param context The context to access the database.
* @param entity The `GtfsRealtime.FeedEntity` object representing the alert.
*/
public static void markAlertAsRead(Context context, GtfsRealtime.FeedEntity entity) {
AlertsRepository.insertAlert(context, new AlertEntity(entity.getId()));
}

public static String getCurrentAppLanguageCode() {
return Locale.getDefault().getLanguage();
}
Expand Down

0 comments on commit f940ff9

Please sign in to comment.