版本更新
This commit is contained in:
parent
ac7a491f57
commit
389f33db1f
@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.angcyo.tablayout.DslTabLayout;
|
import com.angcyo.tablayout.DslTabLayout;
|
||||||
import com.angcyo.tablayout.DslTabLayoutConfig;
|
import com.angcyo.tablayout.DslTabLayoutConfig;
|
||||||
import com.angcyo.tablayout.delegate2.ViewPager2Delegate;
|
import com.angcyo.tablayout.delegate2.ViewPager2Delegate;
|
||||||
|
import com.lxj.xpopup.XPopup;
|
||||||
import com.shayu.onetoone.R;
|
import com.shayu.onetoone.R;
|
||||||
import com.shayu.onetoone.activity.fragments.BaseFragment;
|
import com.shayu.onetoone.activity.fragments.BaseFragment;
|
||||||
import com.shayu.onetoone.activity.fragments.DynamicFragment;
|
import com.shayu.onetoone.activity.fragments.DynamicFragment;
|
||||||
@ -31,13 +32,21 @@ import com.shayu.onetoone.manager.CallClientManager;
|
|||||||
import com.shayu.onetoone.manager.OTONetManager;
|
import com.shayu.onetoone.manager.OTONetManager;
|
||||||
import com.shayu.onetoone.manager.RouteManager;
|
import com.shayu.onetoone.manager.RouteManager;
|
||||||
import com.shayu.onetoone.manager.SendMessageManager;
|
import com.shayu.onetoone.manager.SendMessageManager;
|
||||||
|
import com.yunbao.common.CommonAppConfig;
|
||||||
|
import com.yunbao.common.bean.ConfigBean;
|
||||||
import com.yunbao.common.http.base.HttpCallback;
|
import com.yunbao.common.http.base.HttpCallback;
|
||||||
|
import com.yunbao.common.interfaces.CommonCallback;
|
||||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||||
|
import com.yunbao.common.manager.APKManager;
|
||||||
import com.yunbao.common.manager.IMLoginManager;
|
import com.yunbao.common.manager.IMLoginManager;
|
||||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||||
import com.yunbao.common.utils.Bus;
|
import com.yunbao.common.utils.Bus;
|
||||||
|
import com.yunbao.common.utils.DialogUitl;
|
||||||
import com.yunbao.common.utils.SpUtil;
|
import com.yunbao.common.utils.SpUtil;
|
||||||
import com.yunbao.common.utils.ToastUtil;
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
|
import com.yunbao.common.utils.VersionUtil;
|
||||||
|
import com.yunbao.common.views.APKUpdateCustomPopup;
|
||||||
|
import com.yunbao.common.views.APKUpdateOneToOnePopup;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
@ -118,6 +127,35 @@ public class MainActivity extends AbsOTOActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
CallClientManager.getManager();
|
CallClientManager.getManager();
|
||||||
|
checkVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查版本更新
|
||||||
|
*/
|
||||||
|
private void checkVersion() {
|
||||||
|
CommonAppConfig.getInstance().getConfig(new CommonCallback<ConfigBean>() {
|
||||||
|
@Override
|
||||||
|
public void callback(ConfigBean configBean) {
|
||||||
|
if (configBean != null) {
|
||||||
|
if (configBean.getMaintainSwitch() == 1) {//开启维护
|
||||||
|
DialogUitl.showSimpleTipDialog(mContext, mContext.getString(R.string.main_maintain_notice), configBean.getMaintainTips());
|
||||||
|
}
|
||||||
|
if (!VersionUtil.isLatest(configBean.getVersion())) {
|
||||||
|
if (!APKManager.get().getApkVerNew()) {
|
||||||
|
new XPopup.Builder(mContext)
|
||||||
|
.isDestroyOnDismiss(true)
|
||||||
|
.dismissOnBackPressed(false) // 按返回键是否关闭弹窗,默认为true
|
||||||
|
.dismissOnTouchOutside(false) // 点击外部是否关闭弹窗,默认为true
|
||||||
|
.asCustom(new APKUpdateOneToOnePopup(MainActivity.this, false))
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//requestBonus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFirstLoginTips() {
|
private void initFirstLoginTips() {
|
||||||
|
@ -53,7 +53,6 @@ public class AuthBloggerInletActivity extends AbsActivity {
|
|||||||
|
|
||||||
dialog = DialogUitl.loadingDialog(mContext, WordUtil.getNewString(R.string.query));
|
dialog = DialogUitl.loadingDialog(mContext, WordUtil.getNewString(R.string.query));
|
||||||
|
|
||||||
getAuthInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthBean authBean;
|
AuthBean authBean;
|
||||||
@ -92,7 +91,7 @@ public class AuthBloggerInletActivity extends AbsActivity {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
personLayout.setBackground(getResources().getDrawable(R.drawable.bg_auth_submit_1));
|
personLayout.setBackground(getResources().getDrawable(R.drawable.bg_auth_submit_1));
|
||||||
personImg.setImageDrawable(getResources().getDrawable(R.mipmap.icon_suc));
|
personImg.setImageDrawable(getResources().getDrawable(R.mipmap.icon_fail));
|
||||||
perStatus.setText(R.string.to_upload);
|
perStatus.setText(R.string.to_upload);
|
||||||
perStatus.setBackground(getResources().getDrawable(R.drawable.bg_auth_submit_5));
|
perStatus.setBackground(getResources().getDrawable(R.drawable.bg_auth_submit_5));
|
||||||
findViewById(R.id.personBt).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.personBt).setOnClickListener(new View.OnClickListener() {
|
||||||
@ -167,8 +166,6 @@ public class AuthBloggerInletActivity extends AbsActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (Constants.isShowPage != -1) {
|
getAuthInfo();
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,6 +339,8 @@
|
|||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:layout_marginRight="70dp"
|
android:layout_marginRight="70dp"
|
||||||
android:layout_marginBottom="20dp"
|
android:layout_marginBottom="20dp"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
android:background="@drawable/bg_auth_submit_1"
|
android:background="@drawable/bg_auth_submit_1"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingTop="10dp"
|
android:paddingTop="10dp"
|
||||||
|
@ -0,0 +1,208 @@
|
|||||||
|
package com.yunbao.common.views;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
|
import com.lxj.xpopup.core.CenterPopupView;
|
||||||
|
import com.yunbao.common.CommonAppConfig;
|
||||||
|
import com.yunbao.common.CommonAppContext;
|
||||||
|
import com.yunbao.common.R;
|
||||||
|
import com.yunbao.common.manager.APKManager;
|
||||||
|
import com.yunbao.common.utils.APKDownloadUtil;
|
||||||
|
import com.yunbao.common.utils.RouteUtil;
|
||||||
|
import com.yunbao.common.utils.ToastUtil;
|
||||||
|
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* apk更新弹窗
|
||||||
|
*/
|
||||||
|
public class APKUpdateOneToOnePopup extends CenterPopupView {
|
||||||
|
private TextView updateText, versionImmediateUse, no_update;
|
||||||
|
private Activity mContext;
|
||||||
|
private boolean mInside;
|
||||||
|
|
||||||
|
public APKUpdateOneToOnePopup(@NonNull Activity context, boolean inside) {
|
||||||
|
super(context);
|
||||||
|
mContext = context;
|
||||||
|
mInside = inside;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回自定义弹窗的布局
|
||||||
|
@Override
|
||||||
|
protected int getImplLayoutId() {
|
||||||
|
return R.layout.apk_update_one_to_one_popup;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑
|
||||||
|
@Override
|
||||||
|
protected void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
initView();
|
||||||
|
initData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView() {
|
||||||
|
if (!mInside) {
|
||||||
|
if (!CommonAppConfig.IS_GOOGLE_PLAY && APKManager.get().getAPKGoogleIsUp() == 1) {
|
||||||
|
findViewById(R.id.dialog_close).setVisibility(GONE);
|
||||||
|
}
|
||||||
|
if (!CommonAppConfig.IS_GOOGLE_PLAY && APKManager.get().getAPKGoogleIsUp() == 1) {
|
||||||
|
findViewById(R.id.dialog_close).setVisibility(GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
no_update = findViewById(R.id.no_update);
|
||||||
|
updateText = findViewById(R.id.update_text);
|
||||||
|
versionImmediateUse = findViewById(R.id.version_immediate_use);
|
||||||
|
versionImmediateUse.setVisibility(VISIBLE);
|
||||||
|
updateText.setText(APKManager.get().getAPKDes());
|
||||||
|
ViewClicksAntiShake.clicksAntiShake(versionImmediateUse, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||||
|
@Override
|
||||||
|
public void onViewClicks() {
|
||||||
|
//不是谷歌
|
||||||
|
if (!CommonAppConfig.IS_GOOGLE_PLAY) {
|
||||||
|
versionImmediateUse.setVisibility(GONE);
|
||||||
|
no_update.setEnabled(false);
|
||||||
|
downloadAPK(mContext, APKManager.get().getAPKUrl(), new APKDownloadUtil.OnUpdateListener() {
|
||||||
|
@Override
|
||||||
|
public void updateFailure(int code, String error) {
|
||||||
|
no_update.setEnabled(true);
|
||||||
|
ToastUtil.show(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
|
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.pdlive.shayu"));
|
||||||
|
mContext.startActivity(i);
|
||||||
|
mContext.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ViewClicksAntiShake.clicksAntiShake(no_update, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||||
|
@Override
|
||||||
|
public void onViewClicks() {
|
||||||
|
mContext.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void downloadAPK(Activity context, String url, APKDownloadUtil.OnUpdateListener listener) {
|
||||||
|
Request request = new Request.Builder().url(url).addHeader("Accept-Encoding", "identity").build();
|
||||||
|
File downloadFile = new File(context.getCacheDir(), "update_app.apk");
|
||||||
|
try {
|
||||||
|
if (!downloadFile.exists() && !downloadFile.createNewFile()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
new OkHttpClient().newCall(request).enqueue(new Callback() {
|
||||||
|
private Handler handler = new Handler();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
// 下载失败
|
||||||
|
handler.post(() -> {
|
||||||
|
listener.updateFailure(-1, e.getMessage());
|
||||||
|
dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) {
|
||||||
|
Looper.prepare();
|
||||||
|
byte[] buf = new byte[2048];
|
||||||
|
int len;
|
||||||
|
try (InputStream inputStream = response.body().byteStream(); FileOutputStream outputStream = new FileOutputStream(downloadFile)) {
|
||||||
|
long total = response.body().contentLength();
|
||||||
|
long sum = 0;
|
||||||
|
while ((len = inputStream.read(buf)) != -1) {
|
||||||
|
outputStream.write(buf, 0, len);
|
||||||
|
sum += len;
|
||||||
|
int progress = (int) (sum * 1.0f / total * 100);
|
||||||
|
// 下载中
|
||||||
|
handler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
no_update.setText("正在下載,請稍後.." + progress + "%");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
outputStream.flush();
|
||||||
|
//启动安装app
|
||||||
|
installApk(context, downloadFile, context.getPackageName() + ".fileprovider");
|
||||||
|
handler.post(() -> dismiss());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
new Handler().post(() -> {
|
||||||
|
listener.updateFailure(-1, e.getMessage());
|
||||||
|
dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安装apk
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param file
|
||||||
|
*/
|
||||||
|
public void installApk(Context context, File file, String authority) {
|
||||||
|
Intent intent = getInstallIntent(context, file, authority);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取安装Intent
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
* @param file
|
||||||
|
* @param authority
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Intent getInstallIntent(Context context, File file, String authority) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
Uri uriData;
|
||||||
|
String type = "application/vnd.android.package-archive";
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
uriData = FileProvider.getUriForFile(context, authority, file);
|
||||||
|
} else {
|
||||||
|
uriData = Uri.fromFile(file);
|
||||||
|
}
|
||||||
|
intent.setDataAndType(uriData, type);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
}
|
77
common/src/main/res/layout/apk_update_one_to_one_popup.xml
Normal file
77
common/src/main/res/layout/apk_update_one_to_one_popup.xml
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="280dp"
|
||||||
|
android:layout_height="410dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="280dp"
|
||||||
|
android:layout_height="410dp"
|
||||||
|
android:src="@mipmap/update_tips_bos_one_to_one" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="230dp"
|
||||||
|
android:text="發現新版本"
|
||||||
|
android:textColor="@color/black2"
|
||||||
|
android:textSize="12dp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scroll_layout"
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="250dp"
|
||||||
|
android:scrollbars="none">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/update_text"
|
||||||
|
android:layout_width="180dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="
|
||||||
|
1、內容內容內容內容內容內容\n
|
||||||
|
2、內容內容內容內容內容內容\n
|
||||||
|
3、內容內容內容內容內容\n
|
||||||
|
4、內容內容內容內容內容"
|
||||||
|
android:textColor="#1B1B1B"
|
||||||
|
android:textSize="10sp" />
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/scroll_layout"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/version_immediate_use"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="25dp"
|
||||||
|
android:background="@mipmap/update_one_to_one_bt"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="立即升級"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_update"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:layout_below="@+id/version_immediate_use"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="不更新,退出APP"
|
||||||
|
android:textColor="@color/gray1"
|
||||||
|
android:textSize="10sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
BIN
common/src/main/res/mipmap-mdpi/update_one_to_one_bt.png
Normal file
BIN
common/src/main/res/mipmap-mdpi/update_one_to_one_bt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
common/src/main/res/mipmap-xxhdpi/update_tips_bos_one_to_one.png
Normal file
BIN
common/src/main/res/mipmap-xxhdpi/update_tips_bos_one_to_one.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 481 KiB |
Loading…
x
Reference in New Issue
Block a user