Commit 0e901650 by pye52

优化状态切换流程:

1、现在在线、离线支付失败(离线支付则为订单标记失败)后都会走同一个流程,进而最终换重置到扫码状态
2、收到在线支付结果时,若当前处理订单为空,则重置扫码状态
parent bbd70a5f
......@@ -160,40 +160,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
sendText.setText(log);
break;
case PayOnlineState.SUCCESS:
message.setTextColor(getResources().getColor(R.color.pay_success));
String successText = event.getMessage();
if (TextUtils.isEmpty(successText)) {
message.setText(R.string.pay_success);
TTSHelper.speak(getString(R.string.pay_success));
} else {
message.setText(successText);
TTSHelper.speak(successText);
}
qrCodeViewModel.scan();
String successTime = payDateFormat.format(new Date());
String successLog = "支付成功: " + successTime + " - " + event.getMessage();
LogUtils.file(TAG, successLog);
if (debugVs != null) return;
recText.setText(successLog);
paidSuccess(event.getMessage());
break;
case PayOnlineState.FAILED:
message.setTextColor(getResources().getColor(R.color.pay_failed));
String failedText = event.getMessage();
if (TextUtils.isEmpty(failedText)) {
message.setText(R.string.pay_failed);
TTSHelper.speak(getString(R.string.pay_failed));
} else {
message.setText(failedText);
TTSHelper.speak(failedText);
}
qrCodeViewModel.scan();
String failedTime = payDateFormat.format(new Date());
String failedLog = "支付失败: " + failedTime + " - " + event.getMessage();
LogUtils.file(TAG, failedLog);
if (debugVs != null) return;
recText.setText(failedLog);
paidFailed(event.getMessage());
break;
}
});
......@@ -212,6 +182,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
qrCodeViewModel.scan();
break;
case PayOfflineState.MARK_FAILED:
paidFailed(event.getMessage());
break;
}
});
......@@ -286,6 +259,42 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient.getInstance().tryConnect();
}
private void paidSuccess(String successMessage) {
message.setTextColor(getResources().getColor(R.color.pay_success));
if (TextUtils.isEmpty(successMessage)) {
message.setText(R.string.pay_success);
TTSHelper.speak(getString(R.string.pay_success));
} else {
message.setText(successMessage);
TTSHelper.speak(successMessage);
}
qrCodeViewModel.scan();
String successTime = payDateFormat.format(new Date());
String successLog = "支付成功: " + successTime + " - " + successMessage;
LogUtils.file(TAG, successLog);
if (debugVs != null) return;
recText.setText(successLog);
}
private void paidFailed(String failedMessage) {
message.setTextColor(getResources().getColor(R.color.pay_failed));
if (TextUtils.isEmpty(failedMessage)) {
message.setText(R.string.pay_failed);
TTSHelper.speak(getString(R.string.pay_failed));
} else {
message.setText(failedMessage);
TTSHelper.speak(failedMessage);
}
qrCodeViewModel.scan();
String failedTime = payDateFormat.format(new Date());
String failedLog = "支付失败: " + failedTime + " - " + failedMessage;
LogUtils.file(TAG, failedLog);
if (debugVs != null) return;
recText.setText(failedLog);
}
@Override
protected void onDestroy() {
super.onDestroy();
......
......@@ -103,6 +103,7 @@ public class PayOnlineViewModel extends ViewModel {
// 1、action为"PAY_RESULT"
if (payRequest == null || payRequest.getData().isEmpty()) {
LogUtils.w(TAG, "后台返回在线支付结果,但没有待处理任务");
payOnlineState.postValue(new PayOnlineState(PayOnlineState.IDLE));
return;
}
LogUtils.d(TAG, "在线支付结果响应: " + original);
......
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