Commit cdeeadd6 by wjg

init

parent c8dcfce4
...@@ -2,11 +2,16 @@ package com.ihaoin.hooloo.device; ...@@ -2,11 +2,16 @@ package com.ihaoin.hooloo.device;
import android.app.Application; import android.app.Application;
import com.ihaoin.hooloo.device.config.AppConfig;
public class HLApplication extends Application { public class HLApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
AppConfig.MACHINE_CODE = ""; // TODO 获取机器编码
AppConfig.SCREEN_NO = ""; // TODO 点单屏编码
} }
@Override @Override
......
...@@ -3,6 +3,7 @@ package com.ihaoin.hooloo.device.adapter; ...@@ -3,6 +3,7 @@ package com.ihaoin.hooloo.device.adapter;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -13,12 +14,18 @@ import com.bumptech.glide.request.RequestOptions; ...@@ -13,12 +14,18 @@ import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseSectionQuickAdapter; import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.BaseViewHolder;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.data.Goods; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.ScrollBean; import com.ihaoin.hooloo.device.data.ScrollBean;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
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;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHolder> { public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHolder> {
private Context mContext; private Context mContext;
...@@ -63,10 +70,47 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo ...@@ -63,10 +70,47 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
RequestOptions options = RequestOptions.bitmapTransform(roundedCorners); RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
Glide.with(mContext).load(goods.getPics().getThumbnail()).apply(options).into(imgThumbnail); Glide.with(mContext).load(goods.getPics().getThumbnail()).apply(options).into(imgThumbnail);
Sku sku = getSku(goods.getSkus());
if (sku == null) {
helper.setGone(R.id.txt_sellout, true);
helper.setGone(R.id.butn_add, false);
} else {
helper.setGone(R.id.txt_sellout, false);
helper.setGone(R.id.butn_add, true);
View butnAdd = helper.getView(R.id.butn_add); View butnAdd = helper.getView(R.id.butn_add);
butnAdd.setOnClickListener(v -> Utils.sendBroadcast(mContext, goods, goods.getSkus().get(0), 1)); butnAdd.setOnClickListener(v -> Utils.sendAddGoodsBroadcast(mContext, goods, sku, 1));
ViewGroup layoutItem = helper.getView(R.id.layout_item);
Utils.setTouchDelegate(layoutItem, Arrays.asList(butnAdd), 15);
// butnAdd.post(() -> {
// Rect bounds = new Rect();
// ViewGroupUtils.getDescendantRect(layoutItem, butnAdd, bounds);
// bounds.top -= Utils.dpToPx(mContext, 15);
// bounds.left -= Utils.dpToPx(mContext, 15);
// bounds.bottom += Utils.dpToPx(mContext, 15);
// bounds.right += Utils.dpToPx(mContext, 15);
// layoutItem.setTouchDelegate(new TouchDelegate(bounds, butnAdd));
// });
}
View layoutItem = helper.getView(R.id.layout_item); View layoutItem = helper.getView(R.id.layout_item);
layoutItem.setOnClickListener(v -> Utils.showGoodsDetail(mContext, goods)); layoutItem.setOnClickListener(v -> Utils.showGoodsDetail(mContext, goods));
} }
/** 获取SKU,优选获取默认的SKU */
private Sku getSku(List<Sku> skus) {
if (CollectionUtils.isEmpty(skus)) {
return null;
}
Optional<Sku> optional = skus.stream().filter(x -> Base.TRUE.equals(x.getIsDefault()) && Base.TRUE.equals(x.getState())).findAny();
if (optional.isPresent()) {
return optional.get();
}
optional = skus.stream().filter(x -> Base.TRUE.equals(x.getState())).findAny();
if (optional.isPresent()) {
return optional.get();
}
return null;
}
} }
...@@ -10,7 +10,7 @@ import com.bumptech.glide.request.RequestOptions; ...@@ -10,7 +10,7 @@ import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseSectionQuickAdapter; import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.BaseViewHolder;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.data.Recommend; import com.ihaoin.hooloo.device.data.vo.Recommend;
import com.ihaoin.hooloo.device.data.ScrollBean; import com.ihaoin.hooloo.device.data.ScrollBean;
import com.ihaoin.hooloo.device.util.Utils; import com.ihaoin.hooloo.device.util.Utils;
......
...@@ -14,8 +14,10 @@ import com.ihaoin.hooloo.device.R; ...@@ -14,8 +14,10 @@ import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.data.TrolleyGoods; import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.util.CollectionUtils; import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.StringAppend; import com.ihaoin.hooloo.device.util.StringAppend;
import com.ihaoin.hooloo.device.util.Utils;
import com.ihaoin.hooloo.device.view.TrolleyView; import com.ihaoin.hooloo.device.view.TrolleyView;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class TrolleyAdapter extends BaseAdapter { public class TrolleyAdapter extends BaseAdapter {
...@@ -57,6 +59,17 @@ public class TrolleyAdapter extends BaseAdapter { ...@@ -57,6 +59,17 @@ public class TrolleyAdapter extends BaseAdapter {
View butnAdd = convertView.findViewById(R.id.butn_add); View butnAdd = convertView.findViewById(R.id.butn_add);
butnState.setChecked(goods.getChecked()); butnState.setChecked(goods.getChecked());
butnState.setOnCheckedChangeListener((buttonView, isChecked) -> {
goods.setChecked(isChecked);
if (isChecked) {
if (!trolleyView.checkGoodsCount()) { // 购物车选中数量超过阈值,不允许选中
goods.setChecked(false);
butnState.setChecked(false);
return;
}
}
trolleyView.goodsChanged();
});
txtName.setText(goods.getName()); txtName.setText(goods.getName());
if (!CollectionUtils.isEmpty(goods.getRules())) { if (!CollectionUtils.isEmpty(goods.getRules())) {
StringAppend stringAppend = new StringAppend("/"); StringAppend stringAppend = new StringAppend("/");
...@@ -74,6 +87,9 @@ public class TrolleyAdapter extends BaseAdapter { ...@@ -74,6 +87,9 @@ public class TrolleyAdapter extends BaseAdapter {
butnAdd.setOnClickListener(v -> trolleyView.addGoods(position)); butnAdd.setOnClickListener(v -> trolleyView.addGoods(position));
Glide.with(mContext).load(goods.getPics().getThumbnail()).into(imgThumbnail); Glide.with(mContext).load(goods.getPics().getThumbnail()).into(imgThumbnail);
ViewGroup layoutItem = convertView.findViewById(R.id.layout_item);
Utils.setTouchDelegate(layoutItem, Arrays.asList(butnAdd, butnSubtract), 15);
return convertView; return convertView;
} }
......
package com.ihaoin.hooloo.device.component;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
public class TouchDelegateComposite extends TouchDelegate {
private final List<TouchDelegate> delegates = new ArrayList<TouchDelegate>();
private static final Rect emptyRect = new Rect();
public TouchDelegateComposite(View view) {
super(emptyRect, view);
}
public void addDelegate(TouchDelegate delegate) {
if (delegate != null) {
delegates.add(delegate);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean res = false;
float x = event.getX();
float y = event.getY();
for (TouchDelegate delegate : delegates) {
event.setLocation(x, y);
res = delegate.onTouchEvent(event) || res;
}
return res;
}
}
\ No newline at end of file
package com.ihaoin.hooloo.device.config; package com.ihaoin.hooloo.device.config;
public class AppConfig { public class AppConfig {
// pub /** 机器编码 */
public static String MACHINE_CODE = "";
/** 点单屏编码 */
public static String SCREEN_NO = "";
} }
package com.ihaoin.hooloo.device.config;
public class Base {
public static final Integer TRUE = 1;
public static final Integer FALSE = 0;
}
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data;
import com.ihaoin.hooloo.device.data.vo.Category;
import com.ihaoin.hooloo.device.data.vo.Recommend;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data;
import com.ihaoin.hooloo.device.data.vo.Pics;
import com.ihaoin.hooloo.device.data.vo.SkuRule;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
......
package com.ihaoin.hooloo.device.data.po;
import java.io.Serializable;
public class ConfirmGoods implements Serializable {
/**
* 商品id
*/
private Integer goodsId;
/**
* skuId
*/
private Integer skuId;
/**
* 数量
*/
private Integer count;
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getSkuId() {
return skuId;
}
public void setSkuId(Integer skuId) {
this.skuId = skuId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}
package com.ihaoin.hooloo.device.data.po;
import java.io.Serializable;
import java.util.List;
public class ConfirmOrder implements Serializable {
/**
* 机器编码
*/
private String machineCode;
/**
* 点单屏编码
*/
private String screenNo;
/**
* 商品信息
*/
private List<ConfirmGoods> goods;
public String getMachineCode() {
return machineCode;
}
public void setMachineCode(String machineCode) {
this.machineCode = machineCode;
}
public String getScreenNo() {
return screenNo;
}
public void setScreenNo(String screenNo) {
this.screenNo = screenNo;
}
public List<ConfirmGoods> getGoods() {
return goods;
}
public void setGoods(List<ConfirmGoods> goods) {
this.goods = goods;
}
}
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import com.ihaoin.hooloo.device.config.Base;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
public class GoodsRule implements Serializable { public class GoodsRule implements Serializable {
/** 选项id */ /**
* 选项id
*/
private Integer ruleId; private Integer ruleId;
/** 名称 */ /**
* 名称
*/
private String ruleName; private String ruleName;
/** 是否默认 */ /**
* 是否默认
*/
private Integer isDefault; private Integer isDefault;
/** 价格 */ /**
* 状态,1-可售、0-不可售
*/
private Integer state = Base.TRUE;
/**
* 价格
*/
private BigDecimal price; private BigDecimal price;
public Integer getRuleId() { public Integer getRuleId() {
...@@ -45,4 +59,12 @@ public class GoodsRule implements Serializable { ...@@ -45,4 +59,12 @@ public class GoodsRule implements Serializable {
public void setPrice(BigDecimal price) { public void setPrice(BigDecimal price) {
this.price = price; this.price = price;
} }
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
} }
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
...@@ -12,7 +12,6 @@ public class GoodsSpec implements Serializable { ...@@ -12,7 +12,6 @@ public class GoodsSpec implements Serializable {
/** 选项列表 */ /** 选项列表 */
private List<GoodsRule> rules; private List<GoodsRule> rules;
public Integer getSpecId() { public Integer getSpecId() {
return specId; return specId;
} }
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
......
package com.ihaoin.hooloo.device.data; package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
......
package com.ihaoin.hooloo.device.network;
public class BaseParams {
private static final String HOST = "http://www.baidu.com";
public static final String GET_MAIN_DATA = HOST + "/mainData";
public static final String POST_CONFIRM_ORDER = HOST + "/confirm/order";
}
package com.ihaoin.hooloo.device.network;
import android.os.Handler;
import android.os.Message;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class HttpUtil {
public static void post(String url, String body, Handler handler) {
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), body);
Request request = new Request.Builder().url(url).post(requestBody).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
HttpUtil.onFailure(handler, e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
HttpUtil.onResponse(handler, response);
}
});
}
private static void onFailure(Handler handler, Exception e) {
try {
Thread.sleep(3000);
} catch (InterruptedException e3) {
e3.printStackTrace();
}
Message msg = handler.obtainMessage(0, e);
handler.sendMessage(msg);
}
private static void onResponse(Handler handler, Response response) throws IOException {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Message msg = handler.obtainMessage(1, response.body() == null ? "" : response.body().string());
handler.sendMessage(msg);
}
public static void postConfirmOrder(String body, Handler handler) throws IOException {
post(BaseParams.POST_CONFIRM_ORDER, body, handler);
}
}
package com.ihaoin.hooloo.device.util; package com.ihaoin.hooloo.device.util;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
public class CollectionUtils { public class CollectionUtils {
public static Boolean isEmpty(Collection collection) { public static Boolean isEmpty(Collection collection) {
...@@ -9,4 +10,11 @@ public class CollectionUtils { ...@@ -9,4 +10,11 @@ public class CollectionUtils {
} }
return false; return false;
} }
public static Boolean isEmpty(Map map) {
if (map == null || map.isEmpty()) {
return true;
}
return false;
}
} }
package com.ihaoin.hooloo.device.util; package com.ihaoin.hooloo.device.util;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Rect;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewGroup;
import com.ihaoin.hooloo.device.data.Goods; import androidx.coordinatorlayout.widget.ViewGroupUtils;
import com.ihaoin.hooloo.device.data.Sku;
import com.ihaoin.hooloo.device.component.TouchDelegateComposite;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.po.ConfirmGoods;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.view.ConfirmOrderDialog;
import com.ihaoin.hooloo.device.view.GoodsDetailDialog; import com.ihaoin.hooloo.device.view.GoodsDetailDialog;
import com.ihaoin.hooloo.device.view.TipsDialog; import com.ihaoin.hooloo.device.view.TipsDialog;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Utils { public class Utils {
public static String ADD_TROLLEY_ACTION = ""; public static String ADD_GOODS_ACTION = "ADD_GOODS_ACTION";
public static String GOODS_CHANGED_ACTION = "GOODS_CHANGED_ACTION";
public static String CLEAR_GOODS_ACTION = "CLEAR_GOODS_ACTION";
public static void sendBroadcast(Context context, Goods goods, Sku sku, Integer count) { public static void sendAddGoodsBroadcast(Context context, Goods goods, Sku sku, Integer count) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(Utils.ADD_TROLLEY_ACTION); intent.setAction(Utils.ADD_GOODS_ACTION);
intent.putExtra("goods", goods); intent.putExtra("goods", goods);
intent.putExtra("sku", sku); intent.putExtra("sku", sku);
intent.putExtra("count", count); intent.putExtra("count", count);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
public static void sendGoodsChnagedBroadcast(Context context) {
Intent intent = new Intent();
intent.setAction(Utils.GOODS_CHANGED_ACTION);
context.sendBroadcast(intent);
}
public static void sendClearGoodsBroadcast(Context context) {
Intent intent = new Intent();
intent.setAction(Utils.CLEAR_GOODS_ACTION);
context.sendBroadcast(intent);
}
public static void showGoodsDetail(Context context, Goods goods) { public static void showGoodsDetail(Context context, Goods goods) {
GoodsDetailDialog dialog = new GoodsDetailDialog(context, goods); GoodsDetailDialog dialog = new GoodsDetailDialog(context, goods);
dialog.show(); dialog.show();
...@@ -31,6 +60,18 @@ public class Utils { ...@@ -31,6 +60,18 @@ public class Utils {
dialog.show(); dialog.show();
} }
public static void showConfirmOrder(Context context, List<TrolleyGoods> trolleyGoods) {
ConfirmOrderDialog dialog = new ConfirmOrderDialog(context);
dialog.setGoods(trolleyGoods);
dialog.show();
}
public static void showConfirmOrder(Context context, Goods goods, Sku sku, Integer count) {
ConfirmOrderDialog dialog = new ConfirmOrderDialog(context);
dialog.setGoods(goods, sku, count);
dialog.show();
}
/** /**
* 获得资源 dimens (dp) * 获得资源 dimens (dp)
* *
...@@ -55,4 +96,44 @@ public class Utils { ...@@ -55,4 +96,44 @@ public class Utils {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
return (int) ((dp * displayMetrics.density) + 0.5f); return (int) ((dp * displayMetrics.density) + 0.5f);
} }
public static List<ConfirmGoods> translate(List<TrolleyGoods> trolleyGoods) {
if (CollectionUtils.isEmpty(trolleyGoods)) {
return null;
}
return trolleyGoods.stream().map(x -> {
ConfirmGoods g = new ConfirmGoods();
g.setGoodsId(x.getGoodId());
g.setSkuId(x.getSkuId());
g.setCount(x.getCount());
return g;
}).collect(Collectors.toList());
}
public static List<ConfirmGoods> translate(Goods goods, Sku sku, Integer count) {
if (goods == null || sku == null || count <= 0) {
return null;
}
ConfirmGoods g = new ConfirmGoods();
g.setGoodsId(goods.getGoodId());
g.setSkuId(sku.getSkuId());
g.setCount(count);
return Arrays.asList(g);
}
@SuppressLint("RestrictedApi")
public static void setTouchDelegate(ViewGroup group, List<View> views, Integer dp) {
Integer px = Utils.dpToPx(group.getContext(), dp);
TouchDelegateComposite composite = new TouchDelegateComposite(group);
views.forEach(view -> view.post(() -> {
Rect bounds = new Rect();
ViewGroupUtils.getDescendantRect(group, view, bounds);
bounds.top -= px;
bounds.left -= px;
bounds.bottom += px;
bounds.right += px;
composite.addDelegate(new TouchDelegate(bounds, view));
}));
group.setTouchDelegate(composite);
}
} }
package com.ihaoin.hooloo.device.view;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.po.ConfirmGoods;
import com.ihaoin.hooloo.device.data.po.ConfirmOrder;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.Utils;
import java.util.ArrayList;
import java.util.List;
public class ConfirmOrderDialog extends Dialog {
private List<ConfirmGoods> goods = new ArrayList<>();
private UIHandler uiHandler;
private ConfirmOrderHandler confirmOrderHandler;
private Thread expireThread;
private Thread returnThread;
private final Integer EXPIRE_TIMES = 60;
private final Integer RETURN_TIMES = 5;
private View layoutContent;
private View layoutConfirm;
private View layoutSucceed;
private TextView txtExpire;
private TextView txtReturn;
private View butnClose;
private View loading;
public ConfirmOrderDialog(@NonNull Context context) {
super(context);
}
public void setGoods(List<TrolleyGoods> trolleyGoods) {
this.goods = Utils.translate(trolleyGoods);
}
public void setGoods(Goods goods, Sku sku, Integer count) {
this.goods = Utils.translate(goods, sku, count);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.view_confirm_order);
initViews();
}
private void initViews() {
layoutContent = findViewById(R.id.layout_content);
layoutConfirm = findViewById(R.id.layout_confirm);
layoutSucceed = findViewById(R.id.layout_succeed);
txtExpire = findViewById(R.id.txt_expire);
txtReturn = findViewById(R.id.txt_return);
butnClose = findViewById(R.id.butn_close);
loading = findViewById(R.id.loading);
layoutConfirm.setVisibility(View.VISIBLE);
layoutSucceed.setVisibility(View.GONE);
butnClose.setOnClickListener(x -> dismiss());
uiHandler = new UIHandler();
setOnDismissListener(dismissListener);
setCancelable(false);
setCanceledOnTouchOutside(false);
postConfirmOrder();
}
private void postConfirmOrder() {
try {
startLoading();
confirmOrderHandler = new ConfirmOrderHandler();
HttpUtil.postConfirmOrder(genJson(), confirmOrderHandler);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getContext(), R.string.error_get_qrcode, Toast.LENGTH_LONG).show();
dismiss();
}
}
private void startLoading() {
layoutContent.setVisibility(View.INVISIBLE);
loading.setVisibility(View.VISIBLE);
AnimationDrawable animationDrawable = (AnimationDrawable) loading.getBackground();
animationDrawable.start();
}
private void stopLoading() {
layoutContent.setVisibility(View.VISIBLE);
loading.setVisibility(View.INVISIBLE);
AnimationDrawable animationDrawable = (AnimationDrawable) loading.getBackground();
animationDrawable.stop();
}
private String genJson() {
try {
ConfirmOrder confirmOrder = new ConfirmOrder();
confirmOrder.setMachineCode(AppConfig.MACHINE_CODE);
confirmOrder.setScreenNo(AppConfig.SCREEN_NO);
confirmOrder.setGoods(goods);
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(confirmOrder);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
OnDismissListener dismissListener = new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (expireThread != null) {
expireThread.interrupt();
}
if (returnThread != null) {
returnThread.interrupt();
}
if (uiHandler != null) {
uiHandler.removeCallbacksAndMessages(null);
uiHandler = null;
}
if (confirmOrderHandler != null) {
confirmOrderHandler.removeCallbacksAndMessages(null);
confirmOrderHandler = null;
}
}
};
private void startExpireThread() {
expireThread = new Thread() {
@Override
public void run() {
try {
for (int i = EXPIRE_TIMES; i >= 0; i--) {
if (uiHandler == null) {
return;
}
Message msg = new Message();
msg.what = 0;// 二维码失效倒计时
msg.obj = i;
uiHandler.sendMessage(msg);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
expireThread.start();
}
private void startReturnThread() {
returnThread = new Thread() {
@Override
public void run() {
try {
for (int i = RETURN_TIMES; i >= 0; i--) {
if (uiHandler == null) {
return;
}
Message msg = new Message();
msg.what = 1;// 扫码成功倒计时
msg.obj = i;
uiHandler.sendMessage(msg);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
returnThread.start();
}
class UIHandler extends Handler {
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what) {
case 0:
Integer expireTimes = (Integer) msg.obj;
txtExpire.setText(getContext().getString(R.string.expire_times, expireTimes.toString()));
if (expireTimes <= 0) {
Utils.sendClearGoodsBroadcast(getContext());
dismiss();
}
break;
case 1:
Integer returnTimes = (Integer) msg.obj;
txtReturn.setText(getContext().getString(R.string.scan_succeed, returnTimes.toString()));
if (returnTimes <= 0) {
Utils.sendClearGoodsBroadcast(getContext());
dismiss();
}
break;
}
}
}
class ConfirmOrderHandler extends Handler {
@Override
public void handleMessage(@NonNull Message msg) {
stopLoading();
if (msg.what == 0) {
Toast.makeText(getContext(), R.string.error_get_qrcode, Toast.LENGTH_LONG).show();
dismiss();
return;
}
String s = (String) msg.obj;
Log.d("HTTP", s);
startExpireThread();
}
}
}
...@@ -4,24 +4,38 @@ import android.app.Dialog; ...@@ -4,24 +4,38 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.data.Goods; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.Datas;
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.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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class GoodsDetailDialog extends Dialog { public class GoodsDetailDialog extends Dialog {
private Goods goods; private Goods goods;
private Sku checkSku;
private View butnClose; private View butnClose;
private ImageView imgIntro; private ImageView imgIntro;
private TextView txtName; private TextView txtName;
...@@ -35,11 +49,14 @@ public class GoodsDetailDialog extends Dialog { ...@@ -35,11 +49,14 @@ public class GoodsDetailDialog extends Dialog {
private Button butnBuy; private Button butnBuy;
private Button butnTrolley; private Button butnTrolley;
private Integer count; private Integer count = 1;
public GoodsDetailDialog(@NonNull Context context, Goods goods) { public GoodsDetailDialog(@NonNull Context context, Goods goods) {
super(context); super(context);
this.goods = goods; this.goods = goods;
// 处理售罄的SKU和规格选项
processSpecRules();
} }
@Override @Override
...@@ -68,10 +85,54 @@ public class GoodsDetailDialog extends Dialog { ...@@ -68,10 +85,54 @@ public class GoodsDetailDialog extends Dialog {
Glide.with(getContext()).load(goods.getPics().getIntroImages().get(0)).into(imgIntro); Glide.with(getContext()).load(goods.getPics().getIntroImages().get(0)).into(imgIntro);
txtName.setText(goods.getName()); txtName.setText(goods.getName());
butnSubtract.setOnClickListener(v -> subtractGoods());
butnAdd.setOnClickListener(v -> addGoods());
butnBuy.setOnClickListener(v -> buyNow());
butnTrolley.setOnClickListener(v -> addTrolley());
ViewGroup layoutItem = findViewById(R.id.layout_item);
Utils.setTouchDelegate(layoutItem, Arrays.asList(butnAdd, butnSubtract), 15);
buildSpecs(); buildSpecs();
buildDetails(); buildDetails();
} }
private void buyNow() {
if (checkSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return;
}
Utils.showConfirmOrder(getContext(), goods, checkSku, count);
dismiss();
}
private void addTrolley() {
if (checkSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return;
}
Utils.sendAddGoodsBroadcast(getContext(), goods, checkSku, count);
dismiss();
}
private void addGoods() {
if (count >= Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
return;
}
count++;
txtCount.setText(String.valueOf(count));
}
private void subtractGoods() {
if (count <= 1) {
return;
}
count--;
txtCount.setText(String.valueOf(count));
}
private void buildSpecs() { private void buildSpecs() {
if (CollectionUtils.isEmpty(goods.getSpecs())) { if (CollectionUtils.isEmpty(goods.getSpecs())) {
return; return;
...@@ -91,13 +152,56 @@ public class GoodsDetailDialog extends Dialog { ...@@ -91,13 +152,56 @@ public class GoodsDetailDialog extends Dialog {
RadioButton button = (RadioButton) getLayoutInflater().inflate(R.layout.item_spec_rule, null); RadioButton button = (RadioButton) getLayoutInflater().inflate(R.layout.item_spec_rule, null);
button.setId(rule.getRuleId()); button.setId(rule.getRuleId());
button.setText(rule.getRuleName()); button.setText(rule.getRuleName());
if (rule.getIsDefault() != null && rule.getIsDefault().equals(1)) { button.setTag(rule);
if (!Base.TRUE.equals(rule.getState())) {
button.setEnabled(false);
} else if (!Base.TRUE.equals(rule.getIsDefault())) {
button.setChecked(true); button.setChecked(true);
} }
specGroup.addView(button, layoutParams); specGroup.addView(button, layoutParams);
}); });
layoutSpecs.addView(specView); layoutSpecs.addView(specView);
specGroup.setOnCheckedChangeListener((group, checkedId) -> changeSkuWithRule());
}); });
changeSkuWithRule();
}
private void changeSkuWithRule() {
if (layoutSpecs.getChildCount() <= 0) {
return;
}
List<GoodsRule> rules = new ArrayList<>();
for (int i = 0; i < layoutSpecs.getChildCount(); i++) {
View v = layoutSpecs.getChildAt(i);
RadioGroup group = v.findViewById(R.id.group_spec);
RadioButton button = group.findViewById(group.getCheckedRadioButtonId());
rules.add((GoodsRule) button.getTag());
}
if (CollectionUtils.isEmpty(rules)) {
Toast.makeText(getContext(), R.string.error_choose_spec, Toast.LENGTH_LONG).show();
return;
}
checkSku = matchSku(rules);
if (checkSku == null) {
Toast.makeText(getContext(), R.string.not_found_goods, Toast.LENGTH_SHORT).show();
return;
}
txtPrice.setText(String.valueOf(checkSku.getPrice()));
txtDiscount.setText(String.valueOf(checkSku.getDiscount()));
}
private Sku matchSku(List<GoodsRule> rules) {
if (CollectionUtils.isEmpty(goods.getSkus())) {
return null;
}
List<Integer> checkRuleIds = rules.stream().map(GoodsRule::getRuleId).sorted().collect(Collectors.toList());
for (Sku sku : goods.getSkus()) {
List<Integer> skuRuleIds = sku.getRules().stream().map(SkuRule::getRuleId).sorted().collect(Collectors.toList());
if (skuRuleIds.toString().equals(checkRuleIds.toString())) {
return sku;
}
}
return null;
} }
private void buildDetails() { private void buildDetails() {
...@@ -116,4 +220,65 @@ public class GoodsDetailDialog extends Dialog { ...@@ -116,4 +220,65 @@ public class GoodsDetailDialog extends Dialog {
layoutImages.addView(imageView, layoutParams); layoutImages.addView(imageView, layoutParams);
}); });
} }
private void processSpecRules() {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
return;
}
// 将售罄和未售罄的SKU分组
Map<Integer, List<Sku>> map = goods.getSkus().stream().collect(Collectors.groupingBy(Sku::getState));
if (CollectionUtils.isEmpty(map)) {
return;
}
// 售罄SKU列表
List<Sku> sellOuts = map.get(Base.FALSE);
List<Sku> sellIns = map.get(Base.TRUE);
if (CollectionUtils.isEmpty(sellOuts)) {
return;
}
sellOuts.forEach(sku -> {
if (CollectionUtils.isEmpty(sku.getRules())) {
return;
}
sku.getRules().forEach(skuRule -> {
// 检查未售罄的sku里是否有此规格选项,如果有则此选项可选
Integer ruleState = checkRuleState(skuRule, sellIns);
setRuleState(skuRule, ruleState);
});
});
}
private void setRuleState(SkuRule skuRule, Integer ruleState) {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
return;
}
goods.getSpecs().forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getRules())) {
return;
}
spec.getRules().forEach(rule -> {
if (rule.getRuleId().equals(skuRule.getRuleId())) {
rule.setState(ruleState);
}
});
});
}
private Integer checkRuleState(SkuRule skuRule, List<Sku> sellIns) {
if (CollectionUtils.isEmpty(sellIns)) {
return Base.FALSE;
}
for (Sku sku : sellIns) {
if (CollectionUtils.isEmpty(sku.getRules())) {
continue;
}
for (SkuRule rule : sku.getRules()) {
if (rule.getRuleId().equals(skuRule.getRuleId())) {
return Base.TRUE;
}
}
}
return Base.FALSE;
}
} }
...@@ -15,8 +15,8 @@ import android.widget.Toast; ...@@ -15,8 +15,8 @@ import android.widget.Toast;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.TrolleyAdapter; import com.ihaoin.hooloo.device.adapter.TrolleyAdapter;
import com.ihaoin.hooloo.device.data.Datas; import com.ihaoin.hooloo.device.data.Datas;
import com.ihaoin.hooloo.device.data.Goods; import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.Sku; import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.data.TrolleyGoods; import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.util.RandomUtils; import com.ihaoin.hooloo.device.util.RandomUtils;
import com.ihaoin.hooloo.device.util.Utils; import com.ihaoin.hooloo.device.util.Utils;
...@@ -67,8 +67,8 @@ public class TrolleyView extends RelativeLayout { ...@@ -67,8 +67,8 @@ public class TrolleyView extends RelativeLayout {
} }
public void addGoods(Goods goods, Sku sku, Integer count) { public void addGoods(Goods goods, Sku sku, Integer count) {
if (getCount() >= Datas.COUNT_OF_ORDER) { if (getCheckedCount() >= Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), String.format("每个订单商品数量不能越过%s个", Datas.COUNT_OF_ORDER), Toast.LENGTH_SHORT).show(); Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
return; return;
} }
Optional<TrolleyGoods> optional = this.trolleyGoods.stream().filter(x -> x.getGoodId().equals(goods.getGoodId()) && x.getSkuId().equals(sku.getSkuId())).findAny(); Optional<TrolleyGoods> optional = this.trolleyGoods.stream().filter(x -> x.getGoodId().equals(goods.getGoodId()) && x.getSkuId().equals(sku.getSkuId())).findAny();
...@@ -95,11 +95,14 @@ public class TrolleyView extends RelativeLayout { ...@@ -95,11 +95,14 @@ public class TrolleyView extends RelativeLayout {
this.trolleyGoods.add(g); this.trolleyGoods.add(g);
} }
this.measureListHeight();
this.goodsChanged(); this.goodsChanged();
} }
public void addGoods(Integer position) { public void addGoods(Integer position) {
if (getCheckedCount() >= Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
return;
}
TrolleyGoods goods = this.trolleyGoods.get(position); TrolleyGoods goods = this.trolleyGoods.get(position);
goods.setCount(goods.getCount() + 1); goods.setCount(goods.getCount() + 1);
this.goodsChanged(); this.goodsChanged();
...@@ -115,23 +118,38 @@ public class TrolleyView extends RelativeLayout { ...@@ -115,23 +118,38 @@ public class TrolleyView extends RelativeLayout {
this.goodsChanged(); this.goodsChanged();
} }
private void goodsChanged() { public void goodsChanged() {
this.trolleyAdapter.notifyDataSetChanged(); this.trolleyAdapter.notifyDataSetChanged();
// BigDecimal discountTotal = this.getTrolleyGoods().stream().map(TrolleyGoods::getDiscount).reduce(BigDecimal.ZERO, BigDecimal::add); this.txtCount.setText(getCheckedCount().toString());
this.txtCount.setText(getCount().toString()); this.txtTotal.setText(getCheckedTotal().toString());
this.txtTotal.setText(getTotal().toString());
this.setView(); this.setView();
this.measureListHeight();
}
public Boolean checkGoodsCount() {
if (getCheckedCount() > Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
return false;
}
return true;
} }
private Integer getCount() { private Integer getCount() {
return this.getTrolleyGoods().stream().collect(Collectors.summingInt(TrolleyGoods::getCount)); return this.getTrolleyGoods().stream().mapToInt(TrolleyGoods::getCount).sum();
}
private Integer getCheckedCount() {
return this.getTrolleyGoods().stream().filter(TrolleyGoods::getChecked).mapToInt(TrolleyGoods::getCount).sum();
} }
private BigDecimal getTotal() { private BigDecimal getTotal() {
return this.getTrolleyGoods().stream().map(x -> x.getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add); return this.getTrolleyGoods().stream().map(x -> x.getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
} }
private BigDecimal getCheckedTotal() {
return this.getTrolleyGoods().stream().filter(TrolleyGoods::getChecked).map(x -> x.getDiscount().multiply(new BigDecimal(x.getCount()))).reduce(BigDecimal.ZERO, BigDecimal::add);
}
private void setView() { private void setView() {
if (this.trolleyGoods.isEmpty()) { if (this.trolleyGoods.isEmpty()) {
this.setVisibility(View.INVISIBLE); this.setVisibility(View.INVISIBLE);
...@@ -151,7 +169,7 @@ public class TrolleyView extends RelativeLayout { ...@@ -151,7 +169,7 @@ public class TrolleyView extends RelativeLayout {
listTrolley.setLayoutParams(layoutParams); listTrolley.setLayoutParams(layoutParams);
} }
private void clearTrolley() { public void clearTrolley() {
this.trolleyGoods.clear(); this.trolleyGoods.clear();
setView(); setView();
} }
...@@ -224,6 +242,16 @@ public class TrolleyView extends RelativeLayout { ...@@ -224,6 +242,16 @@ public class TrolleyView extends RelativeLayout {
} }
private void showPayDialog() { private void showPayDialog() {
if (getCheckedCount() <= 0) {
Toast.makeText(getContext(), R.string.error_choose_goods, Toast.LENGTH_LONG).show();
return;
}
if (getCheckedTotal().compareTo(BigDecimal.ZERO) < 0) {
Toast.makeText(getContext(), R.string.error_price, Toast.LENGTH_LONG).show();
return;
}
Utils.showConfirmOrder(getContext(), trolleyGoods);
} }
public TrolleyView(Context context) { public TrolleyView(Context context) {
......
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="40" android:drawable="@mipmap/mm_001"/>
<item android:duration="40" android:drawable="@mipmap/mm_002"/>
<item android:duration="40" android:drawable="@mipmap/mm_003"/>
<item android:duration="40" android:drawable="@mipmap/mm_004"/>
<item android:duration="40" android:drawable="@mipmap/mm_005"/>
<item android:duration="40" android:drawable="@mipmap/mm_006"/>
<item android:duration="40" android:drawable="@mipmap/mm_007"/>
<item android:duration="40" android:drawable="@mipmap/mm_008"/>
<item android:duration="40" android:drawable="@mipmap/mm_009"/>
<item android:duration="40" android:drawable="@mipmap/mm_010"/>
<item android:duration="40" android:drawable="@mipmap/mm_011"/>
<item android:duration="40" android:drawable="@mipmap/mm_012"/>
<item android:duration="40" android:drawable="@mipmap/mm_013"/>
<item android:duration="40" android:drawable="@mipmap/mm_014"/>
<item android:duration="40" android:drawable="@mipmap/mm_015"/>
<item android:duration="40" android:drawable="@mipmap/mm_016"/>
<item android:duration="40" android:drawable="@mipmap/mm_017"/>
<item android:duration="40" android:drawable="@mipmap/mm_018"/>
<item android:duration="40" android:drawable="@mipmap/mm_019"/>
<item android:duration="40" android:drawable="@mipmap/mm_020"/>
<item android:duration="40" android:drawable="@mipmap/mm_021"/>
<item android:duration="40" android:drawable="@mipmap/mm_022"/>
<item android:duration="40" android:drawable="@mipmap/mm_023"/>
<item android:duration="40" android:drawable="@mipmap/mm_024"/>
<item android:duration="40" android:drawable="@mipmap/mm_025"/>
<item android:duration="40" android:drawable="@mipmap/mm_026"/>
<item android:duration="40" android:drawable="@mipmap/mm_027"/>
<item android:duration="40" android:drawable="@mipmap/mm_028"/>
<item android:duration="40" android:drawable="@mipmap/mm_029"/>
<item android:duration="40" android:drawable="@mipmap/mm_030"/>
<item android:duration="40" android:drawable="@mipmap/mm_031"/>
<item android:duration="40" android:drawable="@mipmap/mm_032"/>
<item android:duration="40" android:drawable="@mipmap/mm_033"/>
<item android:duration="40" android:drawable="@mipmap/mm_034"/>
<item android:duration="40" android:drawable="@mipmap/mm_035"/>
<item android:duration="40" android:drawable="@mipmap/mm_036"/>
<item android:duration="40" android:drawable="@mipmap/mm_037"/>
<item android:duration="40" android:drawable="@mipmap/mm_038"/>
<item android:duration="40" android:drawable="@mipmap/mm_039"/>
<item android:duration="40" android:drawable="@mipmap/mm_040"/>
<item android:duration="40" android:drawable="@mipmap/mm_041"/>
<item android:duration="40" android:drawable="@mipmap/mm_042"/>
<item android:duration="40" android:drawable="@mipmap/mm_043"/>
<item android:duration="40" android:drawable="@mipmap/mm_044"/>
<item android:duration="40" android:drawable="@mipmap/mm_045"/>
<item android:duration="40" android:drawable="@mipmap/mm_046"/>
<item android:duration="40" android:drawable="@mipmap/mm_047"/>
<item android:duration="40" android:drawable="@mipmap/mm_048"/>
<item android:duration="40" android:drawable="@mipmap/mm_049"/>
</animation-list>
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item> <item>
<shape android:shape="rectangle"> <shape android:shape="rectangle">
<corners android:radius="5dp" /> <corners android:radius="2dp" />
<stroke <stroke
android:width="1dp" android:width="1dp"
android:color="@color/colorPrimary" /> android:color="@color/colorPrimary" />
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/textPrimary" android:state_checked="true" /> <item android:color="@color/textPrimary" android:state_checked="true" />
<item android:color="@color/textPrimary" android:state_pressed="true" />
<item android:color="@color/textPrimary" android:state_selected="true" />
<item android:color="@color/textPrimary" android:state_focused="true" />
<item android:color="@color/textSecondPrimary" /> <item android:color="@color/textSecondPrimary" />
</selector> </selector>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_label_checked" android:state_checked="true" /> <item android:drawable="@drawable/ic_label_checked" android:state_checked="true" />
<item android:drawable="@drawable/ic_label_checked" android:state_pressed="true" />
<item android:drawable="@drawable/ic_label_checked" android:state_selected="true" />
<item android:drawable="@drawable/ic_label_checked" android:state_focused="true" />
<item android:drawable="@drawable/ic_label_uncheck" /> <item android:drawable="@drawable/ic_label_uncheck" />
</selector> </selector>
...@@ -4,5 +4,6 @@ ...@@ -4,5 +4,6 @@
<item android:drawable="@drawable/bg_spec_checked" android:state_pressed="true" /> <item android:drawable="@drawable/bg_spec_checked" android:state_pressed="true" />
<item android:drawable="@drawable/bg_spec_checked" android:state_selected="true" /> <item android:drawable="@drawable/bg_spec_checked" android:state_selected="true" />
<item android:drawable="@drawable/bg_spec_checked" android:state_focused="true" /> <item android:drawable="@drawable/bg_spec_checked" android:state_focused="true" />
<item android:drawable="@drawable/bg_spec_uncheck" android:state_enabled="false" />
<item android:drawable="@drawable/bg_spec_uncheck" /> <item android:drawable="@drawable/bg_spec_uncheck" />
</selector> </selector>
...@@ -4,5 +4,6 @@ ...@@ -4,5 +4,6 @@
<item android:color="@color/white" android:state_pressed="true" /> <item android:color="@color/white" android:state_pressed="true" />
<item android:color="@color/white" android:state_selected="true" /> <item android:color="@color/white" android:state_selected="true" />
<item android:color="@color/white" android:state_focused="true" /> <item android:color="@color/white" android:state_focused="true" />
<item android:color="@color/textDisable" android:state_enabled="false" />
<item android:color="@color/textPrimary" /> <item android:color="@color/textPrimary" />
</selector> </selector>
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<LinearLayout <LinearLayout
android:id="@+id/layout_right"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
...@@ -38,11 +39,13 @@ ...@@ -38,11 +39,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:ellipsize="end"
android:lines="1"
android:text="茶叶与咖啡完美的碰撞" android:text="茶叶与咖啡完美的碰撞"
android:textColor="@color/textSecondPrimary" android:textColor="@color/textSecondPrimary"
android:textSize="12sp" /> android:textSize="12sp" />
<LinearLayout <LinearLayout
android:id="@+id/layout_butn"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
...@@ -77,6 +80,15 @@ ...@@ -77,6 +80,15 @@
android:textColor="@color/textSecondPrimary" android:textColor="@color/textSecondPrimary"
android:textSize="9sp" /> android:textSize="9sp" />
<TextView
android:id="@+id/txt_sellout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="已售罄"
android:textColor="@color/textRed"
android:textSize="9sp"
android:visibility="gone" />
<Button <Button
android:id="@+id/butn_add" android:id="@+id/butn_add"
style="@style/button_style" style="@style/button_style"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:text="温度" android:text="温度"
android:textColor="@color/textPrimary" android:textColor="@color/textPrimary"
android:textSize="16sp" android:textSize="14sp"
android:textStyle="bold" /> android:textStyle="bold" />
<RadioGroup <RadioGroup
android:id="@+id/group_spec" android:id="@+id/group_spec"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_item"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
......
...@@ -2,28 +2,33 @@ ...@@ -2,28 +2,33 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white"> android:background="@color/white"
<LinearLayout android:padding="15dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="10dp">
<TextView <TextView
android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="20dp" android:layout_centerHorizontal="true"
android:text="确认订单" android:text="确认订单"
android:textColor="@color/textPrimary" android:textColor="@color/textPrimary"
android:textSize="24sp" android:textSize="18sp"
android:textStyle="bold" /> android:textStyle="bold" />
<LinearLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView <ImageView
android:id="@+id/img_qrcode" android:id="@+id/img_qrcode"
android:layout_width="300dp" android:layout_width="wrap_content"
android:layout_height="300dp" android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@mipmap/qrcode" /> android:src="@mipmap/qrcode" />
<LinearLayout <LinearLayout
android:id="@+id/layout_wait_scan" android:id="@+id/layout_confirm"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
...@@ -33,55 +38,64 @@ ...@@ -33,55 +38,64 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:drawableStart="@mipmap/wx"
android:gravity="center"
android:text="使用微信扫一扫,确认订单并付款" android:text="使用微信扫一扫,确认订单并付款"
android:textColor="@color/textPrimary" android:textColor="@color/textPrimary"
android:textSize="20sp" /> android:textSize="16sp" />
<TextView <TextView
android:id="@+id/txt_times" android:id="@+id/txt_expire"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:text="60秒后失效" android:text="60秒后失效"
android:textColor="@color/textPrimary" android:textColor="@color/textPrimary"
android:textSize="20sp" /> android:textSize="12sp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/layout_scan_succeed" android:id="@+id/layout_succeed"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:visibility="gone"> android:visibility="gone">
<ImageView <ImageView
android:id="@+id/img_succeed" android:id="@+id/img_succeed"
android:layout_width="80dp" android:layout_width="60dp"
android:layout_height="80dp" android:layout_height="60dp"
android:src="@mipmap/qrcode" /> android:src="@mipmap/succ" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/txt_return"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="扫码成功" android:text="扫码成功(1秒后转到首页)"
android:textColor="@color/textPrimary" android:textColor="@color/textPrimary"
android:textSize="20sp" /> android:textSize="16sp" />
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="5dp" android:layout_marginTop="5dp"
android:text="在微信小程序上确认订单并付款" android:text="在微信小程序上确认订单并付款"
android:textColor="@color/textPrimary" android:textColor="@color/textPrimary"
android:textSize="20sp" /> android:textSize="12sp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<ImageView <ImageView
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/anim_qrcode_loading"
android:visibility="invisible" />
<ImageView
android:id="@+id/butn_close" android:id="@+id/butn_close"
android:layout_width="50dp" android:layout_width="30dp"
android:layout_height="50dp" android:layout_height="30dp"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_margin="20dp" android:src="@drawable/ic_outline_close_24" />
android:src="@drawable/ms__arrow" />
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_margin="10dp"
android:layout_weight="1" android:layout_weight="1"
android:adjustViewBounds="true" android:adjustViewBounds="true" />
android:src="@mipmap/wx20220427" />
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -58,6 +57,7 @@ ...@@ -58,6 +57,7 @@
android:background="@color/white" android:background="@color/white"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:id="@+id/layout_item"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
...@@ -158,6 +158,6 @@ ...@@ -158,6 +158,6 @@
android:layout_width="30dp" android:layout_width="30dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_margin="20dp" android:layout_margin="15dp"
android:src="@drawable/ic_outline_close_24" /> android:src="@drawable/ic_outline_close_24" />
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.ihaoin.hooloo.device.view.LauncherActivity">
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<color name="dialog_bg">#CC000000</color> <color name="dialog_bg">#CC000000</color>
<color name="textPrimary">#FF000000</color> <color name="textPrimary">#FF000000</color>
<color name="textSecondPrimary">#FF666666</color> <color name="textSecondPrimary">#FF666666</color>
<color name="textDisable">#FF999999</color>
<color name="line">#FF979797</color> <color name="line">#FF979797</color>
<color name="textRed">#FFFF001D</color> <color name="textRed">#FFFF001D</color>
<color name="white">#FFFFFF</color> <color name="white">#FFFFFF</color>
......
<resources> <resources>
<string name="app_name">hooloo</string> <string name="app_name">hooloo</string>
<string name="action_settings">Settings</string> <string name="not_found_goods">未找到相应商品</string>
<string name="count_limit">每个订单商品数量不能超过%1$s</string>
<string name="error_get_qrcode">获取二维码失败</string>
<string name="expire_times">%1$s秒后失效</string>
<string name="scan_succeed">扫码成功(%s秒后转到首页)</string>
<string name="error_choose_spec">请选择规格</string>
<string name="error_choose_goods">请选择商品</string>
<string name="error_price">商品金额错误</string>
</resources> </resources>
import java.util.Arrays;
import java.util.List;
public class JavaTest {
public static void main(String[] args) {
List<Integer> list = Arrays.asList(1, 2, 3);
System.out.println(list.toString());
}
}
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