Skip to content

Commit

Permalink
- Done #418
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Torres committed Mar 22, 2016
1 parent 503b126 commit 371bbb8
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 77 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ android {
productFlavors {
production {
applicationId "com.bentonow.bentonow"
versionName '1.22-rc07'
versionName '1.22-rc08'
}
stage {
applicationId "com.bentonow.bentonow.stage"
versionName '1.22-rc07-dev'
versionName '1.22-rc08-dev'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import com.bentonow.bentonow.Utils.ConstantUtils;
import com.bentonow.bentonow.Utils.DebugUtils;
import com.bentonow.bentonow.Utils.GoogleAnalyticsUtil;
import com.bentonow.bentonow.Utils.maps.LocationUtils;
import com.bentonow.bentonow.Utils.SharedPreferencesUtil;
import com.bentonow.bentonow.Utils.WidgetsUtils;
import com.bentonow.bentonow.Utils.maps.LocationUtils;
import com.bentonow.bentonow.controllers.BaseFragmentActivity;
import com.bentonow.bentonow.controllers.dialog.ConfirmationDialog;
import com.bentonow.bentonow.controllers.dialog.ProgressDialog;
Expand Down Expand Up @@ -446,48 +446,7 @@ private void getMenusByLocation(String responseString) {

DebugUtils.logDebug(TAG, "onContinuePressed AppState " + MenuDao.gateKeeper.getAppState());

if (MenuDao.gateKeeper.getAppState().contains("map,no_service")) {
CouponRequest mCoupon = new CouponRequest();
mCoupon.reason = "outside of delivery zone";
mCoupon.address = getTxtAddress().getText().toString();
mCoupon.lat = String.valueOf(mLastOrderLocation.latitude);
mCoupon.lng = String.valueOf(mLastOrderLocation.longitude);

Intent mIntentBummer = new Intent(DeliveryLocationActivity.this, BummerActivity.class);
mIntentBummer.putExtra(CouponRequest.TAG, mCoupon);
startActivity(mIntentBummer);
} else if (MenuDao.gateKeeper.getAppState().contains("build")) {
switch (optOpenScreen) {
case COMPLETE_ORDER:
if (BentoNowUtils.isValidCompleteOrder(DeliveryLocationActivity.this))
BentoNowUtils.openCompleteOrderActivity(DeliveryLocationActivity.this, MenuDao.getCurrentMenu());
break;
case BUILD_BENTO:
BentoNowUtils.openBuildBentoActivity(DeliveryLocationActivity.this);
break;
case SUMMARY:
BentoNowUtils.saveOrderLocation(mLastOrderLocation, mOrderAddress);
if (SharedPreferencesUtil.getBooleanPreference(SharedPreferencesUtil.IS_ORDER_AHEAD_MENU))
BentoNowUtils.openBuildBentoActivity(DeliveryLocationActivity.this);
else
onBackPressed();
break;
default:
onBackPressed();
break;
}
finish();
} else if (MenuDao.gateKeeper.getAppState().contains("closed_wall")) {
BentoNowUtils.openErrorActivity(DeliveryLocationActivity.this);
finish();
} else if (MenuDao.gateKeeper.getAppState().contains("sold")) {
BentoNowUtils.openErrorActivity(DeliveryLocationActivity.this);
finish();
} else {
DebugUtils.logError(TAG, "Unknown State: " + MenuDao.gateKeeper.getAppState());
}


nextStepViaAppState(MenuDao.gateKeeper.getAppState());
}

public void onContinuePressed() {
Expand Down Expand Up @@ -522,15 +481,17 @@ public void onSuccess(int statusCode, Header[] headers, String responseString) {
switch (optOpenScreen) {
case SUMMARY:
Order mCurrentOrder = mOrderDao.getCurrentOrder();
if (SharedPreferencesUtil.getBooleanPreference(SharedPreferencesUtil.IS_ORDER_AHEAD_MENU))
if (mCurrentOrder != null && responseString.contains("\"menu_id\":\"" + mCurrentOrder.MenuId + "\"")) {
if (mCurrentOrder != null)
if (responseString.contains("\"menu_id\":\"" + mCurrentOrder.MenuId + "\"")) {
BentoNowUtils.saveOrderLocation(mLastOrderLocation, mOrderAddress);
onBackPressed();
} else {
getMenusByLocation(responseString);
String sAppState = InitParse.getAppState(responseString);
if (sAppState.contains("build"))
showChangeMenuDialog(responseString);
else
nextStepViaAppState(sAppState);
}
else
getMenusByLocation(responseString);
break;
default:
getMenusByLocation(responseString);
Expand All @@ -546,6 +507,46 @@ public void onFinish() {
});
}

private void nextStepViaAppState(String sAppState) {
if (sAppState.contains("map,no_service")) {
CouponRequest mCoupon = new CouponRequest();
mCoupon.reason = "outside of delivery zone";
mCoupon.address = getTxtAddress().getText().toString();
mCoupon.lat = String.valueOf(mLastOrderLocation.latitude);
mCoupon.lng = String.valueOf(mLastOrderLocation.longitude);

Intent mIntentBummer = new Intent(DeliveryLocationActivity.this, BummerActivity.class);
mIntentBummer.putExtra(CouponRequest.TAG, mCoupon);
startActivity(mIntentBummer);
} else if (sAppState.contains("build")) {
switch (optOpenScreen) {
case COMPLETE_ORDER:
if (BentoNowUtils.isValidCompleteOrder(DeliveryLocationActivity.this))
BentoNowUtils.openCompleteOrderActivity(DeliveryLocationActivity.this, MenuDao.getCurrentMenu());
break;
case BUILD_BENTO:
BentoNowUtils.openBuildBentoActivity(DeliveryLocationActivity.this);
break;
case SUMMARY:
BentoNowUtils.saveOrderLocation(mLastOrderLocation, mOrderAddress);
BentoNowUtils.openBuildBentoActivity(DeliveryLocationActivity.this);
break;
default:
onBackPressed();
break;
}
finish();
} else if (sAppState.contains("closed_wall")) {
BentoNowUtils.openErrorActivity(DeliveryLocationActivity.this);
finish();
} else if (sAppState.contains("sold")) {
BentoNowUtils.openErrorActivity(DeliveryLocationActivity.this);
finish();
} else {
DebugUtils.logError(TAG, "Unknown State: " + MenuDao.gateKeeper.getAppState());
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
void setupAutocomplete() {
getTxtAddress().setAdapter(new GooglePlacesAutocompleteAdapter(this, R.layout.listitem_locationaddress));
Expand Down Expand Up @@ -647,33 +648,6 @@ public void onFinish() {
}
});

/*
BentoApplication.instance.webRequest(new RequestGetPlaceDetail(sPlaceId, new ListenerWebRequest() {
@Override
public void onError(String sError, int statusCode) {
checkAddress(sAddress);
onComplete();
}
@Override
public void onResponse(final Object oResponse, int statusCode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
moveMapToCenter((LatLng) oResponse, sAddress);
}
});
onComplete();
}
@Override
public void onComplete() {
dismissDialog();
}
}));*/

}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
Expand All @@ -687,6 +661,21 @@ private void restartSearch() {
mLastOrderLocation = null;
}

private void showChangeMenuDialog(final String sResponse) {
if (mConfirmationDialog == null || !mConfirmationDialog.isShowing()) {
mConfirmationDialog = new ConfirmationDialog(DeliveryLocationActivity.this, "Change Menu", "If you change delivery zone, you will have to create an order again, do you want to continue?");
mConfirmationDialog.addAcceptButton(IosCopyDao.get("build-not-complete-confirmation-2"), new View.OnClickListener() {
@Override
public void onClick(View view) {
getMenusByLocation(sResponse);
}
});
mConfirmationDialog.addCancelButton(IosCopyDao.get("build-not-complete-confirmation-1"), null);
mConfirmationDialog.show();
}

}

private void dismissDialog() {
runOnUiThread(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ public void onMapReady(GoogleMap map) {
map.setBuildingsEnabled(true);
map.getUiSettings().setZoomControlsEnabled(false);
googleMap = map;
googleMap.getUiSettings().setAllGesturesEnabled(false);

addMarker(getOrderMarker(), false);

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/bentonow/bentonow/parse/InitParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,4 +405,26 @@ public static void parseGateKeeper(String sGateKeeper) {

DebugUtils.logDebug(TAG, "GateKeeper Saved: " + (MenuDao.gateKeeper != null));
}

public static String getAppState(String sResponse) {
JSONObject jsonInit;

try {
jsonInit = new JSONObject(sResponse);

String sGateKeeper = jsonInit.getString("/gatekeeper/here/{lat}/{long}");

if (sGateKeeper == null || sGateKeeper.equals("null") || sGateKeeper.isEmpty())
return "";

JSONObject jsonGateKeeper = new JSONObject(sGateKeeper);

if (jsonGateKeeper.has("appState"))
return jsonGateKeeper.getString("appState");

} catch (Exception e) {
DebugUtils.logError(TAG, "getAppState: " + e.getMessage());
}
return "";
}
}

0 comments on commit 371bbb8

Please sign in to comment.