From 788a43b0c2189fe1b35594483abf6d33b621ff74 Mon Sep 17 00:00:00 2001 From: Jose Torres Date: Fri, 5 Feb 2016 15:10:44 -0600 Subject: [PATCH] - Done #403 - Done #401 - Done #400 - Done #398 - Done #396 - Done #394 - Done #393 - Done #385 - Done #384 - Done #383 - Done #381 - Done #379 - Done #377 - Done #368 - Done #364 - Done #365 - Done #360 - Done #355 - Done #354 --- .../dialog/ConfirmationDialog.java | 1 - .../controllers/dialog/LogOutDialog.java | 1 - .../controllers/dialog/ProgressDialog.java | 1 - .../geolocation/DeliveryLocationActivity.java | 44 ++- .../controllers/order/BuildBentoActivity.java | 323 +++++++++--------- .../order/CompleteOrderActivity.java | 32 +- .../order/OrderHistoryActivity.java | 7 + .../order/SelectMainCustomActivity.java | 13 +- .../order/SelectSideCustomActivity.java | 16 +- .../controllers/session/SettingsActivity.java | 5 +- .../com/bentonow/bentonow/dao/BentoDao.java | 9 +- .../com/bentonow/bentonow/dao/DishDao.java | 68 ++-- .../com/bentonow/bentonow/dao/MainDao.java | 11 + .../com/bentonow/bentonow/dao/MenuDao.java | 19 ++ .../com/bentonow/bentonow/dao/OrderDao.java | 43 +-- .../com/bentonow/bentonow/dao/UserDao.java | 32 +- .../bentonow/model/order/post/DishPost.java | 23 ++ .../model/order/post/OrderDetailsPost.java | 54 +++ .../model/order/post/OrderItemPost.java | 20 ++ .../model/order/post/OrderLocationPost.java | 9 + .../bentonow/model/order/post/OrderPost.java | 56 +++ .../main/res/layout/content_build_bento.xml | 4 +- 22 files changed, 527 insertions(+), 264 deletions(-) create mode 100644 app/src/main/java/com/bentonow/bentonow/dao/MainDao.java create mode 100644 app/src/main/java/com/bentonow/bentonow/model/order/post/DishPost.java create mode 100644 app/src/main/java/com/bentonow/bentonow/model/order/post/OrderDetailsPost.java create mode 100644 app/src/main/java/com/bentonow/bentonow/model/order/post/OrderItemPost.java create mode 100644 app/src/main/java/com/bentonow/bentonow/model/order/post/OrderLocationPost.java create mode 100644 app/src/main/java/com/bentonow/bentonow/model/order/post/OrderPost.java diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ConfirmationDialog.java b/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ConfirmationDialog.java index 72be4f2..1c31c8e 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ConfirmationDialog.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ConfirmationDialog.java @@ -127,7 +127,6 @@ public void onClick(View v) { @Override public void show() { - // TODO 自动生成的方法存根 super.show(); // set dialog enter animations view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.dialog_main_show_amination)); diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/dialog/LogOutDialog.java b/app/src/main/java/com/bentonow/bentonow/controllers/dialog/LogOutDialog.java index 1fed459..a248c8a 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/dialog/LogOutDialog.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/dialog/LogOutDialog.java @@ -116,7 +116,6 @@ public void onClick(View v) { @Override public void show() { - // TODO 自动生成的方法存根 super.show(); // set dialog enter animations view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.dialog_main_show_amination)); diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ProgressDialog.java b/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ProgressDialog.java index 76ae2b2..47c2683 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ProgressDialog.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/dialog/ProgressDialog.java @@ -87,7 +87,6 @@ public boolean onTouch(View v, MotionEvent event) { @Override public void show() { - // TODO 自动生成的方法存根 super.show(); // set dialog enter animations view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.dialog_main_show_amination)); 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 62a5d91..7cfef2a 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 @@ -45,9 +45,11 @@ import com.bentonow.bentonow.controllers.help.HelpActivity; import com.bentonow.bentonow.dao.IosCopyDao; import com.bentonow.bentonow.dao.MenuDao; +import com.bentonow.bentonow.dao.SettingsDao; import com.bentonow.bentonow.listener.ListenerWebRequest; import com.bentonow.bentonow.listener.OnCustomDragListener; import com.bentonow.bentonow.model.AutoCompleteModel; +import com.bentonow.bentonow.model.Order; import com.bentonow.bentonow.parse.InitParse; import com.bentonow.bentonow.ui.BackendTextView; import com.bentonow.bentonow.web.request.RequestGetPlaceDetail; @@ -364,11 +366,17 @@ private boolean isValidLocation() { return bIsValid; } - private void getMenusByLocation() { - DebugUtils.logDebug(TAG, "onContinuePressed AppState " + MenuDao.gateKeeper.getAppState()); - BentoNowUtils.saveOrderLocation(mLastOrderLocation, mOrderAddress); + private void getMenusByLocation(String responseString) { + InitParse.parseInitTwo(responseString); + + SharedPreferencesUtil.setAppPreference(SharedPreferencesUtil.POD_MODE, SettingsDao.getCurrent().pod_mode); SharedPreferencesUtil.setAppPreference(SharedPreferencesUtil.STORE_STATUS, MenuDao.gateKeeper.getAppState()); + if (optOpenScreen != ConstantUtils.optOpenScreen.SUMMARY) + BentoNowUtils.saveOrderLocation(mLastOrderLocation, mOrderAddress); + + DebugUtils.logDebug(TAG, "onContinuePressed AppState " + MenuDao.gateKeeper.getAppState()); + if (MenuDao.gateKeeper.getAppState().contains("map,no_service")) { Intent mIntentBummer = new Intent(DeliveryLocationActivity.this, BummerActivity.class); mIntentBummer.putExtra(BummerActivity.TAG_INVALID_ADDRESS, getTxtAddress().getText().toString()); @@ -382,11 +390,7 @@ private void getMenusByLocation() { e.printStackTrace(); } } else if (MenuDao.gateKeeper.getAppState().contains("build")) { - switch (optOpenScreen) { - case NORMAL: - onBackPressed(); - break; case COMPLETE_ORDER: if (BentoNowUtils.isValidCompleteOrder(DeliveryLocationActivity.this)) BentoNowUtils.openCompleteOrderActivity(DeliveryLocationActivity.this, MenuDao.getCurrentMenu()); @@ -395,6 +399,13 @@ private void getMenusByLocation() { 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; } @@ -428,8 +439,23 @@ public void onFailure(int statusCode, Header[] headers, String responseString, T public void onSuccess(int statusCode, Header[] headers, String responseString) { onFinish(); - InitParse.parseInitTwo(responseString); - getMenusByLocation(); + 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 + "\"")) { + BentoNowUtils.saveOrderLocation(mLastOrderLocation, mOrderAddress); + onBackPressed(); + } else { + getMenusByLocation(responseString); + } + else + getMenusByLocation(responseString); + break; + default: + getMenusByLocation(responseString); + break; + } } diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/order/BuildBentoActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/order/BuildBentoActivity.java index 32eef30..4511b3b 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/order/BuildBentoActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/order/BuildBentoActivity.java @@ -217,178 +217,189 @@ protected void onResume() { } public void updateUI() { - if (bIsMenuAlreadySelected) { - if (bShowAppOnAhead) { - getTxtOdHeader().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getTitle()); - getTxtOdDescription().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getText()); - } - - getTxtOdHeader().setTextColor(getResources().getColor(optMenu == ConstantUtils.optMenuSelected.ORDER_AHEAD ? R.color.black : R.color.primary)); - getTxtOaHeader().setTextColor(getResources().getColor(optMenu == ConstantUtils.optMenuSelected.ORDER_AHEAD ? R.color.primary : R.color.black)); - - switch (optMenu) { - case ON_DEMAND: - case ORDER_AHEAD: - getContentMenuPreview().setVisibility(View.GONE); - getContentBuildBento().setVisibility(View.VISIBLE); - updateDishUI(); - getButtonCancel().setVisibility(bIsMenuAlreadySelected ? View.VISIBLE : View.GONE); - getTxtEta().setVisibility(optMenu == ConstantUtils.optMenuSelected.ON_DEMAND ? View.VISIBLE : View.GONE); - getImgDividerStatus().setVisibility(optMenu == ConstantUtils.optMenuSelected.ON_DEMAND ? View.VISIBLE : View.GONE); - getTxtPromoName().setText(String.format(getString(R.string.build_bento_price), BentoNowUtils.getDefaultPriceBento(DishDao.getLowestMainPrice(mMenu)))); - - if (optMenu == ConstantUtils.optMenuSelected.ORDER_AHEAD && bIsMenuAlreadySelected && mMenu.menu_id.equals(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(0).menu_id)) - setOAHashTimer(BentoNowUtils.showOATimer(mMenu)); - else if (mCountDown != null) { - mCountDown.cancel(); - mCountDown = null; + runOnUiThread(new Runnable() { + @Override + public void run() { + if (bIsMenuAlreadySelected) { + if (bShowAppOnAhead) { + getTxtOdHeader().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getTitle()); + getTxtOdDescription().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getText()); } - if (mOrderDao.countCompletedOrders(mOrder) == 0) { - getTxtNumBento().setVisibility(View.GONE); - getTxtNumBento().setText("0"); - getActionbarRightBtn().setImageResource(R.drawable.ic_ab_bento); - getLayoutAddOns().setVisibility(View.GONE); - getBtnContinue().setBackgroundColor(getResources().getColor(R.color.gray)); - getBtnAddAnotherBento().setTextColor(getResources().getColor(R.color.btn_green_trans)); - getBtnAddAnotherBento().setOnClickListener(null); - getBtnAddOn().setTextColor(getResources().getColor(R.color.btn_green_trans)); - getBtnAddOn().setOnClickListener(null); - getBtnAddAnotherBento().setText(IosCopyDao.get("build-add-button")); - - if (mOrderDao.countDishesAdded(mOrder.OrderItems.get(orderIndex)) == 0) - sContinueBtn = IosCopyDao.get("build-title"); - else - sContinueBtn = IosCopyDao.get("build-button-1"); + getTxtOdHeader().setTextColor(getResources().getColor(optMenu == ConstantUtils.optMenuSelected.ORDER_AHEAD ? R.color.black : R.color.primary)); + getTxtOaHeader().setTextColor(getResources().getColor(optMenu == ConstantUtils.optMenuSelected.ORDER_AHEAD ? R.color.primary : R.color.black)); + + switch (optMenu) { + case ON_DEMAND: + case ORDER_AHEAD: + getContentMenuPreview().setVisibility(View.GONE); + getContentBuildBento().setVisibility(View.VISIBLE); + updateDishUI(); + getButtonCancel().setVisibility(bIsMenuAlreadySelected ? View.VISIBLE : View.GONE); + getTxtEta().setVisibility(optMenu == ConstantUtils.optMenuSelected.ON_DEMAND ? View.VISIBLE : View.GONE); + getImgDividerStatus().setVisibility(optMenu == ConstantUtils.optMenuSelected.ON_DEMAND ? View.VISIBLE : View.GONE); + getTxtPromoName().setText(String.format(getString(R.string.build_bento_price), BentoNowUtils.getDefaultPriceBento(DishDao.getLowestMainPrice(mMenu)))); + + if (optMenu == ConstantUtils.optMenuSelected.ORDER_AHEAD && bIsMenuAlreadySelected && mMenu.menu_id.equals(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(0).menu_id)) + setOAHashTimer(BentoNowUtils.showOATimer(mMenu)); + else if (mCountDown != null) { + mCountDown.cancel(); + mCountDown = null; + } - } else { - getTxtNumBento().setVisibility(View.VISIBLE); - getTxtNumBento().setText(mOrderDao.countCompletedOrders(mOrder) + ""); - getActionbarRightBtn().setImageResource(R.drawable.ic_ab_bento_completed); - getLayoutAddOns().setVisibility(View.VISIBLE); - getBtnContinue().setBackgroundColor(getResources().getColor(R.color.btn_green)); - getBtnAddOn().setTextColor(getResources().getColor(R.color.btn_green)); - getBtnAddOn().setOnClickListener(this); - getBtnAddAnotherBento().setTextColor(getResources().getColor(R.color.btn_green)); - getBtnAddAnotherBento().setOnClickListener(this); - sContinueBtn = IosCopyDao.get("build-button-2"); - - if (mBentoDao.isBentoComplete(mOrder.OrderItems.get(orderIndex)) || orderIndex == 0) - getBtnAddAnotherBento().setText(IosCopyDao.get("build-add-button")); - else if (mOrderDao.countDishesAdded(mOrder.OrderItems.get(orderIndex)) == 0) - getBtnAddAnotherBento().setText(IosCopyDao.get("build-title")); - else - getBtnAddAnotherBento().setText(IosCopyDao.get("build-button-1")); - } + if (mOrderDao.countCompletedOrders(mOrder) == 0) { + getTxtNumBento().setVisibility(View.GONE); + getTxtNumBento().setText("0"); + getActionbarRightBtn().setImageResource(R.drawable.ic_ab_bento); + getLayoutAddOns().setVisibility(View.GONE); + getBtnContinue().setBackgroundColor(getResources().getColor(R.color.gray)); + getBtnAddAnotherBento().setTextColor(getResources().getColor(R.color.btn_green_trans)); + getBtnAddAnotherBento().setOnClickListener(null); + getBtnAddOn().setTextColor(getResources().getColor(R.color.btn_green_trans)); + getBtnAddOn().setOnClickListener(null); + getBtnAddAnotherBento().setText(IosCopyDao.get("build-add-button")); + + if (mOrderDao.countDishesAdded(mOrder.OrderItems.get(orderIndex)) == 0) + sContinueBtn = IosCopyDao.get("build-title"); + else + sContinueBtn = IosCopyDao.get("build-button-1"); + + } else { + getTxtNumBento().setVisibility(View.VISIBLE); + getTxtNumBento().setText(mOrderDao.countCompletedOrders(mOrder) + ""); + getActionbarRightBtn().setImageResource(R.drawable.ic_ab_bento_completed); + getLayoutAddOns().setVisibility(View.VISIBLE); + getBtnContinue().setBackgroundColor(getResources().getColor(R.color.btn_green)); + getBtnAddOn().setTextColor(getResources().getColor(R.color.btn_green)); + getBtnAddOn().setOnClickListener(BuildBentoActivity.this); + getBtnAddAnotherBento().setTextColor(getResources().getColor(R.color.btn_green)); + getBtnAddAnotherBento().setOnClickListener(BuildBentoActivity.this); + sContinueBtn = IosCopyDao.get("build-button-2"); + + if (mBentoDao.isBentoComplete(mOrder.OrderItems.get(orderIndex)) || orderIndex == 0) + getBtnAddAnotherBento().setText(IosCopyDao.get("build-add-button")); + else if (mOrderDao.countDishesAdded(mOrder.OrderItems.get(orderIndex)) == 0) + getBtnAddAnotherBento().setText(IosCopyDao.get("build-title")); + else + getBtnAddAnotherBento().setText(IosCopyDao.get("build-button-1")); + } - getBtnContinue().setText(sContinueBtn); + getBtnContinue().setText(sContinueBtn); + + getBtnAddOn().setVisibility(bHasAddOns ? View.VISIBLE : View.GONE); + break; + case MENU_PREVIEW: + getButtonCancel().setVisibility(bIsMenuAlreadySelected ? View.VISIBLE : View.GONE); + getTxtNumBento().setVisibility(View.GONE); + getActionbarRightBtn().setImageResource(R.drawable.ic_ab_bento); + getTxtDateTimeToolbar().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getTitle()); + + if (getMainAdapter().isEmpty()) { + for (DishModel dishModel : mMenu.dishModels) { + switch (dishModel.type) { + case "main": + getMainAdapter().add(dishModel); + break; + case "side": + getSideAdapter().add(dishModel); + break; + case "addon": + getAddOnAdapter().add(dishModel); + break; + default: + DebugUtils.logError(TAG, "Unknown Type: " + dishModel.type + " Dish: " + dishModel.name); + break; + } - getBtnAddOn().setVisibility(bHasAddOns ? View.VISIBLE : View.GONE); - break; - case MENU_PREVIEW: - getButtonCancel().setVisibility(bIsMenuAlreadySelected ? View.VISIBLE : View.GONE); - getTxtNumBento().setVisibility(View.GONE); - getActionbarRightBtn().setImageResource(R.drawable.ic_ab_bento); - getTxtDateTimeToolbar().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getTitle()); - - if (getMainAdapter().isEmpty()) { - for (DishModel dishModel : mMenu.dishModels) { - switch (dishModel.type) { - case "main": - getMainAdapter().add(dishModel); - break; - case "side": - getSideAdapter().add(dishModel); - break; - case "addon": - getAddOnAdapter().add(dishModel); - break; - default: - DebugUtils.logError(TAG, "Unknown Type: " + dishModel.type + " Dish: " + dishModel.name); - break; - } + } - } + getMainAdapter().notifyDataSetChanged(); + getSideAdapter().notifyDataSetChanged(); + getAddOnAdapter().notifyDataSetChanged(); - getMainAdapter().notifyDataSetChanged(); - getSideAdapter().notifyDataSetChanged(); - getAddOnAdapter().notifyDataSetChanged(); + getListMain().setOnItemClickListener(BuildBentoActivity.this); + getListAddOn().setOnItemClickListener(BuildBentoActivity.this); + getGridSide().setOnItemClickListener(BuildBentoActivity.this); + } - getListMain().setOnItemClickListener(this); - getListAddOn().setOnItemClickListener(this); - getGridSide().setOnItemClickListener(this); + getContentMenuPreview().setVisibility(View.VISIBLE); + getContentBuildBento().setVisibility(View.GONE); + break; } - - getContentMenuPreview().setVisibility(View.VISIBLE); - getContentBuildBento().setVisibility(View.GONE); - break; + } } - } + }); } private void updateWidget() { - getSpinnerDayAdapter().clear(); - getSpinnerTimeAdapter().clear(); - bShowAppOnDemand = MenuDao.gateKeeper.getAppOnDemandWidget() != null && (MenuDao.getTodayMenu() != null || MenuDao.gateKeeper.getAppOnDemandWidget().getMenu() != null); - bShowAppOnAhead = MenuDao.gateKeeper.getAvailableServices() != null && MenuDao.gateKeeper.getAvailableServices().mOrderAhead != null && !MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.isEmpty(); + runOnUiThread(new Runnable() { + @Override + public void run() { + getSpinnerDayAdapter().clear(); + getSpinnerTimeAdapter().clear(); + bShowAppOnDemand = MenuDao.gateKeeper.getAppOnDemandWidget() != null && (MenuDao.getTodayMenu() != null || MenuDao.gateKeeper.getAppOnDemandWidget().getMenu() != null); + bShowAppOnAhead = MenuDao.gateKeeper.getAvailableServices() != null && MenuDao.gateKeeper.getAvailableServices().mOrderAhead != null && !MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.isEmpty(); - if (bShowAppOnDemand) { - getWrapperOd().setVisibility(View.VISIBLE); - getTxtOdHeader().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getTitle()); - getTxtOdDescription().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getText()); - } else - getWrapperOd().setVisibility(View.GONE); - - if (bShowAppOnAhead) { - getWrapperOa().setVisibility(View.VISIBLE); - getSpinnerDayAdapter().addAll(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus); - getSpinnerDayAdapter().notifyDataSetChanged(); - getSpinnerTimeAdapter().addAll(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(0).listTimeModel); - getSpinnerTimeAdapter().notifyDataSetChanged(); - getTxtOaHeader().setText(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.title); - getSpinnerDate().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int i, long l) { - updateDayOASpinner(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(i), 0); - getSpinnerDayAdapter().iSelectedPosition = i; - } + if (bShowAppOnDemand) { + getWrapperOd().setVisibility(View.VISIBLE); + getTxtOdHeader().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getTitle()); + getTxtOdDescription().setText(MenuDao.gateKeeper.getAppOnDemandWidget().getText()); + } else + getWrapperOd().setVisibility(View.GONE); - @Override - public void onNothingSelected(AdapterView adapterView) { + if (bShowAppOnAhead) { + getWrapperOa().setVisibility(View.VISIBLE); + getSpinnerDayAdapter().addAll(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus); + getSpinnerDayAdapter().notifyDataSetChanged(); + getSpinnerTimeAdapter().addAll(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(0).listTimeModel); + getSpinnerTimeAdapter().notifyDataSetChanged(); + getTxtOaHeader().setText(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.title); + getSpinnerDate().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + updateDayOASpinner(MenuDao.gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(i), 0); + getSpinnerDayAdapter().iSelectedPosition = i; + } - } - }); - getSpinnerTime().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int iPosition, long l) { - for (int a = 0; a < mOAPreselectedMenu.listTimeModel.size(); a++) { - if (a == iPosition) { - mOAPreselectedMenu.listTimeModel.get(a).isSelected = true; - } else - mOAPreselectedMenu.listTimeModel.get(a).isSelected = false; - } - getSpinnerTimeAdapter().iSelectedPosition = iPosition; - } + @Override + public void onNothingSelected(AdapterView adapterView) { - @Override - public void onNothingSelected(AdapterView adapterView) { + } + }); + getSpinnerTime().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int iPosition, long l) { + for (int a = 0; a < mOAPreselectedMenu.listTimeModel.size(); a++) { + if (a == iPosition) { + mOAPreselectedMenu.listTimeModel.get(a).isSelected = true; + } else + mOAPreselectedMenu.listTimeModel.get(a).isSelected = false; + } + getSpinnerTimeAdapter().iSelectedPosition = iPosition; + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + } else + getWrapperOa().setVisibility(View.GONE); + + if (bShowAppOnDemand && MenuDao.gateKeeper.getAppOnDemandWidget().isSelected()) { + optMenu = ConstantUtils.optMenuSelected.ON_DEMAND; + bIsAsapChecked = true; + } else { + optMenu = ConstantUtils.optMenuSelected.ORDER_AHEAD; + bIsAsapChecked = false; } - }); - } else - getWrapperOa().setVisibility(View.GONE); + updateWidgetSelection(); - if (bShowAppOnDemand && MenuDao.gateKeeper.getAppOnDemandWidget().isSelected()) { - optMenu = ConstantUtils.optMenuSelected.ON_DEMAND; - bIsAsapChecked = true; - } else { - optMenu = ConstantUtils.optMenuSelected.ORDER_AHEAD; - bIsAsapChecked = false; - } - updateWidgetSelection(); + setDateTime(true, false); + } + }); - setDateTime(true, false); } private void updateOrderByMenu() { @@ -703,13 +714,13 @@ private void autocomplete() { if (dishModel == null) { bAutoCompleteFails = true; + updateUI(); return; } ids[i - 1] = dishModel.itemId; dishModel = DishDao.clone(dishModel); - dishModel.type += i; mOrder.OrderItems.get(orderIndex).items.set(i, mDishDao.updateDishItem(mOrder.OrderItems.get(orderIndex).items.get(i), dishModel)); } @@ -894,11 +905,12 @@ public void onAddSide4Pressed(View view) { public void onAddAnotherBentoPressed() { // restartDishUI(); + if (mDishDao.canCreateAnotherBento(mMenu, mOrder.OrderItems.get(orderIndex).items.size(), optMenu == ConstantUtils.optMenuSelected.ON_DEMAND)) { + mOrder.OrderItems.add(mBentoDao.getNewBento(ConstantUtils.optItemType.CUSTOM_BENTO_BOX)); + mOrder.currentOrderItem = orderIndex = mOrder.OrderItems.size() - 1; - mOrder.OrderItems.add(mBentoDao.getNewBento(ConstantUtils.optItemType.CUSTOM_BENTO_BOX)); - mOrder.currentOrderItem = orderIndex = mOrder.OrderItems.size() - 1; - - mOrderDao.updateOrder(mOrder); + mOrderDao.updateOrder(mOrder); + } updateUI(); } @@ -913,6 +925,7 @@ public void onContinueOrderPressed() { } else openSummaryScreen(); } else if (mOrderDao.countDishesAdded(mOrder.OrderItems.get(orderIndex)) == 0 || bAutoCompleteFails) { + bAutoCompleteFails = false; mBentoDao.removeBento(mOrder.OrderItems.get(orderIndex).order_pk); BentoNowUtils.openCompleteOrderActivity(BuildBentoActivity.this, mMenu); } else if (mBentoDao.isBentoComplete(mOrder.OrderItems.get(orderIndex))) { diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/order/CompleteOrderActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/order/CompleteOrderActivity.java index 6488995..b4982e3 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/order/CompleteOrderActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/order/CompleteOrderActivity.java @@ -27,6 +27,7 @@ import com.bentonow.bentonow.controllers.dialog.ConfirmationDialog; import com.bentonow.bentonow.controllers.dialog.CouponDialog; import com.bentonow.bentonow.controllers.dialog.ProgressDialog; +import com.bentonow.bentonow.controllers.geolocation.DeliveryLocationActivity; import com.bentonow.bentonow.controllers.session.SignInActivity; import com.bentonow.bentonow.dao.IosCopyDao; import com.bentonow.bentonow.dao.MenuDao; @@ -40,6 +41,7 @@ import com.bentonow.bentonow.model.Order; import com.bentonow.bentonow.model.User; import com.bentonow.bentonow.model.order.OrderItem; +import com.bentonow.bentonow.model.order.post.OrderPost; import com.bentonow.bentonow.parse.InitParse; import com.bentonow.bentonow.service.BentoCustomerService; import com.bentonow.bentonow.ui.AutoFitTxtView; @@ -119,6 +121,8 @@ protected void onCreate(Bundle savedInstanceState) { container_discount = findViewById(R.id.container_discount); + bIsMenuOD = !SharedPreferencesUtil.getBooleanPreference(SharedPreferencesUtil.IS_ORDER_AHEAD_MENU); + getExpandableListOrder().setAdapter(getExpandableListAdapter()); mMenu = getIntent().getParcelableExtra(Menu.TAG); @@ -137,7 +141,6 @@ private void initActionbar() { private void getCurrentOrder() { mOrder = mOrderDao.getCurrentOrder(); - bIsMenuOD = !mOrder.order_type.equals("2"); aOrder = new ArrayList<>(); @@ -249,7 +252,7 @@ void requestPromoCode(final String code) { public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { dismissDialog(); - DebugUtils.logDebug(TAG, "requestPromoCode failed: " + responseString + " StatusCode:" + statusCode); + DebugUtils.logError(TAG, "requestPromoCode failed: " + responseString + " StatusCode:" + statusCode); String sError; try { @@ -365,7 +368,10 @@ public void run() { public void onChangeAddressPressed(View v) { MixpanelUtils.track("Tapped On Change - Address"); - BentoNowUtils.openDeliveryLocationScreen(this, ConstantUtils.optOpenScreen.SUMMARY); + Intent intent = new Intent(CompleteOrderActivity.this, DeliveryLocationActivity.class); + intent.putExtra(ConstantUtils.TAG_OPEN_SCREEN, ConstantUtils.optOpenScreen.SUMMARY); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); + startActivity(intent); } public void onChangeCreditCardPressed(View v) { @@ -408,21 +414,12 @@ public void onLetsEatPressed() { } } + OrderPost mOrderPost = new OrderPost(mOrder); RequestParams params = new RequestParams(); - params.put("data", mOrder.toString()); + params.put("data", mOrderPost.toString()); params.put("api_token", mCurrentUser.api_token); - - if (mOrder.OrderItems == null || mOrder.OrderItems.isEmpty()) { - action = "no_items"; - track(action); - Crashlytics.log(Log.ERROR, "Order", "No Items in the Order"); - DebugUtils.logError(TAG, "Order Items 0 "); - emptyOrders(); - return; - } - - DebugUtils.logDebug(TAG, "Order: " + mOrder.toString()); + DebugUtils.logDebug(TAG, "Order: " + mOrderPost.toString()); BentoRestClient.post("/order", params, new TextHttpResponseHandler() { @SuppressWarnings("deprecation") @@ -431,6 +428,8 @@ public void onFailure(int statusCode, Header[] headers, String responseString, T String error = ""; JSONObject json; + DebugUtils.logError(TAG, "Status: " + statusCode + " Response(): " + responseString); + try { json = new JSONObject(responseString); if (json.has("Error")) { @@ -440,7 +439,6 @@ public void onFailure(int statusCode, Header[] headers, String responseString, T } trackError(error); } catch (Exception ignore) { - DebugUtils.logError(TAG, "Order: " + statusCode + " Response(): " + responseString); trackError("Order: " + statusCode + " Response(): " + responseString); } @@ -506,8 +504,6 @@ public void onSuccess(int statusCode, Header[] headers, String responseString) { mCurrentUser.stripe_token = null; - SharedPreferencesUtil.setAppPreference(SharedPreferencesUtil.UUID_BENTO, ""); - dismissDialog(); mOrderDao.cleanUp(); diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/order/OrderHistoryActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/order/OrderHistoryActivity.java index 5399c7e..48f0493 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/order/OrderHistoryActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/order/OrderHistoryActivity.java @@ -80,6 +80,13 @@ private void getOrderHistoryByUser() { public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { DebugUtils.logError(TAG, "getOrderHistoryByUser failed: " + responseString + " StatusCode: " + statusCode); //TODO show login at 401 error code + runOnUiThread(new Runnable() { + @Override + public void run() { + getTxtEmptyOrderHistory().setVisibility(View.VISIBLE); + getExpandableListOrderHistory().setVisibility(View.GONE); + } + }); dismissDialog(); } diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectMainCustomActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectMainCustomActivity.java index 9c48dba..7c735ec 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectMainCustomActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectMainCustomActivity.java @@ -58,9 +58,6 @@ protected void onCreate(Bundle savedInstanceState) { mCurrentDish = mDishDao.clone(mOrder.OrderItems.get(orderIndex).items.get(0)); - if (mCurrentDish.type.isEmpty()) - mCurrentDish.type = "main"; - getListAdapter().setCurrentAdded(mOrder.OrderItems.get(orderIndex).items.get(0)); getListAdapter().setCurrentSelected(mOrder.OrderItems.get(orderIndex).items.get(0)); @@ -94,12 +91,18 @@ public void onAddedClick(int iDishPosition) { MixpanelUtils.track("Withdrew Main Dish"); mCurrentDish.name = ""; + mCurrentDish.itemId = -1; mDishDao.updateDishItem(mCurrentDish); getListAdapter().setCurrentAdded(null); - getListAdapter().notifyDataSetChanged(); + runOnUiThread(new Runnable() { + @Override + public void run() { + getListAdapter().notifyDataSetChanged(); + } + }); } @Override @@ -114,7 +117,7 @@ public void onAddToBentoClick(int iDishPosition) { mDishDao.updateDishItem(mDish); - DebugUtils.logDebug(TAG, "added " + mDish.type); + DebugUtils.logDebug(TAG, "Added: " + mDish.type); onBackPressed(); } diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectSideCustomActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectSideCustomActivity.java index 5d72f50..8963df2 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectSideCustomActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/order/SelectSideCustomActivity.java @@ -56,10 +56,6 @@ protected void onCreate(Bundle savedInstanceState) { getGridView().setOnItemClickListener(this); mCurrentDish = mDishDao.clone(mOrder.OrderItems.get(orderIndex).items.get(itemIndex)); - if (mCurrentDish.type.isEmpty()) - mCurrentDish.type = "side" + itemIndex; - else if (mCurrentDish.type.equals("side")) - mCurrentDish.type = "side" + itemIndex; getListAdapter().setCurrentSelected(mOrder.OrderItems.get(orderIndex).items.get(itemIndex)); getListAdapter().setCurrentAdded(mOrder.OrderItems.get(orderIndex).items.get(itemIndex)); @@ -105,12 +101,18 @@ public void onAddedClick(int iDishPosition) { MixpanelUtils.track("Withdrew Side Dish"); mCurrentDish.name = ""; + mCurrentDish.itemId = -1; mDishDao.updateDishItem(mCurrentDish); - getListAdapter().setCurrentAdded(null); + getListAdapter().setCurrentAdded(mCurrentDish); + runOnUiThread(new Runnable() { + @Override + public void run() { + getListAdapter().notifyDataSetChanged(); + } + }); - getListAdapter().notifyDataSetChanged(); } @Override @@ -124,7 +126,7 @@ public void onAddToBentoClick(int iDishPosition) { mDishDao.updateDishItem(mDish); - DebugUtils.logDebug(TAG, "added " + mDish.type); + DebugUtils.logDebug(TAG, "Added: " + mDish.type); onBackPressed(); } diff --git a/app/src/main/java/com/bentonow/bentonow/controllers/session/SettingsActivity.java b/app/src/main/java/com/bentonow/bentonow/controllers/session/SettingsActivity.java index 8f4b0cf..bd2413d 100644 --- a/app/src/main/java/com/bentonow/bentonow/controllers/session/SettingsActivity.java +++ b/app/src/main/java/com/bentonow/bentonow/controllers/session/SettingsActivity.java @@ -25,7 +25,6 @@ import com.bentonow.bentonow.controllers.dialog.EditPhoneDialog; import com.bentonow.bentonow.controllers.dialog.LogOutDialog; import com.bentonow.bentonow.controllers.help.HelpActivity; -import com.bentonow.bentonow.controllers.order.OrderHistoryActivity; import com.bentonow.bentonow.dao.IosCopyDao; import com.bentonow.bentonow.listener.ListenerDialog; import com.bentonow.bentonow.model.User; @@ -106,7 +105,7 @@ void initActionbar() { void updateUI() { getContainerUser().setVisibility(mCurrentUser == null ? View.GONE : View.VISIBLE); getContainerSettingsSignIn().setVisibility(mCurrentUser != null ? View.GONE : View.VISIBLE); - getContainerSettingsCreditCard().setVisibility(mCurrentUser != null ? View.VISIBLE : View.GONE); + getContainerSettingsCreditCard().setVisibility(View.GONE); getContainerSettingsOrders().setVisibility(mCurrentUser != null ? View.VISIBLE : View.GONE); getLayoutContainerPhone().setOnClickListener(this); @@ -369,7 +368,7 @@ public void btnOnCancel() { onCreditCardPressed(); break; case R.id.container_settings_orders: - BentoNowUtils.openOrderHistoryActivity(SettingsActivity.this); + BentoNowUtils.openOrderHistoryActivity(SettingsActivity.this); break; default: DebugUtils.logError(TAG, "No found: " + v.getId()); diff --git a/app/src/main/java/com/bentonow/bentonow/dao/BentoDao.java b/app/src/main/java/com/bentonow/bentonow/dao/BentoDao.java index 3a0f12e..7642eb8 100644 --- a/app/src/main/java/com/bentonow/bentonow/dao/BentoDao.java +++ b/app/src/main/java/com/bentonow/bentonow/dao/BentoDao.java @@ -17,7 +17,7 @@ /** * Created by Jose Torres on 10/27/15. */ -public class BentoDao { +public class BentoDao extends MainDao { public final static String TABLE_NAME = "table_bento"; public final static String ID_PK = "bento_pk"; @@ -72,9 +72,8 @@ public OrderItem getNewBento(ConstantUtils.optItemType optItemType) { switch (optItemType) { case CUSTOM_BENTO_BOX: DishDao mDishDao = new DishDao(); -//TODO add the type name here for (int a = 0; a < iNumBento; a++) { - DishModel mDish = mDishDao.getEmptyDish(mOrder.order_pk); + DishModel mDish = mDishDao.getEmptyDish(mOrder.order_pk, a == 0 ? "main" : String.valueOf("side" + a)); mOrder.items.add(mDish); } break; @@ -124,7 +123,7 @@ public List getAllBento() { for (int i = 0; i < cursor.getCount(); i++) { OrderItem mOrder = new OrderItem(); mOrder.order_pk = (cursor.getInt(_ID_PK)); - mOrder.item_type = (cursor.getString(_ITEM_TYPE)); + mOrder.item_type = getStringFromColumn(cursor.getString(_ITEM_TYPE)); mOrder.bIsSoldoOut = (cursor.getInt(_IS_SOLD_OUT) == 1 ? true : false); mOrder.unit_price = (cursor.getDouble(_UNIT_PRICE)); mListBento.add(mOrder); @@ -170,7 +169,7 @@ public OrderItem getAddOnBento() { cursor.moveToFirst(); for (int i = 0; i < cursor.getCount(); i++) { mOrder.order_pk = (cursor.getInt(_ID_PK)); - mOrder.item_type = (cursor.getString(_ITEM_TYPE)); + mOrder.item_type = getStringFromColumn(cursor.getString(_ITEM_TYPE)); mOrder.bIsSoldoOut = (cursor.getInt(_IS_SOLD_OUT) == 1 ? true : false); mOrder.unit_price = (cursor.getDouble(_UNIT_PRICE)); cursor.moveToNext(); diff --git a/app/src/main/java/com/bentonow/bentonow/dao/DishDao.java b/app/src/main/java/com/bentonow/bentonow/dao/DishDao.java index ed5b5d0..8dfcfe5 100644 --- a/app/src/main/java/com/bentonow/bentonow/dao/DishDao.java +++ b/app/src/main/java/com/bentonow/bentonow/dao/DishDao.java @@ -19,7 +19,7 @@ /** * Created by Jose Torres on 27/09/15. */ -public class DishDao { +public class DishDao extends MainDao { public final static String TABLE_NAME = "table_dish"; public final static String ID_PK = "dish_pk"; static final String TAG = "DishDao"; @@ -88,9 +88,10 @@ public boolean insertDish(DishModel mDish) { return success; } - public DishModel getEmptyDish(int iOrderPk) { + public DishModel getEmptyDish(int iOrderPk, String sType) { DishModel mDish = new DishModel(); mDish.bento_pk = iOrderPk; + mDish.type = sType; dbAdapter.begginTransaction(); @@ -133,15 +134,15 @@ public List getAllDishByOrder(int iOrderPk) { DishModel mDish = new DishModel(); mDish.dish_pk = (cursor.getInt(_ID_PK)); mDish.itemId = (cursor.getInt(_ITEM_ID)); - mDish.name = (cursor.getString(_NAME)); - mDish.description = (cursor.getString(_DESCRIPTION)); - mDish.type = (cursor.getString(_TYPE)); - mDish.image1 = (cursor.getString(_IMAGE1)); - mDish.max_per_order = (cursor.getString(_MAX_PER_ORDER)); + mDish.name = getStringFromColumn(cursor.getString(_NAME)); + mDish.description = getStringFromColumn(cursor.getString(_DESCRIPTION)); + mDish.type = getStringFromColumn(cursor.getString(_TYPE)); + mDish.image1 = getStringFromColumn(cursor.getString(_IMAGE1)); + mDish.max_per_order = getStringFromColumn(cursor.getString(_MAX_PER_ORDER)); mDish.price = (cursor.getDouble(_PRICE)); mDish.unit_price = (cursor.getDouble(_PRICE)); mDish.bento_pk = (cursor.getInt(_BENTO_PK)); - mDish.qty = (cursor.getString(_QTY)); + mDish.qty = getStringFromColumn(cursor.getString(_QTY)); mListDish.add(mDish); cursor.moveToNext(); @@ -200,15 +201,15 @@ public List getAllDishByType(ConstantUtils.optDishType optDish) { DishModel mDish = new DishModel(); mDish.dish_pk = (cursor.getInt(_ID_PK)); mDish.itemId = (cursor.getInt(_ITEM_ID)); - mDish.name = (cursor.getString(_NAME)); - mDish.description = (cursor.getString(_DESCRIPTION)); - mDish.type = (cursor.getString(_TYPE)); - mDish.image1 = (cursor.getString(_IMAGE1)); - mDish.max_per_order = (cursor.getString(_MAX_PER_ORDER)); + mDish.name = getStringFromColumn(cursor.getString(_NAME)); + mDish.description = getStringFromColumn(cursor.getString(_DESCRIPTION)); + mDish.type = getStringFromColumn(cursor.getString(_TYPE)); + mDish.image1 = getStringFromColumn(cursor.getString(_IMAGE1)); + mDish.max_per_order = getStringFromColumn(cursor.getString(_MAX_PER_ORDER)); mDish.price = (cursor.getDouble(_PRICE)); mDish.unit_price = (cursor.getDouble(_PRICE)); mDish.bento_pk = (cursor.getInt(_BENTO_PK)); - mDish.qty = (cursor.getString(_QTY)); + mDish.qty = getStringFromColumn(cursor.getString(_QTY)); mDish.count_max = 1; boolean bAdded = false; @@ -220,6 +221,7 @@ public List getAllDishByType(ConstantUtils.optDishType optDish) { } } + if (!bAdded) { mListDish.add(mDish); } @@ -307,15 +309,15 @@ public DishModel getDishItem(int iPk) { mDish = new DishModel(); mDish.dish_pk = (cursor.getInt(_ID_PK)); mDish.itemId = (cursor.getInt(_ITEM_ID)); - mDish.name = (cursor.getString(_NAME)); - mDish.description = (cursor.getString(_DESCRIPTION)); - mDish.type = (cursor.getString(_TYPE)); - mDish.image1 = (cursor.getString(_IMAGE1)); - mDish.max_per_order = (cursor.getString(_MAX_PER_ORDER)); + mDish.name = getStringFromColumn(cursor.getString(_NAME)); + mDish.description = getStringFromColumn(cursor.getString(_DESCRIPTION)); + mDish.type = getStringFromColumn(cursor.getString(_TYPE)); + mDish.image1 = getStringFromColumn(cursor.getString(_IMAGE1)); + mDish.max_per_order = getStringFromColumn(cursor.getString(_MAX_PER_ORDER)); mDish.price = (cursor.getDouble(_PRICE)); mDish.unit_price = (cursor.getDouble(_PRICE)); mDish.bento_pk = (cursor.getInt(_BENTO_PK)); - mDish.qty = (cursor.getString(_QTY)); + mDish.qty = getStringFromColumn(cursor.getString(_QTY)); cursor.moveToNext(); } @@ -354,6 +356,7 @@ public DishModel updateDishItem(DishModel mOldDish, DishModel mNewDish) { if (mNewDish == null) return null; + mNewDish.type = mOldDish.type; mNewDish.bento_pk = mOldDish.bento_pk; mNewDish.dish_pk = mOldDish.dish_pk; @@ -510,6 +513,31 @@ public DishModel getFirstAvailable(Menu mMenu, String type, int[] tryExcludeIds, return null; } + public boolean canCreateAnotherBento(Menu mMenu, int iNumDish, boolean bIsOD) { + if (mMenu != null) { + if (getFirstAvailable(mMenu, "main", null, bIsOD) == null) { + DebugUtils.logError(TAG, "Cant Create Other Bento: Main"); + return false; + } + + int[] ids = new int[iNumDish - 1]; + + for (int i = 1; i < iNumDish; ++i) { + DishModel dishModel = getFirstAvailable(mMenu, "side", ids, bIsOD); + + if (dishModel == null) { + DebugUtils.logError(TAG, "Cant Create Other Bento: Side"); + return false; + } + + ids[i - 1] = dishModel.itemId; + + } + } + + return true; + } + public int countItemsById(int itemId) { int count = 0; diff --git a/app/src/main/java/com/bentonow/bentonow/dao/MainDao.java b/app/src/main/java/com/bentonow/bentonow/dao/MainDao.java new file mode 100644 index 0000000..1ac0db8 --- /dev/null +++ b/app/src/main/java/com/bentonow/bentonow/dao/MainDao.java @@ -0,0 +1,11 @@ +package com.bentonow.bentonow.dao; + +/** + * Created by Kokusho on 05/02/16. + */ +public class MainDao { + + protected String getStringFromColumn(String sColumn) { + return sColumn == null ? "" : sColumn; + } +} diff --git a/app/src/main/java/com/bentonow/bentonow/dao/MenuDao.java b/app/src/main/java/com/bentonow/bentonow/dao/MenuDao.java index 7b59674..4a976f4 100644 --- a/app/src/main/java/com/bentonow/bentonow/dao/MenuDao.java +++ b/app/src/main/java/com/bentonow/bentonow/dao/MenuDao.java @@ -120,6 +120,25 @@ public static ArrayList getCurrentMenuIds() { return aNewMenus; } + + public static boolean hasCurrentMenu(String sMenuId) { + boolean bHasMenu = false; + + refreshDataToday(); + + if (!mListToday.isEmpty()) + for (int a = 0; a < mListToday.size(); a++) + if (mListToday.get(a).menu_id.equals(sMenuId)) + bHasMenu = true; + + if (!bHasMenu && gateKeeper.getAvailableServices() != null && gateKeeper.getAvailableServices().mOrderAhead != null) + for (int b = 0; b < gateKeeper.getAvailableServices().mOrderAhead.availableMenus.size(); b++) + if (gateKeeper.getAvailableServices().mOrderAhead.availableMenus.get(b).menu_id.equals(sMenuId)) + bHasMenu = true; + + return bHasMenu; + } + public static void refreshDataToday() { if (MenuDao.mListToday == null || MenuDao.mListToday.isEmpty()) try { diff --git a/app/src/main/java/com/bentonow/bentonow/dao/OrderDao.java b/app/src/main/java/com/bentonow/bentonow/dao/OrderDao.java index 3c609b1..950c34f 100644 --- a/app/src/main/java/com/bentonow/bentonow/dao/OrderDao.java +++ b/app/src/main/java/com/bentonow/bentonow/dao/OrderDao.java @@ -20,7 +20,7 @@ /** * Created by Jose Torres on 10/27/15. */ -public class OrderDao { +public class OrderDao extends MainDao { public final static String TABLE_NAME = "table_order"; public final static String ID_PK = "order_pk"; @@ -202,18 +202,18 @@ public Order getCurrentOrder() { mOrder = new Order(); mOrder.order_pk = (cursor.getInt(_ID_PK)); mOrder.currentOrderItem = (cursor.getInt(_CURRENT_ORDER_ITEM)); - mOrder.CouponCode = (cursor.getString(_COUPON_CODE)); - mOrder.IdempotentToken = (cursor.getString(_IDEMPOTENT_TOKEN)); - mOrder.Platform = (cursor.getString(_PLATFORM)); - mOrder.MenuType = (cursor.getString(_MENU_TYPE)); - mOrder.MealName = (cursor.getString(_MEAL_NAME)); - mOrder.order_type = (cursor.getString(_ORDER_TYPE)); - mOrder.kitchen = (cursor.getString(_KITCHEN)); - mOrder.OrderAheadZone = (cursor.getString(_ORDER_AHEAD_ZONE)); - mOrder.for_date = (cursor.getString(_FOR_DATE)); - mOrder.scheduled_window_start = (cursor.getString(_SCHEDULED_WINDOW_START)); - mOrder.scheduled_window_end = (cursor.getString(_SCHEDULED_WINDOW_END)); - mOrder.MenuId = (cursor.getString(_MENU_ID)); + mOrder.CouponCode = getStringFromColumn(cursor.getString(_COUPON_CODE)); + mOrder.IdempotentToken = getStringFromColumn(cursor.getString(_IDEMPOTENT_TOKEN)); + mOrder.Platform = getStringFromColumn(cursor.getString(_PLATFORM)); + mOrder.MenuType = getStringFromColumn(cursor.getString(_MENU_TYPE)); + mOrder.MealName = getStringFromColumn(cursor.getString(_MEAL_NAME)); + mOrder.order_type = getStringFromColumn(cursor.getString(_ORDER_TYPE)); + mOrder.kitchen = getStringFromColumn(cursor.getString(_KITCHEN)); + mOrder.OrderAheadZone = getStringFromColumn(cursor.getString(_ORDER_AHEAD_ZONE)); + mOrder.for_date = getStringFromColumn(cursor.getString(_FOR_DATE)); + mOrder.scheduled_window_start = getStringFromColumn(cursor.getString(_SCHEDULED_WINDOW_START)); + mOrder.scheduled_window_end = getStringFromColumn(cursor.getString(_SCHEDULED_WINDOW_END)); + mOrder.MenuId = getStringFromColumn(cursor.getString(_MENU_ID)); OrderDetails mOrderDetail = new OrderDetails(); mOrderDetail.coupon_discount_cents = (cursor.getInt(_ORDER_DETAIL_COUPON_DISCOUNT_CENTS)); @@ -228,22 +228,22 @@ public Order getCurrentOrder() { mOrderDetail.total_cents_without_coupon = (cursor.getInt(_ORDER_DETAIL_TOTAL_CENTS_WITHOUT_COUPON)); OrderAddress mOrderAddress = new OrderAddress(); - mOrderAddress.number = (cursor.getString(_ORDER_ADDRESS_NUMBER)); - mOrderAddress.street = (cursor.getString(_ORDER_ADDRESS_STREET)); - mOrderAddress.city = (cursor.getString(_ORDER_ADDRESS_CITY)); - mOrderAddress.state = (cursor.getString(_ORDER_ADDRESS_STATE)); - mOrderAddress.zip = (cursor.getString(_ORDER_ADDRESS_ZIP)); + mOrderAddress.number = getStringFromColumn(cursor.getString(_ORDER_ADDRESS_NUMBER)); + mOrderAddress.street = getStringFromColumn(cursor.getString(_ORDER_ADDRESS_STREET)); + mOrderAddress.city = getStringFromColumn(cursor.getString(_ORDER_ADDRESS_CITY)); + mOrderAddress.state = getStringFromColumn(cursor.getString(_ORDER_ADDRESS_STATE)); + mOrderAddress.zip = getStringFromColumn(cursor.getString(_ORDER_ADDRESS_ZIP)); OrderLocation mOrderLocation = new OrderLocation(); mOrderLocation.lat = (cursor.getDouble(_ORDER_LOCATION_LAT)); mOrderLocation.lng = (cursor.getDouble(_ORDER_LOCATION_LNG)); OrderStripe mOrderStripe = new OrderStripe(); - mOrderStripe.stripeToken = (cursor.getString(_ORDER_STRIPE_STRIPE_TOKEN)); + mOrderStripe.stripeToken = getStringFromColumn(cursor.getString(_ORDER_STRIPE_STRIPE_TOKEN)); OrderEta mOrderEta = new OrderEta(); - mOrderEta.max = (cursor.getString(_ETA_MAX)); - mOrderEta.min = (cursor.getString(_ETA_MIN)); + mOrderEta.max = getStringFromColumn(cursor.getString(_ETA_MAX)); + mOrderEta.min = getStringFromColumn(cursor.getString(_ETA_MIN)); mOrderDetail.address = mOrderAddress; mOrderDetail.coords = mOrderLocation; @@ -504,6 +504,7 @@ public int countCompletedOrders(Order mOrder) { public void cleanUp() { DebugUtils.logDebug(TAG, "Clean Up"); SharedPreferencesUtil.setAppPreference(SharedPreferencesUtil.IS_ORDER_AHEAD_MENU, false); + SharedPreferencesUtil.setAppPreference(SharedPreferencesUtil.UUID_BENTO, ""); SharedPreferencesUtil.setAppPreference(SharedPreferencesUtil.POD_MODE, ""); OrderDao mOrderDao = new OrderDao(); mOrderDao.clearAllData(); diff --git a/app/src/main/java/com/bentonow/bentonow/dao/UserDao.java b/app/src/main/java/com/bentonow/bentonow/dao/UserDao.java index ed4221c..bf252a7 100644 --- a/app/src/main/java/com/bentonow/bentonow/dao/UserDao.java +++ b/app/src/main/java/com/bentonow/bentonow/dao/UserDao.java @@ -12,7 +12,7 @@ /** * Created by Jose Torres on 11/3/15. */ -public class UserDao { +public class UserDao extends MainDao { public static final String TAG = "UserDao"; private DBAdapter dbAdapter; @@ -102,22 +102,22 @@ public User getCurrentUser() { cursor.moveToFirst(); for (int i = 0; i < cursor.getCount(); i++) { mUser = new User(); - mUser.firstname = (cursor.getString(_FIRST_NAME)); - mUser.lastname = (cursor.getString(_LAST_NAME)); - mUser.password = (cursor.getString(_PASSWORD)); - mUser.email = (cursor.getString(_EMAIL)); - mUser.phone = (cursor.getString(_PHONE)); - mUser.coupon_code = (cursor.getString(_COUPON_CODE)); - mUser.api_token = (cursor.getString(_API_TOKEN)); - mUser.stripe_token = (cursor.getString(_STRIPE_TOKEN)); - mUser.fb_token = (cursor.getString(_FB_TOKEN)); - mUser.fb_id = (cursor.getString(_FB_ID)); - mUser.fb_profile_pic = (cursor.getString(_FB_PROFILE_PIC)); - mUser.fb_age_range = (cursor.getString(_FB_AGE_RANGE)); - mUser.fb_gender = (cursor.getString(_FB_GENDER)); + mUser.firstname = getStringFromColumn(cursor.getString(_FIRST_NAME)); + mUser.lastname = getStringFromColumn(cursor.getString(_LAST_NAME)); + mUser.password = getStringFromColumn(cursor.getString(_PASSWORD)); + mUser.email = getStringFromColumn(cursor.getString(_EMAIL)); + mUser.phone = getStringFromColumn(cursor.getString(_PHONE)); + mUser.coupon_code = getStringFromColumn(cursor.getString(_COUPON_CODE)); + mUser.api_token = getStringFromColumn(cursor.getString(_API_TOKEN)); + mUser.stripe_token = getStringFromColumn(cursor.getString(_STRIPE_TOKEN)); + mUser.fb_token = getStringFromColumn(cursor.getString(_FB_TOKEN)); + mUser.fb_id = getStringFromColumn(cursor.getString(_FB_ID)); + mUser.fb_profile_pic = getStringFromColumn(cursor.getString(_FB_PROFILE_PIC)); + mUser.fb_age_range = getStringFromColumn(cursor.getString(_FB_AGE_RANGE)); + mUser.fb_gender = getStringFromColumn(cursor.getString(_FB_GENDER)); Card mCard = new Card(); - mCard.brand = (cursor.getString(_CARD_BRAND)); - mCard.last4 = (cursor.getString(_CARD_LAST4)); + mCard.brand = getStringFromColumn(cursor.getString(_CARD_BRAND)); + mCard.last4 = getStringFromColumn(cursor.getString(_CARD_LAST4)); mUser.card = mCard; cursor.moveToNext(); diff --git a/app/src/main/java/com/bentonow/bentonow/model/order/post/DishPost.java b/app/src/main/java/com/bentonow/bentonow/model/order/post/DishPost.java new file mode 100644 index 0000000..128b1a6 --- /dev/null +++ b/app/src/main/java/com/bentonow/bentonow/model/order/post/DishPost.java @@ -0,0 +1,23 @@ +package com.bentonow.bentonow.model.order.post; + +import com.bentonow.bentonow.model.DishModel; + +public class DishPost { + + public static final String TAG = "DishPost"; + + public int id; + public String type = ""; + public String name = ""; + public String qty = ""; + public double unit_price; + + public DishPost(DishModel mDish) { + id = mDish.itemId; + type = String.valueOf(mDish.type); + name = String.valueOf(mDish.name); + qty = String.valueOf(mDish.qty); + unit_price = mDish.unit_price; + } + +} diff --git a/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderDetailsPost.java b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderDetailsPost.java new file mode 100644 index 0000000..117b171 --- /dev/null +++ b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderDetailsPost.java @@ -0,0 +1,54 @@ +package com.bentonow.bentonow.model.order.post; + +import android.location.Address; + +import com.bentonow.bentonow.Utils.SharedPreferencesUtil; +import com.bentonow.bentonow.model.order.OrderAddress; +import com.bentonow.bentonow.model.order.OrderDetails; +import com.bentonow.bentonow.model.order.OrderLocation; +import com.google.android.gms.maps.model.LatLng; +import com.google.gson.Gson; + +public class OrderDetailsPost { + public int coupon_discount_cents = 0; + public double tip_percentage = 15; + public double tax_cents = 0; + public double tip_cents = 0; + public double total_cents = 0; + public double delivery_price = 0; + public double items_total = 0; + public double tax_percentage = 0; + public double subtotal = 0; + public double total_cents_without_coupon = 0; + public OrderLocation coords = new OrderLocation(); + public OrderAddress address = new OrderAddress(); + + public OrderDetailsPost(OrderDetails mOrderDetails) { + coupon_discount_cents = mOrderDetails.coupon_discount_cents; + tip_percentage = mOrderDetails.tip_percentage; + tax_cents = mOrderDetails.tax_cents; + tip_cents = mOrderDetails.tip_cents; + total_cents = mOrderDetails.total_cents; + delivery_price = mOrderDetails.delivery_price; + items_total = mOrderDetails.items_total; + tax_percentage = mOrderDetails.tax_percentage; + subtotal = mOrderDetails.subtotal; + total_cents_without_coupon = mOrderDetails.total_cents_without_coupon; + + String sLocation = SharedPreferencesUtil.getStringPreference(SharedPreferencesUtil.LOCATION); + String sAddress = SharedPreferencesUtil.getStringPreference(SharedPreferencesUtil.ADDRESS); + + LatLng location = new Gson().fromJson(sLocation, LatLng.class); + Address mAddress = new Gson().fromJson(sAddress, Address.class); + + coords.lat = location.latitude; + coords.lng = location.longitude; + + address.number = mAddress.getSubThoroughfare(); + address.street = mAddress.getThoroughfare(); + address.city = mAddress.getLocality(); + address.state = mAddress.getAdminArea(); + address.zip = mAddress.getPostalCode(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderItemPost.java b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderItemPost.java new file mode 100644 index 0000000..fea6a87 --- /dev/null +++ b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderItemPost.java @@ -0,0 +1,20 @@ +package com.bentonow.bentonow.model.order.post; + +import com.bentonow.bentonow.model.order.OrderItem; + +import java.util.ArrayList; +import java.util.List; + +public class OrderItemPost { + public List items = new ArrayList<>(); + public double unit_price = 0; + public String item_type; + + public OrderItemPost(OrderItem mOrderItem) { + unit_price = mOrderItem.unit_price; + item_type = String.valueOf(mOrderItem.item_type); + for (int a = 0; a < mOrderItem.items.size(); a++) + items.add(new DishPost(mOrderItem.items.get(a))); + } + +} diff --git a/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderLocationPost.java b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderLocationPost.java new file mode 100644 index 0000000..048333f --- /dev/null +++ b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderLocationPost.java @@ -0,0 +1,9 @@ +package com.bentonow.bentonow.model.order.post; + +import com.bentonow.bentonow.model.order.OrderDetails; + +public class OrderLocationPost { + public String lat; + public String lng; + +} diff --git a/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderPost.java b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderPost.java new file mode 100644 index 0000000..a270d11 --- /dev/null +++ b/app/src/main/java/com/bentonow/bentonow/model/order/post/OrderPost.java @@ -0,0 +1,56 @@ +package com.bentonow.bentonow.model.order.post; + +import com.bentonow.bentonow.model.Order; +import com.bentonow.bentonow.model.order.OrderEta; +import com.bentonow.bentonow.model.order.OrderStripe; +import com.google.gson.GsonBuilder; + +import java.util.ArrayList; +import java.util.List; + +public class OrderPost { + static final String TAG = "OrderPost"; + + public OrderStripe Stripe = new OrderStripe(); + public OrderDetailsPost OrderDetails; + public String order_type = ""; + public List OrderItems = new ArrayList<>(); + public String AppVersion = ""; + public String kitchen = ""; + public String CouponCode = ""; + public String for_date = ""; + public String Platform = ""; + public String scheduled_window_start = ""; + public String scheduled_window_end = ""; + public String OrderAheadZone = ""; + public OrderEta Eta = new OrderEta(); + public String MenuId = ""; + public String IdempotentToken = ""; + + public OrderPost(Order mOrder) { + Stripe = mOrder.Stripe; + OrderDetails = new OrderDetailsPost(mOrder.OrderDetails); + order_type = mOrder.order_type; + for (int a = 0; a < mOrder.OrderItems.size(); a++) + OrderItems.add(new OrderItemPost(mOrder.OrderItems.get(a))); + Eta = mOrder.Eta; + CouponCode = mOrder.CouponCode; + IdempotentToken = mOrder.IdempotentToken; + Platform = mOrder.Platform; + AppVersion = mOrder.AppVersion; + kitchen = mOrder.kitchen; + OrderAheadZone = mOrder.OrderAheadZone; + for_date = mOrder.for_date; + scheduled_window_start = mOrder.scheduled_window_start; + scheduled_window_end = mOrder.scheduled_window_end; + MenuId = mOrder.MenuId; + } + + + @Override + public String toString() { + return new GsonBuilder().serializeNulls().create().toJson(this).replace("lng", "long").replaceAll("itemId", "id"); + } + + +} diff --git a/app/src/main/res/layout/content_build_bento.xml b/app/src/main/res/layout/content_build_bento.xml index f1e7511..57bd359 100644 --- a/app/src/main/res/layout/content_build_bento.xml +++ b/app/src/main/res/layout/content_build_bento.xml @@ -23,7 +23,7 @@ android:layout_alignParentStart="true" android:layout_toLeftOf="@+id/img_divider_status" android:gravity="center" - android:text="aasdasd" /> + android:text="" /> + app:key="build-title" />