Commit 38d5b2be by pye52

1、适配后台的离线订单响应(上传成功、写入成功)

2、修复一个离线订单支付超时后又收到后台响应时的显示问题(此前会一直显示支付成功)
3、更新第三方库版本
parent e9f2136f
......@@ -161,6 +161,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
payOnlineViewModel.getPayOnlineStateEvent().observe(this, event -> {
switch (event.getState()) {
case PayOnlineState.IDLE:
message.setTextColor(getResources().getColor(R.color.qrcode_normal));
message.setText(R.string.pay_idle);
break;
case PayOnlineState.SEND:
message.setTextColor(getResources().getColor(R.color.pay_idle));
message.setText(R.string.pay_wait);
......
package com.bgycc.smartcanteen.viewModel;
import android.text.TextUtils;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
......@@ -97,8 +95,7 @@ public class PayOfflineViewModel extends ViewModel {
}
private SCWebSocketListener listener = new SCWebSocketListenerAdapter() {
private static final String RESPONSE_MESSAGE = "message";
private static final String RESPONSE_OFFLINE_RESULT = "操作完成";
private static final String RESPONSE_PAY_OFFLINE_UPLOAD = "PAY_OFFLINE_UPLOAD";
private static final String RESPONSE_PAY_OFFLINE_RESULT = "PAY_OFFLINE_RESULT";
private static final String RESPONSE_SUCCESS = "0";
// 每心跳多少次后进行一次离线订单检测
......@@ -123,30 +120,28 @@ public class PayOfflineViewModel extends ViewModel {
@Override
public void onMessage(String action, JsonObject obj, String original) {
if (action.equals(RESPONSE_PAY_OFFLINE_RESULT)) {
String code = null;
// 这里为了兼容新的消息体需要单独对code作判断
if (obj.has("code")) {
code = obj.get("code").getAsString();
}
switch (action) {
case RESPONSE_PAY_OFFLINE_UPLOAD:
if (code != null && code.equals(RESPONSE_SUCCESS)) {
// 离线订单只上传到服务器,未写入到服务器数据库
// 此时只需要更改其uploadTime(保证一定时间内不会频繁发送到服务器)
UpdateUploadTimeRunnable runnable = new UpdateUploadTimeRunnable();
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
break;
case RESPONSE_PAY_OFFLINE_RESULT:
if (code != null && code.equals(RESPONSE_SUCCESS)) {
// 离线订单已写入到服务器数据库,可以标记为支付成功
LogUtils.d(TAG, "离线支付结果响应: " + original);
ResponseRunnable runnable = new ResponseRunnable(original);
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
return;
}
String message = "";
if (obj.has(RESPONSE_MESSAGE)) {
message = obj.get(RESPONSE_MESSAGE).getAsString();
break;
}
if (!TextUtils.isEmpty(action) || !message.equals(RESPONSE_OFFLINE_RESULT)) return;
// 离线订单只上传到服务器,未写入到服务器数据库
// 此时只需要更改其uploadTime(保证一定时间内不会频繁发送到服务器)
UpdateUploadTimeRunnable runnable = new UpdateUploadTimeRunnable();
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
};
......
......@@ -100,5 +100,5 @@ dependencies {
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.blankj:utilcodex:1.28.4'
implementation 'com.blankj:utilcodex:1.29.0'
}
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