use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class ProfilManager method getEtudiant.
public Etudiant getEtudiant() {
DatabaseHelper dbHelper = new DatabaseHelper(context);
Etudiant etudiant = null;
try {
List<Etudiant> etudiantList = dbHelper.getDao(Etudiant.class).queryForAll();
if (!etudiantList.isEmpty())
// Get Student if exists
etudiant = etudiantList.get(0);
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
return etudiant;
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class TodayFragment method updateUI.
@Override
void updateUI() {
if (isAdded()) {
dateTime = new DateTime();
DateTime.Property pDoW = dateTime.dayOfWeek();
DateTime.Property pDoM = dateTime.dayOfMonth();
DateTime.Property pMoY = dateTime.monthOfYear();
Locale locale = getResources().getConfiguration().locale;
todaysTv.setText(getActivity().getString(R.string.horaire, pDoW.getAsText(locale), pDoM.getAsText(locale), pMoY.getAsText(locale)));
databaseHelper = new DatabaseHelper(getActivity());
listSeances = new ArrayList<Seances>();
events = new ArrayList<Event>();
try {
SimpleDateFormat seancesFormatter = new SimpleDateFormat("yyyy-MM-dd", getResources().getConfiguration().locale);
listSeances = (ArrayList<Seances>) databaseHelper.getDao(Seances.class).queryBuilder().where().like("dateDebut", seancesFormatter.format(dateTime.toDate()) + "%").query();
Collections.sort(listSeances, new SeanceComparator());
events = (ArrayList<Event>) databaseHelper.getDao(Event.class).queryBuilder().where().like("startDate", seancesFormatter.format(dateTime.toDate()) + "%").query();
} catch (Exception e) {
e.printStackTrace();
}
ArrayList<TodayDataRowItem> dataRowItems = new ArrayList<TodayDataRowItem>();
if (!events.isEmpty()) {
dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_EVENT));
for (Event event : events) {
dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_EVENT, event));
}
}
dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_TITLE_SEANCE));
if (listSeances.isEmpty()) {
tvNoCourses.setVisibility(View.VISIBLE);
} else {
for (Seances seances : listSeances) {
dataRowItems.add(new TodayDataRowItem(TodayDataRowItem.viewType.VIEW_TYPE_SEANCE, seances));
}
tvNoCourses.setVisibility(View.GONE);
}
adapter = new TodayAdapter(getActivity(), dataRowItems);
todaysList.setAdapter(adapter);
}
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class HoraireManager method deleteExpiredJoursRemplaces.
/**
* Deletes entries in DB that doesn't exist on API
*
* @param listeJoursRemplaces
*/
private void deleteExpiredJoursRemplaces(listeJoursRemplaces listeJoursRemplaces) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
HashMap<String, JoursRemplaces> listeJoursRemplacesInAPI = new HashMap<String, JoursRemplaces>();
// Building the list of entries in API
for (JoursRemplaces JoursRemplacesInAPI : listeJoursRemplaces.listeJours) {
listeJoursRemplacesInAPI.put(JoursRemplacesInAPI.dateOrigine, JoursRemplacesInAPI);
}
ArrayList<JoursRemplaces> listeJoursRemplacesInDB = new ArrayList<JoursRemplaces>();
// Comparing entries on DB and API
try {
listeJoursRemplacesInDB = (ArrayList<JoursRemplaces>) dbHelper.getDao(JoursRemplaces.class).queryForAll();
for (JoursRemplaces JoursRemplacesInDB : listeJoursRemplacesInDB) {
if (!listeJoursRemplacesInAPI.containsKey((String) JoursRemplacesInDB.dateOrigine)) {
Dao<JoursRemplaces, String> JoursRemplacesDao = dbHelper.getDao(JoursRemplaces.class);
JoursRemplacesDao.deleteById(JoursRemplacesInDB.dateOrigine);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of ca.etsmtl.applets.etsmobile.db.DatabaseHelper in project ETSMobile-Android2 by ApplETS.
the class NoteManager method updateCours.
public void updateCours(List<Cours> coursList) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
try {
for (Cours cours : coursList) {
// Id field upgraded to make difference between upgrading row or creating row
cours.id = cours.sigle + cours.session;
dbHelper.getDao(Cours.class).createOrUpdate(cours);
}
} 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 deleteExpiredTrimestres.
/**
* Deletes trimestres in DB that doesn't exist on API
*
* @param
*/
public void deleteExpiredTrimestres(ListeDeSessions listeDeSessions) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
HashMap<String, Trimestre> trimestresHashMap = new HashMap<String, Trimestre>();
for (Trimestre trimestre : listeDeSessions.liste) {
trimestresHashMap.put(trimestre.abrege, trimestre);
}
ArrayList<Trimestre> dbTrimestres = new ArrayList<Trimestre>();
try {
dbTrimestres = (ArrayList<Trimestre>) dbHelper.getDao(Trimestre.class).queryForAll();
for (Trimestre trimestreNew : dbTrimestres) {
if (!trimestresHashMap.containsKey(trimestreNew.abrege)) {
Dao<Trimestre, String> trimestreDao = dbHelper.getDao(Trimestre.class);
trimestreDao.deleteById(trimestreNew.abrege);
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Aggregations