diff --git a/app/src/main/java/com/gh/gamecenter/fragment/HomeSearchToolWrapperViewModel.kt b/app/src/main/java/com/gh/gamecenter/fragment/HomeSearchToolWrapperViewModel.kt index dc31f26f03..8255b3b9a5 100644 --- a/app/src/main/java/com/gh/gamecenter/fragment/HomeSearchToolWrapperViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/fragment/HomeSearchToolWrapperViewModel.kt @@ -67,11 +67,11 @@ class HomeSearchToolWrapperViewModel(application: Application) : AndroidViewMode } // 从推广包配置信息里找是否需要默认选中一个 tab - PkgHelper.getPkgConfig()?.let { pkgLinkEntity -> - if (pkgLinkEntity.isHomeTopTabLink) { - PkgHelper.markConfigUsed() + PkgHelper.getPkgConfig(true)?.let { pkgLinkEntity -> + if (pkgLinkEntity.shouldStayAtHomePage) { for ((index, tab) in homeTab.withIndex()) { - if (pkgLinkEntity.type == tab.type && pkgLinkEntity.link == tab.link) { + if (pkgLinkEntity.type == tab.type + && (pkgLinkEntity.link == tab.link || tab.link == null)) { defaultTabPosition = index break } diff --git a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java index 720e23ddd9..74e89e30b3 100644 --- a/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java +++ b/app/src/main/java/com/gh/gamecenter/fragment/MainWrapperFragment.java @@ -269,20 +269,23 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem } }); - applyPkgConfig(); - ViewModelProviders.of(this) .get(MessageUnreadViewModel.class) .getUnreadMessageTotalLiveData().observe(this, isShow -> ExtensionsKt.goneIf(mBinding.mainIvMessageHint, !isShow)); } private void applyPkgConfig() { - PkgConfigEntity.PkgLinkEntity pkgLinkEntity = PkgHelper.INSTANCE.getPkgConfig(); - if (pkgLinkEntity != null && !pkgLinkEntity.isHomeTopTabLink()) { + PkgConfigEntity.PkgLinkEntity pkgLinkEntity = PkgHelper.INSTANCE.getPkgConfig(false); + if (pkgLinkEntity != null) { String bottomTab = pkgLinkEntity.getHomeBottomTab(); - PkgHelper.INSTANCE.markConfigUsed(); - if (!TextUtils.isEmpty(bottomTab)) { + if (!pkgLinkEntity.getShouldStayAtHomePage()) { + // 不停留在首页,执行跳转,标记已用 + PkgHelper.INSTANCE.markConfigUsed(); + DirectUtils.directToLinkPage(requireContext(), pkgLinkEntity, "推广包配置", "首页"); + } else if (!"home".equals(bottomTab)) { + // 停留首页,但选中底部 tab 不是首页的,执行选中,标记已用 + PkgHelper.INSTANCE.markConfigUsed(); // TODO 根据具体 tab 来作为跳转的具体位置,避免硬编码 int targetIndex = INDEX_HOME; @@ -304,8 +307,6 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem mViewPager.setCurrentItem(targetIndex); onPageChanged(targetIndex); changeColor(targetIndex); - } else { - DirectUtils.directToLinkPage(requireContext(), pkgLinkEntity, "推广包配置", "首页"); } } } @@ -393,6 +394,8 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem } }); } + + applyPkgConfig(); } @Override diff --git a/app/src/main/java/com/gh/gamecenter/pkg/PkgHelper.kt b/app/src/main/java/com/gh/gamecenter/pkg/PkgHelper.kt index 2d0da1e62a..9373eae7fc 100644 --- a/app/src/main/java/com/gh/gamecenter/pkg/PkgHelper.kt +++ b/app/src/main/java/com/gh/gamecenter/pkg/PkgHelper.kt @@ -8,6 +8,7 @@ import com.gh.gamecenter.common.entity.PkgConfigEntity import com.gh.gamecenter.common.utils.toObject import com.gh.gamecenter.core.provider.IPkgProvider import com.gh.gamecenter.core.utils.SPUtils +import java.nio.charset.Charset object PkgHelper { @@ -18,11 +19,25 @@ object PkgHelper { ARouter.getInstance().build(RouteConsts.provider.pkg).navigation() as? IPkgProvider } - fun getPkgConfig(): PkgConfigEntity.PkgLinkEntity? { + fun getPkgConfig(isFromHomeTopTab: Boolean): PkgConfigEntity.PkgLinkEntity? { if (mPkgConfigLink == null && !SPUtils.getBoolean(SP_PKG_CONFIG_IS_USED, false) - && BuildConfig.FIRST_LAUNCH.isNotEmpty()) { - mPkgConfigLink = Base64.decode(BuildConfig.FIRST_LAUNCH, Base64.DEFAULT).toString().toObject() + && BuildConfig.FIRST_LAUNCH.isNotEmpty() + ) { + + mPkgConfigLink = + String(Base64.decode(BuildConfig.FIRST_LAUNCH, Base64.DEFAULT), Charset.defaultCharset()).toObject() + + return if (isFromHomeTopTab) { + if (mPkgConfigLink?.shouldStayAtHomePage != true && mPkgConfigLink?.homeBottomTab == "home") { + markConfigUsed() + mPkgConfigLink + } else { + null + } + } else { + mPkgConfigLink + } } return mPkgConfigLink diff --git a/module_common/src/main/java/com/gh/gamecenter/common/entity/PkgConfigEntity.kt b/module_common/src/main/java/com/gh/gamecenter/common/entity/PkgConfigEntity.kt index 28feecc273..98059fd891 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/entity/PkgConfigEntity.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/entity/PkgConfigEntity.kt @@ -12,7 +12,7 @@ class PkgConfigEntity( class PkgLinkEntity( @SerializedName("home_index") - var isHomeTopTabLink: Boolean = false, + var shouldStayAtHomePage: Boolean = false, @SerializedName("bottom_index") var homeBottomTab: String = "" ) : LinkEntity()