From d86dc7a03c8c2b12b4ea01cfa295aafffd0a03ce Mon Sep 17 00:00:00 2001 From: chenjuntao Date: Mon, 14 Aug 2023 17:44:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccelerateNotificationHandler.kt | 127 +++ .../common/prioritychain/HomePushHandler.kt | 42 + .../NotificationPermissionDialogHandler.kt | 20 + .../gh/common/prioritychain/PriorityChain.kt | 20 + .../prioritychain/PriorityChainHandler.kt | 62 ++ .../PrivacyPolicyDialogHandler.kt | 47 + .../prioritychain/ReserveDialogHandler.kt | 52 ++ .../prioritychain/UpdateDialogHandler.kt | 18 + .../prioritychain/WelcomeDialogHandler.kt | 79 ++ .../java/com/gh/gamecenter/MainActivity.java | 44 +- .../fragment/MainWrapperFragment.java | 801 ------------------ .../fragment/MainWrapperFragment.kt | 687 +++++++++++++++ .../fragment/MainWrapperViewModel.kt | 18 +- .../fragment/WelcomeDialogFragment.kt | 132 +-- .../common/base/fragment/BaseFragment.java | 2 +- 15 files changed, 1222 insertions(+), 929 deletions(-) create mode 100644 app/src/main/java/com/gh/common/prioritychain/AccelerateNotificationHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/HomePushHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/NotificationPermissionDialogHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/PriorityChain.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/PriorityChainHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/PrivacyPolicyDialogHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/ReserveDialogHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/UpdateDialogHandler.kt create mode 100644 app/src/main/java/com/gh/common/prioritychain/WelcomeDialogHandler.kt delete mode 100644 app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java create mode 100644 app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.kt diff --git a/app/src/main/java/com/gh/common/prioritychain/AccelerateNotificationHandler.kt b/app/src/main/java/com/gh/common/prioritychain/AccelerateNotificationHandler.kt new file mode 100644 index 0000000000..d7bdf0fcef --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/AccelerateNotificationHandler.kt @@ -0,0 +1,127 @@ +package com.gh.common.prioritychain + +import android.app.Activity +import android.view.Gravity +import android.view.LayoutInflater +import android.widget.FrameLayout +import com.gh.common.util.NewFlatLogUtils +import com.gh.gamecenter.GameDetailActivity +import com.gh.gamecenter.R +import com.gh.gamecenter.common.base.fragment.BaseFragment +import com.gh.gamecenter.common.constant.Constants +import com.gh.gamecenter.common.view.BugFixedPopupWindow +import com.gh.gamecenter.core.utils.DisplayUtils +import com.gh.gamecenter.core.utils.SPUtils +import com.gh.gamecenter.databinding.PopupAccelerateNotificationBinding +import com.gh.gamecenter.feature.entity.GameEntity +import com.gh.gamecenter.fragment.MainWrapperViewModel + +class AccelerateNotificationHandler(priority: Int) : PriorityChainHandler(priority) { + + private var mActivity: Activity? = null + private var mBaseHandler: BaseFragment.BaseHandler? = null + private var mGameList: List? = null + private var mViewModel: MainWrapperViewModel? = null + + /** + * 提前预处理显示弹窗的内容 + */ + fun doPreProcess( + activity: Activity, + baseHandler: BaseFragment.BaseHandler, + gameEntityList: List?, + viewModel: MainWrapperViewModel + ) { + mActivity = activity + mGameList = gameEntityList + mBaseHandler = baseHandler + mViewModel = viewModel + + if (getStatus() == STATUS_PENDING) { + if (gameEntityList == null) { + processNext() + } else { + onProcess() + } + } else { + if (gameEntityList == null) { + updateStatus(STATUS_INVALID) + } else { + updateStatus(STATUS_VALID) + } + } + } + + override fun onProcess() { + when (getStatus()) { + STATUS_VALID -> { + val accelerateSet = + HashSet(SPUtils.getStringSet(Constants.SP_ACCELERATE_NOTIFICATION_POP_UP_SET)) + if (!mGameList.isNullOrEmpty() && !accelerateSet.contains(mGameList!![0].messageId)) { + showAccelerateNotificationPopupWindow(mGameList!![0]) { + processNext() + } + accelerateSet.add(mGameList!![0].messageId) + SPUtils.setStringSet(Constants.SP_ACCELERATE_NOTIFICATION_POP_UP_SET, accelerateSet) + } else { + processNext() + } + } + + STATUS_INVALID -> { + processNext() + } + } + } + + private fun showAccelerateNotificationPopupWindow(gameEntity: GameEntity?, dismissCallback: () -> Unit) { + val binding: PopupAccelerateNotificationBinding = + PopupAccelerateNotificationBinding.inflate(LayoutInflater.from(mActivity)) + if (gameEntity != null) { + binding.gameIconView.displayGameIcon(gameEntity) + binding.gameNameTv.text = gameEntity.name + binding.root.setOnClickListener { + NewFlatLogUtils.logMessageInformClickPluginVersion( + gameEntity.id, + gameEntity.name!! + ) + if (gameEntity.messageId.isNotEmpty()) { + // 把对应系统消息设为已读 + mViewModel?.postMessageRead(gameEntity.messageId) + } + GameDetailActivity.startGameDetailActivity( + context = mActivity!!, + gameId = gameEntity.id, + entrance = "首页插件上架弹窗", + defaultTab = -1, + isSkipGameComment = false, + scrollToLibao = false, + openVideoStreaming = false, + openPlatformWindow = true, + traceEvent = null + ) + } + } + BugFixedPopupWindow( + binding.root, + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.WRAP_CONTENT + ).apply { + isTouchable = true + isFocusable = true + isOutsideTouchable = true + animationStyle = R.style.popup_window_ease_in_and_out_anim_style + showAtLocation( + mActivity!!.window.decorView, + Gravity.TOP, + 0, + DisplayUtils.getStatusBarHeight(mActivity!!.resources) + DisplayUtils.dip2px(42f) + ) + setOnDismissListener { + dismissCallback.invoke() + } + mBaseHandler?.postDelayed({ dismiss() }, 5000) + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/HomePushHandler.kt b/app/src/main/java/com/gh/common/prioritychain/HomePushHandler.kt new file mode 100644 index 0000000000..e8875d7e39 --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/HomePushHandler.kt @@ -0,0 +1,42 @@ +package com.gh.common.prioritychain + +import com.gh.gamecenter.fragment.HomeSearchToolWrapperFragment + +class HomePushHandler(priority: Int): PriorityChainHandler(priority) { + + private var mHomeFragment: HomeSearchToolWrapperFragment? = null + + /** + * 提前预处理显示弹窗的内容 + */ + fun doPreProcess(homeFragment: HomeSearchToolWrapperFragment?, shouldShow: Boolean) { + mHomeFragment = homeFragment + + if (getStatus() == STATUS_PENDING) { + if (shouldShow && homeFragment != null) { + onProcess() + } else { + processNext() + } + } else { + if (shouldShow && homeFragment != null) { + updateStatus(STATUS_VALID) + } else { + updateStatus(STATUS_INVALID) + } + } + } + + override fun onProcess() { + when (getStatus()) { + STATUS_VALID -> { + // 目前首页下拉二楼是首页最后一个弹窗类的东西,还没实现回调,如果有其它要在它后面弹出的,需要自行在它的实现结果后添加回调 + mHomeFragment?.popUpHomePushIfNeeded() + } + STATUS_INVALID -> { + processNext() + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/NotificationPermissionDialogHandler.kt b/app/src/main/java/com/gh/common/prioritychain/NotificationPermissionDialogHandler.kt new file mode 100644 index 0000000000..12d0e1e48f --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/NotificationPermissionDialogHandler.kt @@ -0,0 +1,20 @@ +package com.gh.common.prioritychain + +import com.gh.gamecenter.common.entity.NotificationUgc +import com.gh.gamecenter.common.utils.NotificationHelper +import com.gh.gamecenter.login.user.UserManager + +class NotificationPermissionDialogHandler(priority: Int) : PriorityChainHandler(priority) { + + override fun onProcess() { + // 仅登录后再启动光环时请求一次权限 + if (UserManager.getInstance().isLoggedIn) { + NotificationHelper.showNotificationHintDialog(NotificationUgc.LOGIN) { + processNext() + } + } else { + processNext() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/PriorityChain.kt b/app/src/main/java/com/gh/common/prioritychain/PriorityChain.kt new file mode 100644 index 0000000000..f3089561ec --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/PriorityChain.kt @@ -0,0 +1,20 @@ +package com.gh.common.prioritychain + +import java.util.* +import java.util.concurrent.PriorityBlockingQueue + +class PriorityChain { + + private val mHandlerQueue: Queue = PriorityBlockingQueue() + + fun addHandler(handler: PriorityChainHandler) { + mHandlerQueue.add(handler.also { + it.setPriorityChain(this) + }) + } + + fun start() { + mHandlerQueue.poll()?.process(mHandlerQueue) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/PriorityChainHandler.kt b/app/src/main/java/com/gh/common/prioritychain/PriorityChainHandler.kt new file mode 100644 index 0000000000..10ee802dab --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/PriorityChainHandler.kt @@ -0,0 +1,62 @@ +package com.gh.common.prioritychain + +import java.util.* + +abstract class PriorityChainHandler(private val mPriority: Int) : Comparable { + + private var mStatus = STATUS_UNKNOWN + private var mQueue: Queue? = null + + private var mPriorityChain: PriorityChain? = null + + /** + * 获取当前 handler 的状态 + * - 等待结果返回 (STATUS_PENDING) + * - 无需执行 (STATUS_INVALID) + * - 可执行 (STATUS_VALID) + * - 未知 (STATUS_UNKNOWN) + */ + fun getStatus(): Int = mStatus + + fun updateStatus(status: Int) { + mStatus = status + } + + fun setPriorityChain(priorityChain: PriorityChain) { + mPriorityChain = priorityChain + } + + fun process(queue: Queue) { + mQueue = queue + // 若当前 handler 未经处理,将其状态改为 pending + if (mStatus == STATUS_UNKNOWN) { + updateStatus(STATUS_PENDING) + } + + onProcess() + } + + /** + * 执行相关功能的地方 + */ + abstract fun onProcess() + + /** + * 分发给下一个 handler 处理 + */ + fun processNext() { + mQueue?.poll()?.process(mQueue!!) + } + + override fun compareTo(other: PriorityChainHandler): Int { + return (mPriority - other.mPriority) + } + + companion object { + internal const val STATUS_PENDING = 0 + internal const val STATUS_INVALID = 1 + internal const val STATUS_VALID = 2 + internal const val STATUS_UNKNOWN = 3 + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/PrivacyPolicyDialogHandler.kt b/app/src/main/java/com/gh/common/prioritychain/PrivacyPolicyDialogHandler.kt new file mode 100644 index 0000000000..7c24cdf090 --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/PrivacyPolicyDialogHandler.kt @@ -0,0 +1,47 @@ +package com.gh.common.prioritychain + +import androidx.fragment.app.FragmentActivity +import com.gh.common.dialog.PrivacyPolicyDialogFragment +import com.gh.gamecenter.entity.DialogEntity + +class PrivacyPolicyDialogHandler(priority: Int) : PriorityChainHandler(priority) { + + private var mActivity: FragmentActivity? = null + private var mPrivacyPolicyEntity: DialogEntity.PrivacyPolicyEntity? = null + + /** + * 提前预处理显示弹窗的内容 + */ + fun doPreProcess(fragmentActivity: FragmentActivity, privacyPolicyEntity: DialogEntity.PrivacyPolicyEntity?) { + mActivity = fragmentActivity + mPrivacyPolicyEntity = privacyPolicyEntity + + if (getStatus() == STATUS_PENDING) { + if (privacyPolicyEntity == null) { + processNext() + } else { + onProcess() + } + } else { + if (privacyPolicyEntity == null) { + updateStatus(STATUS_INVALID) + } else { + updateStatus(STATUS_VALID) + } + } + } + + override fun onProcess() { + when(getStatus()) { + STATUS_VALID -> { + PrivacyPolicyDialogFragment.show(mActivity!!, mPrivacyPolicyEntity) { _: Boolean? -> + processNext() + } + } + STATUS_INVALID -> { + processNext() + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/ReserveDialogHandler.kt b/app/src/main/java/com/gh/common/prioritychain/ReserveDialogHandler.kt new file mode 100644 index 0000000000..d5ada65369 --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/ReserveDialogHandler.kt @@ -0,0 +1,52 @@ +package com.gh.common.prioritychain + +import androidx.fragment.app.Fragment +import com.gh.common.dialog.ReserveDialog +import com.gh.gamecenter.common.entity.SimpleGameEntity +import com.gh.gamecenter.message.MessageUnreadRepository + +class ReserveDialogHandler(priority: Int) : PriorityChainHandler(priority) { + + private var mFragment: Fragment? = null + private var mReserveData: List? = null + + /** + * 提前预处理显示弹窗的内容 + */ + fun doPreProcess(fragment: Fragment, reserveData: List?) { + mFragment = fragment + mReserveData = reserveData + + if (getStatus() == STATUS_PENDING) { + if (reserveData.isNullOrEmpty()) { + processNext() + } else { + onProcess() + } + } else { + if (reserveData.isNullOrEmpty()) { + updateStatus(STATUS_INVALID) + } else { + updateStatus(STATUS_VALID) + } + } + } + + override fun onProcess() { + when (getStatus()) { + STATUS_VALID -> { + val reserveDialog = ReserveDialog.getInstance(mReserveData!!) + reserveDialog.setOnDismissListener { + MessageUnreadRepository.loadMessageUnreadData() + processNext() + } + reserveDialog.show(mFragment!!.childFragmentManager, "reserveDialog") + } + + STATUS_INVALID -> { + processNext() + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/UpdateDialogHandler.kt b/app/src/main/java/com/gh/common/prioritychain/UpdateDialogHandler.kt new file mode 100644 index 0000000000..5bfe4997fa --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/UpdateDialogHandler.kt @@ -0,0 +1,18 @@ +package com.gh.common.prioritychain + +import android.content.Context +import com.gh.gamecenter.manager.UpdateManager + +class UpdateDialogHandler(context: Context, priority: Int) : PriorityChainHandler(priority) { + + private val mUpdateManager = UpdateManager.getInstance(context) + + override fun onProcess() { + mUpdateManager.checkUpdate(true, null) + mUpdateManager.setDismissCallback { + updateStatus(STATUS_VALID) + processNext() + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/common/prioritychain/WelcomeDialogHandler.kt b/app/src/main/java/com/gh/common/prioritychain/WelcomeDialogHandler.kt new file mode 100644 index 0000000000..a3f4b96948 --- /dev/null +++ b/app/src/main/java/com/gh/common/prioritychain/WelcomeDialogHandler.kt @@ -0,0 +1,79 @@ +package com.gh.common.prioritychain + +import android.graphics.Bitmap +import androidx.fragment.app.Fragment +import com.gh.gamecenter.common.callback.BiCallback +import com.gh.gamecenter.common.utils.ImageUtils +import com.gh.gamecenter.entity.WelcomeDialogEntity +import com.gh.gamecenter.fragment.MainWrapperViewModel +import com.gh.gamecenter.fragment.WelcomeDialogFragment +import com.halo.assistant.HaloApp + +class WelcomeDialogHandler(priority: Int): PriorityChainHandler(priority) { + + private var mFragment: Fragment? = null + private var mWelcomeDialogEntity: WelcomeDialogEntity? = null + + fun doPreProcess(fragment: Fragment, welcomeDialogEntity: WelcomeDialogEntity?) { + mFragment = fragment + mWelcomeDialogEntity = welcomeDialogEntity + + val preLoadClosure = { + // 判断启动本次应用是否已经弹窗,不是的话弹启动弹窗 + if (HaloApp.get(MainWrapperViewModel.SHOULD_SHOW_OPENING_DIALOG, false) == null) { + HaloApp.put(MainWrapperViewModel.SHOULD_SHOW_OPENING_DIALOG, false) + ImageUtils.getBitmap(mWelcomeDialogEntity!!.icon, object : BiCallback { + override fun onFirst(first: Bitmap) { + if (getStatus() == STATUS_PENDING) { + updateStatus(STATUS_VALID) + onProcess() + } else { + updateStatus(STATUS_VALID) + } + } + + override fun onSecond(second: Boolean) { + processNext() + } + }) + } else { + processNext() + } + } + + if (getStatus() == STATUS_PENDING) { + if (welcomeDialogEntity == null) { + processNext() + } else { + preLoadClosure.invoke() + } + } else { + if (welcomeDialogEntity == null) { + updateStatus(STATUS_INVALID) + } else { + preLoadClosure.invoke() + } + } + } + + override fun onProcess() { + when (getStatus()) { + STATUS_VALID -> { + if (mFragment == null || !mFragment!!.isAdded) { + updateStatus(STATUS_INVALID) + processNext() + } else { + val welcomeDialog = WelcomeDialogFragment.getInstance(mWelcomeDialogEntity) + welcomeDialog.setOnDismissListener { + processNext() + } + welcomeDialog.show(mFragment!!.childFragmentManager, "WelcomeDialog") + } + } + STATUS_INVALID -> { + processNext() + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index cf6dfe7b70..81d90366fc 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -38,15 +38,13 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.content.res.AppCompatResources; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProviders; -import com.facebook.drawee.view.SimpleDraweeView; import com.gh.ad.AdDelegateHelper; import com.gh.common.constant.Config; -import com.gh.common.exposure.ExposureManager; import com.gh.common.filter.RegionSettingHelper; import com.gh.common.history.HistoryDatabase; import com.gh.common.history.HistoryHelper; @@ -63,7 +61,6 @@ import com.gh.common.util.ErrorHelper; import com.gh.common.util.HomePluggableHelper; import com.gh.common.util.LogUtils; import com.gh.common.util.LunchType; -import com.gh.common.util.NewFlatLogUtils; import com.gh.common.util.PackageInstaller; import com.gh.common.util.PackageUtils; import com.gh.common.util.WechatBindHelper; @@ -76,7 +73,6 @@ import com.gh.gamecenter.common.base.fragment.ToolbarFragment; import com.gh.gamecenter.common.constant.CommonConsts; import com.gh.gamecenter.common.constant.Constants; import com.gh.gamecenter.common.constant.EntranceConsts; -import com.gh.gamecenter.common.entity.LinkEntity; import com.gh.gamecenter.common.entity.NotificationUgc; import com.gh.gamecenter.common.entity.SuggestType; import com.gh.gamecenter.common.eventbus.EBNetworkState; @@ -86,7 +82,6 @@ import com.gh.gamecenter.common.retrofit.BiResponse; import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.common.utils.DialogHelper; import com.gh.gamecenter.common.utils.ExtensionsKt; -import com.gh.gamecenter.common.utils.ImageUtils; import com.gh.gamecenter.common.utils.NotificationHelper; import com.gh.gamecenter.common.utils.ShareUtils; import com.gh.gamecenter.core.AppExecutor; @@ -96,17 +91,14 @@ import com.gh.gamecenter.core.utils.GsonUtils; import com.gh.gamecenter.core.utils.MtaHelper; import com.gh.gamecenter.core.utils.SPUtils; import com.gh.gamecenter.core.utils.SentryHelper; -import com.gh.gamecenter.core.utils.TimeUtils; import com.gh.gamecenter.core.utils.ToastUtils; import com.gh.gamecenter.core.utils.UrlFilterUtils; import com.gh.gamecenter.entity.StartupAdEntity; import com.gh.gamecenter.eventbus.EBSkip; import com.gh.gamecenter.feature.entity.GameEntity; -import com.gh.gamecenter.feature.exposure.ExposureEvent; -import com.gh.gamecenter.feature.exposure.ExposureSource; -import com.gh.gamecenter.feature.exposure.ExposureType; import com.gh.gamecenter.feature.utils.PlatformUtils; import com.gh.gamecenter.fragment.MainWrapperFragment; +import com.gh.gamecenter.fragment.MainWrapperViewModel; import com.gh.gamecenter.home.skip.PackageSkipActivity; import com.gh.gamecenter.login.user.UserManager; import com.gh.gamecenter.login.utils.QuickLoginHelper; @@ -171,6 +163,8 @@ public class MainActivity extends BaseActivity { private PackageViewModel mPackageViewModel; + private MainWrapperViewModel mMainWrapperViewModel; + private MainWrapperFragment mMainWrapperFragment; // 黄壮华 按连续按返回键两次才退出应用 @@ -187,6 +181,9 @@ public class MainActivity extends BaseActivity { HaloApp.getInstance().isAlreadyUpAndRunning = true; + mMainWrapperViewModel = new ViewModelProvider(this, new MainWrapperViewModel.Factory(HaloApp.getInstance())) + .get(MainWrapperViewModel.class); + super.onCreate(savedInstanceState); setStatusBarColor(Color.TRANSPARENT); @@ -339,8 +336,15 @@ public class MainActivity extends BaseActivity { // 检查是否需要触发 XAPK 安装 AppExecutor.getUiExecutor().executeWithDelay(this::resumeXapkInstallIfNeeded, 150); + mMainWrapperViewModel.requestAllDialogData(); + + // TODO 去掉一键登录? QuickLoginHelper.getPhoneInfo(); + + // TODO 搞清楚为什么这里要获取微信相关配置 WechatBindHelper.getWechatConfig(null); + + // TODO 根据用户是否安装微博来确定是否需要初始化微博 SDK initWBSDK(); CertificationSwitchHelper.getCertificationSwitch(); } @@ -580,17 +584,10 @@ public class MainActivity extends BaseActivity { ExtensionsKt.removeFromParent(startSdkAdContainer); AdDelegateHelper.INSTANCE.cancelSplashAd(this); } - checkDialog(); - } - private void checkDialog() { - // 检查通知权限 - checkNotificationPermission(); - // 检查助手更新 - AppExecutor.getIoExecutor().execute(() -> { - UpdateManager updateManager = UpdateManager.getInstance(this); - updateManager.checkUpdate(true, null); - updateManager.setDismissCallback(mMainWrapperFragment::getDialog); + // 通知优先级高的弹窗可以显示了 + AppExecutor.getUiExecutor().execute(() -> { + mMainWrapperFragment.showDialog(); }); } @@ -797,13 +794,6 @@ public class MainActivity extends BaseActivity { }); } - private void checkNotificationPermission() { - // 仅登录后再启动光环时请求一次权限 - if (UserManager.getInstance().isLoggedIn()) { - NotificationHelper.showNotificationHintDialog(NotificationUgc.LOGIN, null); - } - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && !mMainWrapperFragment.onHandleBackPressed()) { diff --git a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java deleted file mode 100644 index 59b8c7a9ec..0000000000 --- a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java +++ /dev/null @@ -1,801 +0,0 @@ -package com.gh.gamecenter.fragment; - -import static com.gh.gamecenter.MainActivity.EB_SKIP_MAIN; - -import android.graphics.Bitmap; -import android.graphics.PorterDuff; -import android.graphics.drawable.Animatable; -import android.net.Uri; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.CheckedTextView; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.PopupWindow; - -import androidx.annotation.ColorRes; -import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProviders; - -import com.airbnb.lottie.LottieAnimationView; -import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.drawee.controller.BaseControllerListener; -import com.facebook.drawee.interfaces.DraweeController; -import com.facebook.drawee.view.SimpleDraweeView; -import com.facebook.fresco.animation.drawable.AnimatedDrawable2; -import com.facebook.fresco.animation.drawable.BaseAnimationListener; -import com.facebook.imagepipeline.image.ImageInfo; -import com.gh.common.constant.Config; -import com.gh.common.dialog.PrivacyPolicyDialogFragment; -import com.gh.common.dialog.ReserveDialog; -import com.gh.common.util.DirectUtils; -import com.gh.common.util.HomeBottomBarHelper; -import com.gh.common.util.IntegralLogHelper; -import com.gh.common.util.LogUtils; -import com.gh.common.util.NewFlatLogUtils; -import com.gh.common.util.NewLogUtils; -import com.gh.gamecenter.GameDetailActivity; -import com.gh.gamecenter.R; -import com.gh.gamecenter.ShellActivity; -import com.gh.gamecenter.category2.CategoryV2Fragment; -import com.gh.gamecenter.common.base.fragment.BaseFragment_ViewPager_Checkable; -import com.gh.gamecenter.common.callback.BiCallback; -import com.gh.gamecenter.common.callback.OnDoubleTapListener; -import com.gh.gamecenter.common.constant.Constants; -import com.gh.gamecenter.common.constant.EntranceConsts; -import com.gh.gamecenter.common.entity.PkgConfigEntity; -import com.gh.gamecenter.common.eventbus.EBReuse; -import com.gh.gamecenter.common.syncpage.SyncPageRepository; -import com.gh.gamecenter.common.tracker.TrackerLogger; -import com.gh.gamecenter.common.utils.ExtensionsKt; -import com.gh.gamecenter.common.utils.ImageUtils; -import com.gh.gamecenter.common.utils.SensorsBridge; -import com.gh.gamecenter.common.view.BugFixedPopupWindow; -import com.gh.gamecenter.core.utils.DisplayUtils; -import com.gh.gamecenter.core.utils.GsonUtils; -import com.gh.gamecenter.core.utils.SPUtils; -import com.gh.gamecenter.databinding.FragmentMainBinding; -import com.gh.gamecenter.databinding.PopupAccelerateNotificationBinding; -import com.gh.gamecenter.entity.SubjectData; -import com.gh.gamecenter.entity.SubjectRecommendEntity; -import com.gh.gamecenter.entity.WelcomeDialogEntity; -import com.gh.gamecenter.eventbus.EBSkip; -import com.gh.gamecenter.eventbus.EBUISwitch; -import com.gh.gamecenter.feature.entity.GameEntity; -import com.gh.gamecenter.feature.entity.SettingsEntity; -import com.gh.gamecenter.feature.exposure.ExposureSource; -import com.gh.gamecenter.forum.home.CommunityHomeFragment; -import com.gh.gamecenter.game.GameFragment; -import com.gh.gamecenter.game.columncollection.detail.ColumnCollectionDetailFragment; -import com.gh.gamecenter.game.commoncollection.detail.CommonCollectionDetailFragment; -import com.gh.gamecenter.gamecollection.square.GameCollectionSquareFragment; -import com.gh.gamecenter.login.entity.UserInfoEntity; -import com.gh.gamecenter.message.MessageUnreadRepository; -import com.gh.gamecenter.message.MessageUnreadViewModel; -import com.gh.gamecenter.personal.HaloPersonalFragment; -import com.gh.gamecenter.pkg.PkgHelper; -import com.gh.gamecenter.servers.GameServersPublishFragment; -import com.gh.gamecenter.servers.GameServersTestFragment; -import com.gh.gamecenter.subject.SubjectFragment; -import com.gh.gamecenter.video.detail.HomeVideoFragment; -import com.halo.assistant.HaloApp; -import com.halo.assistant.fragment.WebFragment; -import com.lightgame.listeners.OnBackPressedListener; -import com.lightgame.view.CheckableLinearLayout; -import com.lightgame.view.NoScrollableViewPager; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implements OnBackPressedListener { - - public static final int INDEX_HOME = 0; - public static final int INDEX_GAME = 1; - public static final int INDEX_BBS = 2; - public static final int INDEX_VIDEO = 3; - public static final int INDEX_PERSONAL = 4; - - public static final String EB_MAIN_SCROLL_TOP = "main_scroll_top"; - - private FragmentMainBinding mBinding; - private MainWrapperViewModel mViewModel; - private HomeSearchToolWrapperViewModel mHomeSearchViewModel; - - private SearchToolWrapperFragment mGameWrapperFragment; - private HomeSearchToolWrapperFragment mHomeFragment; - private HomeVideoFragment mHomeVideoFragment; - private CommunityHomeFragment mCommunityHomeFragment; - - private final String[] resAssets = {"lottie/tab_home.json", "lottie/tab_game.json", "lottie/tab_forum.json", "lottie/tab_video.json", "tab_mine.gif"}; - - private Boolean mPopUpHomePush = false; - - private PopupWindow mPopupWindow = null; - - @Override - protected int getLayoutId() { - return 0; - } - - @Override - protected View getInflatedLayout() { - mBinding = FragmentMainBinding.inflate(getLayoutInflater()); - return mBinding.getRoot(); - } - - @Override - protected int getCheckableGroupId() { - return R.id.lightgame_tab_container; - } - - @Override - protected int getViewPagerId() { - return R.id.lightgame_tab_viewpager; - } - - @Override - protected void initFragmentList(List fragments) { - mHomeFragment = new HomeSearchToolWrapperFragment(); - fragments.add(mHomeFragment); - - initGameWrapperFragment(); - fragments.add(mGameWrapperFragment); - - mHomeVideoFragment = new HomeVideoFragment(); - Bundle videoArgs = new Bundle(); - videoArgs.putBoolean(EntranceConsts.KEY_IS_HOME_VIDEO, true); - mHomeVideoFragment.setArguments(videoArgs); - - mCommunityHomeFragment = new CommunityHomeFragment(); - mCommunityHomeFragment.setArguments(getArguments()); - fragments.add(mCommunityHomeFragment); - fragments.add(mHomeVideoFragment); - - if (mViewModel.shouldHideVideoTab()) { - mBinding.mainTabVideo.setVisibility(View.GONE); - } - fragments.add(new HaloPersonalFragment()); - } - - private void initGameWrapperFragment() { - mGameWrapperFragment = new SearchToolWrapperFragment(); - Bundle homeArgs = new Bundle(); - String className = GameFragment.class.getName(); - SubjectRecommendEntity entity = mViewModel.getNavBar().getValue(); - if (entity == null) { - entity = HomeBottomBarHelper.getDefaultGameBarData(); - } - if (entity.getType() != null) { - switch (entity.getType()) { - case "block": - className = HomeGameWrapperFragment.class.getName(); - homeArgs.putBoolean(EntranceConsts.KEY_SHOW_SEARCH_TOOLBAR, false); - homeArgs.putParcelable(EntranceConsts.KEY_BLOCK_DATA, entity); - break; - case "column": - className = SubjectFragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库"); - homeArgs.putParcelable( - EntranceConsts.KEY_SUBJECT_DATA, - new SubjectData(entity.getLink(), entity.getText(), false, "", "", "", "", true, false, false) - ); - break; - case "column_collection": - className = ColumnCollectionDetailFragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库"); - homeArgs.putString(EntranceConsts.KEY_COLLECTION_ID, entity.getLink()); - homeArgs.putInt(EntranceConsts.KEY_POSITION, 0); - homeArgs.putString(EntranceConsts.KEY_COLUMNNAME, entity.getText()); - homeArgs.putBoolean(EntranceConsts.KEY_IS_COLUMN_COLLECTION, true); - break; - case "server": - className = GameServersPublishFragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库"); - break; - case "column_test": - className = GameServersTestFragment.class.getName(); - homeArgs.putString(GameServersTestFragment.TEST_COLUMN_ID, entity.getLink()); - break; - case "category_v2": - className = CategoryV2Fragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_CATEGORY_ID, entity.getLink()); - homeArgs.putString(EntranceConsts.KEY_CATEGORY_TITLE, entity.getText()); - break; - case "common_collection": - className = CommonCollectionDetailFragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库"); - homeArgs.putString(EntranceConsts.KEY_COLLECTION_ID, entity.getLink()); - homeArgs.putString(EntranceConsts.KEY_COLUMNNAME, entity.getText()); - break; - case "game_list": - className = GameCollectionSquareFragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库"); - homeArgs.putInt(EntranceConsts.KEY_TAB_INDEX, 0); - homeArgs.putString(EntranceConsts.KEY_NAME, entity.getName()); - break; - case "web": - className = WebFragment.class.getName(); - homeArgs.putString(EntranceConsts.KEY_URL, entity.getLink()); - homeArgs.putBoolean(WebFragment.KEY_OPEN_NATIVE_PAGE, false); - homeArgs.putBoolean(WebFragment.KEY_ENABLE_HORIZONTAL_SCROLL_DISPATCH, true); - if (entity.getLink() != null && entity.getLink().contains("leave_web_page_handle_back_pressed=true")) { - homeArgs.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_BACK_PRESSED, true); - } - break; - } - } - - homeArgs.putString(SearchToolWrapperFragment.WRAPPER_FRAGMENT_NAME, className); - homeArgs.putBoolean(EntranceConsts.KEY_IS_HOME, true); - if (!"block".equals(entity.getType())) { - homeArgs.putParcelable( - EntranceConsts.KEY_EXPOSURE_SOURCE, - new ExposureSource("游戏库", "") - ); - } - mGameWrapperFragment.setArguments(homeArgs); - } - - @Override - public ArrayList restoreFragments() { - ArrayList restoreFragments = super.restoreFragments(); - for (Fragment fragment : restoreFragments) { - if (fragment instanceof SearchToolWrapperFragment && !(fragment instanceof HomeSearchToolWrapperFragment)) { - mGameWrapperFragment = (SearchToolWrapperFragment) fragment; - } else if (fragment instanceof HomeVideoFragment) { - mHomeVideoFragment = (HomeVideoFragment) fragment; - } else if (fragment instanceof CommunityHomeFragment) { - mCommunityHomeFragment = (CommunityHomeFragment) fragment; - } else if (fragment instanceof HomeSearchToolWrapperFragment) { - mHomeFragment = (HomeSearchToolWrapperFragment) fragment; - } - } - return restoreFragments; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - mViewModel = ViewModelProviders.of(this, new MainWrapperViewModel.Factory(HaloApp.getInstance())).get(MainWrapperViewModel.class); - mHomeSearchViewModel = ViewModelProviders.of(requireActivity(), null).get(HomeSearchToolWrapperViewModel.class); - - super.onCreate(savedInstanceState); - - mBinding.viewShadow.setVisibility(mIsDarkModeOn ? View.GONE : View.VISIBLE); - - mViewModel.getNavBar().observe(this, this::updateGameBarContent); - - mHomeSearchViewModel.getHomeDataLiveData().observe(this, homeDataEntity -> { - Set homePushSet = SPUtils.getStringSet(Constants.SP_HOME_PUSH_POP_UP_SET); - mPopUpHomePush = homeDataEntity != null && homeDataEntity.getHomePush() != null && "on".equals(homeDataEntity.getHomePush().getPopSwitch()) && !homePushSet.contains(homeDataEntity.getHomePush().getId()); - mViewModel.getPrivacyPolicyDialog().observe(this, it -> { - if (it != null) { - PrivacyPolicyDialogFragment.show(requireActivity(), it, isSuccess -> { - if (mPopUpHomePush) { - mViewModel.requestReserveDialog(); - } else { - showWelcomeDialogIfNeeded(mViewModel.getOpeningDialog().getValue()); - } - return null; - }); - } else { - if (mPopUpHomePush) { - mViewModel.requestReserveDialog(); - } else { - showWelcomeDialogIfNeeded(mViewModel.getOpeningDialog().getValue()); - } - } - }); - }); - - mViewModel.getReserveDialog().observe(this, reserveData -> { - if (reserveData != null && !reserveData.isEmpty()) { - ReserveDialog reserveDialog = ReserveDialog.getInstance(reserveData); - reserveDialog.setOnDismissListener(() -> { - MessageUnreadRepository.INSTANCE.loadMessageUnreadData(); - mViewModel.requestAccelerateNotificationPopup(); - return null; - }); - reserveDialog.show(getChildFragmentManager(), "reserveDialog"); - } else { - MessageUnreadRepository.INSTANCE.loadMessageUnreadData(); - mViewModel.requestAccelerateNotificationPopup(); - } - }); - - mViewModel.getAccelerateNotificationPopup().observe(this, gameEntityList -> { - HashSet accelerateSet = new HashSet<>(SPUtils.getStringSet(Constants.SP_ACCELERATE_NOTIFICATION_POP_UP_SET)); - if (gameEntityList != null && !gameEntityList.isEmpty() && !accelerateSet.contains(gameEntityList.get(0).getMessageId())) { - showAccelerateNotificationPopupWindow(gameEntityList.get(0)); - accelerateSet.add(gameEntityList.get(0).getMessageId()); - SPUtils.setStringSet(Constants.SP_ACCELERATE_NOTIFICATION_POP_UP_SET, accelerateSet); - } else { - if (mPopUpHomePush) { - mHomeFragment.popUpHomePushIfNeeded(); - } - } - }); - - ViewModelProviders.of(this) - .get(MessageUnreadViewModel.class) - .getUnreadMessageTotalLiveData().observe(this, isShow -> ExtensionsKt.goneIf(mBinding.mainIvMessageHint, !isShow)); - } - - private void showAccelerateNotificationPopupWindow(GameEntity gameEntity) { - PopupAccelerateNotificationBinding binding = PopupAccelerateNotificationBinding.inflate(LayoutInflater.from(requireContext())); - if (gameEntity != null) { - binding.gameIconView.displayGameIcon(gameEntity); - binding.gameNameTv.setText(gameEntity.getName()); - binding.getRoot().setOnClickListener((view) -> { - NewFlatLogUtils.logMessageInformClickPluginVersion(gameEntity.getId(), gameEntity.getName()); - if (!gameEntity.getMessageId().isEmpty()) { - // 把对应系统消息设为已读 - mViewModel.postMessageRead(gameEntity.getMessageId()); - } - GameDetailActivity.startGameDetailActivity(requireContext(), gameEntity.getId(), "首页插件上架弹窗", -1, false, false, false, true, null); - }); - } - mPopupWindow = new BugFixedPopupWindow( - binding.getRoot(), - FrameLayout.LayoutParams.MATCH_PARENT, - FrameLayout.LayoutParams.WRAP_CONTENT - ); - mPopupWindow.setTouchable(true); - mPopupWindow.setFocusable(true); - mPopupWindow.setOutsideTouchable(true); - mPopupWindow.setAnimationStyle(R.style.popup_window_ease_in_and_out_anim_style); - mPopupWindow.showAtLocation(requireActivity().getWindow().getDecorView(), Gravity.TOP, 0, DisplayUtils.getStatusBarHeight(requireContext().getResources()) + DisplayUtils.dip2px(42F)); - mBaseHandler.postDelayed(() -> mPopupWindow.dismiss(), 5000); - } - - private void applyPkgConfig() { - PkgConfigEntity.PkgLinkEntity pkgLinkEntity = PkgHelper.INSTANCE.getPkgConfig(false, false); - if (pkgLinkEntity != null) { - String bottomTab = pkgLinkEntity.getHomeBottomTab(); - - if (!pkgLinkEntity.getShouldStayAtMainActivity()) { - // 不停留在首页,执行跳转,标记已用 - PkgHelper.INSTANCE.markConfigUsed(); - DirectUtils.directToLinkPage(requireContext(), pkgLinkEntity, "推广包配置", "首页"); - } else if (!"home".equals(bottomTab)) { - // 停留首页,但选中底部 tab 不是首页,执行选中 - // 若没有配置游戏库 tab 的,标记为已用,否则留给游戏库 tab 来处理已用标记 - if (!"game_lib".equals(bottomTab) || pkgLinkEntity.getLink() == null) { - PkgHelper.INSTANCE.markConfigUsed(); - } - // TODO 根据具体 tab 来作为跳转的具体位置,避免硬编码 - int targetIndex = INDEX_HOME; - - switch (bottomTab) { - case "game_lib": - targetIndex = INDEX_GAME; - break; - case "community": - targetIndex = INDEX_BBS; - break; - case "video": - targetIndex = INDEX_VIDEO; - break; - case "gh": - targetIndex = INDEX_PERSONAL; - break; - } - - mViewPager.setCurrentItem(targetIndex); - onPageChanged(targetIndex); - changeColor(targetIndex); - } - } - } - - public void getDialog() { - mViewModel.requestOpeningData(); - } - - private void showWelcomeDialogIfNeeded(WelcomeDialogEntity welcomeDialogEntity) { - // 判断启动本次应用是否已经弹窗,不是的话弹启动弹窗 - if (welcomeDialogEntity != null && HaloApp.get(MainWrapperViewModel.SHOULD_SHOW_OPENING_DIALOG, false) == null) { - HaloApp.put(MainWrapperViewModel.SHOULD_SHOW_OPENING_DIALOG, false); - ImageUtils.getBitmap(welcomeDialogEntity.getIcon(), new BiCallback() { - @Override - public void onFirst(Bitmap bitmap) { - // 网络速度追不上用户操作的时候可能会出现要弹启动弹窗但用户已经不停留在 MainActivity 的情况 - if (!isAdded()) return; - - WelcomeDialogFragment welcomeDialog = WelcomeDialogFragment.getInstance(welcomeDialogEntity); - welcomeDialog.show(getChildFragmentManager(), "openingDialog"); - } - - @Override - public void onSecond(Boolean aBoolean) { - mViewModel.requestReserveDialog(); - } - }); - } else { - mViewModel.requestReserveDialog(); - } - } - - private void updateGameBarContent(SubjectRecommendEntity navBarEntity) { - if (navBarEntity != null) { - mBinding.mainTabGame.setVisibility(View.VISIBLE); - mBinding.mainTabGameName.setText(navBarEntity.getName()); - ImageUtils.getPicasso() - .load(Uri.parse(navBarEntity.getIconUnselect())) - //.placeholder(R.drawable.ic_game_unselect) - .into(mBinding.mainTabGameIcon); - if (navBarEntity.getDefault()) setCurrentItem(INDEX_GAME); - } else { - mBinding.mainTabGame.setVisibility(View.GONE); - } - } - - @Override - public void onPause() { - super.onPause(); - SyncPageRepository.clearSyncData(); - } - - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - if (mViewPager instanceof NoScrollableViewPager) { - ((NoScrollableViewPager) mViewPager).setScrollable(false); - } - - // 启动时即当选中第一个 tab - onPageChanged(INDEX_HOME); - changeColor(INDEX_HOME); - - for (int i = 0; i < mCheckableGroup.getChildCount(); i++) { - View child = mCheckableGroup.getChildAt(i); - int finalI = i; - child.setOnTouchListener(new OnDoubleTapListener(getContext()) { - @Override - public void onDoubleTap() { - EventBus.getDefault().post(new EBUISwitch(EB_MAIN_SCROLL_TOP, finalI)); - } - }); - } - - applyPkgConfig(); - } - - @Override - protected boolean handleOnClick(View view) { - final int toCheck = mCheckableGroup.indexOfChild(view); - playTabAnimation(toCheck); - changeColor(toCheck); - mHomeFragment.finishTwoLevel("跳转收起"); - - JSONObject trackEvent = new JSONObject(); - try { - trackEvent.put("position", toCheck); - trackEvent.put("tab_content", getTabName(toCheck)); - } catch (JSONException e) { - e.printStackTrace(); - } - SensorsBridge.trackEvent("HomeBottomTabSelect", trackEvent); - - return super.handleOnClick(view); - } - - private String getTabName(int index) { - switch (index) { - case 0: - return "首页"; - case 1: - return mBinding.mainTabGameName.getText().toString(); - case 2: - return "社区"; - case 3: - return "视频"; - case 4: - return "我的光环"; - default: - return ""; - } - } - - private void changeColor(int toCheck) { - if (toCheck == INDEX_VIDEO) { - mBinding.viewShadow.setVisibility(View.GONE); - mCheckableGroup.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.transparent)); - changeTabImageColor(R.color.text_A1A5B7, PorterDuff.Mode.SRC_ATOP, toCheck); - } else { - mBinding.viewShadow.setVisibility(mIsDarkModeOn ? View.GONE : View.VISIBLE); - mCheckableGroup.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white)); - changeTabImageColor(mIsDarkModeOn ? R.color.text_A1A5B7 : R.color.text_50556B, mIsDarkModeOn ? PorterDuff.Mode.SRC_ATOP : PorterDuff.Mode.DST, toCheck); - } - changeTabTextColor(toCheck); - } - - private void playTabAnimation(int toCheck) { - switch (toCheck) { - case INDEX_HOME: - stopAnimation(mBinding.lottieGame, INDEX_GAME); - stopAnimation(mBinding.lottieVideo, INDEX_VIDEO); - stopAnimation(mBinding.lottieCommunity, INDEX_BBS); - stopAnimation(mBinding.lottieMine, INDEX_PERSONAL); - playAnimation(mBinding.lottieHome, toCheck); - break; - case INDEX_GAME: - SubjectRecommendEntity value = mViewModel.getNavBar().getValue(); - if (value != null && !TextUtils.isEmpty(value.getAnimationCode())) { - stopAnimation(mBinding.lottieHome, INDEX_HOME); - stopAnimation(mBinding.lottieVideo, INDEX_VIDEO); - stopAnimation(mBinding.lottieCommunity, INDEX_BBS); - stopAnimation(mBinding.lottieMine, INDEX_PERSONAL); - playGameAnimation(value, toCheck); - } - break; - case INDEX_BBS: - stopAnimation(mBinding.lottieHome, INDEX_HOME); - stopAnimation(mBinding.lottieGame, INDEX_GAME); - stopAnimation(mBinding.lottieVideo, INDEX_VIDEO); - stopAnimation(mBinding.lottieMine, INDEX_PERSONAL); - playAnimation(mBinding.lottieCommunity, toCheck); - break; - case INDEX_VIDEO: - stopAnimation(mBinding.lottieHome, INDEX_HOME); - stopAnimation(mBinding.lottieGame, INDEX_GAME); - stopAnimation(mBinding.lottieCommunity, INDEX_BBS); - stopAnimation(mBinding.lottieMine, INDEX_PERSONAL); - playAnimation(mBinding.lottieVideo, toCheck); - break; - case INDEX_PERSONAL: - stopAnimation(mBinding.lottieHome, INDEX_HOME); - stopAnimation(mBinding.lottieGame, INDEX_GAME); - stopAnimation(mBinding.lottieVideo, INDEX_VIDEO); - stopAnimation(mBinding.lottieCommunity, INDEX_BBS); - playAnimation(mBinding.lottieMine, toCheck); - break; - default: - break; - } - } - - private void changeTabImageColor(@ColorRes int colorRes, PorterDuff.Mode mode, int toCheck) { - for (int i = 0; i < mCheckableGroup.getChildCount(); i++) { - CheckableLinearLayout checkableGroupChild = (CheckableLinearLayout) mCheckableGroup.getChildAt(i); - ImageView checkableView = (ImageView) checkableGroupChild.findCheckableImageView(checkableGroupChild); - if (checkableView != null) { - if (i != toCheck) { - checkableView.setColorFilter(ContextCompat.getColor(requireContext(), colorRes), mode); - } else { - checkableView.setColorFilter(null); - } - } - } - } - - private void changeTabTextColor(int toCheck) { - for (int i = 0; i < mCheckableGroup.getChildCount(); i++) { - CheckableLinearLayout checkableGroupChild = (CheckableLinearLayout) mCheckableGroup.getChildAt(i); - CheckedTextView checkableView = (CheckedTextView) checkableGroupChild.findCheckableTextView(checkableGroupChild); - boolean isChecked = (i == toCheck); - if (checkableView != null) { - int unselectColor = toCheck == INDEX_VIDEO ? R.color.text_A1A5B7 : R.color.tab_text_unselect; - checkableView.setTextColor(ContextCompat.getColor(requireContext(), isChecked ? R.color.theme_font : unselectColor)); - } - } - } - - private void playGameAnimation(SubjectRecommendEntity entity, int position) { - CheckableLinearLayout checkableGroupChild = (CheckableLinearLayout) mCheckableGroup.getChildAt(position); - View checkableView = checkableGroupChild.findCheckableImageView(checkableGroupChild); - if (checkableView != null) checkableView.setVisibility(View.INVISIBLE); - mBinding.lottieGame.setVisibility(View.VISIBLE); - mBinding.lottieGame.setAnimationFromJson(entity.getAnimationCode(), entity.getIconSelect()); - mBinding.lottieGame.playAnimation(); - ExtensionsKt.doOnAnimationEnd(mBinding.lottieGame, () -> { - mBinding.lottieGame.setVisibility(View.GONE); - if (checkableView != null) checkableView.setVisibility(View.VISIBLE); - return null; - }); - } - - private void playAnimation(View view, int position) { - CheckableLinearLayout checkableGroupChild = (CheckableLinearLayout) mCheckableGroup.getChildAt(position); - View checkableView = checkableGroupChild.findCheckableImageView(checkableGroupChild); - if (checkableView != null) checkableView.setVisibility(View.INVISIBLE); - view.setVisibility(View.VISIBLE); - if (view instanceof LottieAnimationView) { - LottieAnimationView lottieView = (LottieAnimationView) view; - lottieView.setAnimation(resAssets[position]); - lottieView.playAnimation(); - ExtensionsKt.doOnAnimationEnd(lottieView, () -> { - lottieView.setVisibility(View.GONE); - if (checkableView != null) checkableView.setVisibility(View.VISIBLE); - return null; - }); - } else { - SimpleDraweeView lottieView = (SimpleDraweeView) view; - Uri uri = Uri.parse("asset:///" + resAssets[position]); - DraweeController controller = Fresco.newDraweeControllerBuilder() - .setUri(uri) - .setAutoPlayAnimations(true) - .setControllerListener(new BaseControllerListener() { - @Override - public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) { - super.onFinalImageSet(id, imageInfo, animatable); - if (animatable != null) { - AnimatedDrawable2 animatedDrawable = (AnimatedDrawable2) animatable; - animatedDrawable.setAnimationListener(new BaseAnimationListener() { - @Override - public void onAnimationStop(AnimatedDrawable2 drawable) { - super.onAnimationStop(drawable); - lottieView.setVisibility(View.GONE); - if (checkableView != null) - checkableView.setVisibility(View.VISIBLE); - } - }); - } - } - }).build(); - lottieView.setController(controller); - } - - } - - - private void stopAnimation(View lottieView, int position) { - CheckableLinearLayout checkableGroupChild = (CheckableLinearLayout) mCheckableGroup.getChildAt(position); - View checkableView = checkableGroupChild.findCheckableImageView(checkableGroupChild); - if (checkableView != null) checkableView.setVisibility(View.VISIBLE); - lottieView.setVisibility(View.GONE); - } - - @Override - protected void onPageChanged(int index) { - super.onPageChanged(index); - - String tabText = ""; - - switch (index) { - case INDEX_HOME: - tabText = "首页"; - NewLogUtils.logBottomNavigationClick("首页", "", "", ""); - break; - case INDEX_GAME: - tabText = "游戏库"; - SubjectRecommendEntity entity = mViewModel.getNavBar().getValue(); - if (entity == null) { - entity = HomeBottomBarHelper.getDefaultGameBarData(); - } - NewLogUtils.logBottomNavigationClick("游戏库", entity.getType() != null ? entity.getType() : "", - entity.getText() != null ? entity.getText() : "", entity.getLink() != null ? entity.getLink() : ""); - break; - case INDEX_BBS: - tabText = "论坛"; - LogUtils.uploadAccessBbsTab(); - NewLogUtils.logBottomNavigationClick("社区", "", "", ""); - break; - case INDEX_VIDEO: - tabText = "视频"; - DisplayUtils.setLightStatusBar(requireActivity(), false); - NewLogUtils.INSTANCE.logCommunityHomeEvent("click_button_video_tab"); - NewLogUtils.logBottomNavigationClick("视频", "", "", ""); - break; - case INDEX_PERSONAL: - tabText = "我的光环"; - IntegralLogHelper.INSTANCE.log("view_me", "我的光环"); - NewLogUtils.logBottomNavigationClick("我的光环", "", "", ""); - break; - } - - TrackerLogger.logHomeTabSelected(index, tabText); - - SubjectRecommendEntity navBarEntity = mViewModel.getNavBar().getValue(); - if (navBarEntity != null) { - if (index == INDEX_GAME) { - ImageUtils.getPicasso() - .load(Uri.parse(navBarEntity.getIconSelect())) - //.placeholder(R.drawable.ic_game_select) - .into(mBinding.mainTabGameIcon); - } else { - ImageUtils.getPicasso() - .load(Uri.parse(navBarEntity.getIconUnselect())) - //.placeholder(R.drawable.ic_game_unselect) - .into(mBinding.mainTabGameIcon); - } - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBSkip skip) { - if (EB_SKIP_MAIN.equals(skip.getType())) { - checkIndex(skip.getCurrentItem()); - changeColor(skip.getCurrentItem()); - mViewPager.setCurrentItem(skip.getCurrentItem(), false); - } - } - - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEventMainThread(EBReuse reuse) { - if ("Refresh".equals(reuse.getType())) { - SettingsEntity settings = Config.getSettings(); - if (settings != null && !settings.showCommunityEntrance()) { - mBinding.mainTabCommunity.setVisibility(View.GONE); - } else { - mBinding.mainTabCommunity.setVisibility(View.VISIBLE); - } - } else if (Constants.EB_REALNAME_RESULT.equals(reuse.getType())) { - updateRealNameErrorContainer(); - } - } - - private void updateRealNameErrorContainer() { - String deviceCertificationInfoString = - SPUtils.getString(Constants.SP_DEVICE_CERTIFICATION_PREFIX + HaloApp.getInstance().getGid()); - - // 未点过关闭按钮并且处于实名认证失败状态的,显示提示 view - if (!SPUtils.getBoolean(Constants.SP_REALNAME_ERROR_HINT_IGNORED) - && !TextUtils.isEmpty(deviceCertificationInfoString)) { - UserInfoEntity entity = GsonUtils.fromJson(deviceCertificationInfoString, UserInfoEntity.class); - if (entity.getIdCard() != null - && entity.getIdCard().getStatus() == 2) { - mBinding.realNameErrorContainer.setVisibility(View.VISIBLE); - ExtensionsKt.enlargeTouchArea(mBinding.realNameErrorCloseIv, 100); - mBinding.realNameErrorCloseIv.setOnClickListener(v -> { - SPUtils.setBoolean(Constants.SP_REALNAME_ERROR_HINT_IGNORED, true); - mBinding.realNameErrorContainer.setVisibility(View.GONE); - }); - mBinding.realNameErrorContainer.setOnClickListener(v -> { - startActivity(ShellActivity.getIntent(requireActivity(), ShellActivity.Type.REAL_NAME_INFO, null)); - }); - } else { - mBinding.realNameErrorContainer.setVisibility(View.GONE); - } - } - } - - public void setCurrentItem(int page) { - mViewPager.setCurrentItem(page, false); - changeColor(page); - } - - public int getCurrentItem() { - return mViewPager.getCurrentItem(); - } - - @Override - public boolean onHandleBackPressed() { - if (mHomeVideoFragment.getCurrentFragment() != null) { - return mHomeVideoFragment.getCurrentFragment().onHandleBackPressed(); - } - if (mViewPager.getCurrentItem() == INDEX_HOME) { - return mHomeFragment.onBackPressed(); - } - if (mViewPager.getCurrentItem() == INDEX_GAME) { - return mGameWrapperFragment.onBackPressed(); - } - if (mViewPager.getCurrentItem() == INDEX_BBS) { - return mCommunityHomeFragment.onBackPressed(); - } - return false; - } - - @Override - public int getChildCount() { - return 5; - } - - @Override - protected void onDarkModeChanged() { - super.onDarkModeChanged(); - changeColor(mViewPager.getCurrentItem()); - } -} diff --git a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.kt b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.kt new file mode 100644 index 0000000000..8b819e18de --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.kt @@ -0,0 +1,687 @@ +package com.gh.gamecenter.fragment + +import android.graphics.PorterDuff +import android.graphics.drawable.Animatable +import android.net.Uri +import android.os.Bundle +import android.text.TextUtils +import android.view.View +import android.widget.CheckedTextView +import android.widget.ImageView +import androidx.annotation.ColorRes +import androidx.core.content.ContextCompat +import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider +import com.airbnb.lottie.LottieAnimationView +import com.facebook.drawee.backends.pipeline.Fresco +import com.facebook.drawee.controller.BaseControllerListener +import com.facebook.drawee.interfaces.DraweeController +import com.facebook.drawee.view.SimpleDraweeView +import com.facebook.fresco.animation.drawable.AnimatedDrawable2 +import com.facebook.fresco.animation.drawable.BaseAnimationListener +import com.facebook.imagepipeline.image.ImageInfo +import com.gh.common.constant.Config +import com.gh.common.prioritychain.* +import com.gh.common.util.* +import com.gh.common.util.LogUtils +import com.gh.common.util.NewLogUtils +import com.gh.gamecenter.MainActivity +import com.gh.gamecenter.R +import com.gh.gamecenter.ShellActivity +import com.gh.gamecenter.category2.CategoryV2Fragment +import com.gh.gamecenter.common.base.activity.BaseActivity +import com.gh.gamecenter.common.base.fragment.BaseFragment +import com.gh.gamecenter.common.base.fragment.BaseFragment_ViewPager_Checkable +import com.gh.gamecenter.common.callback.OnDoubleTapListener +import com.gh.gamecenter.common.constant.Constants +import com.gh.gamecenter.common.constant.EntranceConsts +import com.gh.gamecenter.common.eventbus.EBReuse +import com.gh.gamecenter.common.syncpage.SyncPageRepository +import com.gh.gamecenter.common.tracker.TrackerLogger +import com.gh.gamecenter.common.utils.* +import com.gh.gamecenter.core.utils.DisplayUtils +import com.gh.gamecenter.core.utils.SPUtils +import com.gh.gamecenter.databinding.FragmentMainBinding +import com.gh.gamecenter.entity.* +import com.gh.gamecenter.eventbus.EBSkip +import com.gh.gamecenter.eventbus.EBUISwitch +import com.gh.gamecenter.feature.exposure.ExposureSource +import com.gh.gamecenter.forum.home.CommunityHomeFragment +import com.gh.gamecenter.game.GameFragment +import com.gh.gamecenter.game.columncollection.detail.ColumnCollectionDetailFragment +import com.gh.gamecenter.game.commoncollection.detail.CommonCollectionDetailFragment +import com.gh.gamecenter.gamecollection.square.GameCollectionSquareFragment +import com.gh.gamecenter.login.entity.UserInfoEntity +import com.gh.gamecenter.message.MessageUnreadRepository +import com.gh.gamecenter.message.MessageUnreadViewModel +import com.gh.gamecenter.personal.HaloPersonalFragment +import com.gh.gamecenter.pkg.PkgHelper +import com.gh.gamecenter.servers.GameServersPublishFragment +import com.gh.gamecenter.servers.GameServersTestFragment +import com.gh.gamecenter.subject.SubjectFragment +import com.gh.gamecenter.video.detail.HomeVideoFragment +import com.halo.assistant.HaloApp +import com.halo.assistant.fragment.WebFragment +import com.lightgame.listeners.OnBackPressedListener +import com.lightgame.view.CheckableLinearLayout +import com.lightgame.view.NoScrollableViewPager +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode +import org.json.JSONException +import org.json.JSONObject + +class MainWrapperFragment : BaseFragment_ViewPager_Checkable(), OnBackPressedListener { + + private val mBinding by lazy { FragmentMainBinding.inflate(layoutInflater) } + private var mViewModel: MainWrapperViewModel? = null + private var mGameWrapperFragment: SearchToolWrapperFragment? = null + private var mHomeFragment: HomeSearchToolWrapperFragment? = null + private var mHomeVideoFragment: HomeVideoFragment? = null + private var mCommunityHomeFragment: CommunityHomeFragment? = null + private val mResAssets = arrayOf( + "lottie/tab_home.json", + "lottie/tab_game.json", + "lottie/tab_forum.json", + "lottie/tab_video.json", + "tab_mine.gif" + ) + private var mPopUpHomePush = false + + private val mPriorityChain by lazy { PriorityChain() } + + override fun getLayoutId(): Int = 0 + override fun getInflatedLayout() = mBinding.root + override fun getCheckableGroupId(): Int = R.id.lightgame_tab_container + override fun getViewPagerId(): Int = R.id.lightgame_tab_viewpager + override fun getCurrentItem() = mViewPager.currentItem + override fun getChildCount(): Int = 5 + + override fun initFragmentList(fragments: MutableList) { + mHomeFragment = HomeSearchToolWrapperFragment() + fragments.add(mHomeFragment!!) + initGameWrapperFragment() + fragments.add(mGameWrapperFragment!!) + mHomeVideoFragment = HomeVideoFragment() + val videoArgs = Bundle() + videoArgs.putBoolean(EntranceConsts.KEY_IS_HOME_VIDEO, true) + mHomeVideoFragment!!.arguments = videoArgs + mCommunityHomeFragment = CommunityHomeFragment() + mCommunityHomeFragment!!.arguments = arguments + fragments.add(mCommunityHomeFragment!!) + fragments.add(mHomeVideoFragment!!) + if (mViewModel!!.shouldHideVideoTab()) { + mBinding.mainTabVideo.visibility = View.GONE + } + fragments.add(HaloPersonalFragment()) + } + + private fun initGameWrapperFragment() { + mGameWrapperFragment = SearchToolWrapperFragment() + val homeArgs = Bundle() + var className = GameFragment::class.java.name + var entity = mViewModel!!.navBar.value + if (entity == null) { + entity = HomeBottomBarHelper.getDefaultGameBarData() + } + if (entity.type != null) { + when (entity.type) { + "block" -> { + className = HomeGameWrapperFragment::class.java.name + homeArgs.putBoolean(EntranceConsts.KEY_SHOW_SEARCH_TOOLBAR, false) + homeArgs.putParcelable(EntranceConsts.KEY_BLOCK_DATA, entity) + } + + "column" -> { + className = SubjectFragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库") + homeArgs.putParcelable( + EntranceConsts.KEY_SUBJECT_DATA, + SubjectData(entity.link, entity.text, false, "", "", "", "", true, false, false) + ) + } + + "column_collection" -> { + className = ColumnCollectionDetailFragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库") + homeArgs.putString(EntranceConsts.KEY_COLLECTION_ID, entity.link) + homeArgs.putInt(EntranceConsts.KEY_POSITION, 0) + homeArgs.putString(EntranceConsts.KEY_COLUMNNAME, entity.text) + homeArgs.putBoolean(EntranceConsts.KEY_IS_COLUMN_COLLECTION, true) + } + + "server" -> { + className = GameServersPublishFragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库") + } + + "column_test" -> { + className = GameServersTestFragment::class.java.name + homeArgs.putString(GameServersTestFragment.TEST_COLUMN_ID, entity.link) + } + + "category_v2" -> { + className = CategoryV2Fragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_CATEGORY_ID, entity.link) + homeArgs.putString(EntranceConsts.KEY_CATEGORY_TITLE, entity.text) + } + + "common_collection" -> { + className = CommonCollectionDetailFragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库") + homeArgs.putString(EntranceConsts.KEY_COLLECTION_ID, entity.link) + homeArgs.putString(EntranceConsts.KEY_COLUMNNAME, entity.text) + } + + "game_list" -> { + className = GameCollectionSquareFragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_ENTRANCE, "游戏库") + homeArgs.putInt(EntranceConsts.KEY_TAB_INDEX, 0) + homeArgs.putString(EntranceConsts.KEY_NAME, entity.name) + } + + "web" -> { + className = WebFragment::class.java.name + homeArgs.putString(EntranceConsts.KEY_URL, entity.link) + homeArgs.putBoolean(WebFragment.KEY_OPEN_NATIVE_PAGE, false) + homeArgs.putBoolean(WebFragment.KEY_ENABLE_HORIZONTAL_SCROLL_DISPATCH, true) + if (entity.link != null && entity.link!!.contains("leave_web_page_handle_back_pressed=true")) { + homeArgs.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_BACK_PRESSED, true) + } + } + } + } + homeArgs.putString(SearchToolWrapperFragment.WRAPPER_FRAGMENT_NAME, className) + homeArgs.putBoolean(EntranceConsts.KEY_IS_HOME, true) + if ("block" != entity.type) { + homeArgs.putParcelable( + EntranceConsts.KEY_EXPOSURE_SOURCE, + ExposureSource("游戏库", "") + ) + } + mGameWrapperFragment!!.arguments = homeArgs + } + + override fun restoreFragments(): ArrayList { + val restoreFragments = super.restoreFragments() + for (fragment in restoreFragments) { + if (fragment is SearchToolWrapperFragment && fragment !is HomeSearchToolWrapperFragment) { + mGameWrapperFragment = fragment + } else if (fragment is HomeVideoFragment) { + mHomeVideoFragment = fragment + } else if (fragment is CommunityHomeFragment) { + mCommunityHomeFragment = fragment + } else if (fragment is HomeSearchToolWrapperFragment) { + mHomeFragment = fragment + } + } + return restoreFragments + } + + override fun onCreate(savedInstanceState: Bundle?) { + mViewModel = viewModelProviderFromParent(MainWrapperViewModel.Factory(HaloApp.getInstance())) + + super.onCreate(savedInstanceState) + + buildPriorityChain() + + mViewModel?.navBar?.observe(this) { updateGameBarContent(it) } + + mBinding.viewShadow.visibility = if (mIsDarkModeOn) View.GONE else View.VISIBLE + + ViewModelProvider(this)[MessageUnreadViewModel::class.java] + .unreadMessageTotalLiveData.observe(this) { isShow: Boolean? -> + mBinding.mainIvMessageHint.goneIf(!isShow!!) + } + } + + /** + * 构建 PriorityChain,使用优先队列来决定当前需要显示哪一个弹窗 + * 正常弹窗顺序(不含首页自动下拉二楼),更新弹窗、隐私政策弹窗、消息通知权限弹窗、预约弹窗、插件化通知 popup、启动弹窗 + * 特殊弹窗顺序(含首页自动下拉二楼,无需请求显示启动弹窗),更新弹窗、隐私政策弹窗、消息通知权限弹窗、预约弹窗、插件化通知 popup、首页自动下拉二楼 + * 可以根据上述的顺序为弹窗预设优先级 + * 更新弹窗 (-100) + * 隐私政策弹窗 (-99) + * 消息通知权限弹窗 (0) + * 预约弹窗 (1) + * 插件化通知 popup (2) + * 首页自动下拉二楼 (3) + * 启动弹窗 (4) + */ + private fun buildPriorityChain() { + val homeSearchToolWrapperViewModel: HomeSearchToolWrapperViewModel = viewModelProviderFromParent() + + val updateDialogHandler = UpdateDialogHandler(requireContext(), -100) + val privacyPolicyDialogHandler = PrivacyPolicyDialogHandler(-99) + val notificationPermissionDialogHandler = NotificationPermissionDialogHandler(0) + val reserveDialogHandler = ReserveDialogHandler(1) + val accelerateNotificationHandler = AccelerateNotificationHandler(2) + val homePushHandler = HomePushHandler(3) + val welcomeDialogHandler = WelcomeDialogHandler(4) + + mPriorityChain.addHandler(updateDialogHandler) + mPriorityChain.addHandler(privacyPolicyDialogHandler) + mPriorityChain.addHandler(welcomeDialogHandler) + mPriorityChain.addHandler(reserveDialogHandler) + mPriorityChain.addHandler(notificationPermissionDialogHandler) + mPriorityChain.addHandler(accelerateNotificationHandler) + mPriorityChain.addHandler(homePushHandler) + + mViewModel?.privacyPolicyDialog?.observe(this) { + privacyPolicyDialogHandler.doPreProcess(requireActivity(), it) + } + + mViewModel?.reserveDialog?.observe(this) { + reserveDialogHandler.doPreProcess(this, it) + MessageUnreadRepository.loadMessageUnreadData() + } + + mViewModel?.accelerateNotificationPopup?.observe(this) { + accelerateNotificationHandler.doPreProcess( + requireActivity(), + mBaseHandler!! as BaseHandler, + it, + mViewModel!! + ) + } + + homeSearchToolWrapperViewModel.homeDataLiveData.observe(this) { homeDataEntity: HomeDataEntity? -> + val homePushSet = + SPUtils.getStringSet(Constants.SP_HOME_PUSH_POP_UP_SET) + mPopUpHomePush = homeDataEntity?.homePush != null + && "on" == homeDataEntity.homePush?.popSwitch + && !homePushSet.contains(homeDataEntity.homePush?.id) + + if (mPopUpHomePush) { + welcomeDialogHandler.doPreProcess(this, null) + } else { + welcomeDialogHandler.doPreProcess(this, mViewModel!!.openingDialog.value) + } + + homePushHandler.doPreProcess(mHomeFragment!!, mPopUpHomePush) + } + } + + fun showDialog() { + mPriorityChain.start() + } + + private fun applyPkgConfig() { + val pkgLinkEntity = PkgHelper.getPkgConfig() + if (pkgLinkEntity != null) { + val bottomTab = pkgLinkEntity.homeBottomTab + if (!pkgLinkEntity.shouldStayAtMainActivity) { + // 不停留在首页,执行跳转,标记已用 + PkgHelper.markConfigUsed() + DirectUtils.directToLinkPage(requireContext(), pkgLinkEntity, "推广包配置", "首页") + } else if ("home" != bottomTab) { + // 停留首页,但选中底部 tab 不是首页的,执行选中,标记已用 + PkgHelper.markConfigUsed() + // TODO 根据具体 tab 来作为跳转的具体位置,避免硬编码 + var targetIndex = INDEX_HOME + when (bottomTab) { + "game_lib" -> targetIndex = INDEX_GAME + "community" -> targetIndex = INDEX_BBS + "video" -> targetIndex = INDEX_VIDEO + "gh" -> targetIndex = INDEX_PERSONAL + } + mViewPager.currentItem = targetIndex + onPageChanged(targetIndex) + changeColor(targetIndex) + } + } + } + + private fun updateGameBarContent(navBarEntity: SubjectRecommendEntity?) { + if (navBarEntity != null) { + mBinding.mainTabGame.visibility = View.VISIBLE + mBinding.mainTabGameName.text = navBarEntity.name + ImageUtils.picasso + .load(Uri.parse(navBarEntity.iconUnselect)) //.placeholder(R.drawable.ic_game_unselect) + .into(mBinding.mainTabGameIcon) + if (navBarEntity.default) currentItem = INDEX_GAME + } else { + mBinding.mainTabGame.visibility = View.GONE + } + } + + override fun onPause() { + super.onPause() + SyncPageRepository.clearSyncData() + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + if (mViewPager is NoScrollableViewPager) { + (mViewPager as NoScrollableViewPager).setScrollable(false) + } + + // 启动时即当选中第一个 tab + onPageChanged(INDEX_HOME) + changeColor(INDEX_HOME) + for (i in 0 until mCheckableGroup.childCount) { + val child = mCheckableGroup.getChildAt(i) + child.setOnTouchListener(object : OnDoubleTapListener(context) { + override fun onDoubleTap() { + EventBus.getDefault().post(EBUISwitch(EB_MAIN_SCROLL_TOP, i)) + } + }) + } + applyPkgConfig() + } + + override fun handleOnClick(view: View): Boolean { + val toCheck = mCheckableGroup.indexOfChild(view) + playTabAnimation(toCheck) + changeColor(toCheck) + mHomeFragment?.finishTwoLevel("跳转收起") + val trackEvent = JSONObject() + tryWithDefaultCatch { + trackEvent.put("position", toCheck) + trackEvent.put("tab_content", getTabName(toCheck)) + } + SensorsBridge.trackEvent("HomeBottomTabSelect", trackEvent) + return super.handleOnClick(view) + } + + private fun getTabName(index: Int): String { + return when (index) { + 0 -> "首页" + 1 -> mBinding.mainTabGameName.text.toString() + 2 -> "社区" + 3 -> "视频" + 4 -> "我的光环" + else -> "" + } + } + + private fun changeColor(toCheck: Int) { + if (toCheck == INDEX_VIDEO) { + mBinding.viewShadow.visibility = View.GONE + mCheckableGroup.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.transparent)) + changeTabImageColor(R.color.text_A1A5B7, PorterDuff.Mode.SRC_ATOP, toCheck) + } else { + mBinding.viewShadow.visibility = if (mIsDarkModeOn) View.GONE else View.VISIBLE + mCheckableGroup.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background_white)) + changeTabImageColor( + if (mIsDarkModeOn) R.color.text_A1A5B7 else R.color.text_50556B, + if (mIsDarkModeOn) PorterDuff.Mode.SRC_ATOP else PorterDuff.Mode.DST, + toCheck + ) + } + changeTabTextColor(toCheck) + } + + private fun playTabAnimation(toCheck: Int) { + when (toCheck) { + INDEX_HOME -> { + stopAnimation(mBinding.lottieGame, INDEX_GAME) + stopAnimation(mBinding.lottieVideo, INDEX_VIDEO) + stopAnimation(mBinding.lottieCommunity, INDEX_BBS) + stopAnimation(mBinding.lottieMine, INDEX_PERSONAL) + playAnimation(mBinding.lottieHome, toCheck) + } + + INDEX_GAME -> { + val value = mViewModel!!.navBar.value + if (value != null && !TextUtils.isEmpty(value.animationCode)) { + stopAnimation(mBinding.lottieHome, INDEX_HOME) + stopAnimation(mBinding.lottieVideo, INDEX_VIDEO) + stopAnimation(mBinding.lottieCommunity, INDEX_BBS) + stopAnimation(mBinding.lottieMine, INDEX_PERSONAL) + playGameAnimation(value, toCheck) + } + } + + INDEX_BBS -> { + stopAnimation(mBinding.lottieHome, INDEX_HOME) + stopAnimation(mBinding.lottieGame, INDEX_GAME) + stopAnimation(mBinding.lottieVideo, INDEX_VIDEO) + stopAnimation(mBinding.lottieMine, INDEX_PERSONAL) + playAnimation(mBinding.lottieCommunity, toCheck) + } + + INDEX_VIDEO -> { + stopAnimation(mBinding.lottieHome, INDEX_HOME) + stopAnimation(mBinding.lottieGame, INDEX_GAME) + stopAnimation(mBinding.lottieCommunity, INDEX_BBS) + stopAnimation(mBinding.lottieMine, INDEX_PERSONAL) + playAnimation(mBinding.lottieVideo, toCheck) + } + + INDEX_PERSONAL -> { + stopAnimation(mBinding.lottieHome, INDEX_HOME) + stopAnimation(mBinding.lottieGame, INDEX_GAME) + stopAnimation(mBinding.lottieVideo, INDEX_VIDEO) + stopAnimation(mBinding.lottieCommunity, INDEX_BBS) + playAnimation(mBinding.lottieMine, toCheck) + } + + else -> {} + } + } + + private fun changeTabImageColor(@ColorRes colorRes: Int, mode: PorterDuff.Mode, toCheck: Int) { + for (i in 0 until mCheckableGroup.childCount) { + val checkableGroupChild = mCheckableGroup.getChildAt(i) as CheckableLinearLayout + val checkableView = checkableGroupChild.findCheckableImageView(checkableGroupChild) as? ImageView + if (checkableView != null) { + if (i != toCheck) { + checkableView.setColorFilter(ContextCompat.getColor(requireContext(), colorRes), mode) + } else { + checkableView.colorFilter = null + } + } + } + } + + private fun changeTabTextColor(toCheck: Int) { + for (i in 0 until mCheckableGroup.childCount) { + val checkableGroupChild = mCheckableGroup.getChildAt(i) as? CheckableLinearLayout + val checkableView = checkableGroupChild?.findCheckableTextView(checkableGroupChild) as? CheckedTextView + val isChecked = i == toCheck + if (checkableView != null) { + val unselectColor: Int = if (toCheck == INDEX_VIDEO) R.color.text_A1A5B7 else R.color.tab_text_unselect + checkableView.setTextColor( + ContextCompat.getColor(requireContext(), if (isChecked) R.color.theme_font else unselectColor) + ) + } + } + } + + private fun playGameAnimation(entity: SubjectRecommendEntity, position: Int) { + val checkableGroupChild = mCheckableGroup.getChildAt(position) as? CheckableLinearLayout + val checkableView = checkableGroupChild?.findCheckableImageView(checkableGroupChild) + if (checkableView != null) checkableView.visibility = View.INVISIBLE + mBinding.lottieGame.visibility = View.VISIBLE + mBinding.lottieGame.setAnimationFromJson(entity.animationCode, entity.iconSelect) + mBinding.lottieGame.playAnimation() + mBinding.lottieGame.doOnAnimationEnd { + mBinding.lottieGame.visibility = View.GONE + if (checkableView != null) checkableView.visibility = View.VISIBLE + } + } + + private fun playAnimation(view: View, position: Int) { + val checkableGroupChild = mCheckableGroup.getChildAt(position) as CheckableLinearLayout + val checkableView = checkableGroupChild.findCheckableImageView(checkableGroupChild) + if (checkableView != null) checkableView.visibility = View.INVISIBLE + view.visibility = View.VISIBLE + if (view is LottieAnimationView) { + view.setAnimation(mResAssets[position]) + view.playAnimation() + view.doOnAnimationEnd { + view.visibility = View.GONE + checkableView?.visibility = View.VISIBLE + } + } else { + val lottieView = view as SimpleDraweeView + val uri = Uri.parse("asset:///" + mResAssets[position]) + val controller: DraweeController = Fresco.newDraweeControllerBuilder() + .setUri(uri) + .setAutoPlayAnimations(true) + .setControllerListener(object : BaseControllerListener() { + override fun onFinalImageSet(id: String, imageInfo: ImageInfo?, animatable: Animatable?) { + super.onFinalImageSet(id, imageInfo, animatable) + if (animatable != null) { + val animatedDrawable = animatable as AnimatedDrawable2 + animatedDrawable.setAnimationListener(object : BaseAnimationListener() { + override fun onAnimationStop(drawable: AnimatedDrawable2) { + super.onAnimationStop(drawable) + lottieView.visibility = View.GONE + checkableView?.visibility = View.VISIBLE + } + }) + } + } + }).build() + lottieView.controller = controller + } + } + + private fun stopAnimation(lottieView: View, position: Int) { + val checkableGroupChild = mCheckableGroup.getChildAt(position) as CheckableLinearLayout + val checkableView = checkableGroupChild.findCheckableImageView(checkableGroupChild) + checkableView?.visibility = View.VISIBLE + lottieView.visibility = View.GONE + } + + override fun onPageChanged(index: Int) { + super.onPageChanged(index) + var tabText = "" + when (index) { + INDEX_HOME -> { + tabText = "首页" + NewLogUtils.logBottomNavigationClick("首页", "", "", "") + } + + INDEX_GAME -> { + tabText = "游戏库" + var entity = mViewModel!!.navBar.value + if (entity == null) { + entity = HomeBottomBarHelper.getDefaultGameBarData() + } + NewLogUtils.logBottomNavigationClick( + "游戏库", + (if (entity.type != null) entity.type else "")!!, + (if (entity.text != null) entity.text else "")!!, (if (entity.link != null) entity.link else "")!! + ) + } + + INDEX_BBS -> { + tabText = "论坛" + LogUtils.uploadAccessBbsTab() + NewLogUtils.logBottomNavigationClick("社区", "", "", "") + } + + INDEX_VIDEO -> { + tabText = "视频" + DisplayUtils.setLightStatusBar(requireActivity(), false) + NewLogUtils.logCommunityHomeEvent("click_button_video_tab") + NewLogUtils.logBottomNavigationClick("视频", "", "", "") + } + + INDEX_PERSONAL -> { + tabText = "我的光环" + IntegralLogHelper.log("view_me", "我的光环") + NewLogUtils.logBottomNavigationClick("我的光环", "", "", "") + } + } + TrackerLogger.logHomeTabSelected(index, tabText) + val navBarEntity = mViewModel!!.navBar.value + if (navBarEntity != null) { + if (index == INDEX_GAME) { + ImageUtils.picasso + .load(Uri.parse(navBarEntity.iconSelect)) //.placeholder(R.drawable.ic_game_select) + .into(mBinding.mainTabGameIcon) + } else { + ImageUtils.picasso + .load(Uri.parse(navBarEntity.iconUnselect)) //.placeholder(R.drawable.ic_game_unselect) + .into(mBinding.mainTabGameIcon) + } + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(skip: EBSkip) { + if (MainActivity.EB_SKIP_MAIN == skip.type) { + checkIndex(skip.currentItem) + changeColor(skip.currentItem) + mViewPager.setCurrentItem(skip.currentItem, false) + } + } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onEventMainThread(reuse: EBReuse) { + if ("Refresh" == reuse.type) { + val settings = Config.getSettings() + if (settings != null && !settings.showCommunityEntrance()) { + mBinding.mainTabCommunity.visibility = View.GONE + } else { + mBinding.mainTabCommunity.visibility = View.VISIBLE + } + } else if (Constants.EB_REALNAME_RESULT == reuse.type) { + updateRealNameErrorContainer() + } + } + + private fun updateRealNameErrorContainer() { + val deviceCertificationInfoString = + SPUtils.getString(Constants.SP_DEVICE_CERTIFICATION_PREFIX + HaloApp.getInstance().gid) + + // 未点过关闭按钮并且处于实名认证失败状态的,显示提示 view + if (!SPUtils.getBoolean(Constants.SP_REALNAME_ERROR_HINT_IGNORED) + && !TextUtils.isEmpty(deviceCertificationInfoString) + ) { + val entity: UserInfoEntity? = deviceCertificationInfoString.toObject() + if (entity?.idCard != null && entity.idCard!!.status == 2) { + mBinding.realNameErrorContainer.visibility = View.VISIBLE + mBinding.realNameErrorCloseIv.enlargeTouchArea(100) + mBinding.realNameErrorCloseIv.setOnClickListener { + SPUtils.setBoolean(Constants.SP_REALNAME_ERROR_HINT_IGNORED, true) + mBinding.realNameErrorContainer.visibility = View.GONE + } + mBinding.realNameErrorContainer.setOnClickListener { + startActivity(ShellActivity.getIntent(requireActivity(), ShellActivity.Type.REAL_NAME_INFO, null)) + } + } else { + mBinding.realNameErrorContainer.visibility = View.GONE + } + } + } + + fun setCurrentItem(page: Int) { + mViewPager.setCurrentItem(page, false) + changeColor(page) + } + + override fun onHandleBackPressed(): Boolean { + if (mHomeVideoFragment!!.getCurrentFragment() != null) { + return mHomeVideoFragment!!.getCurrentFragment()!!.onHandleBackPressed() + } + if (mViewPager.currentItem == INDEX_HOME) { + return mHomeFragment!!.onBackPressed() + } + if (mViewPager.currentItem == INDEX_GAME) { + return mGameWrapperFragment!!.onBackPressed() + } + return if (mViewPager.currentItem == INDEX_BBS) { + mCommunityHomeFragment!!.onBackPressed() + } else false + } + + override fun onDarkModeChanged() { + super.onDarkModeChanged() + changeColor(mViewPager.currentItem) + } + + companion object { + const val INDEX_HOME = 0 + const val INDEX_GAME = 1 + const val INDEX_BBS = 2 + const val INDEX_VIDEO = 3 + const val INDEX_PERSONAL = 4 + + const val EB_MAIN_SCROLL_TOP = "main_scroll_top" + } +} diff --git a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperViewModel.kt b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperViewModel.kt index cbd3c2cea5..be6f941163 100644 --- a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperViewModel.kt @@ -36,18 +36,25 @@ class MainWrapperViewModel(application: Application, repository: MainWrapperRepo val navBar: MutableLiveData = repository.getNavBarLiveData() - // 无首页下拉推送自动弹出时弹窗优先级: 隐私政策弹窗->启动弹窗->预约弹窗 - // 有首页下拉推送自动弹出时弹窗优先级: 隐私政策弹窗->预约弹窗->首页下拉推送弹出->启动弹窗 val openingDialog = MutableLiveData() val reserveDialog = MutableLiveData?>() val privacyPolicyDialog = MutableLiveData() val accelerateNotificationPopup = MutableLiveData?>() + /** + * 请求各种弹窗的数据 + */ + fun requestAllDialogData() { + requestOpeningData() + requestReserveDialog() + requestAccelerateNotificationPopup() + } + /** * 获取弹窗 */ @SuppressLint("CheckResult") - fun requestOpeningData() { + private fun requestOpeningData() { val lastId = PreferenceManager.getDefaultSharedPreferences(getApplication()) .getString(Constants.SP_LAST_OPENING_ID, "") val lastTime = PreferenceManager.getDefaultSharedPreferences(getApplication()) @@ -105,9 +112,8 @@ class MainWrapperViewModel(application: Application, repository: MainWrapperRepo }) } - @SuppressLint("CheckResult") - fun requestReserveDialog() { + private fun requestReserveDialog() { if (CheckLoginUtils.isLogin()) { mApi.getReserveDialog(UserManager.getInstance().userId) .subscribeOn(Schedulers.io()) @@ -126,7 +132,7 @@ class MainWrapperViewModel(application: Application, repository: MainWrapperRepo } } - fun requestAccelerateNotificationPopup() { + private fun requestAccelerateNotificationPopup() { if (CheckLoginUtils.isLogin()) { mApi.getAccelerateNotificationPopup(UserManager.getInstance().userId) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/com/gh/gamecenter/fragment/WelcomeDialogFragment.kt b/app/src/main/java/com/gh/gamecenter/fragment/WelcomeDialogFragment.kt index e37d6632d3..8441bef1dc 100644 --- a/app/src/main/java/com/gh/gamecenter/fragment/WelcomeDialogFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/fragment/WelcomeDialogFragment.kt @@ -10,12 +10,10 @@ import com.gh.common.util.LogUtils import com.gh.gamecenter.common.base.fragment.BaseDialogFragment import com.gh.gamecenter.common.constant.Constants import com.gh.gamecenter.common.constant.EntranceConsts -import com.gh.gamecenter.common.entity.CommunityEntity import com.gh.gamecenter.common.utils.ImageUtils import com.gh.gamecenter.common.utils.SensorsBridge +import com.gh.gamecenter.common.utils.tryWithDefaultCatch import com.gh.gamecenter.common.view.WrapContentDraweeView -import com.gh.gamecenter.core.utils.MtaHelper -import com.gh.gamecenter.core.utils.TimeElapsedHelper import com.gh.gamecenter.databinding.DialogWelcomeBinding import com.gh.gamecenter.entity.WelcomeDialogEntity import com.halo.assistant.HaloApp @@ -23,131 +21,69 @@ import com.halo.assistant.HaloApp class WelcomeDialogFragment : BaseDialogFragment() { private var mWelcomeEntity: WelcomeDialogEntity? = null - private var mTimeHelper: TimeElapsedHelper? = null - private var mDismissByClickImage = false - - lateinit var binding: DialogWelcomeBinding + private lateinit var mBinding: DialogWelcomeBinding private var mDismissListener: (() -> Unit)? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mWelcomeEntity = arguments?.getParcelable(TAG) - mTimeHelper = TimeElapsedHelper(this) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - binding = DialogWelcomeBinding.inflate(inflater, container, false) - binding.ivOpeningCover.setOnClickListener { + mBinding = DialogWelcomeBinding.inflate(inflater, container, false) + mBinding.ivOpeningCover.setOnClickListener { HaloApp.put(Constants.WELCOME_DIALOG_ID, mWelcomeEntity?.id) HaloApp.put(Constants.WELCOME_DIALOG_LINK_TITLE, mWelcomeEntity?.text) - LogUtils.uploadWelcomeDialog("click", mWelcomeEntity?.id, mWelcomeEntity?.id, mWelcomeEntity?.type, mWelcomeEntity?.text) + LogUtils.uploadWelcomeDialog( + "click", + mWelcomeEntity?.id, + mWelcomeEntity?.id, + mWelcomeEntity?.type, + mWelcomeEntity?.text + ) SensorsBridge.trackEvent("HomeDialogClick") - when (mWelcomeEntity?.type) { - EntranceConsts.HOST_ARTICLE -> { - DirectUtils.directToArticle( - requireContext(), - mWelcomeEntity?.link!!, - EntranceConsts.ENTRANCE_WELCOME - ) - } - EntranceConsts.HOST_GAME -> { - DirectUtils.directToGameDetail( - requireContext(), - mWelcomeEntity?.link!!, - entrance = EntranceConsts.ENTRANCE_WELCOME - ) - } - EntranceConsts.HOST_COLUMN -> { - DirectUtils.directToSubject( - requireContext(), - mWelcomeEntity?.link!!, - null, - EntranceConsts.ENTRANCE_WELCOME - ) - } - EntranceConsts.HOST_QUESTION -> { - DirectUtils.directToQuestionDetail( - requireContext(), - mWelcomeEntity?.link!!, - EntranceConsts.ENTRANCE_WELCOME - ) - } - EntranceConsts.HOST_ANSWER -> { - DirectUtils.directToAnswerDetail( - requireContext(), - mWelcomeEntity?.link!!, - EntranceConsts.ENTRANCE_WELCOME - ) - } - EntranceConsts.HOST_WEB -> { - DirectUtils.directToWebView( - requireContext(), - mWelcomeEntity?.link!!, - EntranceConsts.ENTRANCE_WELCOME - ) - } - EntranceConsts.HOST_QQ -> { - DirectUtils.directToQqConversation(requireContext(), mWelcomeEntity?.link!!) - } - EntranceConsts.HOST_COMMUNITY -> { - DirectUtils.directToCommunity( - requireContext(), - CommunityEntity(mWelcomeEntity?.link!!, mWelcomeEntity?.text!!) - ) - } -// else -> DialogUtils.showLowVersionDialog(context) - else -> DirectUtils.directToLinkPage( - requireContext(), mWelcomeEntity - ?: WelcomeDialogEntity(), EntranceConsts.ENTRANCE_WELCOME, "" - ) + mWelcomeEntity?.let { + DirectUtils.directToLinkPage(requireContext(), it, EntranceConsts.ENTRANCE_WELCOME, "") } - mDismissByClickImage = true - dismissAllowingStateLoss() } - binding.ivOpeningCover.registerLoadingCallback(object : WrapContentDraweeView.LoadingCallback { + mBinding.ivOpeningCover.registerLoadingCallback(object : WrapContentDraweeView.LoadingCallback { override fun loaded() { - binding.root.post { - if (binding.ivOpeningCover.measuredHeight > binding.root.resources.displayMetrics.heightPixels * .8) { - binding.ivCloseBackup.visibility = View.VISIBLE + mBinding.root.post { + if (mBinding.ivOpeningCover.measuredHeight > mBinding.root.resources.displayMetrics.heightPixels * .8) { + mBinding.ivCloseBackup.visibility = View.VISIBLE } else { - binding.ivClose.visibility = View.VISIBLE + mBinding.ivClose.visibility = View.VISIBLE } } } }) - binding.ivCloseBackup.setOnClickListener { + mBinding.ivCloseBackup.setOnClickListener { dismissAllowingStateLoss() } - binding.ivClose.setOnClickListener { + mBinding.ivClose.setOnClickListener { dismissAllowingStateLoss() } - ImageUtils.displayWithoutMemoryCache(binding.ivOpeningCover, mWelcomeEntity?.icon) - return binding.root + ImageUtils.displayWithoutMemoryCache(mBinding.ivOpeningCover, mWelcomeEntity?.icon) + return mBinding.root } override fun dismissAllowingStateLoss() { - try { - mDismissByClickImage = false + tryWithDefaultCatch { super.dismissAllowingStateLoss() - } catch (e: Exception) { - e.printStackTrace() } } override fun dismiss() { - try { - mDismissByClickImage = false + tryWithDefaultCatch { super.dismiss() - } catch (e: Exception) { - e.printStackTrace() } } @@ -156,17 +92,19 @@ class WelcomeDialogFragment : BaseDialogFragment() { } override fun onDestroy() { - val type = if (mDismissByClickImage) "点击图片" else "点击关闭" - - MtaHelper.onEventWithTime("启动弹窗", mTimeHelper?.elapsedTime!!, type, "No parameter.") - PreferenceManager.getDefaultSharedPreferences(context?.applicationContext).edit().apply { putString(Constants.SP_LAST_OPENING_ID, mWelcomeEntity?.id) putLong(Constants.SP_LAST_OPENING_TIME, mWelcomeEntity?.time!!) }.apply() mDismissListener?.invoke() - LogUtils.uploadWelcomeDialog("close", mWelcomeEntity?.id, mWelcomeEntity?.id, mWelcomeEntity?.type, mWelcomeEntity?.text) + LogUtils.uploadWelcomeDialog( + "close", + mWelcomeEntity?.id, + mWelcomeEntity?.id, + mWelcomeEntity?.type, + mWelcomeEntity?.text + ) super.onDestroy() } @@ -177,7 +115,13 @@ class WelcomeDialogFragment : BaseDialogFragment() { fun getInstance(welcomeEntity: WelcomeDialogEntity?) = WelcomeDialogFragment().apply { arguments = Bundle() arguments?.putParcelable(TAG, welcomeEntity) - LogUtils.uploadWelcomeDialog("show", welcomeEntity?.id, welcomeEntity?.id, welcomeEntity?.type, welcomeEntity?.text) + LogUtils.uploadWelcomeDialog( + "show", + welcomeEntity?.id, + welcomeEntity?.id, + welcomeEntity?.type, + welcomeEntity?.text + ) SensorsBridge.trackEvent("HomeDialogShow") } } diff --git a/module_common/src/main/java/com/gh/gamecenter/common/base/fragment/BaseFragment.java b/module_common/src/main/java/com/gh/gamecenter/common/base/fragment/BaseFragment.java index 43603eac9d..ecbe2bdd62 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/base/fragment/BaseFragment.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/base/fragment/BaseFragment.java @@ -69,7 +69,7 @@ public abstract class BaseFragment extends Fragment implements OnRequestCallB protected final Handler mBaseHandler = new BaseFragment.BaseHandler(this); - protected static class BaseHandler extends Handler { + public static class BaseHandler extends Handler { private final WeakReference mFragmentWeakReference; BaseHandler(BaseFragment fragment) {