Search in sources :

Example 1 with CustomIndexItem

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

the class DownloadItemFragment method reloadData.

private void reloadData() {
    DownloadActivity activity = getDownloadActivity();
    OsmandApplication app = activity.getMyApplication();
    DownloadResources indexes = activity.getDownloadThread().getIndexes();
    group = indexes.getGroupById(regionId);
    CustomIndexItem indexItem = (CustomIndexItem) group.getItemByIndex(itemIndex);
    if (indexItem != null) {
        toolbar.setTitle(indexItem.getVisibleName(app, app.getRegions()));
        DownloadDescriptionInfo descriptionInfo = indexItem.getDescriptionInfo();
        if (descriptionInfo != null) {
            updateDescription(app, descriptionInfo, description);
            updateImagesPager(app, descriptionInfo, imagesPager);
            updateActionButtons(activity, descriptionInfo, indexItem, buttonsContainer, R.layout.bottom_buttons, nightMode);
        }
    }
    WorldRegion region = group.getParentGroup().getRegion();
    if (region instanceof CustomRegion) {
        int headerColor = ((CustomRegion) region).getHeaderColor();
        if (headerColor != CustomRegion.INVALID_ID) {
            toolbar.setBackgroundColor(headerColor);
        }
    }
}
Also used : DownloadResources(net.osmand.plus.download.DownloadResources) WorldRegion(net.osmand.map.WorldRegion) OsmandApplication(net.osmand.plus.OsmandApplication) CustomIndexItem(net.osmand.plus.download.CustomIndexItem) DownloadActivity(net.osmand.plus.download.DownloadActivity) CustomRegion(net.osmand.plus.download.CustomRegion)

Example 2 with CustomIndexItem

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

the class DownloadResourceGroupFragment method onChildClick.

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    Object child = listAdapter.getChild(groupPosition, childPosition);
    if (child instanceof DownloadResourceGroup) {
        String uniqueId = ((DownloadResourceGroup) child).getUniqueId();
        final DownloadResourceGroupFragment regionDialogFragment = DownloadResourceGroupFragment.createInstance(uniqueId);
        ((DownloadActivity) getActivity()).showDialog(getActivity(), regionDialogFragment);
        return true;
    } else if (child instanceof CustomIndexItem) {
        String regionId = group.getGroupByIndex(groupPosition).getUniqueId();
        DownloadItemFragment downloadItemFragment = DownloadItemFragment.createInstance(regionId, childPosition);
        ((DownloadActivity) getActivity()).showDialog(getActivity(), downloadItemFragment);
    } else if (child instanceof DownloadItem) {
        DownloadItem downloadItem = (DownloadItem) child;
        ItemViewHolder vh = (ItemViewHolder) v.getTag();
        OnClickListener ls = vh.getRightButtonAction(downloadItem, vh.getClickAction(downloadItem));
        ls.onClick(v);
        return true;
    }
    return false;
}
Also used : DownloadResourceGroup(net.osmand.plus.download.DownloadResourceGroup) OnClickListener(android.view.View.OnClickListener) JSONObject(org.json.JSONObject) CustomIndexItem(net.osmand.plus.download.CustomIndexItem) DownloadItem(net.osmand.plus.download.DownloadItem) DownloadActivity(net.osmand.plus.download.DownloadActivity)

Example 3 with CustomIndexItem

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

the class DownloadResourceGroupAdapter method getChildView.

@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    final Object child = getChild(groupPosition, childPosition);
    if (child instanceof DownloadItem) {
        DownloadItem item = (DownloadItem) child;
        DownloadResourceGroup group = getGroupObj(groupPosition);
        ItemViewHolder viewHolder;
        if (convertView != null && convertView.getTag() instanceof ItemViewHolder) {
            viewHolder = (ItemViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.two_line_with_images_list_item, parent, false);
            viewHolder = new ItemViewHolder(convertView, ctx);
            viewHolder.setShowRemoteDate(true);
            convertView.setTag(viewHolder);
        }
        if (mainGroup.getType() == DownloadResourceGroup.DownloadResourceGroupType.REGION && group != null && group.getType() == DownloadResourceGroup.DownloadResourceGroupType.REGION_MAPS && !(item instanceof CustomIndexItem)) {
            viewHolder.setShowTypeInName(true);
            viewHolder.setShowTypeInDesc(false);
        } else if (group != null && (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.SRTM_HEADER || group.getType() == DownloadResourceGroup.DownloadResourceGroupType.HILLSHADE_HEADER)) {
            viewHolder.setShowTypeInName(false);
            viewHolder.setShowTypeInDesc(false);
        } else {
            viewHolder.setShowTypeInDesc(true);
        }
        viewHolder.bindDownloadItem(item);
    } else {
        DownloadResourceGroup group = (DownloadResourceGroup) child;
        DownloadGroupViewHolder viewHolder;
        if (convertView != null && convertView.getTag() instanceof DownloadGroupViewHolder) {
            viewHolder = (DownloadGroupViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_list_menu_item, parent, false);
            viewHolder = new DownloadGroupViewHolder(ctx, convertView);
            convertView.setTag(viewHolder);
        }
        viewHolder.bindItem(group);
    }
    return convertView;
}
Also used : DownloadResourceGroup(net.osmand.plus.download.DownloadResourceGroup) DownloadItem(net.osmand.plus.download.DownloadItem) CustomIndexItem(net.osmand.plus.download.CustomIndexItem)

Example 4 with CustomIndexItem

use of net.osmand.plus.download.CustomIndexItem 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

CustomIndexItem (net.osmand.plus.download.CustomIndexItem)4 DownloadActivity (net.osmand.plus.download.DownloadActivity)2 DownloadItem (net.osmand.plus.download.DownloadItem)2 DownloadResourceGroup (net.osmand.plus.download.DownloadResourceGroup)2 SuppressLint (android.annotation.SuppressLint)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AccessibilityNodeInfoCompat (androidx.core.view.accessibility.AccessibilityNodeInfoCompat)1 WorldRegion (net.osmand.map.WorldRegion)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 CustomRegion (net.osmand.plus.download.CustomRegion)1 DownloadResources (net.osmand.plus.download.DownloadResources)1 MultipleDownloadItem (net.osmand.plus.download.MultipleDownloadItem)1 AccessibilityAssistant (net.osmand.plus.plugins.accessibility.AccessibilityAssistant)1 JSONObject (org.json.JSONObject)1