Exemple #1
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;
  }
Exemple #2
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);
      }
    }
  }