版本更新問題

This commit is contained in:
18142669586 2022-12-01 16:15:16 +08:00
parent 73684b9962
commit f43ccea32a
6 changed files with 237 additions and 184 deletions

View File

@ -147,7 +147,6 @@ dependencies {
// //
// //
api 'com.android.billingclient:billing:5.0.0' api 'com.android.billingclient:billing:5.0.0'
implementation 'com.teprinciple:updateapputils:2.3.0'
api 'com.squareup.picasso:picasso:2.5.2' api 'com.squareup.picasso:picasso:2.5.2'
api "com.immomo.cosmos.mediax:beautyutils:2.2.1_01071700" api "com.immomo.cosmos.mediax:beautyutils:2.2.1_01071700"
api files('libs/liteavsdk.jar') api files('libs/liteavsdk.jar')
@ -188,5 +187,8 @@ dependencies {
api files('libs/Msc.jar') api files('libs/Msc.jar')
api 'com.github.li-xiaojun:XPopup:2.9.1' api 'com.github.li-xiaojun:XPopup:2.9.1'
//app-updater
api 'com.github.jenly1314.AppUpdater:app-updater:1.1.3'
//app-dialog
api 'com.github.jenly1314.AppUpdater:app-dialog:1.1.3'
} }

View File

@ -10,26 +10,29 @@ import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.king.app.dialog.AppDialog;
import com.king.app.updater.AppUpdater;
import com.king.app.updater.UpdateConfig;
import com.king.app.updater.callback.UpdateCallback;
import com.king.app.updater.http.OkHttpManager;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.R; import com.yunbao.common.R;
import com.yunbao.common.bean.ConfigBean; import com.yunbao.common.bean.ConfigBean;
import constant.UiType; import java.io.File;
import model.UiConfig;
import model.UpdateConfig;
import update.UpdateAppUtils;
/**
* Created by cxf on 2017/10/9.
*/
public class VersionUtil { public class VersionUtil {
private static String sVersion; private static String sVersion;
public TextView tvProgress;
public ProgressBar progressBar;
/** /**
* 是否是最新版本 * 是否是最新版本
*/ */
@ -46,63 +49,122 @@ public class VersionUtil {
else return false; else return false;
// return curVersion.equal(version); // return curVersion.equal(version);
} }
public void updateProgress(long progress, long total){
if(tvProgress == null || progressBar == null){
return;
}
if(progress > 0){
int currProgress = (int)(progress * 1.0f / total * 100.0f);
tvProgress.setText(currProgress + "%");
progressBar.setProgress(currProgress);
}else{
tvProgress.setText("稍等");
}
}
public void upd( Activity context, ConfigBean configBean, String downloadUrl){
UpdateConfig config = new UpdateConfig();
config.setUrl(downloadUrl);
config.addHeader("token","xxxxxx");
AppUpdater mAppUpdater = new AppUpdater(context,config)
.setHttpManager(OkHttpManager.getInstance())
.setUpdateCallback(new UpdateCallback() {
@Override
public void onDownloading(boolean isDownloading) {
if(isDownloading){
ToastUtil.show("已经在下载中,请勿重复下载。");
}else{
// showToast("开始下载…");
View view = LayoutInflater.from(context).inflate(R.layout.dialog_progress,null);
tvProgress = view.findViewById(R.id.tvProgress);
progressBar = view.findViewById(R.id.progressBar);
AppDialog.INSTANCE.showDialog(context,view,false);
}
}
@Override
public void onStart(String url) {
updateProgress(0,100);
}
@Override
public void onProgress(long progress, long total, boolean isChange) {
if(isChange){
updateProgress(progress,total);
}
}
@Override
public void onFinish(File file) {
AppDialog.INSTANCE.dismissDialog();
ToastUtil.show("下载完成");
}
@Override
public void onError(Exception e) {
AppDialog.INSTANCE.dismissDialog();
ToastUtil.show("下载失败");
}
@Override
public void onCancel() {
AppDialog.INSTANCE.dismissDialog();
ToastUtil.show("取消下载");
}
});
mAppUpdater.start();
}
//是否是谷歌版本 //是否是谷歌版本
public static void showDialog(final Activity context, ConfigBean configBean, final String downloadUrl) { public void showDialog( Activity context, ConfigBean configBean, String downloadUrl) {
if (configBean.getForceUpdate() != 0) { //不是谷歌
if (CommonAppConfig.IS_GOOGLE_PLAY == false) { if (CommonAppConfig.IS_GOOGLE_PLAY == false) {
if (!TextUtils.isEmpty(downloadUrl)) { //不强更
try { if(configBean.getForceUpdate()!=1){
UpdateAppUtils.init(context); DialogUitl.Builder builder = new DialogUitl.Builder(context);
UpdateConfig updateConfig = new UpdateConfig(); builder.setTitle(WordUtil.getString(R.string.version_update))
updateConfig.setForce(true); .setContent(configBean.getUpdateDes())
updateConfig.setShowNotification(true); .setConfrimString(WordUtil.getString(R.string.version_immediate_use))
updateConfig.setAlwaysShowDownLoadDialog(true); .setCancelString(WordUtil.getString(R.string.version_not_update))
.setCancelable(false)
.setClickCallback(new DialogUitl.SimpleCallback2() {
public void onCancelClick() {
//UI
UiConfig uiConfig = new UiConfig();
uiConfig.setUiType(UiType.PLENTIFUL);
UpdateAppUtils
.getInstance()
.uiConfig(uiConfig)
.apkUrl(downloadUrl)
.updateConfig(updateConfig)
.updateTitle("发现新版本")
.updateContent(configBean.getUpdateDes())
.update();
} catch (Exception e) {
ToastUtil.show(R.string.version_download_url_error);
}
} else {
ToastUtil.show(R.string.version_download_url_error);
} }
//谷歌更新 @Override
public void onConfirmClick(Dialog dialog, String content) {
upd(context,configBean,downloadUrl);
}
})
.build()
.show();
}else{
DialogUitl.Builder builder = new DialogUitl.Builder(context);
builder.setTitle(WordUtil.getString(R.string.version_update))
.setContent(configBean.getUpdateDes())
.setConfrimString(WordUtil.getString(R.string.version_immediate_use))
.setCancelString(WordUtil.getString(R.string.version_not_update))
.setCancelable(false)
.setClickCallback(new DialogUitl.SimpleCallback2() {
public void onCancelClick() {
context.finish();
}
@Override
public void onConfirmClick(Dialog dialog, String content) {
upd(context,configBean,downloadUrl);
}
})
.build()
.show();
}
//谷歌版本
} else if (CommonAppConfig.IS_GOOGLE_PLAY == true) { } else if (CommonAppConfig.IS_GOOGLE_PLAY == true) {
if ("0".equals(configBean.getGoogle_isup())) { //谷歌强制更新
DialogUitl.Builder builder = new DialogUitl.Builder(context); if(configBean.getGoogle_isup().equals("1")) {
builder.setTitle(WordUtil.getString(R.string.version_update))
.setContent(configBean.getUpdateDes())
.setConfrimString(WordUtil.getString(R.string.version_immediate_use))
.setCancelString(WordUtil.getString(R.string.version_not_update))
.setCancelable(true)
.setClickCallback(new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
try {
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.pdlive.shayu"));
context.startActivity(i);
} catch (Exception e) {
ToastUtil.show(R.string.version_download_url_error);
}
}
})
.build()
.show();
} else {
DialogUitl.Builder builder = new DialogUitl.Builder(context); DialogUitl.Builder builder = new DialogUitl.Builder(context);
builder.setTitle(WordUtil.getString(R.string.version_update)) builder.setTitle(WordUtil.getString(R.string.version_update))
.setContent(configBean.getUpdateDes()) .setContent(configBean.getUpdateDes())
@ -124,64 +186,8 @@ public class VersionUtil {
}) })
.build() .build()
.show(); .show();
} //谷歌不强制
} }else {
} else {
if (CommonAppConfig.IS_GOOGLE_PLAY == false) {
if (!TextUtils.isEmpty(downloadUrl)) {
try {
UpdateAppUtils.init(context);
UpdateConfig updateConfig = new UpdateConfig();
updateConfig.setShowNotification(true);
updateConfig.setAlwaysShowDownLoadDialog(true);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//UI
UiConfig uiConfig = new UiConfig();
uiConfig.setUiType(UiType.PLENTIFUL);
UpdateAppUtils
.getInstance()
.uiConfig(uiConfig)
.apkUrl(downloadUrl)
.updateConfig(updateConfig)
.updateTitle("新版本更新")
.updateContent(configBean.getUpdateDes())
.update();
}
}, 2000);
} catch (Exception e) {
ToastUtil.show(R.string.version_download_url_error);
}
} else {
ToastUtil.show(R.string.version_download_url_error);
}
} else if (CommonAppConfig.IS_GOOGLE_PLAY) {
if ( "0".equals(configBean.getGoogle_isup())) {
Log.e("tagg", "111111");
DialogUitl.Builder builder = new DialogUitl.Builder(context);
builder.setTitle(WordUtil.getString(R.string.version_update))
.setContent(configBean.getUpdateDes())
.setConfrimString(WordUtil.getString(R.string.version_immediate_use))
.setCancelString(WordUtil.getString(R.string.version_not_update))
.setCancelable(true)
.setClickCallback(new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
try {
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.pdlive.shayu"));
context.startActivity(i);
} catch (Exception e) {
ToastUtil.show(R.string.version_download_url_error);
}
}
})
.build()
.show();
} else {
DialogUitl.Builder builder = new DialogUitl.Builder(context); DialogUitl.Builder builder = new DialogUitl.Builder(context);
builder.setTitle(WordUtil.getString(R.string.version_update)) builder.setTitle(WordUtil.getString(R.string.version_update))
.setContent(configBean.getUpdateDes()) .setContent(configBean.getUpdateDes())
@ -190,7 +196,6 @@ public class VersionUtil {
.setCancelable(false) .setCancelable(false)
.setClickCallback(new DialogUitl.SimpleCallback2() { .setClickCallback(new DialogUitl.SimpleCallback2() {
public void onCancelClick() { public void onCancelClick() {
context.finish();
} }
@Override @Override
@ -204,11 +209,10 @@ public class VersionUtil {
.build() .build()
.show(); .show();
} }
} }
} }
}
/** /**

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center_vertical"
android:background="@drawable/app_dialog_bg">
<ImageView
android:id="@+id/ivIcon"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@mipmap/ic_launcher"
android:layout_marginRight="4dp"/>
<TextView
android:id="@+id/tvDialogTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/ivIcon"
android:textSize="14sp"
android:textColor="@color/app_dialog_title_color"
android:text="更新中"/>
<TextView
android:id="@+id/tvProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tvDialogTitle"
android:layout_marginTop="10dp"
android:lineSpacingMultiplier="1.2"
android:text="正在下載中......"
android:textColor="@color/app_dialog_content_color"
android:textSize="14sp" />
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="6dp"
android:layout_below="@+id/tvProgress"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:max="100" />
</RelativeLayout>

View File

@ -85,4 +85,5 @@ dependencies {
// //
implementation 'com.binioter:guideview:1.0.0' implementation 'com.binioter:guideview:1.0.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0' implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0'
} }

View File

@ -668,7 +668,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
DialogUitl.showSimpleTipDialog(mContext, WordUtil.getString(R.string.main_maintain_notice), configBean.getMaintainTips()); DialogUitl.showSimpleTipDialog(mContext, WordUtil.getString(R.string.main_maintain_notice), configBean.getMaintainTips());
} }
if (!VersionUtil.isLatest(configBean.getVersion())) { if (!VersionUtil.isLatest(configBean.getVersion())) {
VersionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl()); VersionUtil versionUtil = new VersionUtil();
versionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl());
} else { } else {
requestBonus(); requestBonus();
} }

View File

@ -293,18 +293,18 @@ public class SettingActivity extends AbsActivity implements OnItemClickListener<
* 检查更新 * 检查更新
*/ */
private void checkVersion() { private void checkVersion() {
CommonAppConfig.getInstance().getConfig(new CommonCallback<ConfigBean>() { // CommonAppConfig.getInstance().getConfig(new CommonCallback<ConfigBean>() {
@Override // @Override
public void callback(ConfigBean configBean) { // public void callback(ConfigBean configBean) {
if (configBean != null) { // if (configBean != null) {
if (VersionUtil.isLatest(configBean.getVersion())) { // if (VersionUtil.isLatest(configBean.getVersion())) {
ToastUtil.show(R.string.version_latest); // ToastUtil.show(R.string.version_latest);
} else { // } else {
VersionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl()); // VersionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl());
} // }
} // }
} // }
}); // });
} }