Commit ef3fc397 by wjg

修改推送逻辑

parent 5082450e
...@@ -2,19 +2,17 @@ package com.ihaoin.hooloo.device.component; ...@@ -2,19 +2,17 @@ package com.ihaoin.hooloo.device.component;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log; import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.network.HttpUtil; import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.JsonUtils; import com.ihaoin.hooloo.device.util.JsonUtils;
import com.ihaoin.hooloo.device.util.StringUtils; import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import cn.jpush.android.api.CmdMessage; import cn.jpush.android.api.CmdMessage;
import cn.jpush.android.api.CustomMessage; import cn.jpush.android.api.CustomMessage;
...@@ -24,16 +22,6 @@ import cn.jpush.android.api.NotificationMessage; ...@@ -24,16 +22,6 @@ import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver; import cn.jpush.android.service.JPushMessageReceiver;
public class PushMessageReceiver extends JPushMessageReceiver { public class PushMessageReceiver extends JPushMessageReceiver {
private static Map<String, Handler> subscribers = new HashMap<>();
public static void subscribe(String key, Handler handler) {
subscribers.put(key, handler);
}
public static void unsubscribe(String key) {
subscribers.remove(key);
}
@Override @Override
public void onMessage(Context context, CustomMessage customMessage) { public void onMessage(Context context, CustomMessage customMessage) {
Log.e(AppConfig.TAG_PUSH, "[onMessage] " + customMessage); Log.e(AppConfig.TAG_PUSH, "[onMessage] " + customMessage);
...@@ -46,24 +34,14 @@ public class PushMessageReceiver extends JPushMessageReceiver { ...@@ -46,24 +34,14 @@ public class PushMessageReceiver extends JPushMessageReceiver {
} }
private void dispatchMsg(CustomMessage customMessage) throws IOException { private void dispatchMsg(CustomMessage customMessage) throws IOException {
// if (CollectionUtils.isEmpty(subscribers)) {
// Log.e(AppConfig.DEBUG_TAG_PUSH,"msg subscribers is empty");
// return;
// }
JsonNode jsonNode = JsonUtils.getMapper().readValue(customMessage.message, JsonNode.class); JsonNode jsonNode = JsonUtils.getMapper().readValue(customMessage.message, JsonNode.class);
String action = jsonNode.get("action").asText(); String action = jsonNode.get("action").asText();
if (StringUtils.isEmpty(action)) { if (StringUtils.isEmpty(action)) {
Log.e(AppConfig.TAG_PUSH, "msg action is empty"); Log.e(AppConfig.TAG_PUSH, "msg action is empty");
return; return;
} }
Handler handler = subscribers.get(action);
if (handler == null) { Utils.fastPushBroadcast(HLApplication.SELF, action, jsonNode.get("data") == null ? null : jsonNode.get("data").toString());
Log.e(AppConfig.TAG_PUSH, String.format("msg action[%s] subscribers is empty", action));
return;
}
JsonNode data = jsonNode.get("data");
Message msg = handler.obtainMessage(1, JsonUtils.getMapper().writeValueAsString(data));
handler.sendMessage(msg);
} }
@Override @Override
......
...@@ -2,7 +2,7 @@ package com.ihaoin.hooloo.device.config; ...@@ -2,7 +2,7 @@ package com.ihaoin.hooloo.device.config;
public class AppConfig { public class AppConfig {
public static Boolean DEBUG = false; // TODO false public static Boolean DEBUG = true; // TODO false
public static String HL = "HL"; public static String HL = "HL";
public static String TAG = HL + "_TEST"; public static String TAG = HL + "_TEST";
public static String TAG_PUSH = HL + "_PUSH"; public static String TAG_PUSH = HL + "_PUSH";
......
...@@ -4,6 +4,7 @@ public class Base { ...@@ -4,6 +4,7 @@ public class Base {
public static final Integer TRUE = 1; public static final Integer TRUE = 1;
public static final Integer FALSE = 0; public static final Integer FALSE = 0;
public static final String PUSH_DEFAULT_EXTRA = "PUSH_DEFAULT_EXTRA";
public static final String PUSH_ACTION_ORDER_STATE_CHANGED = "ORDER_STATE_CHANGED"; public static final String PUSH_ACTION_ORDER_STATE_CHANGED = "ORDER_STATE_CHANGED";
public static final String PUSH_ACTION_SKU_STATE_CHANGED = "SKU_STATE_CHANGED"; public static final String PUSH_ACTION_SKU_STATE_CHANGED = "SKU_STATE_CHANGED";
public static final String PUSH_ACTION_QRCODE_VISITED = "QRCODE_VISITED"; public static final String PUSH_ACTION_QRCODE_VISITED = "QRCODE_VISITED";
......
...@@ -22,4 +22,15 @@ public class JsonUtils { ...@@ -22,4 +22,15 @@ public class JsonUtils {
return null; return null;
} }
} }
public static String toString(Object obj) {
try {
if (obj == null) {
return null;
}
return JsonUtils.getMapper().writeValueAsString(obj);
} catch (Exception e) {
return null;
}
}
} }
...@@ -45,6 +45,13 @@ public class Utils { ...@@ -45,6 +45,13 @@ public class Utils {
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
public static void fastPushBroadcast(Context context, String action, String content) {
Intent intent = new Intent();
intent.setAction(action);
intent.putExtra(Base.PUSH_DEFAULT_EXTRA, content);
context.sendBroadcast(intent);
}
public static void sendAddGoodsBroadcast(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(Base.BROADCAST_ACTION_ADD_GOODS); intent.setAction(Base.BROADCAST_ACTION_ADD_GOODS);
......
package com.ihaoin.hooloo.device.view; package com.ihaoin.hooloo.device.view;
import android.app.Dialog; import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.AnimationDrawable;
...@@ -23,7 +26,6 @@ import com.google.zxing.WriterException; ...@@ -23,7 +26,6 @@ import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.component.NetworkHandler; import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.component.PushMessageReceiver;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.config.Base; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.TrolleyGoods; import com.ihaoin.hooloo.device.data.TrolleyGoods;
...@@ -184,17 +186,13 @@ public class ConfirmOrderDialog extends Dialog { ...@@ -184,17 +186,13 @@ public class ConfirmOrderDialog extends Dialog {
confirmOrderHandler.removeCallbacksAndMessages(null); confirmOrderHandler.removeCallbacksAndMessages(null);
confirmOrderHandler = null; confirmOrderHandler = null;
} }
if (qrCodeVisitedHandler != null) { unregsitQRCodeVisitedReceiver();
qrCodeVisitedHandler.removeCallbacksAndMessages(null);
qrCodeVisitedHandler = null;
}
unregsitQRCodeVisitedListener();
} }
}; };
/** 等待扫码倒计时 */ /** 等待扫码倒计时 */
private void startExpireThread() { private void startExpireThread() {
regsitQRCodeVisitedListener(); regsitQRCodeVisitedReceiver();
expireThread = new Thread(() -> { expireThread = new Thread(() -> {
try { try {
for (int i = EXPIRE_TIMES; i >= 0; i--) { for (int i = EXPIRE_TIMES; i >= 0; i--) {
...@@ -308,28 +306,30 @@ public class ConfirmOrderDialog extends Dialog { ...@@ -308,28 +306,30 @@ public class ConfirmOrderDialog extends Dialog {
return bitmap; return bitmap;
} }
private QRCodeVisitedHandler qrCodeVisitedHandler; private QRCodeVisitedReceiver qrCodeVisitedReceiver;
class QRCodeVisitedHandler extends Handler { class QRCodeVisitedReceiver extends BroadcastReceiver {
@Override @Override
public void handleMessage(@NonNull Message msg) { public void onReceive(Context context, Intent intent) {
if (msg.what != 1) {
return;
}
expireThread.interrupt(); expireThread.interrupt();
showSucceedViews(); showSucceedViews();
startReturnThread(); startReturnThread();
unregsitQRCodeVisitedListener(); unregsitQRCodeVisitedReceiver();
} }
} }
private void regsitQRCodeVisitedListener() { private void regsitQRCodeVisitedReceiver() {
qrCodeVisitedHandler = new QRCodeVisitedHandler(); qrCodeVisitedReceiver = new QRCodeVisitedReceiver();
PushMessageReceiver.subscribe(Base.PUSH_ACTION_QRCODE_VISITED, qrCodeVisitedHandler); IntentFilter filter = new IntentFilter();
filter.addAction(Base.PUSH_ACTION_QRCODE_VISITED);
getContext().registerReceiver(qrCodeVisitedReceiver, filter);
} }
private void unregsitQRCodeVisitedListener() { private void unregsitQRCodeVisitedReceiver() {
PushMessageReceiver.unsubscribe(Base.PUSH_ACTION_QRCODE_VISITED); if (qrCodeVisitedReceiver != null) {
getContext().unregisterReceiver(qrCodeVisitedReceiver);
qrCodeVisitedReceiver = null;
}
} }
/** 将购物车列表按商品id分组保存 */ /** 将购物车列表按商品id分组保存 */
......
...@@ -26,12 +26,14 @@ import com.ihaoin.hooloo.device.R; ...@@ -26,12 +26,14 @@ import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.component.AutoWrapLayout; import com.ihaoin.hooloo.device.component.AutoWrapLayout;
import com.ihaoin.hooloo.device.component.IntroViewPager; import com.ihaoin.hooloo.device.component.IntroViewPager;
import com.ihaoin.hooloo.device.component.NetworkHandler; import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.config.Base; import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.enums.SkuState; import com.ihaoin.hooloo.device.data.enums.SkuState;
import com.ihaoin.hooloo.device.data.vo.Goods; import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.GoodsRule; import com.ihaoin.hooloo.device.data.vo.GoodsRule;
import com.ihaoin.hooloo.device.data.vo.Sku; import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.data.vo.SkuRule; import com.ihaoin.hooloo.device.data.vo.SkuRule;
import com.ihaoin.hooloo.device.data.vo.SkuStateChangedVo;
import com.ihaoin.hooloo.device.network.HttpUtil; import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.CollectionUtils; import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.JsonUtils; import com.ihaoin.hooloo.device.util.JsonUtils;
...@@ -327,6 +329,35 @@ public class GoodsDetailDialog extends Dialog { ...@@ -327,6 +329,35 @@ public class GoodsDetailDialog extends Dialog {
private void setGoods(Goods rspGoods) { private void setGoods(Goods rspGoods) {
this.mGoods = rspGoods; this.mGoods = rspGoods;
if (this.mGoods != null) {
Map<Integer, List<Sku>> map = mGoods.getSkus().stream().collect(Collectors.groupingBy(Sku::getState));
if (CollectionUtils.isEmpty(map)) {
return;
}
// 售罄SKU列表
List<Sku> sellOuts = map.get(SkuState.SELLOUT.getCode());
// 未售罄SKU列表
List<Sku> sellIns = map.get(SkuState.SELLIN.getCode());
if (!CollectionUtils.isEmpty(sellOuts)) {
List<Integer> ids = sellOuts.stream().map(Sku::getSkuId).collect(Collectors.toList());
SkuStateChangedVo changedVo = new SkuStateChangedVo();
changedVo.setMachineCode(AppConfig.MACHINE_CODE);
changedVo.setGoodsId(mGoods.getGoodsId());
changedVo.setState(SkuState.SELLOUT.getCode());
changedVo.setSkuIds(ids);
Utils.fastPushBroadcast(getContext(), Base.PUSH_ACTION_SKU_STATE_CHANGED, JsonUtils.toString(changedVo));
}
if (!CollectionUtils.isEmpty(sellIns)) {
List<Integer> ids = sellIns.stream().map(Sku::getSkuId).collect(Collectors.toList());
SkuStateChangedVo changedVo = new SkuStateChangedVo();
changedVo.setMachineCode(AppConfig.MACHINE_CODE);
changedVo.setGoodsId(mGoods.getGoodsId());
changedVo.setState(SkuState.SELLIN.getCode());
changedVo.setSkuIds(ids);
Utils.fastPushBroadcast(getContext(), Base.PUSH_ACTION_SKU_STATE_CHANGED, JsonUtils.toString(changedVo));
}
}
processSpecRules(); processSpecRules();
buildSpecs(); buildSpecs();
} }
......
...@@ -10,7 +10,6 @@ import android.graphics.Rect; ...@@ -10,7 +10,6 @@ import android.graphics.Rect;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
...@@ -31,7 +30,6 @@ import com.ihaoin.hooloo.device.R; ...@@ -31,7 +30,6 @@ import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.GoodsAdapter; import com.ihaoin.hooloo.device.adapter.GoodsAdapter;
import com.ihaoin.hooloo.device.adapter.RecommendAdapter; import com.ihaoin.hooloo.device.adapter.RecommendAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler; import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.component.PushMessageReceiver;
import com.ihaoin.hooloo.device.component.SettingsQueue; import com.ihaoin.hooloo.device.component.SettingsQueue;
import com.ihaoin.hooloo.device.config.AppConfig; import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.config.Base; import com.ihaoin.hooloo.device.config.Base;
...@@ -54,8 +52,8 @@ import java.util.ArrayList; ...@@ -54,8 +52,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class LauncherActivity extends Activity { public class LauncherActivity extends Activity {
private SkuStateChangeHandler skuStateChangeHandler; private SkuStateChangeReceiver skuChangeReceiver;
private GoodsChangeHandler goodsChangeHandler; private GoodsChangeReceiver goodsChangeReceiver;
private RadioGroup groupCategory; private RadioGroup groupCategory;
private RecyclerView recGoods; private RecyclerView recGoods;
...@@ -75,7 +73,6 @@ public class LauncherActivity extends Activity { ...@@ -75,7 +73,6 @@ public class LauncherActivity extends Activity {
private List<Integer> tPosition = new ArrayList<>(); private List<Integer> tPosition = new ArrayList<>();
//记录商品当前可见的第一个item的position //记录商品当前可见的第一个item的position
private int first = 0; private int first = 0;
private Context mContext;
private TrolleyView trolleyView; private TrolleyView trolleyView;
private MenuPresentation menu; private MenuPresentation menu;
...@@ -84,7 +81,6 @@ public class LauncherActivity extends Activity { ...@@ -84,7 +81,6 @@ public class LauncherActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher); setContentView(R.layout.activity_launcher);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
mContext = this;
requestPermissions(); requestPermissions();
...@@ -108,8 +104,8 @@ public class LauncherActivity extends Activity { ...@@ -108,8 +104,8 @@ public class LauncherActivity extends Activity {
registTrolleyStateChangedReceiver(); registTrolleyStateChangedReceiver();
registSettingChangedReceiver(); registSettingChangedReceiver();
prepareMenuView(); prepareMenuView();
regsitSkuChangeListener(); regsitSkuChangeReceiver();
regsitGoodsChangeListener(); regsitGoodsChangeReceiver();
startLoadDataThread(); startLoadDataThread();
initSettingsQueue(); initSettingsQueue();
...@@ -117,7 +113,7 @@ public class LauncherActivity extends Activity { ...@@ -117,7 +113,7 @@ public class LauncherActivity extends Activity {
private void initSettingsQueue() { private void initSettingsQueue() {
View imgLogo = findViewById(R.id.img_logo); View imgLogo = findViewById(R.id.img_logo);
new SettingsQueue(mContext, imgLogo, txtCategory); new SettingsQueue(this, imgLogo, txtCategory);
} }
private void setMachineCode() { private void setMachineCode() {
...@@ -129,7 +125,7 @@ public class LauncherActivity extends Activity { ...@@ -129,7 +125,7 @@ public class LauncherActivity extends Activity {
} }
private void initRecommends() { private void initRecommends() {
recommendManager = new GridLayoutManager(mContext, 2); recommendManager = new GridLayoutManager(this, 2);
recommendManager.setSpanSizeLookup(new MySpanSizeLookup()); recommendManager.setSpanSizeLookup(new MySpanSizeLookup());
recRecommends.addItemDecoration(new MyItemDecoration()); recRecommends.addItemDecoration(new MyItemDecoration());
...@@ -184,7 +180,7 @@ public class LauncherActivity extends Activity { ...@@ -184,7 +180,7 @@ public class LauncherActivity extends Activity {
} }
private void initGoods() { private void initGoods() {
goodsLayoutManager = new LinearLayoutManager(mContext); goodsLayoutManager = new LinearLayoutManager(this);
if (goodsAdapter == null) { if (goodsAdapter == null) {
goodsAdapter = new GoodsAdapter(this, R.layout.item_goods, R.layout.item_goods_category); goodsAdapter = new GoodsAdapter(this, R.layout.item_goods, R.layout.item_goods_category);
recGoods.setAdapter(goodsAdapter); recGoods.setAdapter(goodsAdapter);
...@@ -227,15 +223,15 @@ public class LauncherActivity extends Activity { ...@@ -227,15 +223,15 @@ public class LauncherActivity extends Activity {
int nextPosition = firstPosition + 1; // 当前显示的下一个索引 int nextPosition = firstPosition + 1; // 当前显示的下一个索引
if (nextPosition < scrollGoods.size()) { // 已经是最后一个item if (nextPosition < scrollGoods.size()) { // 已经是最后一个item
if (scrollGoods.get(nextPosition).isHeader) { // 下一个是否是标题 if (scrollGoods.get(nextPosition).isHeader) { // 下一个是否是标题
int paddingTop = Utils.getDimens(mContext, R.dimen.goods_padding_top); int paddingTop = Utils.getDimens(LauncherActivity.this, R.dimen.goods_padding_top);
View nextView = goodsLayoutManager.findViewByPosition(nextPosition); // 下一个view View nextView = goodsLayoutManager.findViewByPosition(nextPosition); // 下一个view
int[] location = new int[2]; int[] location = new int[2];
nextView.getLocationInWindow(location); nextView.getLocationInWindow(location);
int topMargin = location[1] -paddingTop; int topMargin = location[1] - paddingTop;
int height = nextView.getHeight(); int height = nextView.getHeight();
// Log.d(AppConfig.TAG, String.format("c:%s, n:%s, 0:%s, 1:%s", firstPosition, nextPosition, rect[0], rect[1])); // Log.d(AppConfig.TAG, String.format("c:%s, n:%s, 0:%s, 1:%s", firstPosition, nextPosition, rect[0], rect[1]));
if (topMargin < height) { if (topMargin < height) {
lp.setMargins(0, -(height - topMargin ), 0, 0); lp.setMargins(0, -(height - topMargin), 0, 0);
} }
} }
} }
...@@ -406,8 +402,8 @@ public class LauncherActivity extends Activity { ...@@ -406,8 +402,8 @@ public class LauncherActivity extends Activity {
this.unregistTrolleyGoodsChangedReceiver(); this.unregistTrolleyGoodsChangedReceiver();
this.unregistTrolleyStateChangedReceiver(); this.unregistTrolleyStateChangedReceiver();
this.unregistSettingChangedReceiver(); this.unregistSettingChangedReceiver();
this.unregsitSkuChangeListener(); this.unregsitSkuChangeReceiver();
this.unregsitGoodsChangeListener(); this.unregsitGoodsChangeReceiver();
System.exit(0); System.exit(0);
} }
...@@ -467,7 +463,7 @@ public class LauncherActivity extends Activity { ...@@ -467,7 +463,7 @@ public class LauncherActivity extends Activity {
private void unregistTrolleyStateChangedReceiver() { private void unregistTrolleyStateChangedReceiver() {
if (trolleyStateChangedReceiver != null) { if (trolleyStateChangedReceiver != null) {
mContext.unregisterReceiver(trolleyStateChangedReceiver); this.unregisterReceiver(trolleyStateChangedReceiver);
trolleyStateChangedReceiver = null; trolleyStateChangedReceiver = null;
} }
} }
...@@ -490,22 +486,6 @@ public class LauncherActivity extends Activity { ...@@ -490,22 +486,6 @@ public class LauncherActivity extends Activity {
} }
} }
private void registSettingChangedReceiver() {
settingChangedReceiver = new SettingChangedReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Base.BROADCAST_ACTION_MACHINE_CODE_CHANGED);
filter.addAction(Base.BROADCAST_ACTION_MENU_STATE_CHANGED);
filter.addAction(Base.BROADCAST_ACTION_LOGCAT_STATE_CHANGED);
this.registerReceiver(settingChangedReceiver, filter);
}
private void unregistSettingChangedReceiver() {
if (settingChangedReceiver != null) {
mContext.unregisterReceiver(settingChangedReceiver);
settingChangedReceiver = null;
}
}
private class SettingChangedReceiver extends BroadcastReceiver { private class SettingChangedReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
...@@ -570,33 +550,55 @@ public class LauncherActivity extends Activity { ...@@ -570,33 +550,55 @@ public class LauncherActivity extends Activity {
} }
} }
private void regsitSkuChangeListener() { private void registSettingChangedReceiver() {
skuStateChangeHandler = new SkuStateChangeHandler(); settingChangedReceiver = new SettingChangedReceiver();
PushMessageReceiver.subscribe(Base.PUSH_ACTION_SKU_STATE_CHANGED, skuStateChangeHandler); IntentFilter filter = new IntentFilter();
filter.addAction(Base.BROADCAST_ACTION_MACHINE_CODE_CHANGED);
filter.addAction(Base.BROADCAST_ACTION_MENU_STATE_CHANGED);
filter.addAction(Base.BROADCAST_ACTION_LOGCAT_STATE_CHANGED);
this.registerReceiver(settingChangedReceiver, filter);
}
private void unregistSettingChangedReceiver() {
if (settingChangedReceiver != null) {
this.unregisterReceiver(settingChangedReceiver);
settingChangedReceiver = null;
}
}
private void regsitSkuChangeReceiver() {
skuChangeReceiver = new SkuStateChangeReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Base.PUSH_ACTION_SKU_STATE_CHANGED);
this.registerReceiver(skuChangeReceiver, filter);
} }
private void unregsitSkuChangeListener() { private void unregsitSkuChangeReceiver() {
PushMessageReceiver.unsubscribe(Base.PUSH_ACTION_SKU_STATE_CHANGED); if (skuChangeReceiver != null) {
this.unregisterReceiver(skuChangeReceiver);
skuChangeReceiver = null;
}
} }
private void regsitGoodsChangeListener() { private void regsitGoodsChangeReceiver() {
goodsChangeHandler = new GoodsChangeHandler(); goodsChangeReceiver = new GoodsChangeReceiver();
PushMessageReceiver.subscribe(Base.PUSH_ACTION_GOODS_CHANGED, goodsChangeHandler); IntentFilter filter = new IntentFilter();
filter.addAction(Base.PUSH_ACTION_GOODS_CHANGED);
this.registerReceiver(goodsChangeReceiver, filter);
} }
private void unregsitGoodsChangeListener() { private void unregsitGoodsChangeReceiver() {
PushMessageReceiver.unsubscribe(Base.PUSH_ACTION_GOODS_CHANGED); if (goodsChangeReceiver != null) {
this.unregisterReceiver(goodsChangeReceiver);
goodsChangeReceiver = null;
}
} }
class SkuStateChangeHandler extends Handler { class SkuStateChangeReceiver extends BroadcastReceiver {
@Override @Override
public void handleMessage(@NonNull Message msg) { public void onReceive(Context context, Intent intent) {
try { try {
super.handleMessage(msg); String msgBody = intent.getStringExtra(Base.PUSH_DEFAULT_EXTRA);
if (msg.obj == null) {
return;
}
String msgBody = msg.obj.toString();
if (StringUtils.isEmpty(msgBody)) { if (StringUtils.isEmpty(msgBody)) {
return; return;
} }
...@@ -658,10 +660,9 @@ public class LauncherActivity extends Activity { ...@@ -658,10 +660,9 @@ public class LauncherActivity extends Activity {
} }
} }
class GoodsChangeHandler extends Handler { class GoodsChangeReceiver extends BroadcastReceiver {
@Override @Override
public void handleMessage(@NonNull Message msg) { public void onReceive(Context context, Intent intent) {
super.handleMessage(msg);
loadData(); loadData();
} }
} }
......
package com.ihaoin.hooloo.device.view; package com.ihaoin.hooloo.device.view;
import android.app.Presentation; import android.app.Presentation;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.view.Display; import android.view.Display;
import android.widget.GridView; import android.widget.GridView;
...@@ -16,7 +18,6 @@ import com.ihaoin.hooloo.device.HLApplication; ...@@ -16,7 +18,6 @@ import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.OrderAdapter; import com.ihaoin.hooloo.device.adapter.OrderAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler; 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.config.Base;
import com.ihaoin.hooloo.device.data.MainData; import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.data.enums.ImageState; import com.ihaoin.hooloo.device.data.enums.ImageState;
...@@ -39,7 +40,7 @@ public class MenuPresentation extends Presentation { ...@@ -39,7 +40,7 @@ public class MenuPresentation extends Presentation {
private List<OrderPkg> pkgs; private List<OrderPkg> pkgs;
private LoadOrdersHandler loadOrdersHandler; private LoadOrdersHandler loadOrdersHandler;
private OrderStateChangeHandler orderStateChangeHandler; private OrderStateChangeReceiver orderStateChangeReceiver;
private List<Order> cookingOrders; private List<Order> cookingOrders;
private List<Order> waitingOrders; private List<Order> waitingOrders;
...@@ -148,12 +149,14 @@ public class MenuPresentation extends Presentation { ...@@ -148,12 +149,14 @@ public class MenuPresentation extends Presentation {
completedAdapter.notifyDataSetChanged(); completedAdapter.notifyDataSetChanged();
showImages(); showImages();
regsitOrderChangeListener(); regsitOrderChangeReceiver();
} }
private void regsitOrderChangeListener() { private void regsitOrderChangeReceiver() {
orderStateChangeHandler = new OrderStateChangeHandler(); orderStateChangeReceiver = new OrderStateChangeReceiver();
PushMessageReceiver.subscribe(Base.PUSH_ACTION_ORDER_STATE_CHANGED, orderStateChangeHandler); IntentFilter filter = new IntentFilter();
filter.addAction(Base.PUSH_ACTION_ORDER_STATE_CHANGED);
getContext().registerReceiver(orderStateChangeReceiver, filter);
} }
private List<Order> getOrders(Integer state) { private List<Order> getOrders(Integer state) {
...@@ -190,15 +193,11 @@ public class MenuPresentation extends Presentation { ...@@ -190,15 +193,11 @@ public class MenuPresentation extends Presentation {
} }
} }
class OrderStateChangeHandler extends Handler { class OrderStateChangeReceiver extends BroadcastReceiver {
@Override @Override
public void handleMessage(@NonNull Message msg) { public void onReceive(Context context, Intent intent) {
try { try {
super.handleMessage(msg); String msgBody = intent.getStringExtra(Base.PUSH_DEFAULT_EXTRA);
if (msg.obj == null) {
return;
}
String msgBody = msg.obj.toString();
if (StringUtils.isEmpty(msgBody)) { if (StringUtils.isEmpty(msgBody)) {
return; return;
} }
......
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