Search in sources :

Example 1 with AbstractLoadLocalIndexTask

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);
        }
    }
}
Also used : LiveUpdatesHelper(net.osmand.plus.liveupdates.LiveUpdatesHelper) SuppressLint(android.annotation.SuppressLint) AbstractLoadLocalIndexTask(net.osmand.plus.download.ui.AbstractLoadLocalIndexTask) AlarmManager(android.app.AlarmManager) LocalIndexHelper(net.osmand.plus.activities.LocalIndexHelper) PendingIntent(android.app.PendingIntent) LiveUpdatesHelper.getPendingIntent(net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent) LiveUpdatesHelper.setAlarmForPendingIntent(net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 LocalIndexHelper (net.osmand.plus.activities.LocalIndexHelper)1 LocalIndexInfo (net.osmand.plus.activities.LocalIndexInfo)1 AbstractLoadLocalIndexTask (net.osmand.plus.download.ui.AbstractLoadLocalIndexTask)1 LiveUpdatesHelper (net.osmand.plus.liveupdates.LiveUpdatesHelper)1 LiveUpdatesHelper.getPendingIntent (net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent)1 LiveUpdatesHelper.setAlarmForPendingIntent (net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent)1