Commit 83340ba8 by wjg

添加空闲时间清空购物车,并回到首页

parent d7fdc3e1
...@@ -78,6 +78,7 @@ public class HLApplication extends Application { ...@@ -78,6 +78,7 @@ public class HLApplication extends Application {
} }
} }
@Override @Override
public void onTerminate() { public void onTerminate() {
super.onTerminate(); super.onTerminate();
......
...@@ -19,5 +19,7 @@ public class Base { ...@@ -19,5 +19,7 @@ public class Base {
public static final String BROADCAST_ACTION_MACHINE_CODE_CHANGED = "ACTION_MACHINE_CODE_CHANGED"; public static final String BROADCAST_ACTION_MACHINE_CODE_CHANGED = "ACTION_MACHINE_CODE_CHANGED";
public static final String BROADCAST_ACTION_MENU_STATE_CHANGED = "ACTION_MENU_STATE_CHANGED"; public static final String BROADCAST_ACTION_MENU_STATE_CHANGED = "ACTION_MENU_STATE_CHANGED";
public static final String BROADCAST_ACTION_LOGCAT_STATE_CHANGED = "ACTION_LOGCAT_STATE_CHANGED"; public static final String BROADCAST_ACTION_LOGCAT_STATE_CHANGED = "ACTION_LOGCAT_STATE_CHANGED";
public static final String BROADCAST_ACTION_TOUCH_EVENT = "ACTION_TOUCH_EVENT";
public static final String BROADCAST_ACTION_TIMEOUT = "ACTION_TIMEOUT";
} }
...@@ -34,10 +34,14 @@ import com.ihaoin.hooloo.device.view.TipsDialog; ...@@ -34,10 +34,14 @@ import com.ihaoin.hooloo.device.view.TipsDialog;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
public class Utils { public class Utils {
public static long getTimestamp() {
return new Date().getTime();
}
public static void fastBroadcast(Context context, String action) { public static void fastBroadcast(Context context, String action) {
Intent intent = new Intent(); Intent intent = new Intent();
......
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.Paint; import android.graphics.Paint;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
...@@ -83,6 +87,13 @@ public class GoodsDetailDialog extends Dialog { ...@@ -83,6 +87,13 @@ public class GoodsDetailDialog extends Dialog {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
this.setContentView(R.layout.view_goods_detail); this.setContentView(R.layout.view_goods_detail);
initViews(); initViews();
regsitTimeoutReceiver();
}
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
Utils.fastBroadcast(getContext(), Base.BROADCAST_ACTION_TOUCH_EVENT);
return super.dispatchTouchEvent(ev);
} }
private void initViews() { private void initViews() {
...@@ -209,6 +220,7 @@ public class GoodsDetailDialog extends Dialog { ...@@ -209,6 +220,7 @@ public class GoodsDetailDialog extends Dialog {
pagerThread.interrupt(); pagerThread.interrupt();
pagerThread = null; pagerThread = null;
} }
unregsitTimeoutReceiver();
} }
}; };
...@@ -651,21 +663,29 @@ public class GoodsDetailDialog extends Dialog { ...@@ -651,21 +663,29 @@ public class GoodsDetailDialog extends Dialog {
private void showSelloutViews() { private void showSelloutViews() {
dismiss(); dismiss();
// layoutOperate.setVisibility(View.GONE);
// layoutButns.setVisibility(View.GONE);
// txtSellout.setVisibility(View.VISIBLE);
// setAllRuleSellouts(); // 所有规格设置为售罄
} }
// private void setAllRuleSellouts() { private TimeoutReceiver timeoutReceiver;
// if (mGoods == null || CollectionUtils.isEmpty(mGoods.getSpecs())) {
// return; class TimeoutReceiver extends BroadcastReceiver {
// } @Override
// mGoods.getSpecs().forEach(spec -> { public void onReceive(Context context, Intent intent) {
// if (CollectionUtils.isEmpty(spec.getRules())) { dismiss();
// return; }
// } }
// spec.getRules().forEach(rule -> rule.setState(SkuState.SELLOUT.getCode()));
// }); private void regsitTimeoutReceiver() {
// } timeoutReceiver = new TimeoutReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Base.BROADCAST_ACTION_TIMEOUT);
this.getContext().registerReceiver(timeoutReceiver, filter);
}
private void unregsitTimeoutReceiver() {
if (timeoutReceiver != null) {
this.getContext().unregisterReceiver(timeoutReceiver);
timeoutReceiver = null;
}
}
} }
...@@ -13,6 +13,7 @@ import android.os.Bundle; ...@@ -13,6 +13,7 @@ import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.RadioButton; import android.widget.RadioButton;
...@@ -54,6 +55,7 @@ import java.util.List; ...@@ -54,6 +55,7 @@ import java.util.List;
public class LauncherActivity extends Activity { public class LauncherActivity extends Activity {
private SkuStateChangeReceiver skuChangeReceiver; private SkuStateChangeReceiver skuChangeReceiver;
private GoodsChangeReceiver goodsChangeReceiver; private GoodsChangeReceiver goodsChangeReceiver;
private TouchReceiver touchReceiver;
private RadioGroup groupCategory; private RadioGroup groupCategory;
private RecyclerView recGoods; private RecyclerView recGoods;
...@@ -106,9 +108,19 @@ public class LauncherActivity extends Activity { ...@@ -106,9 +108,19 @@ public class LauncherActivity extends Activity {
prepareMenuView(); prepareMenuView();
regsitSkuChangeReceiver(); regsitSkuChangeReceiver();
regsitGoodsChangeReceiver(); regsitGoodsChangeReceiver();
regsitTouchReceiver();
startLoadDataThread(); startLoadDataThread();
initSettingsQueue(); initSettingsQueue();
new TimeoutThread().start();
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.i(AppConfig.TAG, "dispatchTouchEvent");
TIMESTAMP = Utils.getTimestamp();
return super.dispatchTouchEvent(ev);
} }
private void initSettingsQueue() { private void initSettingsQueue() {
...@@ -402,6 +414,7 @@ public class LauncherActivity extends Activity { ...@@ -402,6 +414,7 @@ public class LauncherActivity extends Activity {
this.unregistSettingChangedReceiver(); this.unregistSettingChangedReceiver();
this.unregsitSkuChangeReceiver(); this.unregsitSkuChangeReceiver();
this.unregsitGoodsChangeReceiver(); this.unregsitGoodsChangeReceiver();
this.unregsitTouchReceiver();
System.exit(0); System.exit(0);
} }
...@@ -592,6 +605,20 @@ public class LauncherActivity extends Activity { ...@@ -592,6 +605,20 @@ public class LauncherActivity extends Activity {
} }
} }
private void regsitTouchReceiver() {
touchReceiver = new TouchReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Base.BROADCAST_ACTION_TOUCH_EVENT);
this.registerReceiver(touchReceiver, filter);
}
private void unregsitTouchReceiver() {
if (touchReceiver != null) {
this.unregisterReceiver(touchReceiver);
touchReceiver = null;
}
}
class SkuStateChangeReceiver extends BroadcastReceiver { class SkuStateChangeReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
...@@ -664,4 +691,33 @@ public class LauncherActivity extends Activity { ...@@ -664,4 +691,33 @@ public class LauncherActivity extends Activity {
loadData(); loadData();
} }
} }
class TouchReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TIMESTAMP = Utils.getTimestamp();
}
}
public static Long TIMESTAMP = System.currentTimeMillis();
/** 判断空闲时间定时器 */
private class TimeoutThread extends Thread {
@Override
public void run() {
super.run();
try {
while (true) {
Thread.sleep(1000);
Log.i(AppConfig.TAG, String.valueOf(Utils.getTimestamp() - TIMESTAMP));
if (Utils.getTimestamp() - TIMESTAMP > 1000 * 5) {
TIMESTAMP = Utils.getTimestamp();
Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_CLEAR_GOODS);
Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_TIMEOUT);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
} }
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.Intent;
import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.webkit.WebResourceRequest; import android.webkit.WebResourceRequest;
import android.webkit.WebView; import android.webkit.WebView;
...@@ -12,6 +17,7 @@ import androidx.annotation.NonNull; ...@@ -12,6 +17,7 @@ import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication; import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R; import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.config.Base;
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;
...@@ -34,6 +40,7 @@ public class TipsDialog extends Dialog { ...@@ -34,6 +40,7 @@ public class TipsDialog extends Dialog {
return; return;
} }
initViews(); initViews();
regsitTimeoutReceiver();
} }
private void initViews() { private void initViews() {
...@@ -50,5 +57,42 @@ public class TipsDialog extends Dialog { ...@@ -50,5 +57,42 @@ public class TipsDialog extends Dialog {
butnClose.setOnClickListener(x -> dismiss()); butnClose.setOnClickListener(x -> dismiss());
Utils.setTouchDelegate(findViewById(R.id.layout_root), Arrays.asList(butnClose)); Utils.setTouchDelegate(findViewById(R.id.layout_root), Arrays.asList(butnClose));
setOnDismissListener(dismissListener);
}
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
Utils.fastBroadcast(getContext(), Base.BROADCAST_ACTION_TOUCH_EVENT);
return super.dispatchTouchEvent(ev);
}
OnDismissListener dismissListener = new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
unregsitTimeoutReceiver();
}
};
private TimeoutReceiver timeoutReceiver;
class TimeoutReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
dismiss();
}
}
private void regsitTimeoutReceiver() {
timeoutReceiver = new TimeoutReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Base.BROADCAST_ACTION_TIMEOUT);
this.getContext().registerReceiver(timeoutReceiver, filter);
}
private void unregsitTimeoutReceiver() {
if (timeoutReceiver != null) {
this.getContext().unregisterReceiver(timeoutReceiver);
timeoutReceiver = null;
}
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_launcher"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/white"> android:background="@color/white">
...@@ -14,7 +15,14 @@ ...@@ -14,7 +15,14 @@
android:layout_weight="0.59375" android:layout_weight="0.59375"
android:orientation="vertical" android:orientation="vertical"
android:paddingHorizontal="@dimen/recommend_padding"> android:paddingHorizontal="@dimen/recommend_padding">
<include layout="@layout/item_logo" />
<ImageView
android:id="@+id/img_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@mipmap/logo" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rec_recommend" android:id="@+id/rec_recommend"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -35,8 +43,9 @@ ...@@ -35,8 +43,9 @@
<include layout="@layout/item_goods_category" /> <include layout="@layout/item_goods_category" />
</FrameLayout> </FrameLayout>
<ScrollView <ScrollView
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="0.09792"
android:descendantFocusability="afterDescendants" android:descendantFocusability="afterDescendants"
android:scrollbars="none"> android:scrollbars="none">
<LinearLayout <LinearLayout
...@@ -64,5 +73,4 @@ ...@@ -64,5 +73,4 @@
android:id="@+id/view_trolley" android:id="@+id/view_trolley"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</FrameLayout>
</RelativeLayout> \ No newline at end of file
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<RelativeLayout <RelativeLayout
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<dimen name="menu_content_padding_top">38px</dimen> <dimen name="menu_content_padding_top">38px</dimen>
<dimen name="menu_content_padding_bottom">38px</dimen> <dimen name="menu_content_padding_bottom">38px</dimen>
<dimen name="menu_order_margin_top">43px</dimen> <dimen name="menu_order_margin_top">43px</dimen>
<dimen name="menu_spacing_hor">37px</dimen> <dimen name="menu_spacing_hor">30px</dimen>
<dimen name="menu_spacing_ver">20px</dimen> <dimen name="menu_spacing_ver">20px</dimen>
<dimen name="goods_detail_padding_ver">55px</dimen> <dimen name="goods_detail_padding_ver">55px</dimen>
......
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