use of ca.etsmtl.applets.etsmobile.http.DataManager in project ETSMobile-Android2 by ApplETS.
the class Utility method loadNotifications.
/**
* Gets MonÉTS notifications and update DB
* @param context
* @param requestListener
*/
public static void loadNotifications(Context context, final RequestListener<Object> requestListener) {
final SecurePreferences securePreferences = new SecurePreferences(context);
final boolean allNotifsLoaded = securePreferences.getBoolean(Constants.ALL_NOTIFS_LOADED, false);
MonETSNotificationsRequest monETSNotificationsRequest;
if (!allNotifsLoaded) {
monETSNotificationsRequest = new MonETSNotificationsRequest(context, false);
} else {
monETSNotificationsRequest = new MonETSNotificationsRequest(context, true);
}
final DataManager dataManager = DataManager.getInstance(context);
dataManager.start();
final DatabaseHelper databaseHelper = new DatabaseHelper(context);
dataManager.sendRequest(monETSNotificationsRequest, new RequestListener<Object>() {
@Override
public void onRequestFailure(SpiceException spiceException) {
requestListener.onRequestFailure(spiceException);
dataManager.stop();
}
@Override
public void onRequestSuccess(Object o) {
if (o instanceof MonETSNotificationList) {
try {
Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
MonETSNotificationList list = (MonETSNotificationList) o;
for (MonETSNotification monETSNotification : list) {
dao.createOrUpdate(monETSNotification);
}
if (!allNotifsLoaded) {
securePreferences.edit().putBoolean(Constants.ALL_NOTIFS_LOADED, true).commit();
}
requestListener.onRequestSuccess(list);
} catch (SQLException e) {
e.printStackTrace();
}
}
dataManager.stop();
}
});
}
use of ca.etsmtl.applets.etsmobile.http.DataManager in project ETSMobile-Android2 by ApplETS.
the class NotificationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notifications);
securePreferences = new SecurePreferences(this);
progressBar = (ProgressBar) findViewById(R.id.progressBar_notifications);
listView = (ListView) findViewById(R.id.listView_notifications);
progressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.ets_red_fonce), PorterDuff.Mode.MULTIPLY);
progressBar.setVisibility(View.VISIBLE);
notificationsAdapter = new NotificationsAdapter(this, R.layout.row_notification, new ArrayList<>());
listView.setAdapter(notificationsAdapter);
listView.setOnItemClickListener((parent, view, position, id) -> {
MonETSNotification item = notificationsAdapter.getItem(position);
String url = item.getUrl();
if (URLUtil.isValidUrl(url)) {
Utility.openChromeCustomTabs(NotificationActivity.this, url);
}
});
syncAdapterWithDB();
DataManager datamanager = DataManager.getInstance(this);
NotificationManager manager = new NotificationManager(this, datamanager.getMonETSService(), this);
manager.updateNotifications();
}
Aggregations