use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper 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.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class NoteManager method updateElementsEvaluation.
/**
* Rajout de l'id pour identifier les éléments d'évaluation par rapport au cours effectué dans une session
*/
public void updateElementsEvaluation(ListeDesElementsEvaluation listElementsEvaluation) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
try {
dbHelper.getDao(ListeDesElementsEvaluation.class).createOrUpdate(listElementsEvaluation);
for (ElementEvaluation elementEvaluation : listElementsEvaluation.liste) {
elementEvaluation.id = listElementsEvaluation.id + elementEvaluation.nom;
elementEvaluation.listeDesElementsEvaluation = listElementsEvaluation;
dbHelper.getDao(ElementEvaluation.class).createOrUpdate(elementEvaluation);
}
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class NoteManager method getTrimestres.
public List<Trimestre> getTrimestres() {
DatabaseHelper dbHelper = new DatabaseHelper(context);
List<Trimestre> trimestresList = null;
try {
trimestresList = dbHelper.getDao(Trimestre.class).queryForAll();
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
return trimestresList;
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class NoteManager method getCours.
public ArrayList<Cours> getCours() {
DatabaseHelper dbHelper = new DatabaseHelper(context);
ArrayList<Cours> coursList = null;
try {
coursList = (ArrayList<Cours>) dbHelper.getDao(Cours.class).queryForAll();
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
return coursList;
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class NoteManager method remove.
public void remove() {
DatabaseHelper dbHelper = new DatabaseHelper(context);
try {
// Delete all rows that contains an Etudiant and listeDesProgrammes classes
dbHelper.getDao(Cours.class).deleteBuilder().delete();
dbHelper.getDao(Trimestre.class).deleteBuilder().delete();
dbHelper.getDao(ListeDesElementsEvaluation.class).deleteBuilder().delete();
dbHelper.getDao(ElementEvaluation.class).deleteBuilder().delete();
// dbHelper.getDao(Programme.class).deleteBuilder().delete();
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
}
Aggregations