From 3aeabfa32b60283b5f1b979740e841b77ccbfd42 Mon Sep 17 00:00:00 2001
From: zlzw <583819556@qq.com>
Date: Fri, 16 Aug 2024 14:22:58 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9B=B4=E6=96=B0?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=EF=BC=9A1=E3=80=81=E6=94=B9=E6=88=90?=
=?UTF-8?q?=E4=BB=A5=E6=9C=8D=E5=8A=A1=E5=BD=A2=E5=BC=8F=E4=B8=8B=E8=BD=BD?=
=?UTF-8?q?=E3=80=822=E3=80=81=E6=96=B0=E5=A2=9E=E6=96=AD=E7=82=B9?=
=?UTF-8?q?=E7=BB=AD=E4=BC=A0=E5=8A=9F=E8=83=BD=E3=80=823=E3=80=81?=
=?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8B=E8=BD=BD=E5=90=8E=E6=A3=80=E6=9F=A5?=
=?UTF-8?q?apk=E5=AE=8C=E6=95=B4=E6=80=A7=E3=80=82=20=E4=BF=AE=E6=94=B9?=
=?UTF-8?q?=E4=B8=BB=E6=92=AD=E8=AE=BE=E7=BD=AE=E8=81=94=E7=B3=BB=E6=96=B9?=
=?UTF-8?q?=E5=BC=8F=E6=8E=A5=E5=8F=A3=E5=9C=B0=E5=9D=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/build.gradle | 5 +-
app/src/main/AndroidManifest.xml | 1 +
common/src/main/AndroidManifest.xml | 2 +
.../com/yunbao/common/http/LiveHttpUtil.java | 7 +
.../yunbao/common/server/DownloadService.java | 282 ++++++++++++++++++
.../yunbao/common/utils/APKDownloadUtil.java | 1 +
.../java/com/yunbao/common/utils/SpUtil.java | 10 +-
.../com/yunbao/common/utils/VersionUtil.java | 10 +
.../common/views/APKUpdateCustomPopup.java | 162 ++++------
.../adapter/LiveAnchorEditCallMeAdapter.java | 1 +
.../com/yunbao/live/dialog/GiftPopDialog.java | 24 ++
.../yunbao/main/activity/MainActivity.java | 35 +++
12 files changed, 439 insertions(+), 101 deletions(-)
create mode 100644 common/src/main/java/com/yunbao/common/server/DownloadService.java
diff --git a/app/build.gradle b/app/build.gradle
index 6011ca6ec..12ded74d9 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -97,11 +97,12 @@ android {
String variantName = variant.name.capitalize()
def processManifestTask = project.tasks.getByName("process${variantName}Manifest")
processManifestTask.doLast { pm ->
- String manifestPath = "build/intermediates/bundle_manifest/google_onlineRelease/bundle-manifest/AndroidManifest.xml"
+ // String manifestPath = "build/intermediates/bundle_manifest/google_onlineRelease/bundle-manifest/AndroidManifest.xml"
+ String manifestPath = "build/intermediates/merged_manifests/google_onlineRelease/processGoogle_onlineReleaseManifest/AndroidManifest.xml"
def isGooglePlay = variant.name.contains("google")
println "谷歌版本:" + isGooglePlay
println "文件存在" + file(manifestPath).exists()
- println "" + (isGooglePlay != 0)
+ println "" + (isGooglePlay == 1)
println "" + (file(manifestPath).exists() && isGooglePlay)
if (file(manifestPath).exists() && isGooglePlay) {
def manifestContent = file(manifestPath).getText()
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5b4fce0f3..00680d337 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -1,6 +1,7 @@
+
+
diff --git a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java
index e3a05088a..9a37aac84 100644
--- a/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java
+++ b/common/src/main/java/com/yunbao/common/http/LiveHttpUtil.java
@@ -542,6 +542,13 @@ public class LiveHttpUtil {
HttpClient.getInstance().get("Live.getGiftListApp", LiveHttpConsts.GET_GIFT_LIST)
.execute(callback);
}
+ /**
+ * 获取礼物列表,同时会返回剩余的钱(新版) -用于获取联系方式时的礼物设置
+ */
+ public static void getHotGiftList(HttpCallback callback) {
+ HttpClient.getInstance().get("Gift.getHotGiftList", LiveHttpConsts.GET_GIFT_LIST)
+ .execute(callback);
+ }
/**
* 获取包裹列表
diff --git a/common/src/main/java/com/yunbao/common/server/DownloadService.java b/common/src/main/java/com/yunbao/common/server/DownloadService.java
new file mode 100644
index 000000000..95f5fe29a
--- /dev/null
+++ b/common/src/main/java/com/yunbao/common/server/DownloadService.java
@@ -0,0 +1,282 @@
+package com.yunbao.common.server;
+
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Build;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+
+import androidx.annotation.Nullable;
+import androidx.core.app.NotificationCompat;
+import androidx.core.content.FileProvider;
+
+import com.blankj.utilcode.util.LogUtils;
+import com.yunbao.common.R;
+import com.yunbao.common.utils.APKDownloadUtil;
+import com.yunbao.common.utils.AppManager;
+import com.yunbao.common.utils.SpUtil;
+import com.yunbao.common.utils.WordUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.util.Locale;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+public class DownloadService extends Service {
+ public static final String DOWNLOAD_TAG = "downloadProgress";
+ public static final String DOWNLOAD_TOTAL = "downloadTotal";
+ private Context mContext;
+ private int progress;
+ private boolean isDownload = false;
+ private boolean isDownloading;
+ private boolean isForceInstall;
+
+ ServiceBinder binder = new ServiceBinder();
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ return binder;
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mContext = this;
+ }
+
+ public class ServiceBinder extends Binder {
+ public void startDownload(String url, boolean isForceInstall, APKDownloadUtil.OnUpdateListener listener) {
+ if (isDownloading) return;
+ DownloadService.this.isForceInstall = isForceInstall;
+ downloadAPK(DownloadService.this, url, listener, 3);
+ }
+
+ public void install() {
+ LogUtils.e("文件大小:" + downloadFile.length(), "总大小:" + SpUtil.getLongValue(DOWNLOAD_TAG));
+ if (SpUtil.getLongValue(DOWNLOAD_TAG) == -1 && downloadFile.exists()) {
+ installApk(mContext, downloadFile, mContext.getPackageName() + ".fileprovider");
+ if (!isForceInstall) {
+ isDownload = false;
+ }
+ }
+ }
+
+ public boolean isDownloadOK() {
+ if (downloadFile == null) {
+ return false;
+ }
+ if (SpUtil.getLongValue(DOWNLOAD_TAG) == -1) {
+ return true;
+ }
+ return downloadFile.exists() && checkApk();
+ }
+
+ }
+
+ File downloadFile;
+
+ public void downloadAPK(Context context, final String url, APKDownloadUtil.OnUpdateListener listener, final int replay) {
+ if (replay <= 0) {
+ listener.updateFailure(-2, "DownloadError");
+ return;
+ }
+ downloadFile = new File(context.getCacheDir(), "update_app.apk");
+ if (SpUtil.getLongValue(DOWNLOAD_TAG) == -1 && checkApk()) {
+ installApk(mContext, downloadFile, mContext.getPackageName() + ".fileprovider");
+ return;
+ }
+ isDownloading = true;
+ Request.Builder builder = new Request.Builder().url(url).addHeader("Accept-Encoding", "identity");
+ if (SpUtil.getLongValue(DOWNLOAD_TAG) > 0) {
+ builder.addHeader("Range", "bytes=" + SpUtil.getLongValue(DOWNLOAD_TAG) + "-");
+ }
+ Request request = builder.build();
+ LogUtils.e("保存路径:" + downloadFile.getAbsolutePath());
+ try {
+ if (!downloadFile.exists() && !downloadFile.createNewFile()) {
+ isDownload = false;
+ return;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ createNotification();
+ new OkHttpClient().newCall(request).enqueue(new Callback() {
+ private Handler handler = new Handler(Looper.getMainLooper());
+
+ @Override
+ public void onFailure(Call call, IOException e) {
+ // 下载失败
+ handler.post(() -> {
+ listener.updateFailure(-1, e.getMessage());
+ });
+ }
+
+ @Override
+ public void onResponse(Call call, Response response) {
+ Looper.prepare();
+ byte[] buf = new byte[2048];
+ int len;
+
+ long downloadProgress = SpUtil.getLongValue(DOWNLOAD_TAG);
+ long total = response.body().contentLength();
+ try (InputStream inputStream = response.body().byteStream(); RandomAccessFile outputStream = new RandomAccessFile(downloadFile, "rw")) {
+ long sum = 0;
+ if (downloadProgress > 0) {
+ LogUtils.e("断点续传:" + downloadProgress);
+ }
+ if (downloadProgress > 0) {
+ sum = downloadProgress;
+ outputStream.seek(downloadProgress);
+ total = downloadProgress + total + 2048;
+ } else {
+ outputStream.setLength(total);
+ SpUtil.setLongValue(DOWNLOAD_TOTAL, total);
+ }
+ int tmp = 0;
+ while ((len = inputStream.read(buf)) != -1) {
+ outputStream.write(buf, 0, len);
+ SpUtil.setLongValue(DOWNLOAD_TAG, outputStream.getFilePointer());
+ sum += len;
+ progress = (int) (sum * 1.0f / total * 100);
+ if (tmp != progress) {
+ tmp = progress;
+ updateNotification(progress, 100);
+ }
+ listener.onProgress(progress);
+ }
+ progress = 100;
+ outputStream.close();
+ inputStream.close();
+ SpUtil.setLongValue(DOWNLOAD_TAG, -1);
+ //启动安装app
+ LogUtils.e("开始下载:" + "下载完成", "文件路径:" + downloadFile.getAbsolutePath(), "文件是否存在:" + downloadFile.exists(), "已下载大小:" + sum, "文件大小:" + total);
+ isDownload = true;
+ updateNotification(progress, 100);
+ listener.onProgress(progress);
+ installApk(context, downloadFile, context.getPackageName() + ".fileprovider");
+ isDownloading = false;
+ } catch (Exception e) {
+ e.printStackTrace();
+ LogUtils.e("下载失败:" + e.getMessage(), "重试次数:" + replay);
+ downloadAPK(mContext, url, listener, replay - 1);
+ }
+ }
+ });
+ }
+
+ private boolean checkApk() {
+ long apkTotal = SpUtil.getLongValue(DOWNLOAD_TOTAL);
+ if (apkTotal == 0) return false;
+ if (downloadFile == null || !downloadFile.exists()) return false;
+ try {
+ PackageManager pm = mContext.getPackageManager();
+ PackageInfo info = pm.getPackageArchiveInfo(downloadFile.getAbsolutePath(), PackageManager.GET_ACTIVITIES);
+ if (info == null) return false;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ LogUtils.e("文件大小:" + downloadFile.length(), "已下载大小:" + apkTotal);
+ return apkTotal == downloadFile.length();
+ }
+
+ private NotificationChannel channel;
+ NotificationCompat.Builder builder;
+
+ private void createNotification() {
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
+ Intent intent = new Intent(this, AppManager.getInstance().getMainActivity().getClass());
+ intent.putExtra("updateApk", true);
+
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ PendingIntent pendingIntent;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
+ pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
+ } else {
+ pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+
+ channel = new NotificationChannel("Download_channel", "pd_download", NotificationManager.IMPORTANCE_HIGH);
+ NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ manager.createNotificationChannel(channel);
+ builder = new NotificationCompat.Builder(mContext, "Download_channel")
+ .setChannelId(channel.getId())
+ .setSmallIcon(R.mipmap.ic_launcher)
+ .setContentTitle(WordUtil.isNewZh() ? "正在下载" : "Downloading")
+ .setContentText(WordUtil.isNewZh() ? "下载中" : "Downloading")
+ .setProgress(100, 0, true)
+ .setOnlyAlertOnce(true)
+ .setContentIntent(pendingIntent)
+ .setPriority(NotificationCompat.PRIORITY_MAX);
+ manager.notify(114514, builder.build());
+ }
+ }
+
+ private void updateNotification(int downloadProgress, int total) {
+ if (channel != null && builder != null) {
+ builder.setProgress(total, downloadProgress, false);
+ if (downloadProgress != total) {
+ builder.setContentText(String.format(Locale.getDefault(), "(%d/%d)", downloadProgress, total));
+ } else {
+ builder.setContentText(WordUtil.isNewZh() ? "完成" : "Over");
+ }
+ NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+ manager.notify(114514, builder.build());
+ }
+ }
+
+ /**
+ * 安装apk
+ *
+ * @param context
+ * @param file
+ */
+ public void installApk(Context context, File file, String authority) {
+ if (!checkApk()) return;
+ 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;
+ }
+
+}
diff --git a/common/src/main/java/com/yunbao/common/utils/APKDownloadUtil.java b/common/src/main/java/com/yunbao/common/utils/APKDownloadUtil.java
index 420f75401..b6e066da9 100644
--- a/common/src/main/java/com/yunbao/common/utils/APKDownloadUtil.java
+++ b/common/src/main/java/com/yunbao/common/utils/APKDownloadUtil.java
@@ -104,6 +104,7 @@ public class APKDownloadUtil {
*/
public interface OnUpdateListener {
void updateFailure(int code, String error);
+ void onProgress(int progress);
}
//
// /**
diff --git a/common/src/main/java/com/yunbao/common/utils/SpUtil.java b/common/src/main/java/com/yunbao/common/utils/SpUtil.java
index e188b7f0d..3ea3aedea 100644
--- a/common/src/main/java/com/yunbao/common/utils/SpUtil.java
+++ b/common/src/main/java/com/yunbao/common/utils/SpUtil.java
@@ -9,7 +9,6 @@ import com.google.gson.Gson;
import com.yunbao.common.CommonAppContext;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -164,7 +163,14 @@ public class SpUtil {
editor.putBoolean(key, value);
editor.apply();
}
-
+ public static void setLongValue(String key, long value) {
+ SharedPreferences.Editor editor=mSharedPreferences.edit();
+ editor.putLong(key, value);
+ editor.apply();
+ }
+ public static long getLongValue(String key) {
+ return mSharedPreferences.getLong(key,0);
+ }
/**
* 获取一个布尔值
*/
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 70439416c..41ac4bfce 100644
--- a/common/src/main/java/com/yunbao/common/utils/VersionUtil.java
+++ b/common/src/main/java/com/yunbao/common/utils/VersionUtil.java
@@ -119,6 +119,11 @@ public class VersionUtil {
public void updateFailure(int code, String error) {
}
+
+ @Override
+ public void onProgress(int progress) {
+
+ }
});
}
});
@@ -147,6 +152,11 @@ public class VersionUtil {
public void updateFailure(int code, String error) {
}
+
+ @Override
+ public void onProgress(int progress) {
+
+ }
});
}
})
diff --git a/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java b/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java
index 7747bfa9b..2f5cffffe 100644
--- a/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java
+++ b/common/src/main/java/com/yunbao/common/views/APKUpdateCustomPopup.java
@@ -1,41 +1,31 @@
package com.yunbao.common.views;
import android.app.Activity;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.net.Uri;
-import android.os.Build;
-import android.os.Handler;
-import android.os.Looper;
+import android.os.IBinder;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
-import androidx.core.content.FileProvider;
import com.alibaba.android.arouter.utils.TextUtils;
import com.lxj.xpopup.core.CenterPopupView;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.R;
import com.yunbao.common.manager.APKManager;
+import com.yunbao.common.server.DownloadService;
import com.yunbao.common.utils.APKDownloadUtil;
+import com.yunbao.common.utils.StringUtil;
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更新弹窗
*/
@@ -45,8 +35,10 @@ public class APKUpdateCustomPopup extends CenterPopupView {
private ProgressBar progressBar;
private Activity mContext;
private boolean mInside;
+ private boolean isForceInstall;
private DialogInterface.OnDismissListener onDismissListener;
+
public APKUpdateCustomPopup(@NonNull Activity context, boolean inside) {
super(context);
mContext = context;
@@ -64,6 +56,11 @@ public class APKUpdateCustomPopup extends CenterPopupView {
return this;
}
+ public APKUpdateCustomPopup setForceInstall(boolean forceInstall) {
+ isForceInstall = forceInstall;
+ return this;
+ }
+
// 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑
@Override
protected void onCreate() {
@@ -140,12 +137,13 @@ public class APKUpdateCustomPopup extends CenterPopupView {
} else {
versionImmediateUse.setVisibility(GONE);
updateLine.setVisibility(VISIBLE);
- downloadAPK(mContext, APKManager.get().getAPKUrl(), new APKDownloadUtil.OnUpdateListener() {
+ /* downloadAPK(mContext, APKManager.get().getAPKUrl(), new APKDownloadUtil.OnUpdateListener() {
@Override
public void updateFailure(int code, String error) {
ToastUtil.show(error);
}
- });
+ });*/
+ startServer(mContext, APKManager.get().getAPKUrl());
}
}
});
@@ -199,96 +197,66 @@ public class APKUpdateCustomPopup extends CenterPopupView {
}
}
+ DownloadService.ServiceBinder binder = null;
+ ServiceConnection connection = null;
- 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();
+ private void connection(String url) {
+ connection = new ServiceConnection() {
@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() {
- progressBar.setProgress(progress);
- }
- });
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ binder = (DownloadService.ServiceBinder) service;
+ if (!StringUtil.isEmpty(url)) {
+ if ("install".equals(url)) {
+ install();
+ } else {
+ startServer(mContext, url);
}
- outputStream.flush();
- //启动安装app
- installApk(context, downloadFile, context.getPackageName() + ".fileprovider");
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+
+ }
+ };
+ mContext.bindService(new Intent(mContext, DownloadService.class), connection, Context.BIND_AUTO_CREATE);
+ }
+
+ private void install() {
+ if (binder == null) {
+ connection("install");
+ return;
+ }
+ binder.install();
+ }
+
+ public void startServer(Context mContext, String url) {
+ if (binder == null) {
+ connection(url);
+ return;
+ }
+ binder.startDownload(url, isForceInstall, new APKDownloadUtil.OnUpdateListener() {
+ @Override
+ public void updateFailure(int code, String error) {
+ handler.post(() -> ToastUtil.show(error));
+ }
+
+ @Override
+ public void onProgress(int progress) {
+ progressBar.setProgress(progress);
+ if (progress == 100) {
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);
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (connection != null) {
+ mContext.unbindService(connection);
}
- intent.setDataAndType(uriData, type);
- return intent;
}
}
diff --git a/live/src/main/java/com/yunbao/live/adapter/LiveAnchorEditCallMeAdapter.java b/live/src/main/java/com/yunbao/live/adapter/LiveAnchorEditCallMeAdapter.java
index c737e98a2..22c9d7668 100644
--- a/live/src/main/java/com/yunbao/live/adapter/LiveAnchorEditCallMeAdapter.java
+++ b/live/src/main/java/com/yunbao/live/adapter/LiveAnchorEditCallMeAdapter.java
@@ -176,6 +176,7 @@ public class LiveAnchorEditCallMeAdapter extends RecyclerView.Adapter 0) {
+ JSONObject obj = JSON.parseObject(info[0]);
+ JSONArray list = obj.getJSONArray("listarray");
+ setDate(list);
+
+ }
+ }
+
@Override
public void onFinish() {
if (mLoading != null) {
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 848525f78..9ecc1d7f4 100644
--- a/main/src/main/java/com/yunbao/main/activity/MainActivity.java
+++ b/main/src/main/java/com/yunbao/main/activity/MainActivity.java
@@ -2,6 +2,7 @@ package com.yunbao.main.activity;
import static com.yunbao.common.CommonAppContext.isReady;
import static com.yunbao.common.manager.imrongcloud.RongcloudIMManager.connectIM;
+import static com.yunbao.common.server.DownloadService.DOWNLOAD_TAG;
import android.Manifest;
import android.animation.Animator;
@@ -12,13 +13,16 @@ import android.app.Dialog;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.ClipData;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
@@ -53,6 +57,7 @@ import com.tencent.imsdk.v2.V2TIMSDKListener;
import com.tencent.imsdk.v2.V2TIMUserFullInfo;
import com.yunbao.common.bean.QiniuLog;
import com.yunbao.common.glide.ImgLoader;
+import com.yunbao.common.server.DownloadService;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.LogUtil;
import com.yunbao.common.utils.MobclickAgent;
@@ -231,6 +236,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
SWAuManager.get().initRtcEngine(this);
ActivityCompat.postponeEnterTransition(this);
ConversationIMListManager.get(this);
+ connectionInstallApkService();
//在请求一下这个接口给我后台版本号
CommonHttpUtil.getConfig(mContext, new CommonCallback() {
@Override
@@ -900,6 +906,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
.dismissOnTouchOutside(false) // 点击外部是否关闭弹窗,默认为true
.asCustom(
new APKUpdateCustomPopup(mContext, false)
+ .setForceInstall(APKManager.get().getAPKGoogleIsUp() == 1)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
@@ -907,6 +914,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
}
})
).show();
+ }else{
+ SpUtil.setLongValue(DOWNLOAD_TAG, 0);
}
} else {
requestBonus();
@@ -920,6 +929,24 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
OpenAdManager.getInstance().show(OpenAdManager.TYPE_HOME, false);
}
+ DownloadService.ServiceBinder binder = null;
+ ServiceConnection connection=null;
+ private void connectionInstallApkService() {
+ connection = new ServiceConnection() {
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ binder = (DownloadService.ServiceBinder) service;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+
+ }
+ };
+ mContext.bindService(new Intent(mContext, DownloadService.class), connection, Context.BIND_AUTO_CREATE);
+ }
+
/**
* 填写邀请码
*/
@@ -1008,6 +1035,11 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
@Override
protected void onResume() {
super.onResume();
+ if (binder != null) {
+ if (binder.isDownloadOK()) {
+ binder.install();
+ }
+ }
if (mFristLoad) {
mFristLoad = false;
// getLocation();
@@ -1141,6 +1173,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
LiveStorge.getInstance().clear();
VideoStorge.getInstance().clear();
floatBanner.release();
+ if(connection!=null){
+ mContext.unbindService(connection);
+ }
super.onDestroy();
}
From a25e22b1429ad11972b649862a9ac6f5cd2e0e54 Mon Sep 17 00:00:00 2001
From: zlzw <583819556@qq.com>
Date: Fri, 16 Aug 2024 14:33:57 +0800
Subject: [PATCH 2/2] =?UTF-8?q?update=20=E4=B8=B4=E6=97=B6=E9=9A=90?=
=?UTF-8?q?=E8=97=8F=E5=A4=84=E7=BD=9A=E9=80=9A=E7=9F=A5=E5=85=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/yunbao/live/activity/SystemMessageActivity.java | 6 +++---
live/src/main/res/layout/view_sys_msg.xml | 8 +++++---
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/live/src/main/java/com/yunbao/live/activity/SystemMessageActivity.java b/live/src/main/java/com/yunbao/live/activity/SystemMessageActivity.java
index 03d9d07f3..cf0100eb1 100644
--- a/live/src/main/java/com/yunbao/live/activity/SystemMessageActivity.java
+++ b/live/src/main/java/com/yunbao/live/activity/SystemMessageActivity.java
@@ -72,7 +72,7 @@ public class SystemMessageActivity extends AbsActivity {
// }
init();
punish = findViewById(R.id.tv_sys_msg_punish);
- punish.setVisibility(View.VISIBLE);
+ punish.setVisibility(View.GONE);
punishNotice = findViewById(R.id.tv_sys_msg_punish_notice);
punish.setOnClickListener(v -> {
RouteUtil.forwardPunishActivity();
@@ -85,7 +85,7 @@ public class SystemMessageActivity extends AbsActivity {
finish();
}
});
- LiveNetManager.get(mContext).getPenalizeStatus(new com.yunbao.common.http.base.HttpCallback() {
+ /*LiveNetManager.get(mContext).getPenalizeStatus(new com.yunbao.common.http.base.HttpCallback() {
@Override
public void onSuccess(ResponseModel responseModel) {
punishNotice.setVisibility(View.VISIBLE);
@@ -95,7 +95,7 @@ public class SystemMessageActivity extends AbsActivity {
public void onError(String error) {
punishNotice.setVisibility(View.GONE);
}
- });
+ });*/
}
//更新新消息
diff --git a/live/src/main/res/layout/view_sys_msg.xml b/live/src/main/res/layout/view_sys_msg.xml
index cc30fbe79..9763cd3d2 100644
--- a/live/src/main/res/layout/view_sys_msg.xml
+++ b/live/src/main/res/layout/view_sys_msg.xml
@@ -56,18 +56,20 @@
android:text="@string/live_end_view_ban_punish_title"
android:textColor="@color/colorWhite"
android:textSize="12sp"
- android:visibility="visible" />
+ android:visibility="gone"
+ tools:visibility="visible" />
+ android:background="@drawable/bg_red_yuan"
+ android:visibility="gone"
+ tools:visibility="visible" />