Commit 0f8ff26c by wjg

修改购物车数据格式

parent 235a6e22
...@@ -3,12 +3,13 @@ package com.ihaoin.hooloo.device.config; ...@@ -3,12 +3,13 @@ package com.ihaoin.hooloo.device.config;
public class AppConfig { public class AppConfig {
public static Boolean DEBUG = true; // TODO false public static Boolean DEBUG = true; // TODO false
public static String TAG = "HL_TEST"; public static String HL = "HL";
public static String TAG_PUSH = TAG + "_PUSH"; public static String TAG = HL + "_TEST";
public static String TAG_NETWORK = TAG + "_NETWORK"; public static String TAG_PUSH = HL + "_PUSH";
public static String TAG_NETWORK = HL + "_NETWORK";
/** 点单屏编码 */ /** 点单屏编码 */
public static String DEFAULT_SCREEN_NO = "A"; public static String DEFAULT_SCREEN_NO = "1";
/** 机器编码 */ /** 机器编码 */
public static String MACHINE_CODE = ""; public static String MACHINE_CODE = "";
/** 打开微信网址 */ /** 打开微信网址 */
......
...@@ -23,12 +23,14 @@ import androidx.viewpager.widget.ViewPager; ...@@ -23,12 +23,14 @@ import androidx.viewpager.widget.ViewPager;
import com.ihaoin.hooloo.device.HLApplication; import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.component.IntroViewPager; import com.ihaoin.hooloo.device.component.IntroViewPager;
import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.config.Base; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.enums.SkuState; import com.ihaoin.hooloo.device.data.enums.SkuState;
import com.ihaoin.hooloo.device.data.vo.Goods; import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.GoodsRule; import com.ihaoin.hooloo.device.data.vo.GoodsRule;
import com.ihaoin.hooloo.device.data.vo.Sku; import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.data.vo.SkuRule; import com.ihaoin.hooloo.device.data.vo.SkuRule;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.CollectionUtils; import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.StringUtils; import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils; import com.ihaoin.hooloo.device.util.Utils;
...@@ -40,8 +42,10 @@ import java.util.Map; ...@@ -40,8 +42,10 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class GoodsDetailDialog extends Dialog { public class GoodsDetailDialog extends Dialog {
private Goods goods; private Goods mGoods;
private Sku checkSku; private Sku mSku;
private Integer mCount = 1;
private View butnClose; private View butnClose;
private IntroViewPager introPager; private IntroViewPager introPager;
private RadioGroup introIndicator; private RadioGroup introIndicator;
...@@ -60,12 +64,11 @@ public class GoodsDetailDialog extends Dialog { ...@@ -60,12 +64,11 @@ public class GoodsDetailDialog extends Dialog {
private View layoutButns; private View layoutButns;
private View txtSellout; private View txtSellout;
private Integer count = 1;
private List<View> introViews; private List<View> introViews;
public GoodsDetailDialog(@NonNull Context context, Goods goods) { public GoodsDetailDialog(@NonNull Context context, Goods goods) {
super(context); super(context);
this.goods = goods; this.mGoods = goods;
} }
@Override @Override
...@@ -97,9 +100,9 @@ public class GoodsDetailDialog extends Dialog { ...@@ -97,9 +100,9 @@ public class GoodsDetailDialog extends Dialog {
butnClose.setOnClickListener(x -> dismiss()); butnClose.setOnClickListener(x -> dismiss());
introViews = new ArrayList<>(); introViews = new ArrayList<>();
if (goods.getPics() != null && !CollectionUtils.isEmpty(goods.getPics().getIntroImages())) { if (mGoods.getPics() != null && !CollectionUtils.isEmpty(mGoods.getPics().getIntroImages())) {
for (int i = 0; i < goods.getPics().getIntroImages().size(); i++) { for (int i = 0; i < mGoods.getPics().getIntroImages().size(); i++) {
String url = goods.getPics().getIntroImages().get(i); String url = mGoods.getPics().getIntroImages().get(i);
View imgIntro = getIntroImage(url); View imgIntro = getIntroImage(url);
View btnIntro = getIntroButton(i); View btnIntro = getIntroButton(i);
introViews.add(imgIntro); introViews.add(imgIntro);
...@@ -130,9 +133,9 @@ public class GoodsDetailDialog extends Dialog { ...@@ -130,9 +133,9 @@ public class GoodsDetailDialog extends Dialog {
} }
} }
txtName.setText(goods.getName()); txtName.setText(mGoods.getName());
txtPrice.setText(Utils.toString(goods.getPrice())); txtPrice.setText(Utils.toString(mGoods.getPrice()));
txtDiscount.setText(Utils.toString(goods.getDiscount())); txtDiscount.setText(Utils.toString(mGoods.getDiscount()));
butnSubtract.setOnClickListener(v -> subtractGoods()); butnSubtract.setOnClickListener(v -> subtractGoods());
butnAdd.setOnClickListener(v -> addGoods()); butnAdd.setOnClickListener(v -> addGoods());
...@@ -231,46 +234,70 @@ public class GoodsDetailDialog extends Dialog { ...@@ -231,46 +234,70 @@ public class GoodsDetailDialog extends Dialog {
return imgIntro; return imgIntro;
} }
class CheckGoodsHandler extends NetworkHandler {
private Goods goods;
private Sku sku;
private Integer count;
public CheckGoodsHandler(Goods goods, Sku sku, Integer count) {
super();
this.goods = goods;
this.sku = sku;
this.count = count;
}
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what != 1) {
Toast.makeText(getContext(), R.string.error_check_sku, Toast.LENGTH_SHORT).show();
return;
}
Utils.showConfirmOrder(getContext(), goods, sku, count);
dismiss();
}
}
private void buyNow() { private void buyNow() {
if (checkSku == null) { if (mSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return; return;
} }
Utils.showConfirmOrder(getContext(), goods, checkSku, count); CheckGoodsHandler handler = new CheckGoodsHandler(mGoods, mSku, mCount);
dismiss(); HttpUtil.checkSku(mSku.getSkuId(), handler);
} }
private void addTrolley() { private void addTrolley() {
if (checkSku == null) { if (mSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return; return;
} }
Utils.sendAddGoodsBroadcast(getContext(), goods, checkSku, count); Utils.sendAddGoodsBroadcast(getContext(), mGoods, mSku, mCount);
dismiss(); dismiss();
} }
private void addGoods() { private void addGoods() {
if (count >= HLApplication.getMainData().getCountOfOrder()) { if (mCount >= HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show(); Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return; return;
} }
count++; mCount++;
txtCount.setText(String.valueOf(count)); txtCount.setText(String.valueOf(mCount));
} }
private void subtractGoods() { private void subtractGoods() {
if (count <= 1) { if (mCount <= 1) {
return; return;
} }
count--; mCount--;
txtCount.setText(String.valueOf(count)); txtCount.setText(String.valueOf(mCount));
} }
private void buildSpecs() { private void buildSpecs() {
if (CollectionUtils.isEmpty(goods.getSpecs())) { if (CollectionUtils.isEmpty(mGoods.getSpecs())) {
return; return;
} }
goods.getSpecs().forEach(spec -> { mGoods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) { if (CollectionUtils.isEmpty(spec.getRules())) {
return; return;
} }
...@@ -341,13 +368,13 @@ public class GoodsDetailDialog extends Dialog { ...@@ -341,13 +368,13 @@ public class GoodsDetailDialog extends Dialog {
} }
rules.add((GoodsRule) view.getTag()); rules.add((GoodsRule) view.getTag());
} }
checkSku = matchSku(rules); mSku = matchSku(rules);
if (checkSku == null) { if (mSku == null) {
// Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show(); // Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return; return;
} }
txtPrice.setText(Utils.toString(checkSku.getPrice())); txtPrice.setText(Utils.toString(mSku.getPrice()));
txtDiscount.setText(Utils.toString(checkSku.getDiscount())); txtDiscount.setText(Utils.toString(mSku.getDiscount()));
} }
private View getSelectedView(LinearLayout layoutRules) { private View getSelectedView(LinearLayout layoutRules) {
...@@ -367,11 +394,11 @@ public class GoodsDetailDialog extends Dialog { ...@@ -367,11 +394,11 @@ public class GoodsDetailDialog extends Dialog {
if (CollectionUtils.isEmpty(rules)) { if (CollectionUtils.isEmpty(rules)) {
return null; return null;
} }
if (CollectionUtils.isEmpty(goods.getSkus())) { if (CollectionUtils.isEmpty(mGoods.getSkus())) {
return null; return null;
} }
List<Integer> checkRuleIds = rules.stream().map(GoodsRule::getRuleId).sorted().collect(Collectors.toList()); List<Integer> checkRuleIds = rules.stream().map(GoodsRule::getRuleId).sorted().collect(Collectors.toList());
for (Sku sku : goods.getSkus()) { for (Sku sku : mGoods.getSkus()) {
List<Integer> skuRuleIds = sku.getRules().stream().map(SkuRule::getRuleId).sorted().collect(Collectors.toList()); List<Integer> skuRuleIds = sku.getRules().stream().map(SkuRule::getRuleId).sorted().collect(Collectors.toList());
if (skuRuleIds.toString().equals(checkRuleIds.toString())) { if (skuRuleIds.toString().equals(checkRuleIds.toString())) {
return sku; return sku;
...@@ -381,29 +408,29 @@ public class GoodsDetailDialog extends Dialog { ...@@ -381,29 +408,29 @@ public class GoodsDetailDialog extends Dialog {
} }
private void buildDetails() { private void buildDetails() {
if (goods.getPics() == null || CollectionUtils.isEmpty(goods.getPics().getDetailImages())) { if (mGoods.getPics() == null || CollectionUtils.isEmpty(mGoods.getPics().getDetailImages())) {
return; return;
} }
goods.getPics().getDetailImages().forEach(url -> { mGoods.getPics().getDetailImages().forEach(url -> {
if (StringUtils.isEmpty(url)) { if (StringUtils.isEmpty(url)) {
return; return;
} }
ImageView imageView = new ImageView(getContext()); ImageView imageView = new ImageView(getContext());
imageView.setAdjustViewBounds(true); imageView.setAdjustViewBounds(true);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.bottomMargin = Utils.getDimens(getContext(), R.dimen.padding5); // layoutParams.bottomMargin = Utils.getDimens(getContext(), R.dimen.padding5);
Utils.getGlide(getContext()).load(url).into(imageView); Utils.getGlide(getContext()).load(url).into(imageView);
layoutImages.addView(imageView, layoutParams); layoutImages.addView(imageView, layoutParams);
}); });
} }
private void processSpecRules() { private void processSpecRules() {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs()) || CollectionUtils.isEmpty(goods.getSkus())) { if (mGoods == null || CollectionUtils.isEmpty(mGoods.getSpecs()) || CollectionUtils.isEmpty(mGoods.getSkus())) {
showSelloutViews(); showSelloutViews();
return; return;
} }
// 将商品所有SKU列表按售罄和未售罄分组 // 将商品所有SKU列表按售罄和未售罄分组
Map<Integer, List<Sku>> map = goods.getSkus().stream().collect(Collectors.groupingBy(Sku::getState)); Map<Integer, List<Sku>> map = mGoods.getSkus().stream().collect(Collectors.groupingBy(Sku::getState));
if (CollectionUtils.isEmpty(map)) { if (CollectionUtils.isEmpty(map)) {
return; return;
} }
...@@ -452,10 +479,10 @@ public class GoodsDetailDialog extends Dialog { ...@@ -452,10 +479,10 @@ public class GoodsDetailDialog extends Dialog {
/** 设备商品规格 选项状态 */ /** 设备商品规格 选项状态 */
private void setRuleState(SkuRule skuRule, Integer ruleState) { private void setRuleState(SkuRule skuRule, Integer ruleState) {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) { if (mGoods == null || CollectionUtils.isEmpty(mGoods.getSpecs())) {
return; return;
} }
goods.getSpecs().forEach(spec -> { mGoods.getSpecs().forEach(spec -> {
// 选项为空的规格不处理 // 选项为空的规格不处理
if (CollectionUtils.isEmpty(spec.getRules())) { if (CollectionUtils.isEmpty(spec.getRules())) {
return; return;
...@@ -477,10 +504,10 @@ public class GoodsDetailDialog extends Dialog { ...@@ -477,10 +504,10 @@ public class GoodsDetailDialog extends Dialog {
} }
private void setAllRuleSellouts() { private void setAllRuleSellouts() {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) { if (mGoods == null || CollectionUtils.isEmpty(mGoods.getSpecs())) {
return; return;
} }
goods.getSpecs().forEach(spec -> { mGoods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) { if (CollectionUtils.isEmpty(spec.getRules())) {
return; return;
} }
......
...@@ -72,7 +72,7 @@ public class SettingsActivity extends Activity { ...@@ -72,7 +72,7 @@ public class SettingsActivity extends Activity {
private void showEditScreen() { private void showEditScreen() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("修改点单屏编码"); builder.setTitle("修改点单屏编码");
String[] items = new String[]{"A", "B"}; String[] items = new String[]{"1", "2"};
builder.setSingleChoiceItems(items, StringUtils.indexOf(items, SharedPreferencesUtils.getScreenNo(SettingsActivity.this)), (dialog, which) -> { builder.setSingleChoiceItems(items, StringUtils.indexOf(items, SharedPreferencesUtils.getScreenNo(SettingsActivity.this)), (dialog, which) -> {
SharedPreferencesUtils.setScreenNo(SettingsActivity.this, items[which]); SharedPreferencesUtils.setScreenNo(SettingsActivity.this, items[which]);
txtScreenNo.setText(SharedPreferencesUtils.getScreenNo(SettingsActivity.this)); txtScreenNo.setText(SharedPreferencesUtils.getScreenNo(SettingsActivity.this));
......
...@@ -94,7 +94,7 @@ public class TrolleyView extends RelativeLayout { ...@@ -94,7 +94,7 @@ public class TrolleyView extends RelativeLayout {
public void handleMessage(@NonNull Message msg) { public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
if (msg.what != 1) { if (msg.what != 1) {
Toast.makeText(getContext(), ((Exception) msg.obj).getMessage(), Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.error_check_sku, Toast.LENGTH_SHORT).show();
return; return;
} }
addGoods(goods, sku, count); addGoods(goods, sku, count);
......
...@@ -10,4 +10,5 @@ ...@@ -10,4 +10,5 @@
<string name="error_price">商品金额错误</string> <string name="error_price">商品金额错误</string>
<string name="error_sku_state">本商品已售罄或已经下架</string> <string name="error_sku_state">本商品已售罄或已经下架</string>
<string name="error_load_main_data">获取数据失败</string> <string name="error_load_main_data">获取数据失败</string>
<string name="error_check_sku">商品状态获取失败</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment