@Override
 protected void onPreExecute() {
   if (context instanceof AbstractDownloadActivity) {
     AbstractDownloadActivity activity = (AbstractDownloadActivity) context;
     activity.setSupportProgressBarIndeterminateVisibility(true);
     OsmandSettings settings = activity.getMyApplication().getSettings();
   }
   final OsmandApplication myApplication = getMyApplication();
   OsmandSettings.CommonPreference<Long> lastCheckPreference =
       LiveUpdatesHelper.preferenceLastCheck(localIndexInfo, myApplication.getSettings());
   lastCheckPreference.set(System.currentTimeMillis());
 }
 @Override
 protected void onPostExecute(IncrementalChangesManager.IncrementalUpdateList result) {
   if (context instanceof AbstractDownloadActivity) {
     AbstractDownloadActivity activity = (AbstractDownloadActivity) context;
     activity.setSupportProgressBarIndeterminateVisibility(false);
   }
   final OsmandApplication application = getMyApplication();
   final OsmandSettings settings = application.getSettings();
   if (result.errorMessage != null) {
     Toast.makeText(context, result.errorMessage, Toast.LENGTH_SHORT).show();
     tryRescheduleDownload(context, settings, localIndexInfo);
   } else {
     settings.LIVE_UPDATES_RETRIES.resetToDefault();
     List<IncrementalChangesManager.IncrementalUpdate> ll = result.getItemsForUpdate();
     if (ll.isEmpty()) {
       Toast.makeText(context, R.string.no_updates_available, Toast.LENGTH_SHORT).show();
     } else {
       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(localIndexInfo, 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();
             }
           }
         }
       }
     }
   }
 }