From 36750a3dc8fc67b87a62c19ebbd2751257c74514 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 5 May 2017 18:58:10 +0300 Subject: [PATCH] Added empty state card --- .../res/drawable/context_menu_card_dark.xml | 14 +-- .../res/drawable/context_menu_card_light.xml | 14 +-- ...ontext_menu_card_add_mapillary_images.xml} | 15 ++- OsmAnd/res/layout/context_menu_card_image.xml | 12 +++ .../layout/context_menu_card_no_images.xml | 88 +++++++++++++++ OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/colors.xml | 2 + OsmAnd/res/values/strings.xml | 2 + OsmAnd/res/values/styles.xml | 2 + OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 14 +++ .../plus/mapcontextmenu/MenuBuilder.java | 82 +++++++++++--- .../plus/mapcontextmenu/MenuController.java | 6 ++ .../builders/AmenityMenuBuilder.java | 1 - .../builders/FavouritePointMenuBuilder.java | 1 - .../builders/WptPtMenuBuilder.java | 1 - .../builders/cards/ImageCard.java | 102 ++++++------------ .../builders/cards/NoImagesCard.java | 31 ++++++ .../builders/cards/UrlImageCard.java | 43 ++++++++ .../controllers/HistoryMenuController.java | 1 - .../controllers/MapMarkerMenuController.java | 1 - .../controllers/MyLocationMenuController.java | 1 - .../PointDescriptionMenuController.java | 1 - .../RenderedObjectMenuController.java | 1 - .../TargetPointMenuController.java | 1 - ...oCard.java => AddMapillaryImagesCard.java} | 8 +- .../plus/mapillary/MapillaryImageCard.java | 11 +- .../plus/mapillary/MapillaryPlugin.java | 63 ----------- 27 files changed, 320 insertions(+), 199 deletions(-) rename OsmAnd/res/layout/{mapillary_context_menu_action.xml => context_menu_card_add_mapillary_images.xml} (78%) create mode 100644 OsmAnd/res/layout/context_menu_card_no_images.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java rename OsmAnd/src/net/osmand/plus/mapillary/{AddMapillaryPhotoCard.java => AddMapillaryImagesCard.java} (75%) diff --git a/OsmAnd/res/drawable/context_menu_card_dark.xml b/OsmAnd/res/drawable/context_menu_card_dark.xml index 625e0ea36c..464456737a 100644 --- a/OsmAnd/res/drawable/context_menu_card_dark.xml +++ b/OsmAnd/res/drawable/context_menu_card_dark.xml @@ -1,18 +1,6 @@ - - - - - - - + diff --git a/OsmAnd/res/drawable/context_menu_card_light.xml b/OsmAnd/res/drawable/context_menu_card_light.xml index 1d0cecf6a0..09cf69450f 100644 --- a/OsmAnd/res/drawable/context_menu_card_light.xml +++ b/OsmAnd/res/drawable/context_menu_card_light.xml @@ -1,18 +1,6 @@ - - - - - - - + diff --git a/OsmAnd/res/layout/mapillary_context_menu_action.xml b/OsmAnd/res/layout/context_menu_card_add_mapillary_images.xml similarity index 78% rename from OsmAnd/res/layout/mapillary_context_menu_action.xml rename to OsmAnd/res/layout/context_menu_card_add_mapillary_images.xml index ccfc6399fa..5cb02ceb06 100644 --- a/OsmAnd/res/layout/mapillary_context_menu_action.xml +++ b/OsmAnd/res/layout/context_menu_card_add_mapillary_images.xml @@ -1,17 +1,18 @@ - - \ No newline at end of file + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/context_menu_card_image.xml b/OsmAnd/res/layout/context_menu_card_image.xml index 41bc934e91..ab4812d3d8 100644 --- a/OsmAnd/res/layout/context_menu_card_image.xml +++ b/OsmAnd/res/layout/context_menu_card_image.xml @@ -18,6 +18,18 @@ android:layout_height="match_parent" android:scaleType="centerCrop"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 47778578e9..8d7c232f86 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -17,6 +17,7 @@ + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index f1bd2ce7a9..bef5c9081f 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -115,6 +115,8 @@ #b4c3cc #d9d9d9 #333b40 + #F5F5F5 + #3d474c #448AFF #eaeaea diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e8e310b62e..6168e7c914 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,7 +9,9 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Online photos Add photos + We don\'t have photos for this location Contribute with your own street-level views of this location with Mapillary. Mapillary widget Allow you to quick contribute to Mapillary diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 50782d0d2f..efef9826c4 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -79,6 +79,7 @@ @drawable/chart_marker_background_light @color/color_myloc_distance @color/ctx_menu_info_divider_light + @color/ctx_menu_card_btn_light @color/searchbar_text_light @color/searchbar_text_hint_light @color/list_divider_dark @@ -251,6 +252,7 @@ @drawable/chart_marker_background_dark @color/osmand_orange @color/ctx_menu_info_divider_dark + @color/ctx_menu_card_btn_dark @color/searchbar_text_dark @color/searchbar_text_hint_dark @color/list_divider_light diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index e102de311f..324cc191ed 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -23,6 +23,7 @@ import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin; import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapillary.MapillaryPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.FavoritesActivity; @@ -104,9 +105,22 @@ public abstract class OsmandPlugin { return null; } + /* + * Return true in case if plugin should fill the map context menu with buildContextMenuRows method. + */ + public boolean isMenuControllerSupported(Class menuControllerClass) { + return false; + } + + /* + * Add menu rows to the map context menu. + */ public void buildContextMenuRows(@NonNull MenuBuilder menuBuilder, @NonNull View view) { } + /* + * Clear resources after menu was closed + */ public void clearContextMenuRows() { } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 3e29a913c9..5a13801d1a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -36,6 +36,13 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard; +import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; +import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; +import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; +import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; +import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener; +import net.osmand.plus.mapillary.AddMapillaryImagesCard; import net.osmand.plus.render.RenderingIcons; import net.osmand.util.MapUtils; @@ -61,7 +68,9 @@ public class MenuBuilder { private boolean hidden; private boolean showNearestWiki = false; protected List nearestWiki = new ArrayList<>(); - private List> pluginMenuBuilders = new ArrayList<>(); + private List menuPlugins = new ArrayList<>(); + private CardsRowBuilder onlinePhotoCardsRow; + private List onlinePhotoCards; public class PlainMenuItem { private int iconId; @@ -197,8 +206,8 @@ public class MenuBuilder { this.showNearestWiki = showNearestWiki; } - public void addPluginMenuBuilder(Class pluginClass) { - pluginMenuBuilders.add(pluginClass); + public void addMenuPlugin(OsmandPlugin plugin) { + menuPlugins.add(plugin); } public void setLight(boolean light) { @@ -213,6 +222,7 @@ public class MenuBuilder { buildPlainMenuItems(view); } buildInternal(view); + buildNearestPhotosRow(view); buildPluginRows(view); buildAfter(view); } @@ -222,6 +232,8 @@ public class MenuBuilder { } void onClose() { + onlinePhotoCardsRow = null; + onlinePhotoCards = null; clearPluginRows(); } @@ -241,20 +253,14 @@ public class MenuBuilder { } protected void buildPluginRows(View view) { - for (Class pluginClass : pluginMenuBuilders) { - OsmandPlugin plugin = OsmandPlugin.getEnabledPlugin(pluginClass); - if (plugin != null) { - plugin.buildContextMenuRows(this, view); - } + for (OsmandPlugin plugin : menuPlugins) { + plugin.buildContextMenuRows(this, view); } } protected void clearPluginRows() { - for (Class pluginClass : pluginMenuBuilders) { - OsmandPlugin plugin = OsmandPlugin.getEnabledPlugin(pluginClass); - if (plugin != null) { - plugin.clearContextMenuRows(); - } + for (OsmandPlugin plugin : menuPlugins) { + plugin.clearContextMenuRows(); } } @@ -266,6 +272,56 @@ public class MenuBuilder { } } + protected void buildNearestPhotosRow(View view) { + if (!app.getSettings().isInternetConnectionAvailable()) { + return; + } + + boolean needUpdateOnly = onlinePhotoCardsRow != null && onlinePhotoCardsRow.getMenuBuilder() == this; + onlinePhotoCardsRow = new CardsRowBuilder(this, view, false); + onlinePhotoCardsRow.build(); + CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(), + app.getSettings().MAPILLARY_MENU_COLLAPSED); + collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() { + @Override + public void onCollapseExpand(boolean collapsed) { + if (!collapsed && onlinePhotoCards == null) { + startLoadingImages(MenuBuilder.this); + } + } + }); + buildRow(view, R.drawable.ic_action_photo_dark, app.getString(R.string.online_photos), 0, true, + collapsableView, false, 1, false, null); + + if (needUpdateOnly && onlinePhotoCards != null) { + onlinePhotoCardsRow.setCards(onlinePhotoCards); + } else if (!collapsableView.isCollapsed()) { + startLoadingImages(this); + } + } + + private void startLoadingImages(final MenuBuilder menuBuilder) { + onlinePhotoCards = new ArrayList<>(); + onlinePhotoCardsRow.setProgressCard(); + ImageCard.execute(new GetImageCardsTask(app, menuBuilder.getLatLon(), + new GetImageCardsListener() { + @Override + public void onFinish(List cardList) { + if (!menuBuilder.isHidden()) { + List cards = new ArrayList<>(); + cards.addAll(cardList); + if (cardList.size() == 0) { + cards.add(new NoImagesCard(app)); + } else { + cards.add(new AddMapillaryImagesCard(app)); + } + onlinePhotoCardsRow.setCards(cards); + onlinePhotoCards = cards; + } + } + })); + } + protected void buildInternal(View view) { } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 046ac958cb..fa32978da4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -23,6 +23,7 @@ import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -115,6 +116,11 @@ public abstract class MenuController extends BaseMenuController { } public void build(View rootView) { + for (OsmandPlugin plugin : OsmandPlugin.getEnabledPlugins()) { + if (plugin.isMenuControllerSupported(this.getClass())) { + builder.addMenuPlugin(plugin); + } + } builder.build(rootView); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 27a547a303..da3c41e835 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -50,7 +50,6 @@ public class AmenityMenuBuilder extends MenuBuilder { public AmenityMenuBuilder(MapActivity mapActivity, final Amenity amenity) { super(mapActivity); this.amenity = amenity; - addPluginMenuBuilder(MapillaryPlugin.class); setShowNearestWiki(true, amenity.getId()); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 6880898e62..c803a626c1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -24,7 +24,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder { public FavouritePointMenuBuilder(MapActivity mapActivity, final FavouritePoint fav) { super(mapActivity); this.fav = fav; - addPluginMenuBuilder(MapillaryPlugin.class); setShowNearestWiki(true); acquireOriginObject(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java index 368d46d66e..2bd01a0222 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java @@ -21,7 +21,6 @@ public class WptPtMenuBuilder extends MenuBuilder { public WptPtMenuBuilder(MapActivity mapActivity, final WptPt wpt) { super(mapActivity); this.wpt = wpt; - addPluginMenuBuilder(MapillaryPlugin.class); setShowNearestWiki(true); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index 25d316d4f8..544b0caeac 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -17,8 +17,8 @@ import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.mapillary.MapillaryImageCard; import net.osmand.util.Algorithms; -import net.osmand.util.MapUtils; import org.json.JSONArray; import org.json.JSONException; @@ -28,8 +28,6 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; @@ -40,8 +38,6 @@ import static java.text.DateFormat.FULL; public abstract class ImageCard extends AbstractCard { - private static final int IMAGES_LIMIT = 15; - private String type; // Image location private LatLon location; @@ -70,10 +66,6 @@ public abstract class ImageCard extends AbstractCard { private float bearingDiff = Float.NaN; private float distance = Float.NaN; - public interface ImageCardFactory { - T createCard(OsmandApplication app, JSONObject imageObject); - } - public ImageCard(OsmandApplication app, JSONObject imageObject) { super(app); try { @@ -112,6 +104,23 @@ public abstract class ImageCard extends AbstractCard { } } + private static ImageCard createCard(OsmandApplication app, JSONObject imageObject) { + ImageCard imageCard = null; + try { + if (imageObject.has("type")) { + String type = imageObject.getString("type"); + if ("mapillary-photo".equals(type)) { + imageCard = new MapillaryImageCard(app, imageObject); + } else { + imageCard = new UrlImageCard(app, imageObject); + } + } + } catch (JSONException e) { + e.printStackTrace(); + } + return imageCard; + } + public double getCa() { return ca; } @@ -243,29 +252,26 @@ public abstract class ImageCard extends AbstractCard { } } - public static class GetImageCardsTask extends AsyncTask> { + public static class GetImageCardsTask extends AsyncTask> { private OsmandApplication app; private LatLon latLon; - private Listener listener; - private ImageCardFactory imageCardFactory; - private List result; + private GetImageCardsListener listener; + private List result; - public interface Listener { - void onFinish(List cardList); + public interface GetImageCardsListener { + void onFinish(List cardList); } - public GetImageCardsTask(@NonNull ImageCardFactory imageCardFactory, - @NonNull OsmandApplication app, LatLon latLon, Listener listener) { - this.imageCardFactory = imageCardFactory; + public GetImageCardsTask(@NonNull OsmandApplication app, LatLon latLon, GetImageCardsListener listener) { this.app = app; this.latLon = latLon; this.listener = listener; } @Override - protected List doInBackground(Void... params) { - List result = new ArrayList<>(); + protected List doInBackground(Void... params) { + List result = new ArrayList<>(); try { final Map pms = new LinkedHashMap<>(); pms.put("lat", "" + latLon.getLatitude()); @@ -286,7 +292,10 @@ public abstract class ImageCard extends AbstractCard { try { JSONObject imageObject = (JSONObject) images.get(i); if (imageObject != JSONObject.NULL) { - result.add(imageCardFactory.createCard(app, imageObject)); + ImageCard imageCard = ImageCard.createCard(app, imageObject); + if (imageCard != null) { + result.add(imageCard); + } } } catch (JSONException e) { e.printStackTrace(); @@ -297,18 +306,11 @@ public abstract class ImageCard extends AbstractCard { } catch (Exception e) { e.printStackTrace(); } - final Location loc = new Location(""); - loc.setLatitude(latLon.getLatitude()); - loc.setLongitude(latLon.getLongitude()); - sortImagesInfo(result, loc); - if (result.size() > IMAGES_LIMIT) { - result = result.subList(0, IMAGES_LIMIT); - } return result; } @Override - protected void onPostExecute(List cardList) { + protected void onPostExecute(List cardList) { result = cardList; if (listener != null) { listener.onFinish(result); @@ -316,48 +318,6 @@ public abstract class ImageCard extends AbstractCard { } } - private static void sortImagesInfo(List cardList, @NonNull final Location location) { - List targetCards = new ArrayList<>(); - List otherCards = new ArrayList<>(); - for (T c : cardList) { - if (c.getLocation() != null) { - Location l = new Location(""); - l.setLatitude(c.getLocation().getLatitude()); - l.setLongitude(c.getLocation().getLongitude()); - c.setDistance(l.distanceTo(location)); - if (!Double.isNaN(c.getCa())) { - float bearingDiff = Math.abs(MapUtils.unifyRotationDiff( - MapUtils.unifyRotationTo360((float) c.getCa()), l.bearingTo(location))); - c.setBearingDiff(bearingDiff); - if (bearingDiff < 30) { - targetCards.add(c); - } else { - otherCards.add(c); - } - } else { - otherCards.add(c); - } - } - } - Collections.sort(targetCards, new Comparator() { - - @Override - public int compare(ImageCard i1, ImageCard i2) { - return Float.compare(i1.bearingDiff, i2.bearingDiff); - } - }); - Collections.sort(otherCards, new Comparator() { - - @Override - public int compare(ImageCard i1, ImageCard i2) { - return Float.compare(i1.distance, i2.distance); - } - }); - cardList.clear(); - cardList.addAll(targetCards); - cardList.addAll(otherCards); - } - private class DownloadImageTask extends AsyncTask { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java new file mode 100644 index 0000000000..68593c397e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java @@ -0,0 +1,31 @@ +package net.osmand.plus.mapcontextmenu.builders.cards; + +import android.view.View; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.mapillary.MapillaryPlugin; + +public class NoImagesCard extends AbstractCard { + + public NoImagesCard(OsmandApplication app) { + super(app); + } + + @Override + public int getCardLayoutId() { + return R.layout.context_menu_card_no_images; + } + + @Override + public void update() { + if (view != null) { + view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapillaryPlugin.openMapillary(getMyApplication()); + } + }); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java new file mode 100644 index 0000000000..3bf0c6aaa4 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/UrlImageCard.java @@ -0,0 +1,43 @@ +package net.osmand.plus.mapcontextmenu.builders.cards; + +import android.content.Intent; +import android.net.Uri; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.util.Algorithms; + +import org.json.JSONObject; + +public class UrlImageCard extends ImageCard { + + public UrlImageCard(OsmandApplication app, JSONObject imageObject) { + super(app, imageObject); + this.icon = app.getIconsCache().getIcon(R.drawable.ic_action_osmand_logo, R.color.osmand_orange); + if (!Algorithms.isEmpty(getImageUrl())) { + this.onClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(getImageUrl())); + v.getContext().startActivity(intent); + } + }; + } + } + + @Override + public void update() { + super.update(); + if (view != null) { + ImageView image = (ImageView) view.findViewById(R.id.image); + image.setVisibility(View.GONE); + TextView urlText = (TextView) view.findViewById(R.id.url); + urlText.setText(getImageUrl()); + urlText.setVisibility(View.VISIBLE); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java index 1f0c45e52d..4bdd240adb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java @@ -20,7 +20,6 @@ public class HistoryMenuController extends MenuController { public HistoryMenuController(MapActivity mapActivity, PointDescription pointDescription, final HistoryEntry entry) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); this.entry = entry; - builder.addPluginMenuBuilder(MapillaryPlugin.class); builder.setShowNearestWiki(true); initData(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java index f9c64a4aa9..4e0bf8570f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java @@ -20,7 +20,6 @@ public class MapMarkerMenuController extends MenuController { public MapMarkerMenuController(MapActivity mapActivity, PointDescription pointDescription, MapMarker mapMarker) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); this.mapMarker = mapMarker; - builder.addPluginMenuBuilder(MapillaryPlugin.class); builder.setShowNearestWiki(true); final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); leftTitleButtonController = new TitleButtonController() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java index 072fc38858..d1f2fc6624 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java @@ -14,7 +14,6 @@ public class MyLocationMenuController extends MenuController { public MyLocationMenuController(MapActivity mapActivity, PointDescription pointDescription) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); - builder.addPluginMenuBuilder(MapillaryPlugin.class); builder.setShowNearestWiki(true); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java index a842b836a4..8d875706c2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java @@ -17,7 +17,6 @@ public class PointDescriptionMenuController extends MenuController { public PointDescriptionMenuController(MapActivity mapActivity, final PointDescription pointDescription) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); - builder.addPluginMenuBuilder(MapillaryPlugin.class); builder.setShowNearestWiki(true); initData(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java index 640e5bbfb9..12b8a07dfa 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java @@ -19,7 +19,6 @@ public class RenderedObjectMenuController extends MenuController { public RenderedObjectMenuController(MapActivity mapActivity, PointDescription pointDescription, final RenderedObject renderedObject) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); - builder.addPluginMenuBuilder(MapillaryPlugin.class); builder.setShowNearestWiki(true); this.renderedObject = renderedObject; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java index 1c07d7e2f7..5baf0985cb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java @@ -20,7 +20,6 @@ public class TargetPointMenuController extends MenuController { public TargetPointMenuController(MapActivity mapActivity, PointDescription pointDescription, TargetPoint targetPoint) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); this.targetPoint = targetPoint; - builder.addPluginMenuBuilder(MapillaryPlugin.class); builder.setShowNearestWiki(true); final TargetPointsHelper targetPointsHelper = getMapActivity().getMyApplication().getTargetPointsHelper(); final int intermediatePointsCount = targetPointsHelper.getIntermediatePoints().size(); diff --git a/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java b/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryImagesCard.java similarity index 75% rename from OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java rename to OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryImagesCard.java index c946e9300b..35fce2e3d1 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryPhotoCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/AddMapillaryImagesCard.java @@ -6,15 +6,15 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard; -class AddMapillaryPhotoCard extends AbstractCard { +public class AddMapillaryImagesCard extends AbstractCard { - AddMapillaryPhotoCard(OsmandApplication app) { + public AddMapillaryImagesCard(OsmandApplication app) { super(app); } @Override public int getCardLayoutId() { - return R.layout.mapillary_context_menu_action; + return R.layout.context_menu_card_add_mapillary_images; } @Override @@ -28,4 +28,4 @@ class AddMapillaryPhotoCard extends AbstractCard { }); } } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java index dde5176389..30a7046195 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageCard.java @@ -8,16 +8,9 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import org.json.JSONObject; -class MapillaryImageCard extends ImageCard { +public class MapillaryImageCard extends ImageCard { - static class MapillaryImageCardFactory implements ImageCardFactory { - @Override - public MapillaryImageCard createCard(OsmandApplication app, JSONObject imageObject) { - return new MapillaryImageCard(app, imageObject); - } - } - - private MapillaryImageCard(OsmandApplication app, JSONObject imageObject) { + public MapillaryImageCard(OsmandApplication app, JSONObject imageObject) { super(app, imageObject); this.icon = app.getIconsCache().getIcon(R.drawable.ic_logo_mapillary); this.onClickListener = new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index 4dce5c8875..bebf89b99e 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -26,12 +26,6 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.mapcontextmenu.MenuBuilder; -import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView; -import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard; -import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; -import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; -import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -39,7 +33,6 @@ import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.util.Algorithms; -import java.util.ArrayList; import java.util.List; public class MapillaryPlugin extends OsmandPlugin { @@ -51,8 +44,6 @@ public class MapillaryPlugin extends OsmandPlugin { private MapillaryLayer rasterLayer; private TextInfoWidget mapillaryControl; private MapWidgetRegInfo mapillaryWidgetRegInfo; - private CardsRowBuilder contextMenuCardsRow; - private List contextMenuCards; public MapillaryPlugin(OsmandApplication app) { this.app = app; @@ -206,60 +197,6 @@ public class MapillaryPlugin extends OsmandPlugin { } } - @Override - public void buildContextMenuRows(@NonNull final MenuBuilder menuBuilder, @NonNull View view) { - if (!menuBuilder.getApplication().getSettings().isInternetConnectionAvailable()) { - return; - } - - boolean needUpdateOnly = contextMenuCardsRow != null && contextMenuCardsRow.getMenuBuilder() == menuBuilder; - contextMenuCardsRow = new CardsRowBuilder(menuBuilder, view, false); - contextMenuCardsRow.build(); - CollapsableView collapsableView = new CollapsableView(contextMenuCardsRow.getContentView(), - app.getSettings().MAPILLARY_MENU_COLLAPSED); - collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() { - @Override - public void onCollapseExpand(boolean collapsed) { - if (!collapsed && contextMenuCards == null) { - startLoadingImages(menuBuilder); - } - } - }); - menuBuilder.buildRow(view, R.drawable.ic_action_photo_dark, "Online photos", 0, true, - collapsableView, false, 1, false, null); - - if (needUpdateOnly && contextMenuCards != null) { - contextMenuCardsRow.setCards(contextMenuCards); - } else if (!collapsableView.isCollapsed()) { - startLoadingImages(menuBuilder); - } - } - - private void startLoadingImages(final MenuBuilder menuBuilder) { - contextMenuCards = new ArrayList<>(); - contextMenuCardsRow.setProgressCard(); - ImageCard.execute(new GetImageCardsTask<>( - new MapillaryImageCard.MapillaryImageCardFactory(), app, menuBuilder.getLatLon(), - new GetImageCardsTask.Listener() { - @Override - public void onFinish(List cardList) { - if (!menuBuilder.isHidden()) { - List cards = new ArrayList<>(); - cards.addAll(cardList); - cards.add(new AddMapillaryPhotoCard(app)); - contextMenuCardsRow.setCards(cards); - contextMenuCards = cards; - } - } - })); - } - - @Override - public void clearContextMenuRows() { - contextMenuCardsRow = null; - contextMenuCards = null; - } - public static boolean openMapillary(OsmandApplication app) { boolean success = false; if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) {