From 1b68b78ab3234a8f03c2a690364359ff34bc684b Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Fri, 30 Dec 2016 11:39:40 +0400 Subject: [PATCH] [android] Review fixes --- .../maps/bookmarks/data/MapObject.java | 5 ++++ .../widget/placepage/PlacePageButtons.java | 20 ++++++++++++++++ .../maps/widget/placepage/PlacePageView.java | 24 ++++--------------- android/src/com/mapswithme/util/Utils.java | 21 ++++++++++++++++ 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java index 15c0e7ef30..04ea86924f 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/MapObject.java @@ -180,6 +180,11 @@ public class MapObject implements Parcelable addMetadata(types[i], values[i]); } + public boolean hasPhoneNumber() + { + return !TextUtils.isEmpty(getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER)); + } + public static boolean isOfType(@MapObjectType int type, MapObject object) { return object != null && object.getMapObjectType() == type; diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java index d6ee8600c4..8ab5faa618 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageButtons.java @@ -17,6 +17,7 @@ import java.util.List; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.util.BottomSheetHelper; import com.mapswithme.util.ThemeUtils; @@ -199,11 +200,30 @@ final class PlacePageButtons int to = res.indexOf(Item.ROUTE_TO); if (to > from && to >= MAX_BUTTONS) Collections.swap(res, from, to); + + preserveNavigationButtons(res, Item.CALL); + preserveNavigationButtons(res, Item.BOOKING); } return res; } + private void preserveNavigationButtons(@NonNull List items, @NonNull Item itemToShift) + { + if (!RoutingController.get().isNavigating() && !RoutingController.get().isPlanning()) + return; + + int pos = items.indexOf(itemToShift); + if (pos > -1) + { + items.remove(pos); + items.add(MAX_BUTTONS, itemToShift); + int to = items.indexOf(Item.ROUTE_TO); + items.remove(Item.ROUTE_FROM); + items.add(to + 1, Item.ROUTE_FROM); + } + } + private void showPopup(final List buttons) { BottomSheetHelper.Builder bs = new BottomSheetHelper.Builder(mPlacePage.getActivity()); diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 63927ef9be..89f2b99ded 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -446,7 +446,7 @@ public class PlacePageView extends RelativeLayout break; case CALL: - callPhone(); + Utils.callPhone(getContext(), mTvPhone.getText().toString()); break; } } @@ -1159,7 +1159,7 @@ public class PlacePageView extends RelativeLayout } } - if (!TextUtils.isEmpty(mMapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER))) + if (mMapObject.hasPhoneNumber()) buttons.add(PlacePageButtons.Item.CALL); buttons.add(PlacePageButtons.Item.BOOKMARK); @@ -1317,7 +1317,7 @@ public class PlacePageView extends RelativeLayout refreshLatLon(); break; case R.id.ll__place_phone: - callPhone(); + Utils.callPhone(getContext(), mTvPhone.getText().toString()); break; case R.id.ll__place_website: followUrl(mTvWebsite.getText().toString()); @@ -1332,10 +1332,7 @@ public class PlacePageView extends RelativeLayout showBigDirection(); break; case R.id.ll__place_email: - Intent intent; - intent = new Intent(Intent.ACTION_SENDTO); - intent.setData(Utils.buildMailUri(mTvEmail.getText().toString(), "", "")); - getContext().startActivity(intent); + Utils.sendTo(getContext(), mTvEmail.getText().toString()); break; case R.id.tv__bookmark_edit: Bookmark bookmark = (Bookmark) mMapObject; @@ -1364,19 +1361,6 @@ public class PlacePageView extends RelativeLayout } } - private void callPhone() - { - Intent intent = new Intent(Intent.ACTION_DIAL); - intent.setData(Uri.parse("tel:" + mTvPhone.getText())); - try - { - getContext().startActivity(intent); - } catch (ActivityNotFoundException e) - { - AlohaHelper.logException(e); - } - } - private void followUrl(String url) { final Intent intent = new Intent(Intent.ACTION_VIEW); diff --git a/android/src/com/mapswithme/util/Utils.java b/android/src/com/mapswithme/util/Utils.java index d6d3bed076..f39903d987 100644 --- a/android/src/com/mapswithme/util/Utils.java +++ b/android/src/com/mapswithme/util/Utils.java @@ -429,4 +429,25 @@ public class Utils } context.startActivity(intent); } + + public static void sendTo(@NonNull Context context, @NonNull String email) + { + Intent intent = new Intent(Intent.ACTION_SENDTO); + intent.setData(Utils.buildMailUri(email, "", "")); + context.startActivity(intent); + } + + public static void callPhone(@NonNull Context context, @NonNull String phone) + { + Intent intent = new Intent(Intent.ACTION_DIAL); + intent.setData(Uri.parse("tel:" + phone)); + try + { + context.startActivity(intent); + } + catch (ActivityNotFoundException e) + { + AlohaHelper.logException(e); + } + } }