From ad40ccb5fedb413937f5b4b5e58547ce4822ce72 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Tue, 6 Oct 2015 15:24:13 +0300 Subject: [PATCH] Buttons are implemented --- .../layout/two_line_with_images_list_item.xml | 3 +- OsmAnd/res/values/strings.xml | 2 ++ .../plus/download/items/ItemViewHolder.java | 32 +++++++++++++++---- .../download/items/RegionItemsFragment.java | 11 ++++--- .../newimplementation/DownloadsUiHelper.java | 1 - 5 files changed, 36 insertions(+), 13 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 0ae308daf2..dbbda7119e 100644 --- a/OsmAnd/res/layout/two_line_with_images_list_item.xml +++ b/OsmAnd/res/layout/two_line_with_images_list_item.xml @@ -57,7 +57,7 @@ - diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0dcd453d21..fb1ca8ed06 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2001,4 +2001,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Show free version banner Even if you have paid version you still can see free version banner BUY + Please activate Seamarks plugin + Please activate SRTM plugin diff --git a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java index 1f54279fa6..183a644ad4 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/items/ItemViewHolder.java @@ -1,7 +1,9 @@ package net.osmand.plus.download.items; +import android.content.Intent; import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.util.TypedValue; import android.view.View; import android.widget.Button; @@ -14,6 +16,7 @@ import net.osmand.PlatformUtil; import net.osmand.access.AccessibleToast; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.Version; import net.osmand.plus.WorldRegion; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; @@ -35,6 +38,7 @@ public class ItemViewHolder { private boolean freeVersion; private int textColorPrimary; private int textColorSecondary; + private RightButtonAction rightButtonAction; private enum RightButtonAction { UNKNOWN, @@ -72,10 +76,11 @@ public class ItemViewHolder { this.freeVersion = freeVersion; } - public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context, boolean showTypeInTitle, boolean showTypeInDesc) { + public void bindIndexItem(final IndexItem indexItem, final DownloadActivity context, + boolean showTypeInTitle, boolean showTypeInDesc) { boolean disabled = false; String textButtonCaption = "GET"; - RightButtonAction rightButtonAction = RightButtonAction.UNKNOWN; + rightButtonAction = RightButtonAction.UNKNOWN; if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { nameTextView.setText(indexItem.getVisibleName(context, @@ -112,7 +117,6 @@ public class ItemViewHolder { } else { descrTextView.setText(indexItem.getSizeDescription(context)); } - // TODO replace with imageView. rightImageButton.setVisibility(View.VISIBLE); rightImageButton.setImageDrawable(getContextIcon(context, R.drawable.ic_action_import)); progressBar.setVisibility(View.GONE); @@ -129,16 +133,26 @@ public class ItemViewHolder { public void onClick(View v) { switch (action) { case ASK_FOR_FULL_VERSION_PURCHASE: - AccessibleToast.makeText(context, "Please purchase Full version", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(Intent.ACTION_VIEW, + Uri.parse(Version.marketPrefix(context.getMyApplication()) + + "net.osmand.plus")); + context.startActivity(intent); break; case ASK_FOR_SEAMARKS_PLUGIN: - AccessibleToast.makeText(context.getApplicationContext(), "Please turn on Seamarks plugin", Toast.LENGTH_SHORT).show(); + context.startActivity(new Intent(context, + context.getMyApplication().getAppCustomization().getPluginsActivity())); + AccessibleToast.makeText(context.getApplicationContext(), + context.getString(R.string.activate_seamarks_plugin), Toast.LENGTH_SHORT).show(); break; case ASK_FOR_SRTM_PLUGIN_PURCHASE: - AccessibleToast.makeText(context, "Please purchase SRTM plugin", Toast.LENGTH_SHORT).show(); + OsmandPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class); + context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); break; case ASK_FOR_SRTM_PLUGIN_ENABLE: - AccessibleToast.makeText(context, "Please activate SRTM plugin", Toast.LENGTH_SHORT).show(); + context.startActivity(new Intent(context, + context.getMyApplication().getAppCustomization().getPluginsActivity())); + AccessibleToast.makeText(context, + context.getString(R.string.activate_srtm_plugin), Toast.LENGTH_SHORT).show(); break; } } @@ -184,4 +198,8 @@ public class ItemViewHolder { private Drawable getContextIcon(DownloadActivity context, int resourceId, int color) { return context.getMyApplication().getIconsCache().getPaintedContentIcon(resourceId, color); } + + public boolean isItemAvailable() { + return rightButtonAction == RightButtonAction.UNKNOWN; + } } diff --git a/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java b/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java index 506fbf13c3..afd13b8f41 100644 --- a/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/items/RegionItemsFragment.java @@ -96,10 +96,13 @@ public class RegionItemsFragment extends OsmandExpandableListFragment { .onRegionSelected(region.getRegionId()); return true; } else if (obj instanceof ItemsListBuilder.ResourceItem) { - IndexItem indexItem = ((ItemsListBuilder.ResourceItem) obj).getIndexItem(); - ((BaseDownloadActivity) getActivity()) - .startDownload(indexItem); - return true; + if(((ItemViewHolder) v.getTag()).isItemAvailable()) { + IndexItem indexItem = ((ItemsListBuilder.ResourceItem) obj).getIndexItem(); + ((BaseDownloadActivity) getActivity()) + .startDownload(indexItem); + + return true; + } } return false; } diff --git a/OsmAnd/src/net/osmand/plus/download/newimplementation/DownloadsUiHelper.java b/OsmAnd/src/net/osmand/plus/download/newimplementation/DownloadsUiHelper.java index bcc3afb2bf..32a67ad694 100644 --- a/OsmAnd/src/net/osmand/plus/download/newimplementation/DownloadsUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/newimplementation/DownloadsUiHelper.java @@ -133,7 +133,6 @@ public final class DownloadsUiHelper { @Override public void onFinished() { - freeVersionBanner.setVisibility(View.VISIBLE); downloadProgressLayout.setVisibility(View.GONE); } }