Commit 2683985d by patpat

调整超时逻辑,超时后自动转为离线支付

parent 4a2f1ade
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -10,8 +10,8 @@ android {
applicationId "com.bgycc.smartcanteen"
minSdkVersion 21
targetSdkVersion 22
versionCode 5
versionName "1.0.5"
versionCode 6
versionName "1.0.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
......@@ -24,6 +24,8 @@ class App : Application() {
private var sVersionName = "0.0.0"
private var sVersionCode = 0
var testQRCode = ""
fun getDefault(): App {
return sDefault
}
......
......@@ -59,7 +59,6 @@ public class PayOnlineAction extends Action {
break;
case RESQUEST_FAIL:
case RESPONSE_FAIL:
case TIMEOUT:
EventBus.getDefault().post(new PayStateEvent(PayStateEvent.StateEnum.FAIL, message));
cancelTimeout();
mPayCode = "";
......@@ -71,12 +70,18 @@ public class PayOnlineAction extends Action {
}
}, 3000);
break;
case TIMEOUT:
cancelTimeout();
mPayCode = "";
fail(message);
setState(State.INITED);
return;
}
}
setState(state);
}
public void exec(String payCode, String payCodeType, ActionResult result) {
public void exec(final String payCode, final String payCodeType, ActionResult result) {
if (getState() != State.INITED) {
if (result != null) {
result.onFail("正在忙");
......@@ -93,13 +98,14 @@ public class PayOnlineAction extends Action {
public void run(long id, boolean isLastTime) {
if (isLastTime) {
setState(State.TIMEOUT, "交易超时");
PayOfflineAction.getDefault().exec(payCode, payCodeType);
} else {
if (mActionRunnable != null) {
mActionRunnable.run();
}
}
}
}, 10000, 4, 10000);
}, 5000, 2, 5000);
final MainWebSocket.Response response = new MainWebSocket.Response() {
@Override
......
......@@ -12,8 +12,11 @@ import android.view.animation.Animation
import android.view.animation.RotateAnimation
import com.bgycc.smartcanteen.App
import com.bgycc.smartcanteen.AppConfig
import com.bgycc.smartcanteen.BuildConfig
import com.bgycc.smartcanteen.R
import com.bgycc.smartcanteen.action.ActionEnum
import com.bgycc.smartcanteen.action.ActionResult
import com.bgycc.smartcanteen.action.PayOnlineAction
import com.bgycc.smartcanteen.action.UpdateAction
import com.bgycc.smartcanteen.event.*
import com.bgycc.smartcanteen.helper.EthernetHelper
......@@ -87,11 +90,7 @@ class MainActivity : BaseActivity() {
}
private fun initView() {
if (!AppConfig.DEBUG) {
_debug.visibility = View.GONE
} else {
_logo.visibility = View.GONE
}
_setting.alpha = 0f
_setting_img.post{
val anim = RotateAnimation(0f, 360f, 0.5f * _setting_img.width, 0.5f * _setting_img.height)
......@@ -103,6 +102,19 @@ class MainActivity : BaseActivity() {
_version.text = "Version: v${App.getVersionName()}(${App.getVersionCode()})"
_eth.text = "Ethernet Mac: ${EthernetHelper.getMacAddress()}"
_sn.text = "SN: ${App.getDeviceSN()}"
if (BuildConfig.DEBUG) {
_message.setOnClickListener {
App.testQRCode = "380000000000000000"
}
_debug.setOnClickListener {
_debug.visibility = View.GONE
_logo.visibility = View.VISIBLE
}
_logo.setOnClickListener {
_debug.visibility = View.VISIBLE
_logo.visibility = View.GONE
}
}
}
private fun initTimer() {
......
......@@ -165,7 +165,6 @@ public class MainWebSocket extends WebSocketClient {
public void onOpen(ServerHandshake handshakeData) {
LogUtil.i(TAG, String.format("onOpen: %d %s", handshakeData.getHttpStatus(), handshakeData.getHttpStatusMessage()));
EventBus.getDefault().post(new ConnectStateEvent(ConnectStateEvent.CONNECTED));
PayOfflineAction.getDefault().upload();
}
@Override
......
package com.bgycc.smartcanteen.task;
import android_serialport_api.SerialPort;
import com.bgycc.smartcanteen.App;
import com.bgycc.smartcanteen.event.QRCodeEvent;
import com.bgycc.smartcanteen.action.*;
import com.bgycc.smartcanteen.event.LogEvent;
......@@ -36,6 +37,7 @@ public class QRCodeTask {
private ScanAsyncTask mScanAsyncTask;
private SerialPort mSerial;
private long mTimerId = -1;
private long mOfflineUpdateDelay = 0;
private QRCodeTask() {}
......@@ -48,18 +50,24 @@ public class QRCodeTask {
if (mScanAsyncTask == null) {
mSerial = SerialPort.build(new File("/dev/ttyS6"), 115200, 0);
if (mSerial != null) {
mScanAsyncTask = new ScanAsyncTask();
mTimerId = TimerHelper.INSTANCE.loop(new TimerHelper.LoopTask() {
@Override
public void run(long id, boolean isLastTime) {
if (mScanAsyncTask == null) return;
if (mScanAsyncTask != null) {
mScanAsyncTask.run();
}
}, 200, -1);
if (mOfflineUpdateDelay >= 30000) {
if (MainWebSocket.isConnected()) {
PayOfflineAction.getDefault().upload();
mOfflineUpdateDelay = 0;
}
} else {
mOfflineUpdateDelay += 200;
}
}
}, 200, -1);
}
}
public void stop() {
......@@ -85,10 +93,9 @@ public class QRCodeTask {
// Log.i(TAG, String.format("step: %d progress: %d", step, progress));
switch (step) {
case 0:
if (progress != 0) break;
LogUtils.file(TAG, "QRCode wait");
String str = null;
if (mSerial != null) {
byte[] buf = null;
int len = 0;
while (true) {
......@@ -107,8 +114,14 @@ public class QRCodeTask {
break;
}
}
if (str == null) break;
}
if (!App.Companion.getTestQRCode().isEmpty()) {
str = App.Companion.getTestQRCode();
App.Companion.setTestQRCode("");
}
if (progress != 0 || str == null) break;
mOfflineUpdateDelay = 0;
LogUtils.file(TAG, "QRCode: " + str);
QRCodeEvent event = new QRCodeEvent(str.getBytes(), str, checkPayCodeType(str));
EventBus.getDefault().post(event);
......
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 sign in to comment