Merge branch 'dev' of gitlab.ghzs.com:halo/assistant-android into dev
This commit is contained in:
@ -28,11 +28,6 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.gh.common.dialog.TrackableDialog;
|
||||
import com.gh.common.view.DrawableView;
|
||||
import com.gh.common.view.FixLinearLayoutManager;
|
||||
@ -52,6 +47,11 @@ import com.lightgame.utils.Utils;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class DialogUtils {
|
||||
|
||||
public static Dialog showWaitDialog(Context context, String msg) {
|
||||
@ -254,14 +254,12 @@ public class DialogUtils {
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(contentView);
|
||||
dialog.show();
|
||||
|
||||
}
|
||||
|
||||
public static void showResumeDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||||
showWarningDialog(context, "下载提示", "当前正在使用移动网络,继续下载会消耗手机流量", "连上WiFi后自动下载", "继续下载", listener, cancelListener);
|
||||
}
|
||||
|
||||
|
||||
public static void showDownloadDialog(Context context, ConfirmListener listener) {
|
||||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", listener);
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.gh.common.AppExecutor
|
||||
import com.gh.gamecenter.R
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.download.DownloadEntity
|
||||
@ -35,6 +35,7 @@ object DownloadNotificationHelper {
|
||||
@JvmStatic
|
||||
@Synchronized
|
||||
fun addOrUpdateDownloadNotification(entity: DownloadEntity) {
|
||||
var requireUpdateNotificationGroupDelay = false
|
||||
val notificationManager = getNotificationManager()
|
||||
val downloadNotificationId = (entity.gameId + entity.packageName).hashCode()
|
||||
|
||||
@ -84,11 +85,12 @@ object DownloadNotificationHelper {
|
||||
val notification = builder.build()
|
||||
notification.flags = notification.flags or Notification.FLAG_NO_CLEAR
|
||||
|
||||
if (entity.status == DownloadStatus.delete ||
|
||||
entity.status == DownloadStatus.cancel ||
|
||||
entity.status == DownloadStatus.hijack ||
|
||||
entity.status == DownloadStatus.notfound ||
|
||||
entity.status == DownloadStatus.overflow) {
|
||||
if (entity.status == DownloadStatus.delete
|
||||
|| entity.status == DownloadStatus.cancel
|
||||
|| entity.status == DownloadStatus.hijack
|
||||
|| entity.status == DownloadStatus.notfound
|
||||
|| entity.status == DownloadStatus.overflow) {
|
||||
requireUpdateNotificationGroupDelay = true
|
||||
notificationManager.cancel(entity.path, DOWNLOAD_NOTIFICATION_ID)
|
||||
} else {
|
||||
if (entity.status != DownloadStatus.downloading) {
|
||||
@ -101,9 +103,14 @@ object DownloadNotificationHelper {
|
||||
notificationManager.notify(entity.path, DOWNLOAD_NOTIFICATION_ID, notification)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
updateNotificationGroup()
|
||||
if (requireUpdateNotificationGroupDelay) {
|
||||
// 虽然运行到这里时 notification 已经被 cancel 了,但在下面的 notificationManager.activieNotifications 里它有可能还是 active 状态,
|
||||
// 这里延时 100 ms 避免出现所有的任务都取消了以后依旧有一条 notification group 常驻
|
||||
AppExecutor.uiExecutor.executeWithDelay(Runnable { updateNotificationGroup() }, 100)
|
||||
} else {
|
||||
updateNotificationGroup()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateNotificationGroup() {
|
||||
|
||||
@ -12,8 +12,6 @@ import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Build;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.TintTypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -22,6 +20,9 @@ import android.widget.RatingBar;
|
||||
import com.gh.common.view.materialratingbar.internal.DrawableCompat;
|
||||
import com.gh.gamecenter.R;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.TintTypedArray;
|
||||
|
||||
|
||||
// AppCompatRatingBar will add undesired measuring behavior.
|
||||
@SuppressLint("AppCompatCustomView")
|
||||
@ -154,6 +155,12 @@ public class MaterialRatingBar extends RatingBar {
|
||||
@Nullable
|
||||
@Override
|
||||
public ColorStateList getProgressTintList() {
|
||||
// Samsung Android 10 might call this in super class constructor.
|
||||
// Base on this PR: https://github.com/zhanghai/MaterialRatingBar/pull/62
|
||||
if (mProgressTintInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
logRatingBarTintWarning();
|
||||
return getSupportProgressTintList();
|
||||
}
|
||||
@ -301,9 +308,6 @@ public class MaterialRatingBar extends RatingBar {
|
||||
}
|
||||
|
||||
private void logRatingBarTintWarning() {
|
||||
if (getContext().getApplicationInfo().minSdkVersion >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return;
|
||||
}
|
||||
Log.w(TAG, "Non-support version of tint method called, this is error-prone and will crash" +
|
||||
" below Lollipop if you are calling it as a method of RatingBar instead of" +
|
||||
" MaterialRatingBar");
|
||||
|
||||
@ -10,9 +10,7 @@ import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.ArrayMap;
|
||||
|
||||
import com.gh.common.AppExecutor;
|
||||
import com.gh.common.exposure.ExposureEvent;
|
||||
import com.gh.common.util.AppDebugConfig;
|
||||
import com.gh.common.util.DataCollectionUtils;
|
||||
@ -58,6 +56,9 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.collection.ArrayMap;
|
||||
|
||||
import static android.os.Build.MANUFACTURER;
|
||||
|
||||
public class DownloadManager implements DownloadStatusListener {
|
||||
@ -721,38 +722,55 @@ public class DownloadManager implements DownloadStatusListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记下载已完成的任务以及更新数据(用于红点判断)
|
||||
* 标记下载已完成的任务为已读 (用于下载管理页入口的 toolbar 红点显示)
|
||||
*/
|
||||
public void markDownloadAndUpdateData() {
|
||||
boolean existWriteMark = false;
|
||||
List<DownloadEntity> all = getAll();
|
||||
for (DownloadEntity downloadEntity : all) {
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status == DownloadStatus.done) {
|
||||
String mark = downloadEntity.getMeta().get(HINT_MARK);
|
||||
if (TextUtils.isEmpty(mark)) {
|
||||
downloadEntity.getMeta().put(HINT_MARK, HINT_MARK);
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
if (!existWriteMark) existWriteMark = true;
|
||||
public void markDownloadedTaskAsRead() {
|
||||
AppExecutor.getIoExecutor().execute(() -> {
|
||||
boolean markHasChanged = false;
|
||||
|
||||
List<DownloadEntity> all = getAll();
|
||||
for (DownloadEntity downloadEntity : all) {
|
||||
DownloadStatus status = downloadEntity.getStatus();
|
||||
if (status == DownloadStatus.done) {
|
||||
String mark = downloadEntity.getMeta().get(HINT_MARK);
|
||||
if (TextUtils.isEmpty(mark)) {
|
||||
downloadEntity.getMeta().put(HINT_MARK, HINT_MARK);
|
||||
mDownloadDao.newOrUpdate(downloadEntity);
|
||||
if (!markHasChanged) markHasChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<GameUpdateEntity> updates = PackageRepository.INSTANCE.getGameUpdate();
|
||||
for (GameUpdateEntity update : updates) {
|
||||
String mark = update.getId() + update.getPackageName();
|
||||
if (!mUpdateMarks.contains(mark)) {
|
||||
mUpdateMarks.add(mark);
|
||||
if (!existWriteMark) existWriteMark = true;
|
||||
|
||||
if (markHasChanged) {
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download", "", "", "", "", ""));
|
||||
}
|
||||
}
|
||||
if (existWriteMark) {
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download", "", "", "", "", ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记可用更新为已读 (用于下载管理页入口的 toolbar 红点显示)
|
||||
*/
|
||||
public void markUpdatableTaskAsRead() {
|
||||
AppExecutor.getIoExecutor().execute(() -> {
|
||||
boolean markHasChanged = false;
|
||||
|
||||
ArrayList<GameUpdateEntity> updates = PackageRepository.INSTANCE.getGameUpdate();
|
||||
for (GameUpdateEntity update : updates) {
|
||||
String mark = update.getId() + update.getPackageName();
|
||||
if (!mUpdateMarks.contains(mark)) {
|
||||
mUpdateMarks.add(mark);
|
||||
if (!markHasChanged) markHasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (markHasChanged) {
|
||||
EventBus.getDefault().post(new EBDownloadStatus("download", "", "", "", "", ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新设置标记数据
|
||||
* 重新设置更新红点标记数据
|
||||
*/
|
||||
public void resetMarkData() {
|
||||
ArrayList<GameUpdateEntity> updates = PackageRepository.INSTANCE.getGameUpdate();
|
||||
|
||||
@ -81,6 +81,13 @@ class DownloadFragment : BaseFragment_TabLayout() {
|
||||
DownloadManager.getInstance(requireContext()).checkRetryDownload()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
|
||||
// onDestory 的回调有点晚,不能及时更新外部红点
|
||||
DownloadManager.getInstance(HaloApp.getInstance().application).markDownloadedTaskAsRead()
|
||||
}
|
||||
|
||||
override fun onPageSelected(index: Int) {
|
||||
EventBus.getDefault().post(EBUISwitch(DownloadManagerActivity.TAG, index))
|
||||
|
||||
@ -90,6 +97,10 @@ class DownloadFragment : BaseFragment_TabLayout() {
|
||||
else -> "已安装"
|
||||
}
|
||||
|
||||
if (index == INDEX_UPDATE) {
|
||||
DownloadManager.getInstance(HaloApp.getInstance().application).markUpdatableTaskAsRead()
|
||||
}
|
||||
|
||||
MtaHelper.onEvent("下载管理", "Tab", tabName)
|
||||
}
|
||||
|
||||
@ -100,7 +111,6 @@ class DownloadFragment : BaseFragment_TabLayout() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun onEventMainThread(changed: EBDownloadChanged) {
|
||||
if ("download" == changed.type) {
|
||||
@ -176,12 +186,4 @@ class DownloadFragment : BaseFragment_TabLayout() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
// 防止卡顿
|
||||
HaloApp.getInstance().mainExecutor.execute {
|
||||
// 标记所有待安装的下载任务以及更新/插件化的更新任务
|
||||
DownloadManager.getInstance(HaloApp.getInstance().application).markDownloadAndUpdateData()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,11 +12,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.collection.ArrayMap;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import com.gh.common.util.BitmapUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
@ -50,6 +45,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.collection.ArrayMap;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/8/15.
|
||||
@ -261,7 +261,8 @@ class GameDownloadFragmentAdapter extends BaseRecyclerAdapter<ViewHolder> {
|
||||
switch (str) {
|
||||
case "继续":
|
||||
case "下载":
|
||||
DialogUtils.checkResumeDownload(mContext, isSubscribe -> {
|
||||
// 下载管理不用判断是否大于50M
|
||||
DialogUtils.checkDownload(mContext, Float.toString(100F), isSubscribe -> {
|
||||
if (isSubscribe) {
|
||||
DownloadManager.getInstance(mContext).subscribe(downloadEntity);
|
||||
statusMap.put(url, DownloadStatus.subscribe.getStatus());
|
||||
|
||||
@ -855,7 +855,7 @@ class GameDetailFragment : NormalFragment() {
|
||||
updateDownloadCountHint(mPackageViewModel.filterSameUpdateLiveData.value)
|
||||
|
||||
val downloadMenuView = mToolbar.menu.findItem(R.id.menu_download).actionView
|
||||
mDownloadCountHint = downloadMenuView.findViewById<TextView>(R.id.menu_download_count_hint)
|
||||
mDownloadCountHint = downloadMenuView.findViewById(R.id.menu_download_count_hint)
|
||||
}
|
||||
|
||||
private fun updateDownloadCountHint(updateList: List<GameUpdateEntity>?) {
|
||||
@ -892,7 +892,7 @@ class GameDetailFragment : NormalFragment() {
|
||||
}
|
||||
|
||||
private fun tabPerformClick(view: View?) {
|
||||
if (!mIsPageChanged) view!!.performClick()
|
||||
if (!mIsPageChanged) view?.performClick()
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
@ -915,6 +915,6 @@ class GameDetailFragment : NormalFragment() {
|
||||
const val OPEN_APPBAR = "openappbar"
|
||||
const val SCROLL_TO_KAIFU = "scrollToKaiFu"
|
||||
|
||||
private val SP_OPENED_DIALOG_TIME_PREFIX = "opened_dialog_time_prefix_"
|
||||
private const val SP_OPENED_DIALOG_TIME_PREFIX = "opened_dialog_time_prefix_"
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,9 +13,9 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gh.common.util.DataLogUtils;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.MD5Utils;
|
||||
import com.gh.common.util.MtaHelper;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
@ -214,9 +214,9 @@ public class UpdateManager {
|
||||
File file = new File(path);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
DataLogUtils.uploadUpgradeLog(mContext, "install"); //上传更新安装数据
|
||||
mContext.startActivity(PackageUtils.getInstallIntent(mContext, path));
|
||||
mContext.startActivity(PackageUtils.getInstallIntent(mContext, path, true));
|
||||
} else {
|
||||
DataUtils.onEvent(mContext, "软件更新", "下载开始");
|
||||
MtaHelper.onEvent("软件更新", "下载开始");
|
||||
showDownloadDialog(md5);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user