From 74abdbc2806db835f80594e7bc961a807b28e599 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E5=A2=9E=E9=A3=9E?= <331023091@qq.com> Date: Wed, 19 Mar 2025 15:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 1 + app/src/main/java/com/sw/st/Test.java | 22 + .../main/java/com/sw/st/api/SwService.java | 28 +- .../java/com/sw/st/model/FoodGoodsInfo.java | 18 + .../com/sw/st/model/NewFoodInfoModel.java | 39 +- .../sw/st/ui/foodinfo/FoodInfoActivity.java | 6 +- .../com/sw/st/ui/setting/FoodNameAdapter.java | 24 +- .../sw/st/ui/setting/FoodSettingActivity.java | 338 +++++++++-- .../st/ui/setting/FoodSettingPresenter.java | 61 +- .../sw/st/ui/setting/IngredientAdapter.java | 72 +++ .../main/java/com/sw/st/utils/AppUtil.java | 56 ++ .../java/com/sw/st/utils/CrashHandler.java | 6 +- .../java/com/sw/st/view/FoodWarningPopup.java | 68 +++ app/src/main/res/drawable/a_blue_bg.xml | 7 + app/src/main/res/drawable/a_blue_line_bg.xml | 9 + app/src/main/res/drawable/a_gray_bg.xml | 9 + app/src/main/res/drawable/a_gray_button.xml | 9 + app/src/main/res/drawable/a_gray_fill_bg.xml | 7 + .../main/res/drawable/a_ingredient_item.xml | 8 + .../res/drawable/a_item_ingredient_bg.xml | 7 + app/src/main/res/drawable/a_num_bg.xml | 7 + app/src/main/res/drawable/a_orange_bg.xml | 9 + app/src/main/res/drawable/a_orange_button.xml | 9 + .../main/res/drawable/a_orange_fill_bg.xml | 7 + .../res/drawable/a_orange_press_fill_bg.xml | 7 + .../main/res/drawable/a_transparent_bg.xml | 7 + app/src/main/res/drawable/new_food_item.xml | 19 + app/src/main/res/layout/activity_setting.xml | 537 ++++++++++++++---- app/src/main/res/layout/input_layout.xml | 163 ++++++ app/src/main/res/layout/item_food_name.xml | 49 ++ app/src/main/res/layout/item_ingredient.xml | 97 ++++ .../main/res/layout/popup_food_warning.xml | 44 ++ app/src/main/res/mipmap-hdpi/icon_del.png | Bin 0 -> 638 bytes app/src/main/res/mipmap-hdpi/icon_fc.png | Bin 0 -> 476 bytes .../res/mipmap-hdpi/icon_food_warning.png | Bin 0 -> 3600 bytes .../icon_foodlist_empty.png | Bin .../icon_search.png | Bin app/src/main/res/mipmap-hdpi/icon_zc.png | Bin 0 -> 355 bytes .../res/mipmap-hdpi/img_checkbox_checked.png | Bin 0 -> 950 bytes .../res/mipmap-hdpi/img_checkbox_normal.png | Bin 0 -> 958 bytes .../main/res/mipmap-hdpi/img_food_making.png | Bin 0 -> 3026 bytes app/src/main/res/values/colors.xml | 4 +- app/src/main/res/values/styles.xml | 13 +- 43 files changed, 1560 insertions(+), 207 deletions(-) create mode 100644 app/src/main/java/com/sw/st/ui/setting/IngredientAdapter.java create mode 100644 app/src/main/java/com/sw/st/view/FoodWarningPopup.java create mode 100644 app/src/main/res/drawable/a_blue_bg.xml create mode 100644 app/src/main/res/drawable/a_blue_line_bg.xml create mode 100644 app/src/main/res/drawable/a_gray_bg.xml create mode 100644 app/src/main/res/drawable/a_gray_button.xml create mode 100644 app/src/main/res/drawable/a_gray_fill_bg.xml create mode 100644 app/src/main/res/drawable/a_ingredient_item.xml create mode 100644 app/src/main/res/drawable/a_item_ingredient_bg.xml create mode 100644 app/src/main/res/drawable/a_num_bg.xml create mode 100644 app/src/main/res/drawable/a_orange_bg.xml create mode 100644 app/src/main/res/drawable/a_orange_button.xml create mode 100644 app/src/main/res/drawable/a_orange_fill_bg.xml create mode 100644 app/src/main/res/drawable/a_orange_press_fill_bg.xml create mode 100644 app/src/main/res/drawable/a_transparent_bg.xml create mode 100644 app/src/main/res/drawable/new_food_item.xml create mode 100644 app/src/main/res/layout/input_layout.xml create mode 100644 app/src/main/res/layout/item_food_name.xml create mode 100644 app/src/main/res/layout/item_ingredient.xml create mode 100644 app/src/main/res/layout/popup_food_warning.xml create mode 100644 app/src/main/res/mipmap-hdpi/icon_del.png create mode 100644 app/src/main/res/mipmap-hdpi/icon_fc.png create mode 100644 app/src/main/res/mipmap-hdpi/icon_food_warning.png rename app/src/main/res/{mipmap-xhdpi => mipmap-hdpi}/icon_foodlist_empty.png (100%) rename app/src/main/res/{mipmap-xhdpi => mipmap-hdpi}/icon_search.png (100%) create mode 100644 app/src/main/res/mipmap-hdpi/icon_zc.png create mode 100644 app/src/main/res/mipmap-hdpi/img_checkbox_checked.png create mode 100644 app/src/main/res/mipmap-hdpi/img_checkbox_normal.png create mode 100644 app/src/main/res/mipmap-hdpi/img_food_making.png diff --git a/app/build.gradle b/app/build.gradle index c98c929..bf7d202 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,6 +78,7 @@ dependencies { // implementation files('libs\\libWeighingscale.jar') implementation files('libs\\org.eclipse.paho.client.mqttv3-1.2.5.jar') + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/app/src/main/java/com/sw/st/Test.java b/app/src/main/java/com/sw/st/Test.java index 03b5db9..392d3a4 100644 --- a/app/src/main/java/com/sw/st/Test.java +++ b/app/src/main/java/com/sw/st/Test.java @@ -87,6 +87,28 @@ public class Test { // System.out.println(s); // } + String temp = calcPct(71.08, 1.49); + System.out.println(temp); + System.out.println(extractNumber(temp)); + } + + public static String calcPct(double weight, double realWeight) { + double pct = (realWeight - weight) / weight; + System.out.println(pct); + String pctStr = ""; + if (pct > 0) { + pctStr = "+" + (int) (pct * 100) + "%"; + } else { + pctStr = (int) (pct * 100) + "%"; + } + return pctStr; + } + + public static int extractNumber(String input) { + // 使用正则表达式替换掉字符串中所有非数字、非负号的字符 + String numberStr = input.replaceAll("[^-0-9.]", ""); + // 将处理后的字符串转换为 double 类型的数字 + return Math.abs(Integer.parseInt(numberStr)); } /** diff --git a/app/src/main/java/com/sw/st/api/SwService.java b/app/src/main/java/com/sw/st/api/SwService.java index 3ed5078..2bf8098 100644 --- a/app/src/main/java/com/sw/st/api/SwService.java +++ b/app/src/main/java/com/sw/st/api/SwService.java @@ -1,6 +1,7 @@ package com.sw.st.api; +import com.google.gson.Gson; import com.google.gson.JsonObject; import com.lzy.okgo.OkGo; import com.lzy.okgo.cache.CacheMode; @@ -21,6 +22,7 @@ import com.sw.st.net.helper.JsonConvert; import com.sw.st.ui.device.BindDeviceModel; import com.sw.st.ui.setting.FoodListModel; import com.sw.st.utils.AppUtil; +import com.sw.st.utils.L; import org.json.JSONException; import org.json.JSONObject; @@ -35,10 +37,11 @@ import static com.sw.st.ui.init.InitActivity.BASE_URL; public class SwService { - private static final String BASE_URL = "http://192.168.10.7:9092"; + // private static final String BASE_URL = "http://192.168.10.25:9092"; +// private static final String BASE_URL = "http://192.168.10.7:9092"; // private static final String BASE_URL = "http://192.168.1.250:9999/"; // private static final String BASE_URL = "http://192.168.1.199:9999/"; -// private static final String BASE_URL = "http://vip.shuziweidao.com"; + private static final String BASE_URL = "http://vip.shuziweidao.com"; public static String getServerAddress = "/equipment/stEquipment/queryByEquipmentCode";//外网服务获取业务服务器地址 public static final String checkUpdate = "/app/stApp/appVersionPpgrade"; @@ -76,7 +79,7 @@ public class SwService { //================================新版本======================================= - public static String getRestInfoFoodsByType = "/shuwei-zhct/scales/getRestInfoFoodsByType";//菜品信息 + public static String getRestInfoFoodsByType = "/shuwei-zhct/scales/getRestInfoFoods";//菜品信息 getRestInfoFoodsByType public static String getUserNutritionData = "/shuwei-zhct/scales/getFoodInfoByplateNumber";//获取用户本餐次就餐数据 public static String startMealService = "/shuwei-zhct/scales/startMealService";//开餐 @@ -491,7 +494,7 @@ public class SwService { .adapt(new ObservableBody>()); } - public static Observable getGoodsUseList(String foodId, double foodWeight) { + public static Observable getGoodsUseList(String foodId, String foodWeight) { return OkGo.get(BASE_URL + getGoodsUseList) .params("foodId", foodId) .params("foodWeight", foodWeight) @@ -501,17 +504,14 @@ public class SwService { .adapt(new ObservableBody()); } - public static Observable saveFoodGoodsUseInfo(String foodId, double foodWeight, ArrayList goodsInfo) { - JSONObject jsonObject = new JSONObject(); - try { - jsonObject.put("foodId", foodId); - jsonObject.put("foodWeight", foodWeight); - jsonObject.put("voList", goodsInfo); - } catch (JSONException e) { - e.printStackTrace(); - } + public static Observable saveFoodGoodsUseInfo(String foodId, double foodWeight, List goodsInfo) { + HashMap hashMap = new HashMap(); + hashMap.put("foodId", foodId); + hashMap.put("foodRealWeight", foodWeight); + hashMap.put("voList", goodsInfo); + String jsonStr = new Gson().toJson(hashMap); return OkGo.post(BASE_URL + saveFoodGoodsUseInfo) - .upJson(jsonObject) + .upJson(jsonStr) .cacheMode(CacheMode.NO_CACHE) .converter(new JsonConvert() { }) diff --git a/app/src/main/java/com/sw/st/model/FoodGoodsInfo.java b/app/src/main/java/com/sw/st/model/FoodGoodsInfo.java index 25fb5a9..0c2aaff 100644 --- a/app/src/main/java/com/sw/st/model/FoodGoodsInfo.java +++ b/app/src/main/java/com/sw/st/model/FoodGoodsInfo.java @@ -8,6 +8,8 @@ public class FoodGoodsInfo { private String goodsName; private double useWeight; private double useRealWeight; + private boolean isSelect = false; + private int materialType; public String getFoodId() { return foodId; @@ -64,4 +66,20 @@ public class FoodGoodsInfo { public void setUseRealWeight(double useRealWeight) { this.useRealWeight = useRealWeight; } + + public int getMaterialType() { + return materialType; + } + + public void setMaterialType(int materialType) { + this.materialType = materialType; + } + + public boolean isSelect() { + return isSelect; + } + + public void setSelect(boolean select) { + isSelect = select; + } } diff --git a/app/src/main/java/com/sw/st/model/NewFoodInfoModel.java b/app/src/main/java/com/sw/st/model/NewFoodInfoModel.java index 449de19..2685fd9 100644 --- a/app/src/main/java/com/sw/st/model/NewFoodInfoModel.java +++ b/app/src/main/java/com/sw/st/model/NewFoodInfoModel.java @@ -4,7 +4,7 @@ import java.io.Serializable; import java.util.List; public class NewFoodInfoModel implements Serializable { - private String id; + private String foodId; private String foodName; private String img; private List labList; @@ -29,14 +29,19 @@ public class NewFoodInfoModel implements Serializable { private double mixedBeans; private double soyaNew; + private double foodWeight; + private double estimateFoodWeight; + + private boolean isFirst = true; + private boolean isSelect = false; - public String getId() { - return id; + public String getFoodId() { + return foodId; } - public void setId(String id) { - this.id = id; + public void setFoodId(String foodId) { + this.foodId = foodId; } public int getTablewareWeight() { @@ -207,6 +212,30 @@ public class NewFoodInfoModel implements Serializable { this.soyaNew = soyaNew; } + public double getFoodWeight() { + return foodWeight; + } + + public void setFoodWeight(double foodWeight) { + this.foodWeight = foodWeight; + } + + public double getEstimateFoodWeight() { + return estimateFoodWeight; + } + + public void setEstimateFoodWeight(double estimateFoodWeight) { + this.estimateFoodWeight = estimateFoodWeight; + } + + public boolean isFirst() { + return isFirst; + } + + public void setFirst(boolean first) { + isFirst = first; + } + public boolean isSelect() { return isSelect; } diff --git a/app/src/main/java/com/sw/st/ui/foodinfo/FoodInfoActivity.java b/app/src/main/java/com/sw/st/ui/foodinfo/FoodInfoActivity.java index 9763c65..d6f098b 100644 --- a/app/src/main/java/com/sw/st/ui/foodinfo/FoodInfoActivity.java +++ b/app/src/main/java/com/sw/st/ui/foodinfo/FoodInfoActivity.java @@ -295,7 +295,7 @@ public class FoodInfoActivity extends BaseActivity() { }.getType()); - foodId = foodInfo.getId(); + foodId = foodInfo.getFoodId(); // foodInfo = (FoodInfoModel) getIntent().getSerializableExtra("foodInfo"); String restName = PrefUtils.getString(this, REST_NAME, ""); restNameTv.setText("欢迎光临" + restName); @@ -644,7 +644,7 @@ public class FoodInfoActivity extends BaseActivity strs, Context context) { - super(R.layout.item_food_name_tv, strs); + super(R.layout.item_food_name, strs); this.context = context; } @Override protected void convert(@NotNull BaseViewHolder baseViewHolder, NewFoodInfoModel info) { + RelativeLayout relativeLayout = baseViewHolder.findView(R.id.foodLayout); + relativeLayout.setSelected(info.isSelect()); - TextView textView = baseViewHolder.findView(R.id.tv); -// baseViewHolder.setText(R.id.tv, info.getFoodName()); - textView.setText(info.getFoodName()); - textView.setSelected(info.isSelect()); - if(info.isSelect()){ + baseViewHolder.setText(R.id.nameTv, info.getFoodName()); + if (info.getFoodWeight() > 0) { + baseViewHolder.setText(R.id.weightTv, "实际:" + info.getFoodWeight() + " kg"); + } else { + baseViewHolder.setText(R.id.weightTv, "实际:" + "-- kg"); + } + if (info.getEstimateFoodWeight() > 0) { + baseViewHolder.setText(R.id.estimateWeightTv, "预计:" + info.getEstimateFoodWeight() + " kg"); + } else { + baseViewHolder.setText(R.id.estimateWeightTv, "预计:" + "-- kg"); + } + if (info.isSelect()) { - }else{ + } else { } } diff --git a/app/src/main/java/com/sw/st/ui/setting/FoodSettingActivity.java b/app/src/main/java/com/sw/st/ui/setting/FoodSettingActivity.java index 74320b5..f665be4 100644 --- a/app/src/main/java/com/sw/st/ui/setting/FoodSettingActivity.java +++ b/app/src/main/java/com/sw/st/ui/setting/FoodSettingActivity.java @@ -1,5 +1,7 @@ package com.sw.st.ui.setting; +import static com.sw.st.utils.AppUtil.extractFirstPart; + import android.Manifest; import android.app.AlertDialog; import android.app.Dialog; @@ -11,19 +13,23 @@ import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.inputmethod.EditorInfo; -import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.listener.OnItemClickListener; +import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.gyf.immersionbar.BarHide; import com.gyf.immersionbar.ImmersionBar; +import com.lxj.xpopup.XPopup; import com.lzy.okgo.OkGo; import com.lzy.okgo.model.HttpHeaders; import com.sw.st.R; @@ -36,12 +42,15 @@ import com.sw.st.utils.AppUtil; import com.sw.st.utils.InputMethod; import com.sw.st.utils.L; import com.sw.st.utils.PrefUtils; +import com.sw.st.view.FoodWarningPopup; import com.wabon.wbintelligenthardwaresdk.api.WeigherTwo; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import butterknife.BindView; @@ -67,17 +76,52 @@ public class FoodSettingActivity extends BaseActivity foodTagList = new ArrayList<>(); private NewFoodInfoModel currentFoodInfo; @@ -92,6 +136,7 @@ public class FoodSettingActivity extends BaseActivity finishedFoodSet = new HashSet<>();//保存已制作food id @Override protected int provideContentViewId() { @@ -118,6 +163,7 @@ public class FoodSettingActivity extends BaseActivity { + // 调用数据刷新的方法 + mPresenter.getRestInfoFoodsByType(restNo, "1"); + }); searchEdit.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -170,12 +224,11 @@ public class FoodSettingActivity extends BaseActivity adapter, @NonNull View view, int position) { // 当按了搜索之后关闭软键盘 - InputMethod.closeInputMethod(FoodSettingActivity.this, startButton); - - startButton.setVisibility(View.VISIBLE); + InputMethod.closeInputMethod(FoodSettingActivity.this, foodNameTv); currentFoodInfo = (NewFoodInfoModel) adapter.getItem(position); - currentFoodTv.setText(currentFoodInfo.getFoodName()); + foodNameTv.setText(currentFoodInfo.getFoodName()); + foodName.setText(currentFoodInfo.getFoodName()); List foodInfoModelList = foodNameAdapter.getData(); for (NewFoodInfoModel foodInfoModel : foodInfoModelList) { @@ -184,17 +237,105 @@ public class FoodSettingActivity extends BaseActivity adapter, @NonNull View view, int position) { + setSelectIngredient(position); + } + }); } + private void setSelectIngredient(int position) { + foodGoodsIndex = position; + List foodGoodsInfos = ingredientAdapter.getData(); + for (FoodGoodsInfo foodInfoModel : foodGoodsInfos) { + foodInfoModel.setSelect(false); + } + currentFoodGoodsInfo = ingredientAdapter.getItem(position); + currentFoodGoodsInfo.setSelect(true); + ingredientAdapter.notifyDataSetChanged(); - @OnClick({R.id.setting_search_edit_cancel_img, R.id.back, - R.id.start, R.id.currentWeight, R.id.zeroTv, R.id.zeroTitleTv}) + setIngredientInfoData(currentFoodGoodsInfo); + } + + private void setIngredientInfoData(FoodGoodsInfo info) { + ingredientName.setText(extractFirstPart(info.getGoodsName())); + switch (info.getMaterialType()) {//1主料 2辅料 3调料 + case 1: + ingredientType.setText("主料"); + break; + case 2: + ingredientType.setText("辅料"); + break; + } + ingredientCalcWeight.setText(info.getUseWeight() + ""); + } + + List currentGoodsInfos; + + @OnClick({R.id.setting_search_edit_cancel_img, R.id.reloadFoodListTv, R.id.ingredientOkTv, + R.id.one, R.id.two, R.id.three, R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, + R.id.nine, R.id.dot, R.id.zero, R.id.del, R.id.inputOkTv, R.id.leftZeroTv, R.id.makingCancelTv, + R.id.calStartTv, R.id.rightZeroTv, R.id.okTv}) public void onViewClicked(View view) { switch (view.getId()) { + case R.id.inputOkTv: + if (currentFoodInfo != null) { +// currentFoodInfo.setFirst(false); + String inputWeight = makeWeightEdit.getText().toString(); + totalWeightTv.setText(inputWeight + "kg"); + mPresenter.getGoodsUseList(currentFoodInfo.getFoodId(), inputWeight); + } else { + showToast("请选择菜品"); + } + break; + case R.id.ingredientOkTv: +// if (Math.abs(AppUtil.extractNumber(ingredientCalcPctTv.getText().toString())) > 5) { +// +// new XPopup.Builder(mContext) +// .asCustom(foodWarningPopup) +// .show(); +// return; +// } + + currentFoodGoodsInfo.setUseRealWeight(leftDeviceWeight); + ingredientAdapter.notifyDataSetChanged(); + + if (ingredientAdapter.getData().size() - 1 > foodGoodsIndex) { + foodGoodsIndex++; + setSelectIngredient(foodGoodsIndex); + ingredientRecyclerView.smoothScrollToPosition(foodGoodsIndex); + currentFoodGoodsInfo = ingredientAdapter.getData().get(foodGoodsIndex); + } else { + currentGoodsInfos = ingredientAdapter.getData(); + for (FoodGoodsInfo foodGoodsInfo : currentGoodsInfos) { + if (foodGoodsInfo.getUseRealWeight() == 0) { + showToast("请确认所有食材重量已录入完成"); + return; + } + } + + ingredientLayout.setVisibility(View.GONE); + foodMakingLayout.setVisibility(View.VISIBLE); + } + break; + case R.id.makingCancelTv: + ingredientLayout.setVisibility(View.VISIBLE); + foodMakingLayout.setVisibility(View.GONE); + break; + case R.id.calStartTv: + foodMakingLayout.setVisibility(View.GONE); + endWeightLayout.setVisibility(View.VISIBLE); + break; case R.id.title_name_tv: break; case R.id.title_back_iv: @@ -204,31 +345,68 @@ public class FoodSettingActivity extends BaseActivity 0) + makeWeightEdit.setText(txt.substring(0, length - 1)); break; } } @@ -245,22 +423,39 @@ public class FoodSettingActivity extends BaseActivity list, String type) { + swipeRefreshLayout.setRefreshing(false); + for (NewFoodInfoModel foodInfoModel : list) { + for (String foodId : finishedFoodSet) { + if (foodId.equals(foodInfoModel.getFoodId())) { + foodInfoModel.setFirst(false); + } + } + } switch (type) { case "0": allFoodList = list; L.e("FoodListSize===" + allFoodList.size()); if (foodTagList == null || foodTagList.size() == 0) { - foodNameAdapter.setList(allFoodList); + foodAdapterSetData(allFoodList); } break; case "1": foodTagList = list; - foodNameAdapter.setList(foodTagList); + foodAdapterSetData(foodTagList); break; } } + private void foodAdapterSetData(ArrayList list) { + foodNameAdapter.setList(list); + if (foodNameAdapter.getData() != null && foodNameAdapter.getData().size() > 0) { + foodListEmptyLayout.setVisibility(View.GONE); + } else { + foodListEmptyLayout.setVisibility(View.VISIBLE); + } + } + @Override public void getFoodListFail(String info) { @@ -286,17 +481,12 @@ public class FoodSettingActivity extends BaseActivity list) { searchResultFoodList = list; - foodNameAdapter.setList(searchResultFoodList); + foodAdapterSetData(searchResultFoodList); } @Override @@ -348,20 +538,33 @@ public class FoodSettingActivity extends BaseActivity foodGoodsInfoArrayList; + private FoodGoodsInfo currentFoodGoodsInfo; + private int foodGoodsIndex = 0; @Override public void getGoodsUseListSuccess(String info) { try { + makeWeightEdit.setText(""); JSONObject jsonObject = new JSONObject(info); foodGoodsInfoArrayList = Convert.fromJson(jsonObject.optString("voList"), new TypeToken>() { }.getType()); - + if (foodGoodsInfoArrayList.size() > 0) { + currentFoodGoodsInfo = foodGoodsInfoArrayList.get(0); + currentFoodGoodsInfo.setSelect(true); + foodGoodsIndex = 0; + setIngredientInfoData(currentFoodGoodsInfo); + } + ingredientAdapter.setList(foodGoodsInfoArrayList); L.e("size===" + foodGoodsInfoArrayList.size()); + + inputLayout.setVisibility(View.GONE); + ingredientLayout.setVisibility(View.VISIBLE); } catch (JSONException e) { throw new RuntimeException(e); } } + @Override public void getGoodsUseListFail(String info) { @@ -369,7 +572,14 @@ public class FoodSettingActivity extends BaseActivity 5) { + ingredientCalcPctTv.setTextColor(getColor(R.color.chart_red)); + } else { + ingredientCalcPctTv.setTextColor(getColor(R.color.chart_green)); + } + ingredientCalcPctTv.setText(pct); + } + } + if (address == RIGHT_WEIGHT_INDEX) { + double rightWeight = weight; + rightDeviceWeight = rightWeight / 1000; + rightWeightTv.setText(rightDeviceWeight + ""); } } }); @@ -534,11 +749,16 @@ public class FoodSettingActivity extends BaseActivity 1000) { - return "余量 " + AppUtil.formatDouble(weight / 1000) + " 千克"; - } else { - return "余量 " + weight + " 克"; - } +// if (weight > 1000) { + leftWeightUnitTv.setText("千克"); + return "" + AppUtil.formatDouble(weight);// / 1000 + +// return "余量 " + AppUtil.formatDouble(weight / 1000) + " 千克"; +// } else { +// leftWeightUnitTv.setText("克"); +// return "" + (int) weight; +//// return "余量 " + weight + " 克"; +// } } } diff --git a/app/src/main/java/com/sw/st/ui/setting/FoodSettingPresenter.java b/app/src/main/java/com/sw/st/ui/setting/FoodSettingPresenter.java index 1fb5268..c54f41a 100644 --- a/app/src/main/java/com/sw/st/ui/setting/FoodSettingPresenter.java +++ b/app/src/main/java/com/sw/st/ui/setting/FoodSettingPresenter.java @@ -3,6 +3,7 @@ package com.sw.st.ui.setting; import com.sw.st.api.SwService; import com.sw.st.base.BasePresenter; +import com.sw.st.model.FoodGoodsInfo; import com.sw.st.model.FoodInfoModel; import com.sw.st.model.NewFoodInfoModel; import com.sw.st.model.UserFaceModel; @@ -15,6 +16,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.List; import io.reactivex.disposables.Disposable; @@ -23,6 +25,7 @@ public class FoodSettingPresenter extends BasePresenter { public void getRestInfoFoodsByType(String restNo, String type) { + getView().showProgress("加载中..."); SwService.getRestInfoFoodsByType(restNo, type) .compose(RxSchedulersHelper.io_main()) .compose(RxResultHelper.handleResult()) @@ -33,20 +36,26 @@ public class FoodSettingPresenter extends BasePresenter { @Override public void _onNext(ArrayList info) { - if (getView() != null) + if (getView() != null) { getView().getFoodListSuccess(info, type); + getView().hideProgress(); + } } @Override public void _onError(String errorMessage) { - if (getView() != null) + if (getView() != null) { getView().getFoodListFail(errorMessage); + getView().hideProgress(); + } } @Override public void _onComplete() { - if (getView() != null) + if (getView() != null) { getView().hideProgress(); + getView().hideProgress(); + } } }); } @@ -249,7 +258,8 @@ public class FoodSettingPresenter extends BasePresenter { }); } - public void getGoodsUseList(String foodId, double foodWeight) { + public void getGoodsUseList(String foodId, String foodWeight) { + getView().showProgress("请稍候..."); SwService.getGoodsUseList(foodId, foodWeight) .compose(RxSchedulersHelper.io_main()) .compose(RxResultHelper.handleJsonResponse()) @@ -283,8 +293,51 @@ public class FoodSettingPresenter extends BasePresenter { @Override public void _onComplete() { + if (getView() != null) + getView().hideProgress(); } }); } + public void saveFoodGoodsUseInfo(String foodId, double foodWeight, List goodsInfo) { + getView().showProgress("上传中..."); + SwService.saveFoodGoodsUseInfo(foodId, foodWeight, goodsInfo) + .compose(RxSchedulersHelper.io_main()) + .compose(RxResultHelper.handleJsonResponse()) + .subscribe(new RxObserver() { + @Override + public void _onSubscribe(Disposable d) { + } + + @Override + public void _onNext(String info) { + try { + JSONObject jsonObject = new JSONObject(info); + if (jsonObject.optInt("code") == 200) { + getView().saveFoodGoodsUseInfoSuccess("提交成功"); + } else { + getView().saveFoodGoodsUseInfoFail(jsonObject.optString("message")); + } + } catch (JSONException e) { + e.printStackTrace(); + if (getView() != null) + getView().saveFoodGoodsUseInfoFail("数据解析异常"); + } + + } + + @Override + public void _onError(String errorMessage) { + if (getView() != null) + getView().saveFoodGoodsUseInfoFail(errorMessage); + } + + @Override + public void _onComplete() { + if (getView() != null) { + getView().hideProgress(); + } + } + }); + } } diff --git a/app/src/main/java/com/sw/st/ui/setting/IngredientAdapter.java b/app/src/main/java/com/sw/st/ui/setting/IngredientAdapter.java new file mode 100644 index 0000000..19f8e7e --- /dev/null +++ b/app/src/main/java/com/sw/st/ui/setting/IngredientAdapter.java @@ -0,0 +1,72 @@ +package com.sw.st.ui.setting; + +import static com.sw.st.utils.AppUtil.extractFirstPart; + +import android.content.Context; +import android.widget.RelativeLayout; + +import com.chad.library.adapter.base.BaseQuickAdapter; +import com.chad.library.adapter.base.viewholder.BaseViewHolder; +import com.sw.st.R; +import com.sw.st.model.FoodGoodsInfo; +import com.sw.st.model.ScalesFoodList; +import com.sw.st.utils.AppUtil; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class IngredientAdapter extends BaseQuickAdapter { + + Context context; + + public IngredientAdapter(@Nullable List listModels, Context context) { + super(R.layout.item_ingredient, listModels); + this.context = context; + } + + + @Override + protected void convert(@NotNull BaseViewHolder baseViewHolder, FoodGoodsInfo info) { + + RelativeLayout relativeLayout = baseViewHolder.findView(R.id.ingredientItemLayout); +// relativeLayout.setSelected(info.isSelect()); + + baseViewHolder.setText(R.id.nameTv, extractFirstPart(info.getGoodsName())); + baseViewHolder.setText(R.id.weightTv, info.getUseRealWeight() + "kg"); + baseViewHolder.setText(R.id.calcWeightTv, info.getUseWeight() + "kg"); + String pct = AppUtil.calcPct(info.getUseWeight(), info.getUseRealWeight()); + baseViewHolder.setText(R.id.pctTv, pct); + if (Math.abs(AppUtil.extractNumber(pct)) > 5) { + baseViewHolder.setTextColor(R.id.pctTv, getContext().getColor(R.color.chart_red)); + } else { + baseViewHolder.setTextColor(R.id.pctTv, getContext().getColor(R.color.chart_green)); + } + switch (info.getMaterialType()) {//1主料 2辅料 3调料 + case 1: + baseViewHolder.setImageResource(R.id.typeImg, R.mipmap.icon_zc); + break; + case 2: + baseViewHolder.setImageResource(R.id.typeImg, R.mipmap.icon_fc); + break; + } + if (info.getUseRealWeight() > 0) { + baseViewHolder.setImageResource(R.id.checkImg, R.mipmap.img_checkbox_checked); + relativeLayout.setBackgroundResource(R.drawable.a_item_ingredient_bg); +// baseViewHolder.setText(R.id.pctTv, info.getUseWeight() + ""); + } else { + baseViewHolder.setImageResource(R.id.checkImg, R.mipmap.img_checkbox_normal); +// baseViewHolder.setText(R.id.pctTv, info.getUseWeight() + ""); + relativeLayout.setBackgroundResource(R.drawable.a_transparent_bg); + } + + if (info.isSelect()) { + relativeLayout.setBackgroundResource(R.drawable.a_blue_line_bg); + } + + + } + + +} diff --git a/app/src/main/java/com/sw/st/utils/AppUtil.java b/app/src/main/java/com/sw/st/utils/AppUtil.java index 464fe6b..b069ebd 100644 --- a/app/src/main/java/com/sw/st/utils/AppUtil.java +++ b/app/src/main/java/com/sw/st/utils/AppUtil.java @@ -658,4 +658,60 @@ public class AppUtil { int min2 = Math.min(min1, c); // 使用之前计算的最小值来比较第三个 return min2; } + + /** + * 计算偏移量 + * + * @param weight + * @param realWeight + * @return + */ + public static String calcPct(double weight, double realWeight) { + if (weight == 0 || realWeight == 0) { + return "--"; + } + double pct = (realWeight - weight) / weight; + System.out.println(pct); + String pctStr = ""; + if (pct > 0) { + pctStr = "+" + (int) (pct * 100) + "%"; + } else { + pctStr = (int) (pct * 100) + "%"; + } + return pctStr; + } + + /** + * 取字符串中数字 + * + * @param input + * @return + */ + public static int extractNumber(String input) { + // 使用正则表达式替换掉字符串中所有非数字、非负号的字符 + String numberStr = input.replaceAll("[^-0-9.]", ""); + try { + return Integer.parseInt(numberStr); + } catch (Exception e) { + return 0; + } + } + + /** + * 从逗号分隔的字符串中提取第一个逗号前的内容 + * + * @param input 输入的逗号分隔的字符串 + * @return 第一个逗号前的字符串内容,如果没有逗号则返回原字符串 + */ + public static String extractFirstPart(String input) { + if (AppUtil.isEmpty(input)) { + return ""; + } + int commaIndex = input.indexOf(','); + if (commaIndex == -1) { + return input; + } + return input.substring(0, commaIndex); + } + } diff --git a/app/src/main/java/com/sw/st/utils/CrashHandler.java b/app/src/main/java/com/sw/st/utils/CrashHandler.java index 2ee11f6..59a3726 100644 --- a/app/src/main/java/com/sw/st/utils/CrashHandler.java +++ b/app/src/main/java/com/sw/st/utils/CrashHandler.java @@ -85,9 +85,9 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { PrefUtils.setString(mContext, "crashUrl", InitActivity.BASE_URL + DeviceUrl); PrefUtils.setString(mContext, "crashData", Convert.toJson(requestMap)); - Intent intent = new Intent(mContext, InitActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.startActivity(intent); +// Intent intent = new Intent(mContext, InitActivity.class); +// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// mContext.startActivity(intent); android.os.Process.killProcess(android.os.Process.myPid()); return true; diff --git a/app/src/main/java/com/sw/st/view/FoodWarningPopup.java b/app/src/main/java/com/sw/st/view/FoodWarningPopup.java new file mode 100644 index 0000000..62baaaf --- /dev/null +++ b/app/src/main/java/com/sw/st/view/FoodWarningPopup.java @@ -0,0 +1,68 @@ +package com.sw.st.view; + +import static com.sw.st.ui.setting.FoodSettingActivity.REST_NAME; +import static com.sw.st.ui.setting.FoodSettingActivity.REST_NUM; + +import android.content.Context; +import android.view.KeyEvent; +import android.view.View; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import com.lxj.xpopup.core.CenterPopupView; +import com.sw.st.R; +import com.sw.st.api.SwService; +import com.sw.st.net.helper.rxjavahelper.RxObserver; +import com.sw.st.net.helper.rxjavahelper.RxResultHelper; +import com.sw.st.net.helper.rxjavahelper.RxSchedulersHelper; +import com.sw.st.utils.AppUtil; +import com.sw.st.utils.InputMethod; +import com.sw.st.utils.PrefUtils; + +import org.json.JSONException; +import org.json.JSONObject; + + +public class FoodWarningPopup extends CenterPopupView { + private Context context; + + + public FoodWarningPopup(@NonNull Context context) { + super(context); + this.context = context; + } + + @Override + protected int getImplLayoutId() { + return R.layout.popup_food_warning; + } + + @Override + protected void onCreate() { + super.onCreate(); + findViewById(R.id.okTv).setOnClickListener(v -> { + dismiss(); + }); + } + + protected void onShow() { + super.onShow(); + } + + + @Override + protected int getMaxHeight() { + return 0; + } + + //返回0表示让宽度撑满window,或者你可以返回一个任意宽度 + @Override + protected int getMaxWidth() { + return 0; + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/a_blue_bg.xml b/app/src/main/res/drawable/a_blue_bg.xml new file mode 100644 index 0000000..2a1ee91 --- /dev/null +++ b/app/src/main/res/drawable/a_blue_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_blue_line_bg.xml b/app/src/main/res/drawable/a_blue_line_bg.xml new file mode 100644 index 0000000..da11c92 --- /dev/null +++ b/app/src/main/res/drawable/a_blue_line_bg.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_gray_bg.xml b/app/src/main/res/drawable/a_gray_bg.xml new file mode 100644 index 0000000..d5e7401 --- /dev/null +++ b/app/src/main/res/drawable/a_gray_bg.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_gray_button.xml b/app/src/main/res/drawable/a_gray_button.xml new file mode 100644 index 0000000..412e0c9 --- /dev/null +++ b/app/src/main/res/drawable/a_gray_button.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_gray_fill_bg.xml b/app/src/main/res/drawable/a_gray_fill_bg.xml new file mode 100644 index 0000000..c10bd1d --- /dev/null +++ b/app/src/main/res/drawable/a_gray_fill_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_ingredient_item.xml b/app/src/main/res/drawable/a_ingredient_item.xml new file mode 100644 index 0000000..89de5eb --- /dev/null +++ b/app/src/main/res/drawable/a_ingredient_item.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_item_ingredient_bg.xml b/app/src/main/res/drawable/a_item_ingredient_bg.xml new file mode 100644 index 0000000..1fd8065 --- /dev/null +++ b/app/src/main/res/drawable/a_item_ingredient_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_num_bg.xml b/app/src/main/res/drawable/a_num_bg.xml new file mode 100644 index 0000000..8764c5e --- /dev/null +++ b/app/src/main/res/drawable/a_num_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_orange_bg.xml b/app/src/main/res/drawable/a_orange_bg.xml new file mode 100644 index 0000000..e4f4ac2 --- /dev/null +++ b/app/src/main/res/drawable/a_orange_bg.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_orange_button.xml b/app/src/main/res/drawable/a_orange_button.xml new file mode 100644 index 0000000..87d2a3c --- /dev/null +++ b/app/src/main/res/drawable/a_orange_button.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_orange_fill_bg.xml b/app/src/main/res/drawable/a_orange_fill_bg.xml new file mode 100644 index 0000000..696bd16 --- /dev/null +++ b/app/src/main/res/drawable/a_orange_fill_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_orange_press_fill_bg.xml b/app/src/main/res/drawable/a_orange_press_fill_bg.xml new file mode 100644 index 0000000..236af2f --- /dev/null +++ b/app/src/main/res/drawable/a_orange_press_fill_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/a_transparent_bg.xml b/app/src/main/res/drawable/a_transparent_bg.xml new file mode 100644 index 0000000..b7bc009 --- /dev/null +++ b/app/src/main/res/drawable/a_transparent_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/new_food_item.xml b/app/src/main/res/drawable/new_food_item.xml new file mode 100644 index 0000000..ce42a82 --- /dev/null +++ b/app/src/main/res/drawable/new_food_item.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 6d45a5b..170d65f 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -43,37 +43,34 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" - android:paddingLeft="32dp" - android:paddingRight="32dp" - android:paddingBottom="32dp"> + android:paddingLeft="@dimen/dp14" + android:paddingRight="@dimen/dp14" + android:paddingBottom="@dimen/dp14"> + android:layout_weight="3" + android:orientation="vertical"> + android:layout_height="@dimen/dp64" + android:background="@drawable/a_gray_bg"> @@ -90,138 +87,460 @@ android:visibility="gone" /> - - - - - - - - - - - - - - - + android:gravity="center" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + android:gravity="center_vertical" + android:orientation="horizontal" + android:paddingLeft="@dimen/dp24" + android:paddingTop="@dimen/dp22" + android:paddingRight="@dimen/dp24" + android:paddingBottom="@dimen/dp22"> + + + + + + + + + + + + + + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1"> - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:textColor="#fffe8402" + android:textSize="@dimen/sp18" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_marginTop="@dimen/dp22" + android:text="--" + android:textColor="@color/white" + android:textSize="@dimen/sp24" /> + + + + + + + - + android:text="确定" + android:textColor="@color/white" + android:textSize="@dimen/sp30" /> - - + -