Search in sources :

Example 1 with AbstractDownloadActivity

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();
            }
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AbstractDownloadActivity(net.osmand.plus.download.AbstractDownloadActivity) ArrayList(java.util.ArrayList) OsmandSettings(net.osmand.plus.OsmandSettings) IndexItem(net.osmand.plus.download.IndexItem) IncrementalChangesManager(net.osmand.plus.resources.IncrementalChangesManager) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread)

Example 2 with AbstractDownloadActivity

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());
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AbstractDownloadActivity(net.osmand.plus.download.AbstractDownloadActivity) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

OsmandApplication (net.osmand.plus.OsmandApplication)2 OsmandSettings (net.osmand.plus.OsmandSettings)2 AbstractDownloadActivity (net.osmand.plus.download.AbstractDownloadActivity)2 ArrayList (java.util.ArrayList)1 DownloadIndexesThread (net.osmand.plus.download.DownloadIndexesThread)1 IndexItem (net.osmand.plus.download.IndexItem)1 IncrementalChangesManager (net.osmand.plus.resources.IncrementalChangesManager)1