From 560206f476cd2afd480fff45cf19657ae48a8dac Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 19 Oct 2015 19:46:27 +0200 Subject: [PATCH] Update items --- .../layout/two_line_with_images_list_item.xml | 9 - .../plus/download/DownloadIndexesThread.java | 2 - .../plus/download/DownloadResources.java | 2 +- .../plus/download/ui/ItemViewHolder.java | 157 +++++++++--------- 4 files changed, 83 insertions(+), 87 deletions(-) diff --git a/OsmAnd/res/layout/two_line_with_images_list_item.xml b/OsmAnd/res/layout/two_line_with_images_list_item.xml index fee66d0940..a096f9082e 100644 --- a/OsmAnd/res/layout/two_line_with_images_list_item.xml +++ b/OsmAnd/res/layout/two_line_with_images_list_item.xml @@ -52,15 +52,6 @@ android:textSize="@dimen/default_sub_text_size" tools:text="Contour Lines"/> - - rawResources; private List itemsToUpdate = new ArrayList<>(); //public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip"; - public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip"; + public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap"; public DownloadResources(OsmandApplication app) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 588a0a8645..0d49d4ea9f 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -18,6 +18,8 @@ import net.osmand.plus.Version; import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.download.DownloadIndexesThread; +import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.IndexItem; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin; @@ -36,9 +38,9 @@ public class ItemViewHolder { protected final ImageView rightImageButton; protected final Button rightButton; protected final ProgressBar progressBar; - protected final TextView mapDateTextView; private boolean srtmDisabled; + private boolean srtmNeedsInstallation; private boolean nauticalPluginDisabled; private boolean freeVersion; @@ -46,10 +48,12 @@ public class ItemViewHolder { private int textColorPrimary; private int textColorSecondary; - private RightButtonAction rightButtonAction; + private RightButtonAction clickAction; + + private enum RightButtonAction { - UNKNOWN, + DOWNLOAD, ASK_FOR_SEAMARKS_PLUGIN, ASK_FOR_SRTM_PLUGIN_PURCHASE, ASK_FOR_SRTM_PLUGIN_ENABLE, @@ -60,7 +64,6 @@ public class ItemViewHolder { public ItemViewHolder(View view, DownloadActivity context) { this.context = context; progressBar = (ProgressBar) view.findViewById(R.id.progressBar); - mapDateTextView = (TextView) view.findViewById(R.id.mapDateTextView); rightButton = (Button) view.findViewById(R.id.rightButton); leftImageView = (ImageView) view.findViewById(R.id.leftImageView); descrTextView = (TextView) view.findViewById(R.id.description); @@ -83,59 +86,52 @@ public class ItemViewHolder { srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null; freeVersion = Version.isFreeVersion(context.getMyApplication()); + OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class); + srtmNeedsInstallation = srtmPlugin == null || srtmPlugin.needsInstallation(); } // FIXME public void bindIndexItem(final IndexItem indexItem, boolean showTypeInTitle, boolean showTypeInDesc) { initAppStatusVariables(); - boolean disabled = false; - rightButtonAction = RightButtonAction.UNKNOWN; - boolean downloading = context.getDownloadThread().isDownloading(indexItem); + boolean isDownloading = context.getDownloadThread().isDownloading(indexItem); int progress = -1; if (context.getDownloadThread().getCurrentDownloadingItem() == indexItem) { progress = context.getDownloadThread().getCurrentDownloadingItemProgress(); } - rightImageButton.setClickable(false); - if (progress != -1) { - rightImageButton.setClickable(true); - rightImageButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - context.makeSureUserCancelDownload(indexItem); - } - }); - } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { - nameTextView.setText(indexItem.getVisibleName(context, - context.getMyApplication().getRegions(), false)); + boolean disabled = checkDisabledAndClickAction(indexItem); + /// name and left item + if (showTypeInTitle) { + nameTextView.setText(indexItem.getType().getString(context)); } else { - if (indexItem.getSimplifiedFileName().equals(WORLD_SEAMARKS_KEY) - && nauticalPluginDisabled) { - rightButtonAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN; - disabled = true; - } - if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE || - indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) { - OsmandPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class); - if (srtmPlugin == null || srtmPlugin.needsInstallation()) { - rightButtonAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_PURCHASE; - } else if (!srtmPlugin.isActive()) { - rightButtonAction = RightButtonAction.ASK_FOR_SRTM_PLUGIN_ENABLE; - } - - disabled = true; - } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) { - rightButtonAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE; - disabled = true; - } - if (showTypeInTitle) { - nameTextView.setText(indexItem.getType().getString(context)); - } else { - nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false)); - } + nameTextView.setText(indexItem.getVisibleName(context, context.getMyApplication().getRegions(), false)); + } + if (indexItem.isDownloaded()) { + String date = indexItem.getLocalDate(); + boolean outdated = indexItem.isOutdated(); + String updateDescr = context.getResources().getString(R.string.local_index_installed) + ": " + + date; + mapDateTextView.setText(updateDescr); + int colorId = outdated ? R.color.color_distance : R.color.color_ok; + final int color = context.getResources().getColor(colorId); + mapDateTextView.setTextColor(color); + leftImageView.setImageDrawable(getContentIcon(context, + indexItem.getType().getIconResource(), color)); + nameTextView.setTextColor(textColorPrimary); + } else if (disabled) { + leftImageView.setImageDrawable(getContentIcon(context, + indexItem.getType().getIconResource(), textColorSecondary)); + nameTextView.setTextColor(textColorSecondary); + } else { + leftImageView.setImageDrawable(getContentIcon(context, + indexItem.getType().getIconResource())); + nameTextView.setTextColor(textColorPrimary); } - if (progress == -1) { + if (isDownloading) { + progressBar.setVisibility(View.GONE); + + // FIXME mapDATETextView descrTextView.setVisibility(View.VISIBLE); if (!showTypeInTitle && (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) && srtmDisabled) { @@ -145,44 +141,54 @@ public class ItemViewHolder { } else { descrTextView.setText(indexItem.getSizeDescription(context)); } + rightImageButton.setVisibility(View.VISIBLE); rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_import)); - progressBar.setVisibility(View.GONE); - - Map indexFileNames = context.getIndexFileNames(); - if (indexItem.isDownloaded()) { - String date = indexItem.getLocalDate(); - boolean outdated = indexItem.isOutdated(); - String updateDescr = context.getResources().getString(R.string.local_index_installed) + ": " - + date; - mapDateTextView.setText(updateDescr); - int colorId = outdated ? R.color.color_distance : R.color.color_ok; - final int color = context.getResources().getColor(colorId); - mapDateTextView.setTextColor(color); - leftImageView.setImageDrawable(getContentIcon(context, - indexItem.getType().getIconResource(), color)); - nameTextView.setTextColor(textColorPrimary); - } else if (disabled) { - leftImageView.setImageDrawable(getContentIcon(context, - indexItem.getType().getIconResource(), textColorSecondary)); - nameTextView.setTextColor(textColorSecondary); - } else { - leftImageView.setImageDrawable(getContentIcon(context, - indexItem.getType().getIconResource())); - nameTextView.setTextColor(textColorPrimary); - } + } else { progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(progress); - rightImageButton.setImageDrawable( - getContentIcon(context, R.drawable.ic_action_remove_dark)); + + descrTextView.setVisibility(View.GONE); + + rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark)); + rightImageButton.setClickable(true); + rightImageButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + context.makeSureUserCancelDownload(indexItem); + } + }); } + } - if (rightButtonAction != RightButtonAction.UNKNOWN) { + + private boolean checkDisabledAndClickAction(final IndexItem indexItem) { + boolean disabled = false; + clickAction = RightButtonAction.DOWNLOAD; + if (indexItem.getBasename().toLowerCase().equals(DownloadResources.WORLD_SEAMARKS_KEY) + && nauticalPluginDisabled) { + clickAction = RightButtonAction.ASK_FOR_SEAMARKS_PLUGIN; + disabled = true; + } 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; + } + + disabled = true; + } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE && freeVersion) { + clickAction = RightButtonAction.ASK_FOR_FULL_VERSION_PURCHASE; + disabled = true; + } + + if (clickAction != RightButtonAction.DOWNLOAD) { rightButton.setText(R.string.get_plugin); rightButton.setVisibility(View.VISIBLE); rightImageButton.setVisibility(View.GONE); - final RightButtonAction action = rightButtonAction; + final RightButtonAction action = clickAction; rightButton.setOnClickListener(new View.OnClickListener() { @Override @@ -210,16 +216,17 @@ public class ItemViewHolder { AccessibleToast.makeText(context, context.getString(R.string.activate_srtm_plugin), Toast.LENGTH_SHORT).show(); break; - case UNKNOWN: + case DOWNLOAD: break; } } }); - } else { rightButton.setVisibility(View.GONE); rightImageButton.setVisibility(View.VISIBLE); } + + return disabled; } private Drawable getContentIcon(DownloadActivity context, int resourceId) { @@ -231,6 +238,6 @@ public class ItemViewHolder { } public boolean isItemAvailable() { - return rightButtonAction == RightButtonAction.UNKNOWN; + return clickAction == RightButtonAction.DOWNLOAD; } }