Search in sources :

Example 6 with OnRequestResultListener

use of net.osmand.plus.utils.AndroidNetworkUtils.OnRequestResultListener in project Osmand by osmandapp.

the class PerformLiveUpdateAsyncTask method updateLatestAvailability.

private void updateLatestAvailability(OsmandApplication app, @NonNull final String localIndexFileName) {
    final OsmandSettings settings = app.getSettings();
    AndroidNetworkUtils.sendRequestAsync(app, LiveUpdatesFragment.URL, null, "Requesting map updates info...", false, false, new OnRequestResultListener() {

        @Override
        public void onResult(@Nullable String result, @Nullable String error, @Nullable Integer resultCode) {
            if (!Algorithms.isEmpty(result)) {
                SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
                source.setTimeZone(TimeZone.getTimeZone("UTC"));
                try {
                    Date parsed = source.parse(result);
                    if (parsed != null) {
                        long dateTime = parsed.getTime();
                        preferenceLatestUpdateAvailable(settings).set(dateTime);
                        preferenceLatestUpdateAvailable(localIndexFileName, settings).set(dateTime);
                        if (runOnSuccess != null) {
                            runOnSuccess.run();
                        }
                    }
                } catch (ParseException e) {
                    long dateTime = preferenceLatestUpdateAvailable(settings).get();
                    preferenceLatestUpdateAvailable(localIndexFileName, settings).set(dateTime);
                    LOG.error(e.getMessage(), e);
                }
            }
        }
    });
}
Also used : OnRequestResultListener(net.osmand.plus.utils.AndroidNetworkUtils.OnRequestResultListener) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) Date(java.util.Date)

Aggregations

OnRequestResultListener (net.osmand.plus.utils.AndroidNetworkUtils.OnRequestResultListener)6 Nullable (androidx.annotation.Nullable)4 NonNull (androidx.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 BackupError (net.osmand.plus.backup.BackupError)2 BackupHelper (net.osmand.plus.backup.BackupHelper)2 LIST_FILES_URL (net.osmand.plus.backup.BackupHelper.LIST_FILES_URL)2 STATUS_EMPTY_RESPONSE_ERROR (net.osmand.plus.backup.BackupHelper.STATUS_EMPTY_RESPONSE_ERROR)2 STATUS_PARSE_JSON_ERROR (net.osmand.plus.backup.BackupHelper.STATUS_PARSE_JSON_ERROR)2 STATUS_SERVER_ERROR (net.osmand.plus.backup.BackupHelper.STATUS_SERVER_ERROR)2 STATUS_SUCCESS (net.osmand.plus.backup.BackupHelper.STATUS_SUCCESS)2 OnDeleteFilesListener (net.osmand.plus.backup.BackupListeners.OnDeleteFilesListener)2 RemoteFile (net.osmand.plus.backup.RemoteFile)2 ExportSettingsType (net.osmand.plus.settings.backend.ExportSettingsType)2 AndroidNetworkUtils (net.osmand.plus.utils.AndroidNetworkUtils)2 Algorithms (net.osmand.util.Algorithms)2