Search in sources :

Example 1 with MultipleDownloadItem

use of net.osmand.plus.download.MultipleDownloadItem in project Osmand by osmandapp.

the class ItemViewHolder method bindDownloadItem.

public void bindDownloadItem(final DownloadItem downloadItem, final String cityName) {
    initAppStatusVariables();
    boolean isDownloading = downloadItem.isDownloading(context.getDownloadThread());
    int progress = -1;
    if (context.getDownloadThread().getCurrentDownloadingItem() == downloadItem) {
        progress = context.getDownloadThread().getCurrentDownloadingItemProgress();
    }
    boolean disabled = checkDisabledAndClickAction(downloadItem);
    // / name and left item
    String name;
    if (showTypeInName) {
        name = downloadItem.getType().getString(context);
    } else {
        name = downloadItem.getVisibleName(context, context.getMyApplication().getRegions(), showParentRegionName);
    }
    String text = (!Algorithms.isEmpty(cityName) && !cityName.equals(name) ? cityName + "\n" : "") + name;
    nameTextView.setText(text);
    ViewCompat.setAccessibilityDelegate(rightImageButton, new AccessibilityAssistant(context) {

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setContentDescription(context.getString(R.string.shared_string_download) + nameTextView.getText());
            info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(AccessibilityNodeInfo.ACTION_CLICK, context.getString(R.string.shared_string_download)));
            info.setEnabled(host.isEnabled());
        }
    });
    if (!disabled) {
        nameTextView.setTextColor(textColorPrimary);
    } else {
        nameTextView.setTextColor(textColorSecondary);
    }
    int color = textColorSecondary;
    if (downloadItem.isDownloaded() && !isDownloading) {
        int colorId = downloadItem.isOutdated() ? R.color.color_distance : R.color.color_ok;
        color = context.getResources().getColor(colorId);
    }
    if (downloadItem.isDownloaded()) {
        leftImageView.setImageDrawable(getContentIcon(context, downloadItem.getType().getIconResource(), color));
    } else if (disabled) {
        leftImageView.setImageDrawable(getContentIcon(context, downloadItem.getType().getIconResource(), textColorSecondary));
    } else {
        leftImageView.setImageDrawable(getContentIcon(context, downloadItem.getType().getIconResource()));
    }
    descrTextView.setTextColor(textColorSecondary);
    if (!isDownloading) {
        progressBar.setVisibility(View.GONE);
        descrTextView.setVisibility(View.VISIBLE);
        if (downloadItem instanceof CustomIndexItem && (((CustomIndexItem) downloadItem).getSubName(context) != null)) {
            descrTextView.setText(((CustomIndexItem) downloadItem).getSubName(context));
        } else if (downloadItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
            descrTextView.setText(context.getString(R.string.depth_contour_descr));
        } else if ((downloadItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE || downloadItem.getType() == DownloadActivityType.HILLSHADE_FILE || downloadItem.getType() == DownloadActivityType.SLOPE_FILE) && srtmDisabled) {
            if (showTypeInName) {
                descrTextView.setText("");
            } else {
                descrTextView.setText(downloadItem.getType().getString(context));
            }
        } else if (downloadItem instanceof MultipleDownloadItem) {
            MultipleDownloadItem item = (MultipleDownloadItem) downloadItem;
            String allRegionsHeader = context.getString(R.string.shared_strings_all_regions);
            String regionsHeader = context.getString(R.string.regions);
            String allRegionsCount = String.valueOf(item.getAllItems().size());
            String leftToDownloadCount = String.valueOf(item.getItemsToDownload().size());
            String header;
            String count;
            if (item.hasActualDataToDownload()) {
                if (!item.isDownloaded()) {
                    header = allRegionsHeader;
                    count = leftToDownloadCount;
                } else {
                    header = regionsHeader;
                    count = String.format(context.getString(R.string.ltr_or_rtl_combine_via_slash), leftToDownloadCount, allRegionsCount);
                }
            } else {
                header = allRegionsHeader;
                count = allRegionsCount;
            }
            String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
            String addDescr = item.getAdditionalDescription(context);
            if (addDescr != null) {
                fullDescription += " " + addDescr;
            }
            if (item.hasActualDataToDownload()) {
                fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_bold_point, fullDescription, item.getSizeDescription(context));
            }
            descrTextView.setText(fullDescription);
        } else {
            String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
            String type = downloadItem.getType().getString(context);
            String size = downloadItem.getSizeDescription(context);
            String addDescr = downloadItem.getAdditionalDescription(context);
            if (addDescr != null) {
                size += " " + addDescr;
            }
            String date = downloadItem.getDate(dateFormat, showRemoteDate);
            String fullDescription = String.format(pattern, size, date);
            if (showTypeInDesc) {
                fullDescription = String.format(pattern, type, fullDescription);
            }
            descrTextView.setText(fullDescription);
        }
    } else {
        progressBar.setVisibility(View.VISIBLE);
        progressBar.setIndeterminate(progress == -1);
        progressBar.setProgress(progress);
        if (showProgressInDesc) {
            double mb = downloadItem.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);
            }
            String fullDescription = v;
            if (showTypeInDesc && downloadItem.getType() == DownloadActivityType.ROADS_FILE) {
                fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_bold_point, downloadItem.getType().getString(context), fullDescription);
            }
            descrTextView.setText(fullDescription);
            descrTextView.setVisibility(View.VISIBLE);
        } else {
            descrTextView.setVisibility(View.GONE);
        }
    }
}
Also used : AccessibilityAssistant(net.osmand.plus.plugins.accessibility.AccessibilityAssistant) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) CustomIndexItem(net.osmand.plus.download.CustomIndexItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MultipleDownloadItem(net.osmand.plus.download.MultipleDownloadItem) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AccessibilityNodeInfoCompat (androidx.core.view.accessibility.AccessibilityNodeInfoCompat)1 CustomIndexItem (net.osmand.plus.download.CustomIndexItem)1 MultipleDownloadItem (net.osmand.plus.download.MultipleDownloadItem)1 AccessibilityAssistant (net.osmand.plus.plugins.accessibility.AccessibilityAssistant)1