diff --git a/common/build.gradle b/common/build.gradle index ba71ce7f2..1e849bc76 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -147,7 +147,6 @@ dependencies { //谷歌支付 //谷歌内购 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.immomo.cosmos.mediax:beautyutils:2.2.1_01071700" api files('libs/liteavsdk.jar') @@ -188,5 +187,8 @@ dependencies { api files('libs/Msc.jar') 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' } diff --git a/common/src/main/java/com/yunbao/common/utils/VersionUtil.java b/common/src/main/java/com/yunbao/common/utils/VersionUtil.java index 6eace2b38..55b441bda 100644 --- a/common/src/main/java/com/yunbao/common/utils/VersionUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/VersionUtil.java @@ -10,26 +10,29 @@ import android.net.Uri; import android.os.Handler; import android.text.TextUtils; 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.CommonAppContext; import com.yunbao.common.R; import com.yunbao.common.bean.ConfigBean; -import constant.UiType; -import model.UiConfig; -import model.UpdateConfig; -import update.UpdateAppUtils; - -/** - * Created by cxf on 2017/10/9. - */ +import java.io.File; public class VersionUtil { private static String sVersion; - + public TextView tvProgress; + public ProgressBar progressBar; /** * 是否是最新版本 */ @@ -46,170 +49,171 @@ public class VersionUtil { else return false; // return curVersion.equal(version); } - - - //是否是谷歌版本 - public static void showDialog(final Activity context, ConfigBean configBean, final String downloadUrl) { - if (configBean.getForceUpdate() != 0) { - if (CommonAppConfig.IS_GOOGLE_PLAY == false) { - if (!TextUtils.isEmpty(downloadUrl)) { - try { - UpdateAppUtils.init(context); - UpdateConfig updateConfig = new UpdateConfig(); - updateConfig.setForce(true); - updateConfig.setShowNotification(true); - updateConfig.setAlwaysShowDownLoadDialog(true); - - //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); - } - - //谷歌更新 - } else if (CommonAppConfig.IS_GOOGLE_PLAY == true) { - if ("0".equals(configBean.getGoogle_isup())) { - 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); - 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) { - 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); - context.finish(); - } - }) - .build() - .show(); - } - } - } 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); - 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) { - 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); - context.finish(); - } - }) - .build() - .show(); - } - - } + 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 void showDialog( Activity context, ConfigBean configBean, String downloadUrl) { + //不是谷歌 + if (CommonAppConfig.IS_GOOGLE_PLAY == false) { + //不强更 + if(configBean.getForceUpdate()!=1){ + 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() { + + } + + @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) { + //谷歌强制更新 + if(configBean.getGoogle_isup().equals("1")) { + 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) { + 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); + context.finish(); + } + }) + .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() { + } + + @Override + public void onConfirmClick(Dialog dialog, String content) { + 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); + context.finish(); + } + }) + .build() + .show(); + } + } + } + + + /** * 获取版本号 diff --git a/common/src/main/res/layout/dialog_progress.xml b/common/src/main/res/layout/dialog_progress.xml new file mode 100644 index 000000000..eb1bbbfb2 --- /dev/null +++ b/common/src/main/res/layout/dialog_progress.xml @@ -0,0 +1,45 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/build.gradle b/main/build.gradle index 4905a1d0f..7f44838fc 100644 --- a/main/build.gradle +++ b/main/build.gradle @@ -85,4 +85,5 @@ dependencies { //引导层 implementation 'com.binioter:guideview:1.0.0' implementation 'androidx.coordinatorlayout:coordinatorlayout:1.2.0' + } diff --git a/main/src/main/java/com/yunbao/main/activity/MainActivity.java b/main/src/main/java/com/yunbao/main/activity/MainActivity.java index e6c193f73..e823ce93f 100644 --- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java @@ -668,7 +668,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene DialogUitl.showSimpleTipDialog(mContext, WordUtil.getString(R.string.main_maintain_notice), configBean.getMaintainTips()); } if (!VersionUtil.isLatest(configBean.getVersion())) { - VersionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl()); + VersionUtil versionUtil = new VersionUtil(); + versionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl()); } else { requestBonus(); } diff --git a/main/src/main/java/com/yunbao/main/activity/SettingActivity.java b/main/src/main/java/com/yunbao/main/activity/SettingActivity.java index e91b6808c..7d1d599b6 100644 --- a/main/src/main/java/com/yunbao/main/activity/SettingActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/SettingActivity.java @@ -293,18 +293,18 @@ public class SettingActivity extends AbsActivity implements OnItemClickListener< * 检查更新 */ private void checkVersion() { - CommonAppConfig.getInstance().getConfig(new CommonCallback() { - @Override - public void callback(ConfigBean configBean) { - if (configBean != null) { - if (VersionUtil.isLatest(configBean.getVersion())) { - ToastUtil.show(R.string.version_latest); - } else { - VersionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl()); - } - } - } - }); +// CommonAppConfig.getInstance().getConfig(new CommonCallback() { +// @Override +// public void callback(ConfigBean configBean) { +// if (configBean != null) { +// if (VersionUtil.isLatest(configBean.getVersion())) { +// ToastUtil.show(R.string.version_latest); +// } else { +// VersionUtil.showDialog(mContext, configBean, configBean.getDownloadApkUrl()); +// } +// } +// } +// }); }