protected void downloadFilesCheckFreeVersion() {
   if (Version.isFreeVersion(getMyApplication())) {
     int total = settings.NUMBER_OF_FREE_DOWNLOADS.get();
     boolean wiki = false;
     for (IndexItem es : downloadListIndexThread.getEntriesToDownload().keySet()) {
       if (es.getBasename() != null && es.getBasename().contains("_wiki")) {
         wiki = true;
         break;
       } else if (DownloadActivityType.isCountedInDownloads(es)) {
         total++;
       }
     }
     if (total > MAXIMUM_AVAILABLE_FREE_DOWNLOADS || wiki) {
       String msgTx =
           getString(R.string.free_version_message, MAXIMUM_AVAILABLE_FREE_DOWNLOADS + "");
       Builder msg = new AlertDialog.Builder(this);
       msg.setTitle(R.string.free_version_title);
       msg.setMessage(msgTx);
       msg.setPositiveButton(R.string.default_buttons_ok, null);
       msg.show();
     } else {
       downloadFilesCheckInternet();
     }
   } else {
     downloadFilesCheckInternet();
   }
 }
 private void selectAll() {
   final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter) getExpandableListAdapter();
   int selected = 0;
   for (int j = 0; j < listAdapter.getGroupCount(); j++) {
     for (int i = 0; i < listAdapter.getChildrenCount(j); i++) {
       IndexItem es = listAdapter.getChild(j, i);
       if (!getEntriesToDownload().containsKey(es)) {
         selected++;
         getEntriesToDownload()
             .put(
                 es,
                 es.createDownloadEntry(
                     getClientContext(), type, new ArrayList<DownloadEntry>(1)));
       }
     }
   }
   AccessibleToast.makeText(
           this,
           MessageFormat.format(getString(R.string.items_were_selected), selected),
           Toast.LENGTH_SHORT)
       .show();
   listAdapter.notifyDataSetInvalidated();
   if (selected > 0) {
     updateDownloadButton(true);
   }
 }
  @Override
  public boolean onChildClick(
      ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    final IndexItem e =
        (IndexItem)
            ((DownloadIndexAdapter) getListAdapter()).getChild(groupPosition, childPosition);
    final CheckBox ch = (CheckBox) v.findViewById(R.id.check_download_item);

    if (ch.isChecked()) {
      ch.setChecked(!ch.isChecked());
      getEntriesToDownload().remove(e);
      updateDownloadButton(true);
      return true;
    }

    List<DownloadEntry> download =
        e.createDownloadEntry(getClientContext(), type, new ArrayList<DownloadEntry>());
    if (download.size() > 0) {
      // if(!fileToUnzip.exists()){
      // builder.setMessage(MessageFormat.format(getString(R.string.download_question), baseName,
      // extractDateAndSize(e.getValue())));
      getEntriesToDownload().put(e, download);
      updateDownloadButton(true);
      ch.setChecked(!ch.isChecked());
    }
    return true;
  }
Example #4
0
  private boolean checkDisabledAndClickAction(final IndexItem item) {
    RightButtonAction clickAction = getClickAction(item);
    boolean disabled = clickAction != RightButtonAction.DOWNLOAD;
    OnClickListener action = getRightButtonAction(item, clickAction);
    if (clickAction != RightButtonAction.DOWNLOAD) {
      rightButton.setText(R.string.get_plugin);
      rightButton.setVisibility(View.VISIBLE);
      rightImageButton.setVisibility(View.GONE);
      rightButton.setOnClickListener(action);
    } else {
      rightButton.setVisibility(View.GONE);
      rightImageButton.setVisibility(View.VISIBLE);
      final boolean isDownloading = context.getDownloadThread().isDownloading(item);
      if (isDownloading) {
        rightImageButton.setImageDrawable(
            getContentIcon(context, R.drawable.ic_action_remove_dark));
        rightImageButton.setContentDescription(context.getString(R.string.shared_string_cancel));
      } else if (item.isDownloaded() && !item.isOutdated()) {
        rightImageButton.setImageDrawable(
            getContentIcon(context, R.drawable.ic_overflow_menu_white));
        rightImageButton.setContentDescription(context.getString(R.string.shared_string_more));
      } else {
        rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import));
        rightImageButton.setContentDescription(context.getString(R.string.shared_string_download));
      }
      rightImageButton.setOnClickListener(action);
    }

    return disabled;
  }
  private void filterExisting() {
    final DownloadIndexAdapter listAdapter = (DownloadIndexAdapter) getExpandableListAdapter();
    final Map<String, String> listAlreadyDownloaded =
        downloadListIndexThread.getDownloadedIndexFileNames();

    final List<IndexItem> filtered = new ArrayList<IndexItem>();
    for (IndexItem fileItem : listAdapter.getIndexFiles()) {
      if (fileItem.isAlreadyDownloaded(listAlreadyDownloaded)) {
        filtered.add(fileItem);
      }
    }
    listAdapter.setIndexFiles(
        filtered, IndexItemCategory.categorizeIndexItems(getClientContext(), filtered));
    listAdapter.notifyDataSetChanged();
  }
Example #6
0
  @SuppressLint("DefaultLocale")
  public RightButtonAction getClickAction(final IndexItem indexItem) {
    RightButtonAction clickAction = RightButtonAction.DOWNLOAD;
    if (indexItem.getBasename().toLowerCase().equals(DownloadResources.WORLD_SEAMARKS_KEY)
        && nauticalPluginDisabled) {
      clickAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN;
    } else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
            || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE)
        && srtmDisabled) {
      if (srtmNeedsInstallation) {
        clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_PURCHASE;
      } else {
        clickAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE;
      }

    } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) {
      clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE;
    }
    return clickAction;
  }
Example #7
0
 protected void download(IndexItem indexItem, DownloadResourceGroup parentOptional) {
   boolean handled = false;
   if (parentOptional != null) {
     WorldRegion region = DownloadResourceGroup.getRegion(parentOptional);
     context.setDownloadItem(
         region, indexItem.getTargetFile(context.getMyApplication()).getAbsolutePath());
   }
   if (indexItem.getType() == DownloadActivityType.ROADS_FILE && parentOptional != null) {
     for (IndexItem ii : parentOptional.getIndividualResources()) {
       if (ii.getType() == DownloadActivityType.NORMAL_FILE) {
         if (ii.isDownloaded()) {
           handled = true;
           confirmDownload(indexItem);
         }
         break;
       }
     }
   }
   if (!handled) {
     context.startDownload(indexItem);
   }
 }
 @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();
             }
           }
         }
       }
     }
   }
 }
Example #9
0
  protected void contextMenu(
      View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) {
    final PopupMenu optionsMenu = new PopupMenu(context, v);
    MenuItem item;

    final File fl = indexItem.getTargetFile(context.getMyApplication());
    if (fl.exists()) {
      item =
          optionsMenu
              .getMenu()
              .add(R.string.shared_string_remove)
              .setIcon(
                  context
                      .getMyApplication()
                      .getIconsCache()
                      .getThemedIcon(R.drawable.ic_action_remove_dark));
      item.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
              LocalIndexType tp = LocalIndexType.MAP_DATA;
              if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
                tp = LocalIndexType.TILES_DATA;
              } else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
                tp = LocalIndexType.MAP_DATA;
              } else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
                tp = LocalIndexType.SRTM_DATA;
              } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
                tp = LocalIndexType.MAP_DATA;
              } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
                tp =
                    indexItem.getBasename().contains("tts")
                        ? LocalIndexType.TTS_VOICE_DATA
                        : LocalIndexType.VOICE_DATA;
              }
              final LocalIndexInfo info =
                  new LocalIndexInfo(tp, fl, false, context.getMyApplication());
              AlertDialog.Builder confirm = new AlertDialog.Builder(context);
              confirm.setPositiveButton(
                  R.string.shared_string_yes,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      new LocalIndexOperationTask(
                              context, null, LocalIndexOperationTask.DELETE_OPERATION)
                          .execute(info);
                    }
                  });
              confirm.setNegativeButton(R.string.shared_string_no, null);
              String fn =
                  FileNameTranslationHelper.getFileName(
                      context,
                      context.getMyApplication().getRegions(),
                      indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
              confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn));
              confirm.show();
              return true;
            }
          });
    }
    item =
        optionsMenu
            .getMenu()
            .add(R.string.shared_string_download)
            .setIcon(
                context
                    .getMyApplication()
                    .getIconsCache()
                    .getThemedIcon(R.drawable.ic_action_import));
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            download(indexItem, parentOptional);
            return true;
          }
        });

    optionsMenu.show();
  }
Example #10
0
  public void bindIndexItem(final IndexItem indexItem, final String cityName) {
    initAppStatusVariables();
    boolean isDownloading = context.getDownloadThread().isDownloading(indexItem);
    int progress = -1;
    if (context.getDownloadThread().getCurrentDownloadingItem() == indexItem) {
      progress = context.getDownloadThread().getCurrentDownloadingItemProgress();
    }
    boolean disabled = checkDisabledAndClickAction(indexItem);
    /// name and left item
    String name;
    if (showTypeInName) {
      name = indexItem.getType().getString(context);
    } else {
      name =
          indexItem.getVisibleName(
              context, context.getMyApplication().getRegions(), showParentRegionName);
    }
    String text =
        (!Algorithms.isEmpty(cityName) && !cityName.equals(name) ? cityName + "\n" : "") + name;
    nameTextView.setText(text);
    if (!disabled) {
      nameTextView.setTextColor(textColorPrimary);
    } else {
      nameTextView.setTextColor(textColorSecondary);
    }
    int color = textColorSecondary;
    if (indexItem.isDownloaded() && !isDownloading) {
      int colorId = indexItem.isOutdated() ? R.color.color_distance : R.color.color_ok;
      color = context.getResources().getColor(colorId);
    }
    if (indexItem.isDownloaded()) {
      leftImageView.setImageDrawable(
          getContentIcon(context, indexItem.getType().getIconResource(), color));
    } else if (disabled) {
      leftImageView.setImageDrawable(
          getContentIcon(context, indexItem.getType().getIconResource(), textColorSecondary));
    } else {
      leftImageView.setImageDrawable(
          getContentIcon(context, indexItem.getType().getIconResource()));
    }
    descrTextView.setTextColor(textColorSecondary);
    if (!isDownloading) {
      progressBar.setVisibility(View.GONE);
      descrTextView.setVisibility(View.VISIBLE);
      if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
              || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE)
          && srtmDisabled) {
        if (showTypeInName) {
          descrTextView.setText("");
        } else {
          descrTextView.setText(indexItem.getType().getString(context));
        }
      } else if (showTypeInDesc) {
        descrTextView.setText(
            indexItem.getType().getString(context)
                + " • "
                + indexItem.getSizeDescription(context)
                + " • "
                + (showRemoteDate
                    ? indexItem.getRemoteDate(dateFormat)
                    : indexItem.getLocalDate(dateFormat)));
      } else {
        descrTextView.setText(
            indexItem.getSizeDescription(context)
                + " • "
                + (showRemoteDate
                    ? indexItem.getRemoteDate(dateFormat)
                    : indexItem.getLocalDate(dateFormat)));
      }

    } else {
      progressBar.setVisibility(View.VISIBLE);
      progressBar.setIndeterminate(progress == -1);
      progressBar.setProgress(progress);

      if (showProgressInDesc) {
        double mb = indexItem.getArchiveSizeMB();
        String v;
        if (progress != -1) {
          v = context.getString(R.string.value_downloaded_of_max, mb * progress / 100, mb);
        } else {
          v = context.getString(R.string.file_size_in_mb, mb);
        }
        if (showTypeInDesc && indexItem.getType() == DownloadActivityType.ROADS_FILE) {
          descrTextView.setText(indexItem.getType().getString(context) + " • " + v);
        } else {
          descrTextView.setText(v);
        }
        descrTextView.setVisibility(View.VISIBLE);
      } else {
        descrTextView.setVisibility(View.GONE);
      }
    }
  }