Commit 5815282424d0eac4ff6b7d359b9b3d112402ac59
1 parent
ec1f1cd7
1.test code
Showing
3 changed files
with
228 additions
and
10 deletions
app/demo_launch/src/main/java/com/cnlive/test/launch/LaunchPresenter.java
| 1 | package com.cnlive.test.launch; | 1 | package com.cnlive.test.launch; |
| 2 | 2 | ||
| 3 | +import android.content.Context; | ||
| 4 | +import android.content.pm.PackageInfo; | ||
| 5 | +import android.content.pm.PackageManager; | ||
| 6 | +import android.os.Build; | ||
| 7 | + | ||
| 8 | +import com.cnlive.core.libs.base.application.BaseApplication; | ||
| 3 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; | 9 | import com.cnlive.core.libs.base.frame.presenter.BasePresenter; |
| 4 | import com.cnlive.core.network.HttpConn; | 10 | import com.cnlive.core.network.HttpConn; |
| 5 | import com.cnlive.core.network.NetCallBack; | 11 | import com.cnlive.core.network.NetCallBack; |
| 6 | import com.cnlive.core.network.model.BaseResult; | 12 | import com.cnlive.core.network.model.BaseResult; |
| 7 | import com.cnlive.core.network.request.BaseRequest; | 13 | import com.cnlive.core.network.request.BaseRequest; |
| 14 | +import com.cnlive.test.launch.bean.AppVersionInfo; | ||
| 8 | 15 | ||
| 16 | +import java.util.HashMap; | ||
| 17 | +import java.util.Map; | ||
| 9 | import java.util.concurrent.TimeUnit; | 18 | import java.util.concurrent.TimeUnit; |
| 10 | 19 | ||
| 11 | import io.reactivex.Observable; | 20 | import io.reactivex.Observable; |
| @@ -16,26 +25,66 @@ class LaunchPresenter extends BasePresenter<LaunchView> { | @@ -16,26 +25,66 @@ class LaunchPresenter extends BasePresenter<LaunchView> { | ||
| 16 | 25 | ||
| 17 | private Disposable disposableLoadLaunchData; | 26 | private Disposable disposableLoadLaunchData; |
| 18 | 27 | ||
| 28 | + private static Map<String, String> getBaseParames() { | ||
| 29 | + Map<String, String> parames = new HashMap<>(); | ||
| 30 | + parames.put("plat", "a"); | ||
| 31 | + return parames; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + public static long getAppVersionCode(Context context) { | ||
| 35 | + long appVersionCode = -1; | ||
| 36 | + try { | ||
| 37 | + PackageInfo packageInfo = context.getApplicationContext() | ||
| 38 | + .getPackageManager() | ||
| 39 | + .getPackageInfo(context.getPackageName(), 0); | ||
| 40 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
| 41 | + appVersionCode = packageInfo.getLongVersionCode(); | ||
| 42 | + } else { | ||
| 43 | + appVersionCode = packageInfo.versionCode; | ||
| 44 | + } | ||
| 45 | + } catch (PackageManager.NameNotFoundException ignored) { | ||
| 46 | + } | ||
| 47 | + return appVersionCode; | ||
| 48 | + } | ||
| 49 | + | ||
| 19 | public void loadLaunchData() { | 50 | public void loadLaunchData() { |
| 20 | - Observable<BaseResult<CreateQrInfo>> observable = BaseRequest | 51 | + Map<String, String> parames = getBaseParames(); |
| 52 | + | ||
| 53 | + Observable<BaseResult<AppVersionInfo>> observable = BaseRequest | ||
| 21 | .init() | 54 | .init() |
| 22 | - .service(ApiServiceQrcode.class) | ||
| 23 | - .getQrContent(requestData); | ||
| 24 | - HttpConn.action(observable, new NetCallBack<BaseResult<CreateQrInfo>>() { | 55 | + .setConnectTimeout(2_500) |
| 56 | + .setReadTimeout(2_500) | ||
| 57 | + .service(LaunchService.class) | ||
| 58 | + .getshotTimeVersion(parames); | ||
| 59 | + | ||
| 60 | + HttpConn.action(observable, new NetCallBack<BaseResult<AppVersionInfo>>() { | ||
| 25 | @Override | 61 | @Override |
| 26 | public void onRequestState(int state) { | 62 | public void onRequestState(int state) { |
| 27 | 63 | ||
| 28 | } | 64 | } |
| 29 | 65 | ||
| 30 | @Override | 66 | @Override |
| 31 | - public void onSuccess(BaseResult<CreateQrInfo> data) { | ||
| 32 | - String content = data.getData().getQrcode(); | ||
| 33 | - if (content.length() > 0) ifViewAttached(view -> view.creataQr(content)); | 67 | + public void onSuccess(BaseResult<AppVersionInfo> data) { |
| 68 | + if (data.getData() != null) { | ||
| 69 | + long versionCodeService = data.getData().getVersionCode(); | ||
| 70 | + long versionCodeApp = getAppVersionCode(BaseApplication.getInstance()); | ||
| 71 | + | ||
| 72 | + | ||
| 73 | + | ||
| 74 | + if(data.getData().isForceUpdating()){ | ||
| 75 | + //当前版本大于0且最新版本大于当前版本,更新App | ||
| 76 | + if (versionCodeApp > 0 && versionCodeService > versionCodeApp) { | ||
| 77 | + ifViewAttached(view -> view.toUpload(content)); | ||
| 78 | + return; | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + ifViewAttached(view -> view.toNextPage()); | ||
| 34 | } | 83 | } |
| 35 | 84 | ||
| 36 | @Override | 85 | @Override |
| 37 | public void onFailure(String errCode, String errMsg, Exception e) { | 86 | public void onFailure(String errCode, String errMsg, Exception e) { |
| 38 | - ifViewAttached(view -> view.showCreateErr(errMsg)); | 87 | + ifViewAttached(view -> view.toNextPage()); |
| 39 | } | 88 | } |
| 40 | } | 89 | } |
| 41 | ); | 90 | ); |
| @@ -45,6 +94,10 @@ class LaunchPresenter extends BasePresenter<LaunchView> { | @@ -45,6 +94,10 @@ class LaunchPresenter extends BasePresenter<LaunchView> { | ||
| 45 | .subscribe(aLong -> ifViewAttached(view -> view.nextPage("test"))); | 94 | .subscribe(aLong -> ifViewAttached(view -> view.nextPage("test"))); |
| 46 | } | 95 | } |
| 47 | 96 | ||
| 97 | + public void chencaAppUpload(AppVersionInfo versionInfo) { | ||
| 98 | + | ||
| 99 | + } | ||
| 100 | + | ||
| 48 | public void cancelLoad() { | 101 | public void cancelLoad() { |
| 49 | if (disposableLoadLaunchData != null) disposableLoadLaunchData.dispose(); | 102 | if (disposableLoadLaunchData != null) disposableLoadLaunchData.dispose(); |
| 50 | } | 103 | } |
app/demo_launch/src/main/java/com/cnlive/test/launch/LaunchService.java
| 1 | package com.cnlive.test.launch; | 1 | package com.cnlive.test.launch; |
| 2 | 2 | ||
| 3 | +import com.cnlive.core.network.model.BaseResult; | ||
| 4 | +import com.cnlive.test.launch.bean.AppVersionInfo; | ||
| 5 | + | ||
| 3 | import java.util.Map; | 6 | import java.util.Map; |
| 4 | 7 | ||
| 5 | import io.reactivex.Observable; | 8 | import io.reactivex.Observable; |
| 6 | -import retrofit2.adapter.rxjava2.Result; | ||
| 7 | import retrofit2.http.POST; | 9 | import retrofit2.http.POST; |
| 8 | import retrofit2.http.QueryMap; | 10 | import retrofit2.http.QueryMap; |
| 9 | 11 | ||
| @@ -15,5 +17,5 @@ public interface LaunchService { | @@ -15,5 +17,5 @@ public interface LaunchService { | ||
| 15 | */ | 17 | */ |
| 16 | 18 | ||
| 17 | @POST("Daren/common/getNewestVersion.action") | 19 | @POST("Daren/common/getNewestVersion.action") |
| 18 | - Observable<Result<BaseInfo<AppVersionInfo>>> getshotTimeVersion(@QueryMap() Map<String, String> map); | 20 | + Observable<BaseResult<AppVersionInfo>> getshotTimeVersion(@QueryMap() Map<String, String> map); |
| 19 | } | 21 | } |
app/demo_launch/src/main/java/com/cnlive/test/launch/bean/AppVersionInfo.java
0 → 100644
| 1 | +package com.cnlive.test.launch.bean; | ||
| 2 | + | ||
| 3 | +import java.io.Serializable; | ||
| 4 | + | ||
| 5 | +public class AppVersionInfo implements Serializable { | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + private String deviceType; | ||
| 9 | + private String msg; | ||
| 10 | + private String createTime; | ||
| 11 | + private String id; | ||
| 12 | + private String type; | ||
| 13 | + private String version; | ||
| 14 | + private int versionCode; | ||
| 15 | + private String downLoadUrl; | ||
| 16 | + private boolean forceUpdating; | ||
| 17 | + private OpenScreenAdv openScreenAdv; | ||
| 18 | + | ||
| 19 | + public OpenScreenAdv getOpenScreenAdv() { | ||
| 20 | + return openScreenAdv; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public void setOpenScreenAdv(OpenScreenAdv openScreenAdv) { | ||
| 24 | + this.openScreenAdv = openScreenAdv; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public boolean isForceUpdating() { | ||
| 28 | + return forceUpdating; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public void setForceUpdating(boolean forceUpdating) { | ||
| 32 | + this.forceUpdating = forceUpdating; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public int getVersionCode() { | ||
| 36 | + return versionCode; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public void setVersionCode(int versionCode) { | ||
| 40 | + this.versionCode = versionCode; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public String getDownLoadUrl() { | ||
| 44 | + return downLoadUrl; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void setDownLoadUrl(String downLoadUrl) { | ||
| 48 | + this.downLoadUrl = downLoadUrl; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public String getDeviceType() { | ||
| 52 | + return deviceType; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public void setDeviceType(String deviceType) { | ||
| 56 | + this.deviceType = deviceType; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public String getMsg() { | ||
| 60 | + return msg; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public void setMsg(String msg) { | ||
| 64 | + this.msg = msg; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public String getCreateTime() { | ||
| 68 | + return createTime; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void setCreateTime(String createTime) { | ||
| 72 | + this.createTime = createTime; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public String getId() { | ||
| 76 | + return id; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setId(String id) { | ||
| 80 | + this.id = id; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public String getType() { | ||
| 84 | + return type; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public void setType(String type) { | ||
| 88 | + this.type = type; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public String getVersion() { | ||
| 92 | + return version; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public void setVersion(String version) { | ||
| 96 | + this.version = version; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public static class OpenScreenAdv implements Serializable { | ||
| 100 | + //广告id | ||
| 101 | + private String id; | ||
| 102 | + // 0 内部打开 1 外部打开 | ||
| 103 | + private int wjjAdv; | ||
| 104 | + //广告链接 | ||
| 105 | + private String url; | ||
| 106 | + //广告图片 | ||
| 107 | + private String andImg; | ||
| 108 | + // 动画时长 | ||
| 109 | + private int duration; | ||
| 110 | + // 是否更新 | ||
| 111 | + private int modifyStatus; | ||
| 112 | + | ||
| 113 | + public int getModifyStatus() { | ||
| 114 | + return modifyStatus; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + public void setModifyStatus(int modifyStatus) { | ||
| 118 | + this.modifyStatus = modifyStatus; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public int getDuration() { | ||
| 122 | + return duration; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + public void setDuration(int duration) { | ||
| 126 | + this.duration = duration; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public String getId() { | ||
| 130 | + return id; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public void setId(String id) { | ||
| 134 | + this.id = id; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + public int getWjjAdv() { | ||
| 138 | + return wjjAdv; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void setWjjAdv(int wjjAdv) { | ||
| 142 | + this.wjjAdv = wjjAdv; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + public String getUrl() { | ||
| 146 | + return url; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public void setUrl(String url) { | ||
| 150 | + this.url = url; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public String getAndImg() { | ||
| 154 | + return andImg; | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + public void setAndImg(String andImg) { | ||
| 158 | + this.andImg = andImg; | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + | ||
| 163 | +} | ||
| 0 | \ No newline at end of file | 164 | \ No newline at end of file |