Skip to content

Commit

Permalink
- Done #409
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Torres committed Feb 19, 2016
1 parent 0f7a7f6 commit 13fd701
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -527,7 +532,7 @@ public ArrayList<AutoCompleteModel> 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();
Expand Down
27 changes: 23 additions & 4 deletions app/src/main/java/com/bentonow/bentonow/web/BentoNowApi.java
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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
Expand All @@ -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());

}


}
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<string name="summary_bento_oa_delivery_day">%1$s, %2$s</string>
<string name="summary_bento_oa_delivery_time">%1$s-%2$s</string>
<string name="summary_bento_od_delivery_time">%1$d-%2$d</string>
<string name="bento_api_url_autocomplete"> https://maps.googleapis.com/maps/api/place/autocomplete/json?key=%1$s&amp;input=%2$s&amp;radius=500</string>
<string name="bento_api_url_autocomplete_location"> https://maps.googleapis.com/maps/api/place/autocomplete/json?key=%1$s&amp;input=%2$s&amp;location=%3$f,%4$f&amp;radius=500</string>


<string name="edit_hint_enter_phone">Enter your phone number</string>
<string name="edit_hint_confirm_phone">Confirm your phone number</string>
Expand Down

0 comments on commit 13fd701

Please sign in to comment.