use of net.osmand.plus.download.ui.AbstractLoadLocalIndexTask in project Osmand by osmandapp.
the class AppInitializer method checkLiveUpdatesAlerts.
private void checkLiveUpdatesAlerts() {
OsmandSettings settings = app.getSettings();
if (!settings.IS_LIVE_UPDATES_ON.get()) {
return;
}
LocalIndexHelper helper = new LocalIndexHelper(app);
List<LocalIndexInfo> fullMaps = helper.getLocalFullMaps(new AbstractLoadLocalIndexTask() {
@Override
public void loadFile(LocalIndexInfo... loaded) {
}
});
AlarmManager alarmMgr = (AlarmManager) app.getSystemService(Context.ALARM_SERVICE);
for (LocalIndexInfo fm : fullMaps) {
String fileName = fm.getFileName();
if (!preferenceLiveUpdatesOn(fileName, settings).get()) {
continue;
}
int updateFrequencyOrd = preferenceUpdateFrequency(fileName, settings).get();
LiveUpdatesHelper.UpdateFrequency updateFrequency = LiveUpdatesHelper.UpdateFrequency.values()[updateFrequencyOrd];
long lastCheck = preferenceLastCheck(fileName, settings).get();
if (System.currentTimeMillis() - lastCheck > updateFrequency.getTime() * 2) {
runLiveUpdate(app, fileName, false);
PendingIntent alarmIntent = getPendingIntent(app, fileName);
int timeOfDayOrd = preferenceTimeOfDayToUpdate(fileName, settings).get();
LiveUpdatesHelper.TimeOfDay timeOfDayToUpdate = LiveUpdatesHelper.TimeOfDay.values()[timeOfDayOrd];
setAlarmForPendingIntent(alarmIntent, alarmMgr, updateFrequency, timeOfDayToUpdate);
}
}
}
Aggregations