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);
}
}
}
});
}
Aggregations