version:3.2.0

fix:优化管控逻辑
update:
This commit is contained in:
2024-01-04 11:44:53 +08:00
parent 576419bbf2
commit ac0ec1feee
12 changed files with 541 additions and 136 deletions

View File

@@ -28,6 +28,7 @@ import com.blankj.utilcode.util.NetworkUtils;
import com.fuying.sn.BuildConfig;
import com.fuying.sn.R;
import com.fuying.sn.base.BaseActivity;
import com.fuying.sn.bean.AppInfo;
import com.fuying.sn.bean.BaseResponse;
import com.fuying.sn.bean.SnInfo;
import com.fuying.sn.config.CommonConfig;
@@ -50,6 +51,8 @@ import com.fuying.sn.utils.SPUtils;
import com.fuying.sn.utils.TimeUtils;
import com.fuying.sn.utils.ToastUtil;
import com.fuying.sn.utils.Utils;
import com.trello.rxlifecycle4.RxLifecycle;
import com.trello.rxlifecycle4.android.ActivityEvent;
import org.jetbrains.annotations.NotNull;
@@ -58,6 +61,9 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
public class MainActivity extends BaseActivity implements MainAContact.MainView, NetworkUtils.OnNetworkStatusChangedListener {
private static final String TAG = MainActivity.class.getSimpleName();
@@ -151,12 +157,58 @@ public class MainActivity extends BaseActivity implements MainAContact.MainView,
tv_update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ToastUtil.show("正在检查更新");
mPresenter.getAllApp();
if (mCheckUpdate) {
ToastUtil.show("您已检查过更新,请稍后再试");
} else {
ToastUtil.show("正在检查更新");
checkUpdate();
}
}
});
}
private boolean mCheckUpdate = false;
private void checkUpdate() {
NetInterfaceManager.getInstance().getUpdateObservable(BuildConfig.APPLICATION_ID)
.compose(RxLifecycle.bindUntilEvent(lifecycleSubject, ActivityEvent.DESTROY))
.subscribe(new Observer<BaseResponse<AppInfo>>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e("checkUpdate", "onSubscribe: ");
}
@Override
public void onNext(@NonNull BaseResponse<AppInfo> appInfoBaseResponse) {
Log.e("checkUpdate", "onSubscribe: " + appInfoBaseResponse);
if (appInfoBaseResponse.code == 200) {
AppInfo appInfo = appInfoBaseResponse.data;
if (appInfo.getApp_version_code() > BuildConfig.VERSION_CODE) {
ToastUtil.show("正在下载更新");
} else {
ToastUtil.show("已是最新版本");
}
} else {
ToastUtil.show("没有找到更新");
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("checkUpdate", "onError: " + e.getMessage());
ToastUtil.show("请稍后重试");
onComplete();
}
@Override
public void onComplete() {
Log.e("checkUpdate", "onComplete: ");
mCheckUpdate = true;
}
});
}
private TimeTask task;
private static class TimeTask extends AsyncTask<String, Long, Long> {