Commit 15a99390 by wjg

优化增加空闲弹窗

parent f4a6688c
...@@ -2,6 +2,7 @@ package com.ihaoin.hooloo.device.adapter; ...@@ -2,6 +2,7 @@ package com.ihaoin.hooloo.device.adapter;
import android.content.Context; import android.content.Context;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
...@@ -45,11 +46,13 @@ public class RecommendAdapter extends BaseQuickAdapter<ScrollBean, BaseViewHolde ...@@ -45,11 +46,13 @@ public class RecommendAdapter extends BaseQuickAdapter<ScrollBean, BaseViewHolde
}); });
helper.getConvertView().setTag(recommend); helper.getConvertView().setTag(recommend);
ViewGroup.LayoutParams lp = imgRecommend.getLayoutParams();
if (recommend.getIndex() == 0) { if (recommend.getIndex() == 0) {
imgRecommend.setMaxHeight(Utils.getDimens(mContext, R.dimen.recommend_image_height_0)); lp.height = Utils.getDimens(mContext, R.dimen.recommend_image_height_0);
} else { } else {
imgRecommend.setMaxHeight(Utils.getDimens(mContext, R.dimen.recommend_image_height_other)); lp.height = Utils.getDimens(mContext, R.dimen.recommend_image_height_other);
} }
imgRecommend.setLayoutParams(lp);
} }
} }
...@@ -27,6 +27,7 @@ import com.ihaoin.hooloo.device.data.TrolleyGoods; ...@@ -27,6 +27,7 @@ import com.ihaoin.hooloo.device.data.TrolleyGoods;
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.Sku; import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.view.ClearDialog;
import com.ihaoin.hooloo.device.view.ConfirmOrderDialog; 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.SettingsActivity; import com.ihaoin.hooloo.device.view.SettingsActivity;
...@@ -75,6 +76,11 @@ public class Utils { ...@@ -75,6 +76,11 @@ public class Utils {
dialog.show(); dialog.show();
} }
public static void showClearDialog(Context context) {
ClearDialog dialog = new ClearDialog(context);
dialog.show();
}
public static void showConfirmOrder(Context context, List<TrolleyGoods> trolleyGoods) { public static void showConfirmOrder(Context context, List<TrolleyGoods> trolleyGoods) {
ConfirmOrderDialog dialog = new ConfirmOrderDialog(context); ConfirmOrderDialog dialog = new ConfirmOrderDialog(context);
dialog.setGoods(trolleyGoods); dialog.setGoods(trolleyGoods);
......
package com.ihaoin.hooloo.device.view;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.util.Utils;
public class ClearDialog extends Dialog {
private TextView txtText;
private View butnYes;
private View butnNo;
private TimerHandler timerHandler;
public ClearDialog(@NonNull Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.view_clear);
setCancelable(false);
setCanceledOnTouchOutside(false);
initViews();
LauncherActivity.TIMEOUT_TOGGLE = false;
timerHandler = new TimerHandler();
new Thread(() -> {
try {
for (int i = 10; i >= 0; i--) {
timerHandler.sendEmptyMessage(i);
Thread.sleep(1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
private void initViews() {
txtText = findViewById(R.id.txt_text);
butnYes = findViewById(R.id.butn_yes);
butnNo = findViewById(R.id.butn_no);
butnYes.setOnClickListener(v -> confirmClear());
butnNo.setOnClickListener(x -> dismiss());
setOnDismissListener(dismissListener);
}
private void confirmClear() {
Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_CLEAR_GOODS);
Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_TIMEOUT);
dismiss();
}
OnDismissListener dismissListener = new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
LauncherActivity.TIMEOUT_TOGGLE = true;
if (timerHandler != null) {
timerHandler.removeCallbacksAndMessages(null);
timerHandler = null;
}
}
};
class TimerHandler extends Handler {
@Override
public void handleMessage(@NonNull Message msg) {
if (msg.what <= 0) {
confirmClear();
return;
}
txtText.setText(getContext().getString(R.string.clear_tips, String.valueOf(msg.what)));
}
}
}
package com.ihaoin.hooloo.device.view; package com.ihaoin.hooloo.device.view;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
...@@ -10,6 +11,7 @@ import android.graphics.Rect; ...@@ -10,6 +11,7 @@ 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;
...@@ -710,15 +712,16 @@ public class LauncherActivity extends Activity { ...@@ -710,15 +712,16 @@ public class LauncherActivity extends Activity {
try { try {
while (true) { while (true) {
Thread.sleep(1000); Thread.sleep(1000);
if (!TIMEOUT_TOGGLE) { // 打开确认订单弹窗,停止判断空闲 if (!TIMEOUT_TOGGLE || HLApplication.getGoodsCount() <= 0) { // 打开确认订单弹窗,停止判断空闲
TIMESTAMP = Utils.getTimestamp(); TIMESTAMP = Utils.getTimestamp();
continue; continue;
} }
// Log.i(AppConfig.TAG, String.valueOf(Utils.getTimestamp() - TIMESTAMP)); // Log.i(AppConfig.TAG, String.valueOf(Utils.getTimestamp() - TIMESTAMP));
if (Utils.getTimestamp() - TIMESTAMP > 1000 * 30) { if (Utils.getTimestamp() - TIMESTAMP > 1000 * 30) {
TIMESTAMP = Utils.getTimestamp(); TIMESTAMP = Utils.getTimestamp();
Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_CLEAR_GOODS); // Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_CLEAR_GOODS);
Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_TIMEOUT); // Utils.fastBroadcast(HLApplication.SELF, Base.BROADCAST_ACTION_TIMEOUT);
clearTipHandler.sendEmptyMessage(0);
} }
} }
} catch (Exception e) { } catch (Exception e) {
...@@ -726,4 +729,12 @@ public class LauncherActivity extends Activity { ...@@ -726,4 +729,12 @@ public class LauncherActivity extends Activity {
} }
} }
} }
Handler clearTipHandler = new Handler() {
@SuppressLint("HandlerLeak")
@Override
public void handleMessage(@NonNull Message msg) {
Utils.showClearDialog(LauncherActivity.this);
}
};
} }
...@@ -3,7 +3,6 @@ package com.ihaoin.hooloo.device.view; ...@@ -3,7 +3,6 @@ package com.ihaoin.hooloo.device.view;
import android.app.Dialog; import android.app.Dialog;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
...@@ -66,12 +65,7 @@ public class TipsDialog extends Dialog { ...@@ -66,12 +65,7 @@ public class TipsDialog extends Dialog {
return super.dispatchTouchEvent(ev); return super.dispatchTouchEvent(ev);
} }
OnDismissListener dismissListener = new OnDismissListener() { OnDismissListener dismissListener = dialog -> unregsitTimeoutReceiver();
@Override
public void onDismiss(DialogInterface dialog) {
unregsitTimeoutReceiver();
}
};
private TimeoutReceiver timeoutReceiver; private TimeoutReceiver timeoutReceiver;
......
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:bottomRightRadius="4px" />
<solid
android:width="1px"
android:color="@color/textPrimary" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:bottomLeftRadius="5px" />
<solid
android:width="1px"
android:color="@color/white" />
<stroke
android:width="1px"
android:color="@color/textPrimary" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4px" />
<solid
android:width="1px"
android:color="@color/white" />
</shape>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="@dimen/dialog_clear_width"
android:layout_height="@dimen/dialog_clear_height"
android:background="@drawable/bg_dialog_clear"
android:orientation="vertical">
<TextView
android:id="@+id/txt_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/clear_tips"
android:textColor="@color/textPrimary"
android:textSize="@dimen/clear_butn_text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/butn_yes"
android:layout_width="0dp"
android:layout_height="@dimen/clear_butn_height"
android:layout_weight="1"
android:background="@drawable/bg_clear_yes"
android:foreground="?selectableItemBackground"
android:text="是"
android:textColor="@color/textPrimary"
android:textSize="@dimen/clear_butn_text" />
<Button
android:id="@+id/butn_no"
android:layout_width="0dp"
android:layout_height="@dimen/clear_butn_height"
android:layout_weight="1"
android:background="@drawable/bg_clear_no"
android:foreground="?selectableItemBackground"
android:text="否"
android:textColor="@color/white"
android:textSize="@dimen/clear_butn_text" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
...@@ -75,7 +75,11 @@ ...@@ -75,7 +75,11 @@
<dimen name="dialog_detail_width">1800px</dimen> <dimen name="dialog_detail_width">1800px</dimen>
<dimen name="dialog_tip_width">1100px</dimen> <dimen name="dialog_tip_width">1100px</dimen>
<dimen name="dialog_clear_width">715px</dimen>
<dimen name="dialog_clear_height">385px</dimen>
<dimen name="dialog_close_margin">35px</dimen> <dimen name="dialog_close_margin">35px</dimen>
<dimen name="clear_butn_height">100px</dimen>
<dimen name="clear_butn_text">40px</dimen>
<dimen name="trolley_width">850px</dimen> <dimen name="trolley_width">850px</dimen>
<dimen name="trolley_item_height">210px</dimen> <dimen name="trolley_item_height">210px</dimen>
......
...@@ -75,7 +75,11 @@ ...@@ -75,7 +75,11 @@
<dimen name="dialog_detail_width">600dp</dimen> <dimen name="dialog_detail_width">600dp</dimen>
<dimen name="dialog_tip_width">600dp</dimen> <dimen name="dialog_tip_width">600dp</dimen>
<dimen name="dialog_close_margin">15dp</dimen> <dimen name="dialog_clear_width">715px</dimen>
<dimen name="dialog_clear_height">385px</dimen>
<dimen name="dialog_close_margin">35px</dimen>
<dimen name="clear_butn_height">100px</dimen>
<dimen name="clear_butn_text">40px</dimen>
<dimen name="trolley_width">400dp</dimen> <dimen name="trolley_width">400dp</dimen>
<dimen name="trolley_item_height">100dp</dimen> <dimen name="trolley_item_height">100dp</dimen>
......
...@@ -14,4 +14,5 @@ ...@@ -14,4 +14,5 @@
<string name="error_load_main_data">获取数据失败</string> <string name="error_load_main_data">获取数据失败</string>
<string name="error_check_sku_wrong">商品状态错误</string> <string name="error_check_sku_wrong">商品状态错误</string>
<string name="error_check_sku">商品已售罄</string> <string name="error_check_sku">商品已售罄</string>
<string name="clear_tips">是否清空购物车(%ss)</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment