Commit c08b2d1c by wjg

init

parent cac7a74f
......@@ -61,6 +61,7 @@ dependencies {
implementation 'com.aliyun.alink.linksdk:iot-linkkit:1.7.2'
implementation 'com.aliyun.alink.linksdk:public-channel-core:0.7.7.1'
implementation 'com.aliyun.alink.linksdk:iot-device-manager:1.7.5.0'
implementation 'com.google.zxing:core:3.3.0'
// 引入极光 SDK
implementation project(':library_jiguang')
......
package com.ihaoin.hooloo.device;
import android.app.Application;
import android.util.Log;
import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.network.HttpUtil;
import cn.jpush.android.api.JPushInterface;
public class HLApplication extends Application {
private static MainData mainData = new MainData();
public static MainData getMainData() {
return mainData;
}
public static void setMainData(MainData data) {
mainData = data;
}
@Override
public void onCreate() {
......@@ -18,6 +29,8 @@ public class HLApplication extends Application {
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
Log.d("PushMessageReceiver", JPushInterface.getRegistrationID(this));
// HttpUtil.postRegistrationId(JPushInterface.getRegistrationID(this), null);
}
@Override
......
......@@ -64,14 +64,16 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
});
}
ImageView imgThumbnail = helper.getView(R.id.img_thumbnail);
RoundedCorners roundedCorners = new RoundedCorners(5);
RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
Glide.with(mContext).load(goods.getPics().getThumbnail()).apply(options).into(imgThumbnail);
if (goods.getPics() == null) {
imgThumbnail.setImageDrawable(null);
} else {
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);
......@@ -83,15 +85,6 @@ public class GoodsAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseViewHo
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);
......
......@@ -34,13 +34,13 @@ public class RecommendAdapter extends BaseSectionQuickAdapter<ScrollBean, BaseVi
protected void convert(BaseViewHolder helper, ScrollBean item) {
ScrollBean.ScrollItemBean t = item.t;
Recommend recommend = (Recommend) t.getObject();
helper.setText(R.id.txt_name, recommend.getTitle());
helper.setText(R.id.txt_name, recommend.getGoodsName());
helper.setText(R.id.txt_intro, recommend.getDesc());
ImageView imgRecommend = helper.getView(R.id.img_recommend);
RoundedCorners roundedCorners = new RoundedCorners(5);
RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
Glide.with(mContext).load(recommend.getBackground()).apply(options).into(imgRecommend);
Glide.with(mContext).load(recommend.getPic()).apply(options).into(imgRecommend);
View layoutItem = helper.getView(R.id.layout_item);
layoutItem.setOnClickListener(v -> Utils.showGoodsDetail(mContext, recommend.getGoods()));
......
......@@ -29,7 +29,7 @@ public class PushMessageReceiver extends JPushMessageReceiver {
subscribers.put(key, handler);
}
public static void unsubscribe(String key, Handler handler) {
public static void unsubscribe(String key) {
subscribers.remove(key);
}
......
......@@ -5,5 +5,7 @@ public class AppConfig {
public static Boolean DEBUG = true;
/** 机器编码 */
public static String MACHINE_CODE = "";
/** 打开微信网址 */
public static String WX_URL = "https://www.bjjsycloud.com/?id=%s";
}
......@@ -5,6 +5,7 @@ public class Base {
public static final Integer FALSE = 0;
public static final String NOTIFY_ACTION_ORDER_STATE_CHANGED = "ORDER_STATE_CHANGED";
public static final String NOTIFY_ACTION_SKU_STATE_CHANGED = "SKU_STATE_CHANGED";
public static final String NOTIFY_ACTION_QRCODE_VISITED = "QRCODE_VISITED";
public static final String ADD_GOODS_ACTION = "ADD_GOODS_ACTION";
......
package com.ihaoin.hooloo.device.data;
import com.ihaoin.hooloo.device.data.vo.Category;
import com.ihaoin.hooloo.device.data.vo.Recommend;
import com.ihaoin.hooloo.device.data.vo.RightImage;
import java.util.List;
public class Datas {
public static Integer COUNT_OF_ORDER = 9;
public static String tips = "http://www.baidu.com";
public static Integer SHOP_STATE = 1;
public static List<String> leftImages;
public static List<RightImage> rightImages;
public static List<Recommend> recommends;
public static List<Category> categorys;
}
package com.ihaoin.hooloo.device.data;
import com.ihaoin.hooloo.device.data.vo.Category;
import com.ihaoin.hooloo.device.data.vo.Images;
import com.ihaoin.hooloo.device.data.vo.Recommend;
import java.util.List;
public class MainData {
private Integer countOfOrder = 9;
private String tips = "http://www.baidu.com";
private Integer shopState = 1;
private Images images;
private List<Recommend> recommends;
private List<Category> categorys;
public Integer getCountOfOrder() {
return countOfOrder;
}
public void setCountOfOrder(Integer countOfOrder) {
this.countOfOrder = countOfOrder;
}
public String getTips() {
return tips;
}
public void setTips(String tips) {
this.tips = tips;
}
public Integer getShopState() {
return shopState;
}
public void setShopState(Integer shopState) {
this.shopState = shopState;
}
public Images getImages() {
return images;
}
public void setImages(Images images) {
this.images = images;
}
public List<Recommend> getRecommends() {
return recommends;
}
public void setRecommends(List<Recommend> recommends) {
this.recommends = recommends;
}
public List<Category> getCategorys() {
return categorys;
}
public void setCategorys(List<Category> categorys) {
this.categorys = categorys;
}
}
package com.ihaoin.hooloo.device.data.enums;
public enum ImageState {
CLOSED(0, "歇业"),
COOKING(1, "制作中"),
COMPLETED(2, "有待取餐"),
NOT_COMPLETED(3, "无待取餐");
CLOSED("closeDown", "歇业"),
COOKING("inProduction", "制作中"),
COMPLETED("thereAOrder", "有待取餐"),
NOT_COMPLETED("noOrder", "无待取餐");
private Integer code;
private String code;
private String name;
ImageState(Integer code, String name) {
ImageState(String code, String name) {
this.code = code;
this.name = name;
}
public static ImageState get(Integer code) {
public static ImageState get(String code) {
for (ImageState state : ImageState.values()) {
if (state.getCode().equals(code)) {
return state;
......@@ -23,7 +23,7 @@ public enum ImageState {
return null;
}
public Integer getCode() {
public String getCode() {
return code;
}
......
......@@ -45,12 +45,6 @@ public class Category implements Serializable {
this.goods = goods;
}
public Category(Integer id, String name, List<Goods> goods) {
this.setId(id);
this.setName(name);
this.setGoods(goods);
}
@Override
public boolean equals(Object o) {
if (o == null) {
......
......@@ -6,7 +6,7 @@ import java.util.List;
public class Goods implements Serializable {
/** 商品id */
private Integer goodId;
private Integer goodsId;
/** 名称 */
private String name;
/** 原价 */
......@@ -16,7 +16,7 @@ public class Goods implements Serializable {
/** 介绍 */
private String desc;
/** 备注 */
private String remark;
private String remarks;
/** 图片信息 */
private Pics pics;
/** 规格 */
......@@ -26,21 +26,12 @@ public class Goods implements Serializable {
/** SKU */
private List<Sku> skus;
// public Goods(Integer id, String name, Pics pics){
// this.setGoodId(id);
// this.setName(name);
// this.setPics(pics);
// }
//
// public Goods(){
// }
public Integer getGoodId() {
return goodId;
public Integer getGoodsId() {
return goodsId;
}
public void setGoodId(Integer goodId) {
this.goodId = goodId;
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public String getName() {
......@@ -75,12 +66,12 @@ public class Goods implements Serializable {
this.desc = desc;
}
public String getRemark() {
return remark;
public String getRemarks() {
return remarks;
}
public void setRemark(String remark) {
this.remark = remark;
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public Pics getPics() {
......
......@@ -20,6 +20,10 @@ public class GoodsRule implements Serializable {
*/
private Integer isDefault;
/**
* 是否推荐
*/
private Integer isRecommend;
/**
* 状态,1-可售、0-不可售
*/
private Integer state = Base.TRUE;
......@@ -67,4 +71,12 @@ public class GoodsRule implements Serializable {
public void setState(Integer state) {
this.state = state;
}
public Integer getIsRecommend() {
return isRecommend;
}
public void setIsRecommend(Integer isRecommend) {
this.isRecommend = isRecommend;
}
}
package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable;
import java.util.Map;
public class Images implements Serializable {
private String left;
private Map<String, String> right;
public String getLeft() {
return left;
}
public void setLeft(String left) {
this.left = left;
}
public Map<String, String> getRight() {
return right;
}
public void setRight(Map<String, String> right) {
this.right = right;
}
}
......@@ -6,7 +6,7 @@ public class Recommend implements Serializable {
/**
* 推荐标题
*/
private String title;
private String goodsName;
/**
* 推荐介绍
......@@ -16,26 +16,19 @@ public class Recommend implements Serializable {
/**
* 推荐背景图
*/
private String background;
private String pic;
/**
* 商品信息
*/
private Goods goods;
public Recommend(String title, String desc, String background, Goods goods) {
this.setTitle(title);
this.setDesc(desc);
this.setBackground(background);
this.setGoods(goods);
public String getGoodsName() {
return goodsName;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getDesc() {
......@@ -46,12 +39,12 @@ public class Recommend implements Serializable {
this.desc = desc;
}
public String getBackground() {
return background;
public String getPic() {
return pic;
}
public void setBackground(String background) {
this.background = background;
public void setPic(String pic) {
this.pic = pic;
}
public Goods getGoods() {
......
package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable;
public class ResultVo<T> implements Serializable {
private Integer code;
private String msg;
private T data;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.ihaoin.hooloo.device.data.vo;
import java.io.Serializable;
public class RightImage implements Serializable {
/**
* 状态
*/
private Integer state;
/**
* 网址
*/
private String url;
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public RightImage(Integer state, String url) {
this.state = state;
this.url = url;
}
}
package com.ihaoin.hooloo.device.data.vo;
import com.alibaba.fastjson.annotation.JSONField;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
......@@ -15,6 +17,7 @@ public class Sku implements Serializable {
/** 原价 */
private BigDecimal price;
/** 折扣价 */
@JSONField(name = "disCount")
private BigDecimal discount;
/** SKU规格 */
private List<SkuRule> rules;
......
package com.ihaoin.hooloo.device.network;
public class BizException extends RuntimeException {
public BizException(String msg) {
super(msg);
}
}
\ No newline at end of file
package com.ihaoin.hooloo.device.network;
public class BaseParams {
public class HttpParams {
private static final String HOST = "http://114.115.234.81:8080";
/** 首页获取数据 */
public static final String GET_MAIN_DATA = HOST + "/application/getOrderTaking?machineCode=%s";
/** 获取订单信息 */
public static final String GET_ORDERS = HOST + "/application/getOrderInfo?machineCode=%s";
/** 校验SKU状态 */
public static final String CHECK_SKU = HOST + "/application/checkSku?machineCode=%s&skuId=%s";
/** 保存购物车数据 */
public static final String POST_CONFIRM_ORDER = HOST + "/application/saveData?machineCode=%s";
/** 保存推送ID */
public static final String POST_REGISTRATION_ID = HOST + "/application/jgRegister?machineCode=%s&registerId=%s";
public static final String GET_CHECK_SKU = HOST + "/application/checkSku?machineCode=%s&skuId=%s";
}
......@@ -4,6 +4,10 @@ import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ihaoin.hooloo.device.config.AppConfig;
import java.io.IOException;
import java.net.NetworkInterface;
import java.util.Collections;
......@@ -21,70 +25,104 @@ public class HttpUtil {
private static final String TAG = "Network";
public static void post(String url, String body, Handler handler) {
if (body == null) {
body = "";
}
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);
HttpUtil.onFailure(handler, call, e);
}
@Override
public void onResponse(Call call, Response response) {
HttpUtil.onResponse(handler, call, response);
}
});
}
public static void get(String url, Handler handler) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).get().build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
HttpUtil.onFailure(handler, call, e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
HttpUtil.onResponse(handler, response);
public void onResponse(Call call, Response response) {
HttpUtil.onResponse(handler, call, response);
}
});
}
private static void onFailure(Handler handler, Exception e) {
private static void onFailure(Handler handler, Call call, Exception e) {
if (AppConfig.DEBUG) {
String msgText = String.format("返回状态:%s, 请求:%s, 返回内容:%s", 0, call.request().url(), e.getMessage());
Log.e(TAG, msgText);
}
if (handler == null) {
String msgText = String.format("返回状态:%s, 返回内容:%s", 0, e.getMessage());
Log.d(TAG, msgText);
return;
}
try {
Thread.sleep(3000);
} catch (InterruptedException e3) {
} catch (Exception e3) {
e3.printStackTrace();
}
Message msg = handler.obtainMessage(0, e);
handler.sendMessage(msg);
}
private static void onResponse(Handler handler, Response response) throws IOException {
if (handler == null) {
String msgText = String.format("返回状态:%s, 返回内容:%s", 1, response.body() == null ? "" : response.body().string());
Log.d(TAG, msgText);
return;
}
private static void onResponse(Handler handler, Call call, Response response) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
String responseBody = response.body().string();
if (AppConfig.DEBUG) {
String msgText = String.format("返回状态:%s, 请求:%s, 返回内容:%s", 1, call.request().url(), responseBody);
Log.i(TAG, msgText);
}
if (handler == null) {
return;
}
// Thread.sleep(3000);
JSONObject jsonObject = JSON.parseObject(responseBody);
if (jsonObject == null || jsonObject.getInteger("code") == null || jsonObject.getInteger("code") != 200) {
onFailure(handler, call, new BizException("返回状态错误"));
return;
}
Message msg = handler.obtainMessage(1, jsonObject.get("data") == null ? "" : jsonObject.get("data").toString());
handler.sendMessage(msg);
} catch (Exception e) {
onFailure(handler, call, e);
}
Message msg = handler.obtainMessage(1, response.body() == null ? "" : response.body().string());
handler.sendMessage(msg);
}
public static void getMainDatas(String body, Handler handler) {
post(BaseParams.GET_MAIN_DATA, body, handler);
public static void getMainDatas(Handler handler) {
String url = String.format(HttpParams.GET_MAIN_DATA, AppConfig.MACHINE_CODE);
get(url, handler);
}
public static void getOrders(String body, Handler handler) {
post(BaseParams.GET_ORDERS, body, handler);
public static void getOrders(Handler handler) {
String url = String.format(HttpParams.GET_ORDERS, AppConfig.MACHINE_CODE);
get(url, handler);
}
public static void postConfirmOrder(String body, Handler handler) {
post(BaseParams.POST_CONFIRM_ORDER, body, handler);
String url = String.format(HttpParams.POST_CONFIRM_ORDER, AppConfig.MACHINE_CODE);
post(url, body, handler);
}
public static void postRegistrationId(String body, Handler handler) {
post(BaseParams.POST_REGISTRATION_ID, body, handler);
public static void postRegistrationId(String registrationId, Handler handler) {
String url = String.format(HttpParams.POST_REGISTRATION_ID, AppConfig.MACHINE_CODE, registrationId);
get(url, handler);
}
public static void checkSku(String body, Handler handler) {
post(BaseParams.GET_CHECK_SKU, body, handler);
public static void checkSku(Integer skuId, Handler handler) {
String url = String.format(HttpParams.CHECK_SKU, AppConfig.MACHINE_CODE, skuId);
get(url, handler);
}
public static String getMacAddress() {
......
......@@ -4,6 +4,14 @@ import java.util.Collection;
import java.util.Map;
public class CollectionUtils {
public static <T> T lastItem(Collection<T> collection) {
if (isEmpty(collection)) {
return null;
}
return (T) collection.toArray()[collection.size() - 1];
}
public static Boolean isEmpty(Object[] collection) {
if (collection == null || collection.length == 0) {
return true;
......
......@@ -7,4 +7,14 @@ public class StringUtils {
}
return false;
}
public static int indexOf(Object[] items, Object obj) {
for (int i = 0; i < items.length; i++) {
Object item = items[i];
if (item.equals(obj)) {
return i;
}
}
return 0;
}
}
......@@ -73,12 +73,13 @@ public class Utils {
public static void openSystemSettings(Context context) {
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); // 打开系统设置界面
}
public static void openAppSettings(Context context) {
Intent intent = new Intent(context, SettingsActivity.class);
context.startActivity(intent); // 打开系统设置界面
context.startActivity(intent);
}
/**
......@@ -124,7 +125,7 @@ public class Utils {
return null;
}
ConfirmGoods g = new ConfirmGoods();
g.setGoodsId(goods.getGoodId());
g.setGoodsId(goods.getGoodsId());
g.setSkuId(sku.getSkuId());
g.setCount(count);
return Arrays.asList(g);
......
......@@ -16,9 +16,9 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
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;
......@@ -48,15 +48,15 @@ public class GoodsDetailDialog extends Dialog {
private Button butnAdd;
private Button butnBuy;
private Button butnTrolley;
private View layoutOperate;
private View layoutButns;
private View txtSellout;
private Integer count = 1;
public GoodsDetailDialog(@NonNull Context context, Goods goods) {
super(context);
this.goods = goods;
// 处理售罄的SKU和规格选项
processSpecRules();
}
@Override
......@@ -67,6 +67,9 @@ public class GoodsDetailDialog extends Dialog {
}
private void initViews() {
layoutButns = findViewById(R.id.layout_butns);
layoutOperate = findViewById(R.id.layout_operate);
txtSellout = findViewById(R.id.txt_sellout);
butnClose = findViewById(R.id.butn_close);
imgIntro = findViewById(R.id.img_intro);
txtName = findViewById(R.id.txt_name);
......@@ -82,7 +85,11 @@ public class GoodsDetailDialog extends Dialog {
butnClose.setOnClickListener(x -> dismiss());
Glide.with(getContext()).load(goods.getPics().getIntroImages().get(0)).into(imgIntro);
if (goods.getPics() == null) {
imgIntro.setImageDrawable(null);
} else {
Glide.with(getContext()).load(goods.getPics().getIntroImages().get(0)).into(imgIntro);
}
txtName.setText(goods.getName());
butnSubtract.setOnClickListener(v -> subtractGoods());
......@@ -94,6 +101,9 @@ public class GoodsDetailDialog extends Dialog {
ViewGroup layoutItem = findViewById(R.id.layout_item);
Utils.setTouchDelegate(layoutItem, Arrays.asList(butnAdd, butnSubtract), 15);
// 处理售罄的SKU和规格选项
processSpecRules();
buildSpecs();
buildDetails();
}
......@@ -117,8 +127,8 @@ public class GoodsDetailDialog extends Dialog {
}
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();
if (count >= HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return;
}
count++;
......@@ -222,7 +232,8 @@ public class GoodsDetailDialog extends Dialog {
}
private void processSpecRules() {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs()) || CollectionUtils.isEmpty(goods.getSkus())) {
showSelloutViews();
return;
}
// 将售罄和未售罄的SKU分组
......@@ -233,6 +244,10 @@ public class GoodsDetailDialog extends Dialog {
// 售罄SKU列表
List<Sku> sellOuts = map.get(Base.FALSE);
List<Sku> sellIns = map.get(Base.TRUE);
if (CollectionUtils.isEmpty(sellIns)) {
showSelloutViews();
return;
}
if (CollectionUtils.isEmpty(sellOuts)) {
return;
}
......@@ -248,6 +263,12 @@ public class GoodsDetailDialog extends Dialog {
});
}
private void showSelloutViews() {
layoutOperate.setVisibility(View.GONE);
layoutButns.setVisibility(View.GONE);
txtSellout.setVisibility(View.VISIBLE);
}
private void setRuleState(SkuRule skuRule, Integer ruleState) {
if (goods == null || CollectionUtils.isEmpty(goods.getSpecs())) {
return;
......
......@@ -14,19 +14,19 @@ import androidx.annotation.NonNull;
import com.alibaba.fastjson2.JSON;
import com.bumptech.glide.Glide;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.OrderAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.component.PushMessageReceiver;
import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.Datas;
import com.ihaoin.hooloo.device.data.enums.ImageState;
import com.ihaoin.hooloo.device.data.enums.OrderState;
import com.ihaoin.hooloo.device.data.vo.Order;
import com.ihaoin.hooloo.device.data.vo.OrderPkg;
import com.ihaoin.hooloo.device.data.vo.RightImage;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.StringUtils;
import java.util.List;
import java.util.Map;
......@@ -82,38 +82,42 @@ public class MenuPresentation extends Presentation {
gridCompleted.setAdapter(completedAdapter);
}
private String getImage(Integer state) {
if (CollectionUtils.isEmpty(Datas.rightImages)) {
private String getRightImage(String state) {
if (HLApplication.getMainData() == null || HLApplication.getMainData().getImages() == null) {
return null;
}
for (RightImage image : Datas.rightImages) {
if (image.getState().equals(state)) {
return image.getUrl();
}
if (CollectionUtils.isEmpty(HLApplication.getMainData().getImages().getRight())) {
return null;
}
return null;
return HLApplication.getMainData().getImages().getRight().get(state);
}
private void showImages() {
if (!CollectionUtils.isEmpty(Datas.leftImages)) {
Glide.with(getContext()).load(Datas.leftImages.get(0)).into(imgLeft);
if (HLApplication.getMainData() == null || HLApplication.getMainData().getImages() == null) {
return;
}
if (!StringUtils.isEmpty(HLApplication.getMainData().getImages().getLeft())) {
Glide.with(getContext()).load(HLApplication.getMainData().getImages().getLeft()).into(imgLeft);
}
if (Datas.SHOP_STATE.equals(0)) {
Glide.with(getContext()).load(getImage(ImageState.CLOSED.getCode())).into(imgRight);
if (HLApplication.getMainData().getShopState().equals(0)) {
Glide.with(getContext()).load(getRightImage(ImageState.CLOSED.getCode())).into(imgRight);
} else if (!CollectionUtils.isEmpty(cookingOrders)) {
Glide.with(getContext()).load(getImage(ImageState.COOKING.getCode())).into(imgRight);
Glide.with(getContext()).load(getRightImage(ImageState.COOKING.getCode())).into(imgRight);
} else if (!CollectionUtils.isEmpty(completedOrders)) {
Glide.with(getContext()).load(getImage(ImageState.COMPLETED.getCode())).into(imgRight);
Glide.with(getContext()).load(getRightImage(ImageState.COMPLETED.getCode())).into(imgRight);
} else {
Glide.with(getContext()).load(getImage(ImageState.NOT_COMPLETED.getCode())).into(imgRight);
Glide.with(getContext()).load(getRightImage(ImageState.NOT_COMPLETED.getCode())).into(imgRight);
}
}
public void mainDataChanged() {
showImages();
}
private void loadDatas() {
loadOrdersHandler = new LoadOrdersHandler(getContext());
String requestParams = "";
HttpUtil.getOrders(requestParams, loadOrdersHandler);
HttpUtil.getOrders(loadOrdersHandler);
}
private void setDatas(String json) {
......@@ -132,10 +136,10 @@ public class MenuPresentation extends Presentation {
completedAdapter.notifyDataSetChanged();
showImages();
regsiterOrderChangeListener();
regsitOrderChangeListener();
}
private void regsiterOrderChangeListener() {
private void regsitOrderChangeListener() {
orderStateChangeHandler = new OrderStateChangeHandler();
PushMessageReceiver.subscribe(Base.NOTIFY_ACTION_ORDER_STATE_CHANGED, orderStateChangeHandler);
}
......
......@@ -6,13 +6,14 @@ import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils;
public class SettingsActivity extends Activity {
......@@ -51,19 +52,18 @@ public class SettingsActivity extends Activity {
butnClose.setOnClickListener(v -> finish());
layoutScreen.setOnClickListener(v -> showEditScreen());
layoutSysSettings.setOnClickListener(v -> Utils.openSystemSettings(getApplicationContext()));
}
private void showEditScreen() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("修改点单屏编码");
EditText editText = new EditText(getApplicationContext());
editText.setText(SharedPreferencesUtils.getScreenNo(SettingsActivity.this));
builder.setView(editText);
builder.setPositiveButton("确定", (dialog, which) -> {
SharedPreferencesUtils.setScreenNo(SettingsActivity.this, editText.getText().toString());
String[] items = new String[]{"A", "B"};
builder.setSingleChoiceItems(items, StringUtils.indexOf(items, SharedPreferencesUtils.getScreenNo(SettingsActivity.this)), (dialog, which) -> {
SharedPreferencesUtils.setScreenNo(SettingsActivity.this, items[which]);
txtScreenNo.setText(SharedPreferencesUtils.getScreenNo(SettingsActivity.this));
dialog.dismiss();
});
builder.setNegativeButton("取消", null);
builder.create().show();
}
......
......@@ -10,8 +10,9 @@ import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.data.Datas;
import com.ihaoin.hooloo.device.util.StringUtils;
public class TipsDialog extends Dialog {
private View butnClose;
......@@ -25,6 +26,10 @@ public class TipsDialog extends Dialog {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.view_tips);
if (HLApplication.getMainData() == null || StringUtils.isEmpty(HLApplication.getMainData().getTips())) {
dismiss();
return;
}
initViews();
}
......@@ -38,7 +43,7 @@ public class TipsDialog extends Dialog {
return false;
}
});
webView.loadUrl(Datas.tips);
webView.loadUrl(HLApplication.getMainData().getTips());
butnClose.setOnClickListener(x -> dismiss());
}
}
package com.ihaoin.hooloo.device.view;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
......@@ -12,12 +14,14 @@ import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.TrolleyAdapter;
import com.ihaoin.hooloo.device.data.Datas;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.data.TrolleyGoods;
import com.ihaoin.hooloo.device.util.RandomUtils;
import com.ihaoin.hooloo.device.util.Utils;
......@@ -67,11 +71,15 @@ public class TrolleyView extends RelativeLayout {
}
public void addGoods(Goods goods, Sku sku, Integer count) {
if (getCount() >= Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
if (!checkSkuState(sku.getSkuId())) {
Toast.makeText(this.getContext(), R.string.error_sku_state, Toast.LENGTH_SHORT).show();
return;
}
Optional<TrolleyGoods> optional = this.trolleyGoods.stream().filter(x -> x.getGoodId().equals(goods.getGoodId()) && x.getSkuId().equals(sku.getSkuId())).findAny();
if (getCount() >= HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return;
}
Optional<TrolleyGoods> optional = this.trolleyGoods.stream().filter(x -> x.getGoodId().equals(goods.getGoodsId()) && x.getSkuId().equals(sku.getSkuId())).findAny();
// 判断是否在购物车里存在同样规格的产品
if (optional.isPresent()) {
TrolleyGoods g = optional.get();
......@@ -80,7 +88,7 @@ public class TrolleyView extends RelativeLayout {
TrolleyGoods g = new TrolleyGoods();
g.setId(RandomUtils.nextLong(trolleyGoods.stream().map(TrolleyGoods::getId).collect(Collectors.toList())));
g.setChecked(true);
g.setGoodId(goods.getGoodId());
g.setGoodId(goods.getGoodsId());
g.setName(goods.getName());
g.setDesc(goods.getDesc());
g.setPics(goods.getPics());
......@@ -99,15 +107,23 @@ public class TrolleyView extends RelativeLayout {
}
public void addGoods(Integer position) {
if (getCount() >= Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
if (getCount() >= HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return;
}
TrolleyGoods goods = this.trolleyGoods.get(position);
if (!checkSkuState(goods.getSkuId())) {
Toast.makeText(this.getContext(), R.string.error_sku_state, Toast.LENGTH_SHORT).show();
return;
}
goods.setCount(goods.getCount() + 1);
this.goodsChanged();
}
private boolean checkSkuState(Integer skuId) {
return true;
}
public void subtractGoods(Integer position) {
TrolleyGoods goods = this.trolleyGoods.get(position);
if (goods.getCount() <= 1) {
......@@ -127,8 +143,8 @@ public class TrolleyView extends RelativeLayout {
}
public Boolean checkGoodsCount() {
if (getCount() > Datas.COUNT_OF_ORDER) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, Datas.COUNT_OF_ORDER.toString()), Toast.LENGTH_SHORT).show();
if (getCount() > HLApplication.getMainData().getCountOfOrder()) {
Toast.makeText(this.getContext(), getContext().getString(R.string.count_limit, HLApplication.getMainData().getCountOfOrder().toString()), Toast.LENGTH_SHORT).show();
return false;
}
return true;
......@@ -254,6 +270,13 @@ public class TrolleyView extends RelativeLayout {
Utils.showConfirmOrder(getContext(), trolleyGoods);
}
class CheckSkuStateHandler extends Handler {
@Override
public void handleMessage(@NonNull Message msg) {
}
}
public TrolleyView(Context context) {
super(context);
init();
......
......@@ -42,4 +42,5 @@
android:id="@+id/view_trolley"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
\ No newline at end of file
......@@ -8,7 +8,7 @@
android:id="@+id/img_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="1.3"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<LinearLayout
......
......@@ -98,6 +98,7 @@
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_operate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
......@@ -125,8 +126,18 @@
android:layout_height="20dp"
android:background="@drawable/ic_add" />
</LinearLayout>
<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="12sp"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_butns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
......
......@@ -8,4 +8,6 @@
<string name="error_choose_spec">请选择规格</string>
<string name="error_choose_goods">请选择商品</string>
<string name="error_price">商品金额错误</string>
<string name="error_sku_state">本商品已售罄或已经下架</string>
<string name="error_load_main_data">获取数据失败</string>
</resources>
package com.chad.library.adapter.base.animation
import android.animation.Animator
......
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