use of net.osmand.plus.download.AbstractDownloadActivity in project Osmand by osmandapp.
the class PerformLiveUpdateAsyncTask method onPostExecute.
@Override
protected void onPostExecute(IncrementalChangesManager.IncrementalUpdateList result) {
LOG.debug("onPostExecute");
if (context instanceof AbstractDownloadActivity) {
AbstractDownloadActivity activity = (AbstractDownloadActivity) context;
activity.setSupportProgressBarIndeterminateVisibility(false);
}
final OsmandApplication application = getMyApplication();
final OsmandSettings settings = application.getSettings();
if (result.errorMessage != null) {
LOG.info(result.errorMessage);
tryRescheduleDownload(context, settings, localIndexFileName);
} else {
settings.LIVE_UPDATES_RETRIES.resetToDefault();
List<IncrementalChangesManager.IncrementalUpdate> ll = result.getItemsForUpdate();
if (ll != null && !ll.isEmpty()) {
ArrayList<IndexItem> itemsToDownload = new ArrayList<>(ll.size());
for (IncrementalChangesManager.IncrementalUpdate iu : ll) {
IndexItem indexItem = new IndexItem(iu.fileName, "Incremental update", iu.timestamp, iu.sizeText, iu.contentSize, iu.containerSize, DownloadActivityType.LIVE_UPDATES_FILE);
itemsToDownload.add(indexItem);
}
DownloadIndexesThread downloadThread = application.getDownloadThread();
if (context instanceof DownloadIndexesThread.DownloadEvents) {
downloadThread.setUiActivity((DownloadIndexesThread.DownloadEvents) context);
}
boolean downloadViaWiFi = LiveUpdatesHelper.preferenceDownloadViaWiFi(localIndexFileName, settings).get();
if (getMyApplication().getSettings().isInternetConnectionAvailable()) {
if (forceUpdate || settings.isWifiConnected() || !downloadViaWiFi) {
long szLong = 0;
int i = 0;
for (IndexItem es : downloadThread.getCurrentDownloadingItems()) {
szLong += es.getContentSize();
i++;
}
for (IndexItem es : itemsToDownload) {
szLong += es.getContentSize();
i++;
}
double sz = ((double) szLong) / (1 << 20);
// get availabile space
double asz = downloadThread.getAvailableSpace();
if (asz == -1 || asz <= 0 || sz / asz <= 0.4) {
IndexItem[] itemsArray = new IndexItem[itemsToDownload.size()];
itemsArray = itemsToDownload.toArray(itemsArray);
downloadThread.runDownloadFiles(itemsArray);
if (context instanceof DownloadIndexesThread.DownloadEvents) {
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
}
}
}
}
} else {
if (context instanceof DownloadIndexesThread.DownloadEvents) {
((DownloadIndexesThread.DownloadEvents) context).downloadInProgress();
}
}
}
}
use of net.osmand.plus.download.AbstractDownloadActivity in project Osmand by osmandapp.
the class PerformLiveUpdateAsyncTask method onPreExecute.
@Override
protected void onPreExecute() {
LOG.debug("onPreExecute");
if (context instanceof AbstractDownloadActivity) {
AbstractDownloadActivity activity = (AbstractDownloadActivity) context;
activity.setSupportProgressBarIndeterminateVisibility(true);
}
final OsmandApplication myApplication = getMyApplication();
OsmandSettings.CommonPreference<Long> lastCheckPreference = LiveUpdatesHelper.preferenceLastCheck(localIndexFileName, myApplication.getSettings());
lastCheckPreference.set(System.currentTimeMillis());
}
Aggregations