From 13fd7017fb6c413dd5550ea55a0ebf1a6a532918 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Fri, 19 Feb 2016 13:12:01 -0600 Subject: [PATCH] - Done #409 --- .../geolocation/DeliveryLocationActivity.java | 9 +++++-- .../bentonow/bentonow/web/BentoNowApi.java | 27 ++++++++++++++++--- app/src/main/res/values/strings.xml | 3 +++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/geolocation/DeliveryLocationActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/geolocation/DeliveryLocationActivity.java index 34567f3..eac570a 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/geolocation/DeliveryLocationActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/geolocation/DeliveryLocationActivity.java @@ -52,6 +52,7 @@ import com.bentonow.bentonow.model.Order; import com.bentonow.bentonow.parse.InitParse; import com.bentonow.bentonow.ui.BackendTextView; +import com.bentonow.bentonow.web.BentoNowApi; import com.bentonow.bentonow.web.request.RequestGetPlaceDetail; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; @@ -75,7 +76,6 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -133,6 +133,11 @@ protected void onCreate(Bundle savedInstanceState) { mLastOrderLocation = BentoNowUtils.getOrderLocation(); + if (mLastOrderLocation != null) { + mCurrentLocation = new Location("Current Location"); + mCurrentLocation.setLatitude(mLastOrderLocation.latitude); + mCurrentLocation.setLongitude(mLastOrderLocation.longitude); + } buildGoogleApiClient(); getGoogleMap().setOnMapClickListener(DeliveryLocationActivity.this); @@ -527,7 +532,7 @@ public ArrayList autocomplete(String input) { HttpURLConnection conn = null; StringBuilder jsonResults = new StringBuilder(); try { - URL url = new URL("https://maps.googleapis.com/maps/api/place/autocomplete/json?key=" + getResources().getString(R.string.google_server_key) + "&input=" + URLEncoder.encode(input, "utf8")); + URL url = new URL(BentoNowApi.getUrlGoogleAutocomplete(mCurrentLocation, input)); DebugUtils.logDebug(TAG, "URL Search: " + url.toString()); conn = (HttpURLConnection) url.openConnection(); diff --git a/app/src/main/java/com/bentonow/bentonow/web/BentoNowApi.java b/app/src/main/java/com/bentonow/bentonow/web/BentoNowApi.java index 8e1679b..a5692d7 100644 --- a/app/src/main/java/com/bentonow/bentonow/web/BentoNowApi.java +++ b/app/src/main/java/com/bentonow/bentonow/web/BentoNowApi.java @@ -1,9 +1,14 @@ package com.bentonow.bentonow.web; +import android.location.Location; + import com.bentonow.bentonow.R; +import com.bentonow.bentonow.Utils.DebugUtils; import com.bentonow.bentonow.controllers.BentoApplication; +import java.net.URLEncoder; + /** * Created by Jose Torres on 8/17/15. */ @@ -13,14 +18,12 @@ public class BentoNowApi { public static final String IOSCOPY = "/ioscopy"; public static final String ORDER = "/order"; public static final String COUPON_REQUEST = "/couponcode/request"; - + //STATUS OVERALL + public static final String STATUS_ALL_RUN = "/status/all"; // INIT public static String INIT_KEY = "key"; public static String INIT_VALUE = "value"; public static String INIT_TYPE = "type"; - - //STATUS OVERALL - public static final String STATUS_ALL_RUN = "/status/all"; public static String STATUS_OVERALL_LABEL_VALUE = "value"; // USER SIGN UP @@ -46,5 +49,21 @@ public static String getPlaceDetailUrl(String sPlaceId) { return sUrl; } + public static String getUrlGoogleAutocomplete(Location mLocation, String sInput) { + String sAddress; + + try { + sAddress = URLEncoder.encode(sInput, "utf8"); + } catch (Exception ex) { + sAddress = sInput; + DebugUtils.logError(ex); + } + if (mLocation == null) + return BentoApplication.instance.getString(R.string.bento_api_url_autocomplete, BentoApplication.instance.getString(R.string.google_server_key), sAddress); + else + return BentoApplication.instance.getString(R.string.bento_api_url_autocomplete_location, BentoApplication.instance.getString(R.string.google_server_key), sAddress, mLocation.getLatitude(), mLocation.getLongitude()); + + } + } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3e21434..bb6643c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,6 +38,9 @@ %1$s, %2$s %1$s-%2$s %1$d-%2$d + https://maps.googleapis.com/maps/api/place/autocomplete/json?key=%1$s&input=%2$s&radius=500 + https://maps.googleapis.com/maps/api/place/autocomplete/json?key=%1$s&input=%2$s&location=%3$f,%4$f&radius=500 + Enter your phone number Confirm your phone number