Commit 0f8ff26c by wjg

修改购物车数据格式

parent 235a6e22
......@@ -3,12 +3,13 @@ package com.ihaoin.hooloo.device.config;
public class AppConfig {
public static Boolean DEBUG = true; // TODO false
public static String TAG = "HL_TEST";
public static String TAG_PUSH = TAG + "_PUSH";
public static String TAG_NETWORK = TAG + "_NETWORK";
public static String HL = "HL";
public static String TAG = HL + "_TEST";
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 = "";
/** 打开微信网址 */
......
......@@ -23,12 +23,14 @@ import androidx.viewpager.widget.ViewPager;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
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.data.enums.SkuState;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.GoodsRule;
import com.ihaoin.hooloo.device.data.vo.Sku;
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.StringUtils;
import com.ihaoin.hooloo.device.util.Utils;
......@@ -40,8 +42,10 @@ import java.util.Map;
import java.util.stream.Collectors;
public class GoodsDetailDialog extends Dialog {
private Goods goods;
private Sku checkSku;
private Goods mGoods;
private Sku mSku;
private Integer mCount = 1;
private View butnClose;
private IntroViewPager introPager;
private RadioGroup introIndicator;
......@@ -60,12 +64,11 @@ public class GoodsDetailDialog extends Dialog {
private View layoutButns;
private View txtSellout;
private Integer count = 1;
private List<View> introViews;
public GoodsDetailDialog(@NonNull Context context, Goods goods) {
super(context);
this.goods = goods;
this.mGoods = goods;
}
@Override
......@@ -97,9 +100,9 @@ public class GoodsDetailDialog extends Dialog {
butnClose.setOnClickListener(x -> dismiss());
introViews = new ArrayList<>();
if (goods.getPics() != null && !CollectionUtils.isEmpty(goods.getPics().getIntroImages())) {
for (int i = 0; i < goods.getPics().getIntroImages().size(); i++) {
String url = goods.getPics().getIntroImages().get(i);
if (mGoods.getPics() != null && !CollectionUtils.isEmpty(mGoods.getPics().getIntroImages())) {
for (int i = 0; i < mGoods.getPics().getIntroImages().size(); i++) {
String url = mGoods.getPics().getIntroImages().get(i);
View imgIntro = getIntroImage(url);
View btnIntro = getIntroButton(i);
introViews.add(imgIntro);
......@@ -130,9 +133,9 @@ public class GoodsDetailDialog extends Dialog {
}
}
txtName.setText(goods.getName());
txtPrice.setText(Utils.toString(goods.getPrice()));
txtDiscount.setText(Utils.toString(goods.getDiscount()));
txtName.setText(mGoods.getName());
txtPrice.setText(Utils.toString(mGoods.getPrice()));
txtDiscount.setText(Utils.toString(mGoods.getDiscount()));
butnSubtract.setOnClickListener(v -> subtractGoods());
butnAdd.setOnClickListener(v -> addGoods());
......@@ -231,46 +234,70 @@ public class GoodsDetailDialog extends Dialog {
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() {
if (checkSku == null) {
if (mSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return;
}
Utils.showConfirmOrder(getContext(), goods, checkSku, count);
dismiss();
CheckGoodsHandler handler = new CheckGoodsHandler(mGoods, mSku, mCount);
HttpUtil.checkSku(mSku.getSkuId(), handler);
}
private void addTrolley() {
if (checkSku == null) {
if (mSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return;
}
Utils.sendAddGoodsBroadcast(getContext(), goods, checkSku, count);
Utils.sendAddGoodsBroadcast(getContext(), mGoods, mSku, mCount);
dismiss();
}
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();
return;
}
count++;
txtCount.setText(String.valueOf(count));
mCount++;
txtCount.setText(String.valueOf(mCount));
}
private void subtractGoods() {
if (count <= 1) {
if (mCount <= 1) {
return;
}
count--;
txtCount.setText(String.valueOf(count));
mCount--;
txtCount.setText(String.valueOf(mCount));
}
private void buildSpecs() {
if (CollectionUtils.isEmpty(goods.getSpecs())) {
if (CollectionUtils.isEmpty(mGoods.getSpecs())) {
return;
}
goods.getSpecs().forEach(spec -> {
mGoods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) {
return;
}
......@@ -341,13 +368,13 @@ public class GoodsDetailDialog extends Dialog {
}
rules.add((GoodsRule) view.getTag());
}
checkSku = matchSku(rules);
if (checkSku == null) {
mSku = matchSku(rules);
if (mSku == null) {
// Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return;
}
txtPrice.setText(Utils.toString(checkSku.getPrice()));
txtDiscount.setText(Utils.toString(checkSku.getDiscount()));
txtPrice.setText(Utils.toString(mSku.getPrice()));
txtDiscount.setText(Utils.toString(mSku.getDiscount()));
}
private View getSelectedView(LinearLayout layoutRules) {
......@@ -367,11 +394,11 @@ public class GoodsDetailDialog extends Dialog {
if (CollectionUtils.isEmpty(rules)) {
return null;
}
if (CollectionUtils.isEmpty(goods.getSkus())) {
if (CollectionUtils.isEmpty(mGoods.getSkus())) {
return null;
}
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());
if (skuRuleIds.toString().equals(checkRuleIds.toString())) {
return sku;
......@@ -381,29 +408,29 @@ public class GoodsDetailDialog extends Dialog {
}
private void buildDetails() {
if (goods.getPics() == null || CollectionUtils.isEmpty(goods.getPics().getDetailImages())) {
if (mGoods.getPics() == null || CollectionUtils.isEmpty(mGoods.getPics().getDetailImages())) {
return;
}
goods.getPics().getDetailImages().forEach(url -> {
mGoods.getPics().getDetailImages().forEach(url -> {
if (StringUtils.isEmpty(url)) {
return;
}
ImageView imageView = new ImageView(getContext());
imageView.setAdjustViewBounds(true);
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);
layoutImages.addView(imageView, layoutParams);
});
}
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();
return;
}
// 将商品所有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)) {
return;
}
......@@ -452,10 +479,10 @@ public class GoodsDetailDialog extends Dialog {
/** 设备商品规格 选项状态 */
private void setRuleState(SkuRule skuRule, Integer ruleState) {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
if (mGoods == null || CollectionUtils.isEmpty(mGoods.getSpecs())) {
return;
}
goods.getSpecs().forEach(spec -> {
mGoods.getSpecs().forEach(spec -> {
// 选项为空的规格不处理
if (CollectionUtils.isEmpty(spec.getRules())) {
return;
......@@ -477,10 +504,10 @@ public class GoodsDetailDialog extends Dialog {
}
private void setAllRuleSellouts() {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
if (mGoods == null || CollectionUtils.isEmpty(mGoods.getSpecs())) {
return;
}
goods.getSpecs().forEach(spec -> {
mGoods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) {
return;
}
......
......@@ -72,7 +72,7 @@ public class SettingsActivity extends Activity {
private void showEditScreen() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
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) -> {
SharedPreferencesUtils.setScreenNo(SettingsActivity.this, items[which]);
txtScreenNo.setText(SharedPreferencesUtils.getScreenNo(SettingsActivity.this));
......
......@@ -94,7 +94,7 @@ public class TrolleyView extends RelativeLayout {
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
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;
}
addGoods(goods, sku, count);
......
......@@ -10,4 +10,5 @@
<string name="error_price">商品金额错误</string>
<string name="error_sku_state">本商品已售罄或已经下架</string>
<string name="error_load_main_data">获取数据失败</string>
<string name="error_check_sku">商品状态获取失败</string>
</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