Merge branch 'dev' of gitlab.ghzs.com:halo/assistant-android into dev

This commit is contained in:
张玉久
2020-05-28 11:16:54 +08:00
25 changed files with 249 additions and 176 deletions

View File

@ -10,6 +10,7 @@ import android.content.Intent
import android.os.Build
import androidx.core.app.NotificationCompat
import com.gh.base.CurrentActivityHolder
import com.gh.common.util.doOnMainProcessOnly
import com.gh.gamecenter.R
import com.m7.imkfsdk.chat.ChatActivity
import com.m7.imkfsdk.utils.Utils
@ -25,51 +26,53 @@ class ImReceiver : BroadcastReceiver() {
var notificationManager: NotificationManager? = null
override fun onReceive(context: Context?, intent: Intent?) {
intent?.let {
if (intent.action == IMChatManager.NEW_MSG_ACTION) {
notificationManager = context?.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// 判断 ImActivity 是否在最顶端
if (CurrentActivityHolder.getCurrentActivity() is ChatActivity) {
ImManager.showFloatingWindow()
ImManager.updateShouldShowFloatingWindowDot(false)
} else {
val contentIntent = Intent(Utils.getApp(), ChatActivity::class.java)
contentIntent.putExtra("PeerId", "")
contentIntent.putExtra("type", "peedId")
contentIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val resultPendingIntent = PendingIntent.getActivity(
Utils.getApp(),
0,
contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
// 新的通知
val builder = NotificationCompat.Builder(Utils.getApp(), "Halo_IM")
val notification = builder.setTicker("您有新的消息")
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.ic_notification)
.setWhen(System.currentTimeMillis())
.setContentIntent(resultPendingIntent)
.setContentTitle("光环助手客服回复")
.setContentText("您有新的消息")
.setAutoCancel(true)
.build()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel("Halo_IM", "Halo_IM", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager?.createNotificationChannel(channel)
}
if (notification != null) {
notificationManager?.notify(NOTIFICATION_ID, notification)
context?.doOnMainProcessOnly {
intent?.let {
if (intent.action == IMChatManager.NEW_MSG_ACTION) {
notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// 判断 ImActivity 是否在最顶端
if (CurrentActivityHolder.getCurrentActivity() is ChatActivity) {
ImManager.showFloatingWindow()
ImManager.updateShouldShowFloatingWindowDot(false)
} else {
val contentIntent = Intent(Utils.getApp(), ChatActivity::class.java)
contentIntent.putExtra("PeerId", "")
contentIntent.putExtra("type", "peedId")
contentIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val resultPendingIntent = PendingIntent.getActivity(
Utils.getApp(),
0,
contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
// 新的通知
val builder = NotificationCompat.Builder(Utils.getApp(), "Halo_IM")
val notification = builder.setTicker("您有新的消息")
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.ic_notification)
.setWhen(System.currentTimeMillis())
.setContentIntent(resultPendingIntent)
.setContentTitle("光环助手客服回复")
.setContentText("您有新的消息")
.setAutoCancel(true)
.build()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel("Halo_IM", "Halo_IM", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager?.createNotificationChannel(channel)
}
if (notification != null) {
notificationManager?.notify(NOTIFICATION_ID, notification)
ImManager.showFloatingWindow()
}
}
} else if (intent.action == IMChatManager.FINISH_ACTION) {
ImManager.dismissFloatingWindow()
}
} else if (intent.action == IMChatManager.FINISH_ACTION) {
ImManager.dismissFloatingWindow()
}
}
}

View File

@ -159,6 +159,7 @@ public class EntranceUtils {
public static final String KEY_QA_ID = "qaId";
public static final String KEY_QA_COLLECTION_ID = "qaCollectionId";
public static final String KEY_SHOW_EDIT_DRAFT = "showEditDraft";
public static final String KEY_ARTICLE_OPEN_IN_NEW_PAGE = "openArticleInNewPage";
public static void jumpActivity(Context context, Bundle bundle) {
bundle.putBoolean(KEY_REQUIRE_REDIRECT, true);

View File

@ -28,6 +28,7 @@ import com.gh.gamecenter.BuildConfig
import com.gh.gamecenter.R
import com.google.gson.reflect.TypeToken
import com.halo.assistant.HaloApp
import com.lightgame.utils.Utils
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
@ -460,6 +461,22 @@ fun SimpleDraweeView.display(url: String) {
ImageUtils.display(this, url)
}
/**
* Process related
*/
fun Context.doOnMainProcessOnly(callback: EmptyCallback) {
doOnMainProcessOnly { callback.onCallback() }
}
fun Context.doOnMainProcessOnly(f: () -> Unit) {
val processName = PackageUtils.obtainProcessName(this)
if (processName == null || BuildConfig.APPLICATION_ID == processName) {
f.invoke()
} else {
Utils.log("Block one useless sub process method call.")
}
}
/**
* 测试用包裹
*/

View File

@ -1,5 +1,6 @@
package com.gh.common.util;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
@ -551,4 +552,24 @@ public class PackageUtils {
&& !TextUtils.isEmpty(apkEntity.getGhVersion())
&& !PackageUtils.isSignedByGh(HaloApp.getInstance().getApplication(), apkEntity.getPackageName());
}
/**
* 获取调用者的进程名
* @param context 调用者的上下文
* @return 进程名
*/
public static String obtainProcessName(Context context) {
final int pid = android.os.Process.myPid();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> listTaskInfo = am.getRunningAppProcesses();
if (listTaskInfo != null && !listTaskInfo.isEmpty()) {
for (ActivityManager.RunningAppProcessInfo info : listTaskInfo) {
if (info != null && info.pid == pid) {
return info.processName;
}
}
}
return null;
}
}

View File

@ -795,21 +795,21 @@ public class DownloadManager implements DownloadStatusListener {
}
/**
* 标记下载中任务为已读状态 (用于下载管理页入口的 toolbar 红点显示)
* 标记下载中任务为已读状态(用于下载页及外部toolbar)
*/
public void markDownloadingTaskAsRead() {
markDownloadingTaskAsReadOrUnread(true);
}
/**
* 标记下载中任务为未读状态 (用于下载管理页入口的 toolbar 红点显示)
* 标记下载中任务为未读状态(用于下载页及外部toolbar)
*/
public void markDownloadingTaskAsUnread() {
markDownloadingTaskAsReadOrUnread(false);
}
/**
* 更改下载中任务已读状态 (用于下载管理页入口的 toolbar 红点显示)
* 更改下载中任务已读状态(用于下载页及外部toolbar)
*/
private void markDownloadingTaskAsReadOrUnread(boolean isRead) {
AppExecutor.getIoExecutor().execute(() -> {

View File

@ -3,10 +3,10 @@ package com.gh.gamecenter.baselist;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import androidx.recyclerview.widget.DiffUtil;
import com.lightgame.adapter.BaseRecyclerAdapter;
import com.lightgame.utils.Utils;
import java.util.ArrayList;
import java.util.List;
@ -103,8 +103,6 @@ public abstract class ListAdapter<DataType> extends BaseRecyclerAdapter {
}
public void loadChange(LoadStatus status) {
Utils.log("=====>>>" + status.name());
switch (status) {
case INIT_OVER:
case LIST_OVER:

View File

@ -81,7 +81,7 @@ public class AnswerAdapter extends ListAdapter<AnswerEntity> implements ISyncAda
viewHolder.itemView.setOnLongClickListener(v -> {
DialogHelper.showDialog(holder.itemView.getContext(),
"删除记录",
"删除浏览记录将不可复,确定删除吗?",
"删除浏览记录将不可复,确定删除吗?",
"确定",
"取消",
() -> {

View File

@ -129,7 +129,7 @@ public class ArticleAdapter extends ListAdapter<NewsEntity> {
holder.itemView.setOnLongClickListener(v -> {
DialogHelper.showDialog(holder.itemView.getContext(),
"删除记录",
"删除浏览记录将不可复,确定删除吗?",
"删除浏览记录将不可复,确定删除吗?",
"确定",
"取消",
() -> {

View File

@ -59,7 +59,7 @@ class CommunityArticleAdapter(context: Context,
consume {
DialogHelper.showDialog(holder.binding.root.context,
"删除记录",
"删除浏览记录将不可复,确定删除吗?",
"删除浏览记录将不可复,确定删除吗?",
"确定",
"取消", {
mViewModel.removeHistory(entity)

View File

@ -57,7 +57,7 @@ class VideoAdapter(context: Context,
consume {
DialogHelper.showDialog(holder.binding.root.context,
"删除记录",
"删除浏览记录将不可复,确定删除吗?",
"删除浏览记录将不可复,确定删除吗?",
"确定",
"取消", {
mViewModel.removeHistory(entity)

View File

@ -3,7 +3,10 @@ package com.gh.gamecenter.history
import android.content.Context
import android.view.ViewGroup
import com.gh.common.constant.ItemViewType
import com.gh.common.util.*
import com.gh.common.util.DialogHelper
import com.gh.common.util.DownloadItemUtils
import com.gh.common.util.StringUtils
import com.gh.common.util.consume
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.FooterViewHolder
@ -66,7 +69,7 @@ class HistoryGameListAdapter(context: Context, private val mViewModel: HistoryGa
consume {
DialogHelper.showDialog(holder.binding.root.context,
"删除记录",
"删除浏览记录将不可复,确定删除吗?",
"删除浏览记录将不可复,确定删除吗?",
"确定",
"取消", {
mViewModel.removeHistory(gameEntity)

View File

@ -151,6 +151,7 @@ class AnswerDraftAdapter extends ListAdapter<AnswerEntity> {
answerEntity.getQuestions(),
"",// 会自动获取草稿所以该数据可以不填
answerEntity.getCommunityName(),
true,
true));
}
});

View File

@ -593,13 +593,15 @@ class AnswerEditActivity : BaseRichEditorActivity(), KeyboardHeightObserver {
question: Questions?,
content: String?,
communityName: String?,
showEditDraft: Boolean = false): Intent {
showEditDraft: Boolean = false,
showInNewPage: Boolean = false): Intent {
val intent = Intent(context, AnswerEditActivity::class.java)
intent.putExtra(EntranceUtils.KEY_ANSWER_ID, answerId)
intent.putExtra(EntranceUtils.KEY_ANSWER_CONTENT, content)
intent.putExtra(EntranceUtils.KEY_COMMUNITY_NAME, communityName)
intent.putExtra(EntranceUtils.KEY_SHOW_EDIT_DRAFT, showEditDraft)
intent.putExtra(Questions::class.java.simpleName, question)
intent.putExtra(EntranceUtils.KEY_ANSWER_OPEN_IN_NEW_PAGE, showInNewPage)
return intent
}
}

View File

@ -47,7 +47,7 @@ class ArticleDraftFragment : ListFragment<ArticleDraftEntity, NormalListViewMode
id = it.articleId,
title = it.title,
community = it.community)
startActivity(ArticleEditActivity.getPatchIntent(requireContext(), detailEntity, it))
startActivity(ArticleEditActivity.getPatchIntent(requireContext(), detailEntity, it, true))
}
}
} else if (activity != null) {

View File

@ -104,6 +104,7 @@ class ArticleEditActivity : BaseRichEditorActivity() {
mViewModel = ViewModelProviders.of(this).get(ArticleEditViewModel::class.java)
mViewModel.detailEntity = intent.getParcelableExtra(ArticleDetailEntity::class.java.simpleName)
mViewModel.draftEntity = intent.getParcelableExtra(ArticleDraftEntity::class.java.simpleName)
mViewModel.openArticleInNewPage = intent.getBooleanExtra(EntranceUtils.KEY_ARTICLE_OPEN_IN_NEW_PAGE, false)
mGameNameTitle.text = Html.fromHtml(getString(R.string.article_edit_game_name))
mRichEditor.setOnTextChangeListener { t ->
@ -518,17 +519,22 @@ class ArticleEditActivity : BaseRichEditorActivity() {
}
@JvmStatic
fun getPatchIntent(context: Context, detailEntity: ArticleDetailEntity, draftEntity: ArticleDraftEntity? = null): Intent {
fun getPatchIntent(context: Context,
detailEntity: ArticleDetailEntity,
draftEntity: ArticleDraftEntity? = null,
showInNewPage: Boolean = false): Intent {
val intent = Intent(context, ArticleEditActivity::class.java)
intent.putExtra(ArticleDetailEntity::class.java.simpleName, detailEntity)
intent.putExtra(ArticleDraftEntity::class.java.simpleName, draftEntity)
intent.putExtra(EntranceUtils.KEY_ARTICLE_OPEN_IN_NEW_PAGE, showInNewPage)
return intent
}
@JvmStatic
fun getDraftIntent(context: Context, draftEntity: ArticleDraftEntity): Intent {
fun getDraftIntent(context: Context, draftEntity: ArticleDraftEntity, showInNewPage: Boolean = true): Intent {
val intent = Intent(context, ArticleEditActivity::class.java)
intent.putExtra(ArticleDraftEntity::class.java.simpleName, draftEntity)
intent.putExtra(EntranceUtils.KEY_ARTICLE_OPEN_IN_NEW_PAGE, showInNewPage)
return intent
}
}

View File

@ -63,6 +63,8 @@ class ArticleEditViewModel(application: Application) : AndroidViewModel(applicat
var title: String? = null
var content: String? = null
var openArticleInNewPage: Boolean = false
/**
* 获取默认标签和确定当前communityId
*/

View File

@ -59,13 +59,13 @@ class ArticleTagsSelectFragment : BaseFragment<String>() {
initTags()
mViewModel?.postArticle?.observe(this, Observer {
if (mViewModel?.detailEntity != null) {
if (mViewModel?.openArticleInNewPage == false) {
val intent = Intent()
intent.putExtra(ArticleDetailEntity::class.java.simpleName, mViewModel?.detailEntity)
activity?.setResult(Activity.RESULT_OK, intent)
} else {
activity?.setResult(Activity.RESULT_OK)
val articleId = JSONObject(it).getString("_id")
val articleId = mViewModel?.detailEntity?.id ?: JSONObject(it).getString("_id")
val intent = ArticleDetailActivity.getIntent(requireContext(),
mViewModel?.mSelectCommunityData!!,
articleId, mEntrance, "撰写文章")

View File

@ -35,7 +35,6 @@ import com.lightgame.utils.Util_System_Keyboard
import org.greenrobot.eventbus.EventBus
// todo 大小输入框交换逻辑出错
open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>(), OnCommentCallBackListener, KeyboardHeightObserver {
@Nullable
@ -100,7 +99,14 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
apiResponse.data != null -> {
mSendingDialog?.dismiss()
toast("发表成功")
commentEt.setText("")
if (mCommentEntity != null) { // 补充默认草稿
mCommentEntity = null // 清空当前评论实体
commentEt.hint = getString(R.string.message_detail_comment_hint)
commentEt.setText(mViewModel.getCommentDraft(mCommentEntity)?.draft ?: "")
} else {
commentEt.setText("")
}
mCommentCount++
updateCommentCount()
@ -164,6 +170,7 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
if (mCommentListener != null) {
mCommentListener?.onCommentDraftChange(commentEt.text.toString())
}
mViewModel.saveCommentDraft(mCommentEntity, commentEt.text.toString())
}
commentEt.filters = arrayOf(TextHelper.getFilter(140, "评论不能多于140字"))
if (!mCommentDraft.isNullOrEmpty()) {
@ -182,8 +189,6 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
}, 200)
} else {
commentEt.clearFocus()
commentSendBtn.setBackgroundResource(R.drawable.comment_send_button_unavailable)
commentSendBtn.setTextColor(R.color.text_cccccc.toColor())
}
commentEt.setOnFocusChangeListener { _, hasFocus ->
@ -225,8 +230,6 @@ open class NewCommentFragment : ListFragment<CommentEntity, NewCommentViewModel>
override fun onDestroy() {
super.onDestroy()
mKeyboardHeightProvider?.close()
mViewModel.saveCommentDraft(mCommentEntity, commentEt.text.toString())
}
private fun updateCommentCount() {

View File

@ -101,11 +101,11 @@ class NewCommentViewModel(application: Application,
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Response<ResponseBody>() {
override fun onResponse(response: ResponseBody?) {
deleteCommentDraft(commentEntity)
val apiResponse = ApiResponse<JSONObject>()
apiResponse.data = JSONObject()
mPostCommentLiveData.postValue(apiResponse)
deleteCommentDraft(commentEntity)
}
override fun onFailure(e: HttpException?) {

View File

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.text.TextUtils;
import com.gh.common.util.ClassUtils;
import com.gh.common.util.ExtensionsKt;
import com.gh.common.util.RunningUtils;
import com.gh.gamecenter.SplashScreenActivity;
@ -20,25 +21,27 @@ public class ActivitySkipReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_ACTIVITY_SKIP.equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
if (RunningUtils.isRunning(context)) {
// 应用正在运行,前台或后台
String to = bundle.getString("to");
if (!TextUtils.isEmpty(to)) {
Class<?> clazz = ClassUtils.forName(to);
if (clazz != null) {
Intent intent1 = new Intent(context, clazz);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.putExtras(bundle);
context.startActivity(intent1);
ExtensionsKt.doOnMainProcessOnly(context, () -> {
if (ACTION_ACTIVITY_SKIP.equals(intent.getAction())) {
Bundle bundle = intent.getExtras();
if (RunningUtils.isRunning(context)) {
// 应用正在运行,前台或后台
String to = bundle.getString("to");
if (!TextUtils.isEmpty(to)) {
Class<?> clazz = ClassUtils.forName(to);
if (clazz != null) {
Intent intent1 = new Intent(context, clazz);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.putExtras(bundle);
context.startActivity(intent1);
}
}
} else {
// 应用未在运行
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
}
} else {
// 应用未在运行
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
}
}
});
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import com.gh.common.util.DirectUtils;
import com.gh.common.util.ExtensionsKt;
import static com.gh.common.util.EntranceUtils.ENTRANCE_DOWNLOAD;
@ -16,6 +17,8 @@ public class DownloadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
DirectUtils.directToDownloadManager(context, ENTRANCE_DOWNLOAD);
ExtensionsKt.doOnMainProcessOnly(context, () -> {
DirectUtils.directToDownloadManager(context, ENTRANCE_DOWNLOAD);
});
}
}

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import com.gh.common.util.DataUtils;
import com.gh.common.util.ExtensionsKt;
import com.gh.common.util.InstallUtils;
import com.gh.common.util.PackageHelper;
import com.gh.common.util.PackageUtils;
@ -23,40 +24,42 @@ public class InstallAndUninstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Utils.log("InstallAndUninstallReceiver:: onReceive->" + intent.getAction() + "==" + intent.getDataString());
// 接收安装广播
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
String packageName = intent.getDataString();
packageName = packageName.substring(packageName.indexOf(":") + 1);
Utils.log("安装了:" + packageName + "包名的程序");
InstallUtils.getInstance(context).removeInstall(packageName);
PackageHelper.refreshLocalPackageList();
String versionName = PackageUtils.getVersionByPackage(packageName);
EventBus.getDefault().post(new EBPackage("安装", packageName, versionName));
}
// 接收卸载广播
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
String packageName = intent.getDataString();
packageName = packageName.substring(packageName.indexOf(":") + 1);
Utils.log("卸载了:" + packageName + "包名的程序");
InstallUtils.getInstance(context).removeUninstall(packageName);
PackageHelper.refreshLocalPackageList();
EventBus.getDefault().post(new EBPackage("卸载", packageName, ""));
}
// 接收替换广播
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
String packageName = intent.getData().getSchemeSpecificPart();
packageName = packageName.substring(packageName.indexOf(":") + 1);
Utils.log("替换了:" + packageName + "包名的程序");
if (packageName.equals(context.getPackageName())) {
DataUtils.onEvent(context, "软件更新", "更新完成");
ExtensionsKt.doOnMainProcessOnly(context, () -> {
Utils.log("InstallAndUninstallReceiver:: onReceive->" + intent.getAction() + "==" + intent.getDataString());
// 接收安装广播
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
String packageName = intent.getDataString();
packageName = packageName.substring(packageName.indexOf(":") + 1);
Utils.log("安装了:" + packageName + "包名的程序");
InstallUtils.getInstance(context).removeInstall(packageName);
PackageHelper.refreshLocalPackageList();
String versionName = PackageUtils.getVersionByPackage(packageName);
EventBus.getDefault().post(new EBPackage("安装", packageName, versionName));
}
String versionName = PackageUtils.getVersionByPackage(packageName);
EventBus.getDefault().post(new EBPackage("替换", packageName, versionName));
}
// 接收卸载广播
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
String packageName = intent.getDataString();
packageName = packageName.substring(packageName.indexOf(":") + 1);
Utils.log("卸载了:" + packageName + "包名的程序");
InstallUtils.getInstance(context).removeUninstall(packageName);
PackageHelper.refreshLocalPackageList();
EventBus.getDefault().post(new EBPackage("卸载", packageName, ""));
}
// 接收替换广播
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
String packageName = intent.getData().getSchemeSpecificPart();
packageName = packageName.substring(packageName.indexOf(":") + 1);
Utils.log("替换了:" + packageName + "包名的程序");
if (packageName.equals(context.getPackageName())) {
DataUtils.onEvent(context, "软件更新", "更新完成");
}
String versionName = PackageUtils.getVersionByPackage(packageName);
EventBus.getDefault().post(new EBPackage("替换", packageName, versionName));
}
});
}
}

View File

@ -10,6 +10,7 @@ import com.gh.base.fragment.BaseFragment_ViewPager;
import com.gh.common.constant.Constants;
import com.gh.common.util.DownloadNotificationHelper;
import com.gh.common.util.EntranceUtils;
import com.gh.common.util.ExtensionsKt;
import com.gh.common.util.GsonUtils;
import com.gh.common.util.PackageUtils;
import com.gh.common.util.RunningUtils;
@ -28,50 +29,50 @@ import static com.gh.common.util.EntranceUtils.KEY_TO;
* notification安装跳转
*/
public class InstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String path = intent.getStringExtra(EntranceUtils.KEY_PATH);
String downloadEntityString = intent.getStringExtra(EntranceUtils.KEY_DATA);
updateNotification(downloadEntityString);
if (PackageUtils.isCanLaunchSetup(context, path)) {
Intent installIntent = PackageUtils.getInstallIntent(context, path);
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(installIntent);
} else {
if (RunningUtils.isRunning(context)) {
if (RunningUtils.isEqualsTop(context, DownloadManagerActivity.class.getName())) {
// 这里是指从后台返回到前台 前两个的是关键
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_MAIN);
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
intent2.setComponent(new ComponentName(context, DownloadManagerActivity.class));
intent2.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
context.startActivity(intent2);
EventBus.getDefault().post(new EBMiPush("plugin_install", path));
} else {
Intent intent2 = new Intent(context, DownloadManagerActivity.class);
intent2.putExtra(BaseFragment_ViewPager.ARGS_INDEX, 0);
intent2.putExtra(EntranceUtils.KEY_PATH, path);
intent2.putExtra(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
ExtensionsKt.doOnMainProcessOnly(context, () -> {
String path = intent.getStringExtra(EntranceUtils.KEY_PATH);
String downloadEntityString = intent.getStringExtra(EntranceUtils.KEY_DATA);
updateNotification(downloadEntityString);
if (PackageUtils.isCanLaunchSetup(context, path)) {
Intent installIntent = PackageUtils.getInstallIntent(context, path);
installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(installIntent);
} else {
// 应用未在运行
Bundle bundle = new Bundle();
bundle.putString(KEY_TO, DownloadManagerActivity.TAG);
bundle.putInt(BaseFragment_ViewPager.ARGS_INDEX, 0);
bundle.putString(EntranceUtils.KEY_PATH, path);
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
if (RunningUtils.isRunning(context)) {
if (RunningUtils.isEqualsTop(context, DownloadManagerActivity.class.getName())) {
// 这里是指从后台返回到前台 前两个的是关键
Intent intent2 = new Intent();
intent2.setAction(Intent.ACTION_MAIN);
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
intent2.setComponent(new ComponentName(context, DownloadManagerActivity.class));
intent2.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
context.startActivity(intent2);
EventBus.getDefault().post(new EBMiPush("plugin_install", path));
} else {
Intent intent2 = new Intent(context, DownloadManagerActivity.class);
intent2.putExtra(BaseFragment_ViewPager.ARGS_INDEX, 0);
intent2.putExtra(EntranceUtils.KEY_PATH, path);
intent2.putExtra(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
}
} else {
// 应用未在运行
Bundle bundle = new Bundle();
bundle.putString(KEY_TO, DownloadManagerActivity.TAG);
bundle.putInt(BaseFragment_ViewPager.ARGS_INDEX, 0);
bundle.putString(EntranceUtils.KEY_PATH, path);
bundle.putString(EntranceUtils.KEY_ENTRANCE, "(安装跳转)");
context.startActivity(SplashScreenActivity.getSplashScreenIntent(context, bundle));
}
}
}
});
}
private void updateNotification(String downloadEntityString) {
@ -79,7 +80,7 @@ public class InstallReceiver extends BroadcastReceiver {
DownloadEntity downloadEntity = GsonUtils.fromJson(downloadEntityString, DownloadEntity.class);
downloadEntity.getMeta().put(Constants.MARK_ALREADY_TRIGGERED_INSTALLATION, "YES");
DownloadNotificationHelper.addOrUpdateDownloadNotification(downloadEntity);
} catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import com.gh.common.constant.Constants;
import com.gh.common.exposure.meta.MetaUtil;
import com.gh.common.repository.ReservationRepository;
import com.gh.common.util.ExtensionsKt;
import com.gh.common.util.NetworkUtils;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.eventbus.EBNetworkState;
@ -20,15 +21,20 @@ public class NetworkStateReceiver extends BroadcastReceiver {
// 监听网络状态的变化
@Override
public void onReceive(Context context, Intent intent) {
EventBus.getDefault().post(new EBNetworkState(NetworkUtils.isNetworkConnected(context)));
MetaUtil.INSTANCE.refreshMeta();
ReservationRepository.refreshReservationsIfNeeded();
DownloadManager.getInstance(HaloApp.getInstance().getApplication()).checkRetryDownload();
if (NetworkUtils.isNetworkConnected(context)) {
if (NetworkUtils.isMobileConnected(context)) {
HaloApp.put(Constants.SHOULD_SHOW_VIDEO_MOBILE_WARNING, true);
// 网络变更这里会被主进程和推送进程分别调用,这里只对主进程响应,
// 但不知道会不会在一些设备上拿不到 process name ,所以拿不到的时候还是让它调用
ExtensionsKt.doOnMainProcessOnly(context, () -> {
EventBus.getDefault().post(new EBNetworkState(NetworkUtils.isNetworkConnected(context)));
MetaUtil.INSTANCE.refreshMeta();
ReservationRepository.refreshReservationsIfNeeded();
DownloadManager.getInstance(HaloApp.getInstance().getApplication()).checkRetryDownload();
if (NetworkUtils.isNetworkConnected(context)) {
if (NetworkUtils.isMobileConnected(context)) {
HaloApp.put(Constants.SHOULD_SHOW_VIDEO_MOBILE_WARNING, true);
}
}
}
});
}
}