|
@@ -17,12 +17,15 @@ import com.allenliu.versionchecklib.v2.callback.ForceUpdateListener;
|
|
|
import com.cooleshow.base.R;
|
|
|
import com.cooleshow.base.bean.UpdateAppBean;
|
|
|
import com.cooleshow.base.common.AppManager;
|
|
|
+import com.cooleshow.base.common.BaseApplication;
|
|
|
+import com.cooleshow.base.common.BaseConstant;
|
|
|
import com.cooleshow.base.data.api.AppVersionApi;
|
|
|
import com.cooleshow.base.data.net.BaseResponse;
|
|
|
import com.cooleshow.base.data.net.RetrofitClientNoToken;
|
|
|
import com.cooleshow.base.data.net.RetrofitFactory;
|
|
|
import com.cooleshow.base.utils.AppUtils;
|
|
|
import com.cooleshow.base.utils.EncodeUtils;
|
|
|
+import com.cooleshow.base.utils.ToastUtil;
|
|
|
import com.cooleshow.base.utils.Utils;
|
|
|
import com.jaygoo.widget.RangeSeekBar;
|
|
|
|
|
@@ -37,6 +40,8 @@ import io.reactivex.rxjava3.schedulers.Schedulers;
|
|
|
* Author by pq, Date on 2022/7/14.
|
|
|
*/
|
|
|
public class UpdateAppHelper {
|
|
|
+ public static final String STUDENT_PLATFORM = "android-student";
|
|
|
+ public static final String TEACHER_PLATFORM = "android-teacher";
|
|
|
private static volatile UpdateAppHelper mHelper;
|
|
|
|
|
|
private UpdateAppHelper() {
|
|
@@ -54,12 +59,23 @@ public class UpdateAppHelper {
|
|
|
return mHelper;
|
|
|
}
|
|
|
|
|
|
- public void checkUpdate(Activity activity, String platform) {
|
|
|
- queryByPlatform(activity, platform);
|
|
|
+ public void checkUpdate() {
|
|
|
+ queryByPlatform(Utils.getApp(), getAppPlatform(), false);
|
|
|
}
|
|
|
|
|
|
+ public void checkUpdate(boolean isNeedTip) {
|
|
|
+ queryByPlatform(Utils.getApp(), getAppPlatform(), isNeedTip);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getAppPlatform() {
|
|
|
+ if (BaseApplication.Companion.isTeacherClient()) {
|
|
|
+ return TEACHER_PLATFORM;
|
|
|
+ }
|
|
|
+ return STUDENT_PLATFORM;
|
|
|
+ }
|
|
|
|
|
|
- private void queryByPlatform(Activity activity, String platform) {
|
|
|
+
|
|
|
+ private void queryByPlatform(Context context, String platform, boolean isNeedTip) {
|
|
|
Observable<BaseResponse<UpdateAppBean>> observable = RetrofitFactory.Companion.getInstance().create(AppVersionApi.class).queryByPlatform(platform);
|
|
|
observable.subscribeOn(Schedulers.newThread())
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
@@ -72,7 +88,7 @@ public class UpdateAppHelper {
|
|
|
@Override
|
|
|
public void onNext(@NonNull BaseResponse<UpdateAppBean> updateAppBeanBaseResponse) {
|
|
|
if (updateAppBeanBaseResponse != null) {
|
|
|
- handleResult(activity, updateAppBeanBaseResponse.getData());
|
|
|
+ handleResult(context, updateAppBeanBaseResponse.getData(), isNeedTip);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,7 +104,7 @@ public class UpdateAppHelper {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void handleResult(Activity activity, UpdateAppBean data) {
|
|
|
+ private void handleResult(Context con, UpdateAppBean data, boolean isNeedTip) {
|
|
|
if (data == null) {
|
|
|
return;
|
|
|
}
|
|
@@ -100,7 +116,7 @@ public class UpdateAppHelper {
|
|
|
.downloadOnly(UIData.create().setDownloadUrl(EncodeUtils.urlDecode(data.getDownloadUrl()))
|
|
|
.setTitle("发现新版本:" + data.getVersion())
|
|
|
.setContent(data.getDescription()))
|
|
|
- .setApkName(getApkName(activity, data.getVersion()));
|
|
|
+ .setApkName(getApkName(con, data.getVersion()));
|
|
|
builder.setCustomVersionDialogListener((context, versionBundle) -> {
|
|
|
Dialog baseDialog;
|
|
|
if (data.isIsForceUpdate()) {
|
|
@@ -189,7 +205,11 @@ public class UpdateAppHelper {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- builder.executeMission(activity);
|
|
|
+ builder.executeMission(con);
|
|
|
+ } else {
|
|
|
+ if (isNeedTip) {
|
|
|
+ ToastUtil.getInstance().showShort("当前是最新版本");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|