【光环助手V5.10.0】游戏库功能优化 https://git.shanqu.cc/pm/halo-app-issues/-/issues/1834

This commit is contained in:
张玉久
2022-05-16 15:09:03 +08:00
parent 5ef4f1d14c
commit a1be8352f0
7 changed files with 170 additions and 49 deletions

View File

@ -29,13 +29,14 @@ 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.exposure.ExposureSource;
import com.gh.common.tracker.TrackerLogger;
import com.gh.common.util.DataUtils;
import com.gh.common.util.FloatingBackViewManager;
import com.gh.common.util.HomeBottomBarHelper;
import com.gh.common.util.IntegralLogHelper;
import com.gh.common.util.LogUtils;
import com.gh.gamecenter.R;
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;
@ -47,6 +48,7 @@ import com.gh.gamecenter.common.utils.NightModeUtils;
import com.gh.gamecenter.core.utils.DisplayUtils;
import com.gh.gamecenter.databinding.FragmentMainBinding;
import com.gh.gamecenter.entity.SettingsEntity;
import com.gh.gamecenter.entity.SubjectData;
import com.gh.gamecenter.entity.SubjectRecommendEntity;
import com.gh.gamecenter.entity.WelcomeDialogEntity;
import com.gh.gamecenter.eventbus.EBReuse;
@ -54,11 +56,18 @@ import com.gh.gamecenter.eventbus.EBSkip;
import com.gh.gamecenter.eventbus.EBUISwitch;
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.message.MessageUnreadRepository;
import com.gh.gamecenter.message.MessageUnreadViewModel;
import com.gh.gamecenter.personal.PersonalFragment;
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;
@ -116,11 +125,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
mHomeFragment = new HomeSearchToolWrapperFragment();
fragments.add(mHomeFragment);
mGameWrapperFragment = new SearchToolWrapperFragment();
Bundle homeArgs = new Bundle();
homeArgs.putBoolean(EntranceConsts.KEY_IS_HOME, true);
homeArgs.putString(SearchToolWrapperFragment.WRAPPER_FRAGMENT_NAME, GameFragment.class.getName());
mGameWrapperFragment.setArguments(homeArgs);
initGameWrapperFragment();
fragments.add(mGameWrapperFragment);
mHomeVideoFragment = new HomeVideoFragment();
@ -139,6 +144,80 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
fragments.add(new PersonalFragment());
}
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 = GameFragment.class.getName();
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)
);
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();
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);
homeArgs.putParcelable(
EntranceConsts.KEY_EXPOSURE_SOURCE,
new ExposureSource("游戏库", "")
);
mGameWrapperFragment.setArguments(homeArgs);
}
@Override
public ArrayList<Fragment> restoreFragments() {
ArrayList<Fragment> restoreFragments = super.restoreFragments();
@ -158,7 +237,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
@Override
public void onCreate(Bundle savedInstanceState) {
mViewModel = ViewModelProviders.of(this).get(MainWrapperViewModel.class);
mViewModel = ViewModelProviders.of(this, new MainWrapperViewModel.Factory(HaloApp.getInstance())).get(MainWrapperViewModel.class);
super.onCreate(savedInstanceState);
@ -193,7 +272,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
.get(MessageUnreadViewModel.class)
.getUnreadMessageTotalLiveData().observe(this, isShow -> ExtensionsKt.goneIf(mBinding.mainIvMessageHint, !isShow));
}
public void getDialog() {
mViewModel.requestOpeningData();
mViewModel.getPrivacyPolicyDialog().observe(this, it -> {
@ -207,7 +286,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
}
});
}
private void showWelcomeDialogIfNeeded(WelcomeDialogEntity welcomeDialogEntity) {
// 判断启动本次应用是否已经弹窗,不是的话弹启动弹窗
if (welcomeDialogEntity != null && HaloApp.get(MainWrapperViewModel.SHOULD_SHOW_OPENING_DIALOG, false) == null) {
@ -217,7 +296,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
public void onFirst(Bitmap bitmap) {
// 网络速度追不上用户操作的时候可能会出现要弹启动弹窗但用户已经不停留在 MainActivity 的情况
if (!isAdded()) return;
WelcomeDialogFragment welcomeDialog = WelcomeDialogFragment.getInstance(welcomeDialogEntity);
welcomeDialog.setOnDismissListener(() -> {
mViewModel.requestReserveDialog();
@ -225,7 +304,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
});
welcomeDialog.show(getChildFragmentManager(), "openingDialog");
}
@Override
public void onSecond(Boolean aBoolean) {
mViewModel.requestReserveDialog();
@ -242,7 +321,7 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
mBinding.mainTabGameName.setText(navBarEntity.getName());
ImageUtils.getPicasso()
.load(Uri.parse(navBarEntity.getIconUnselect()))
.placeholder(R.drawable.ic_game_unselect)
//.placeholder(R.drawable.ic_game_unselect)
.into(mBinding.mainTabGameIcon);
if (navBarEntity.getDefault()) setCurrentItem(INDEX_GAME);
} else {
@ -477,12 +556,12 @@ public class MainWrapperFragment extends BaseFragment_ViewPager_Checkable implem
if (index == INDEX_GAME) {
ImageUtils.getPicasso()
.load(Uri.parse(navBarEntity.getIconSelect()))
.placeholder(R.drawable.ic_game_select)
//.placeholder(R.drawable.ic_game_select)
.into(mBinding.mainTabGameIcon);
} else {
ImageUtils.getPicasso()
.load(Uri.parse(navBarEntity.getIconUnselect()))
.placeholder(R.drawable.ic_game_unselect)
//.placeholder(R.drawable.ic_game_unselect)
.into(mBinding.mainTabGameIcon);
}
}

View File

@ -0,0 +1,48 @@
package com.gh.gamecenter.fragment
import android.annotation.SuppressLint
import androidx.lifecycle.MutableLiveData
import com.gh.common.util.HomeBottomBarHelper
import com.gh.gamecenter.BuildConfig
import com.gh.gamecenter.core.utils.SingletonHolder
import com.gh.gamecenter.entity.SubjectRecommendEntity
import com.gh.gamecenter.retrofit.BiResponse
import com.gh.gamecenter.retrofit.RetrofitManager
import com.halo.assistant.HaloApp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import retrofit2.HttpException
class MainWrapperRepository {
private val mSensitiveApi = RetrofitManager.getInstance().api
private val mNavBar = MutableLiveData<SubjectRecommendEntity?>()
fun getNavBarLiveData() = mNavBar
@SuppressLint("CheckResult")
fun getHomeNavBar() {
mSensitiveApi.getHomeNavBarV2(HaloApp.getInstance().channel, BuildConfig.VERSION_NAME)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<SubjectRecommendEntity>() {
override fun onSuccess(data: SubjectRecommendEntity) {
HomeBottomBarHelper.updateDefaultGameBarData(data)
mNavBar.postValue(data)
}
override fun onFailure(exception: Exception) {
if (exception is HttpException && exception.code() == 404) {
mNavBar.postValue(null)
HomeBottomBarHelper.updateDefaultGameBarData(SubjectRecommendEntity())
} else {
mNavBar.postValue(HomeBottomBarHelper.getDefaultGameBarData())
}
}
})
}
companion object : SingletonHolder<MainWrapperRepository>({ MainWrapperRepository() })
}

View File

@ -5,11 +5,13 @@ import android.app.Application
import android.preference.PreferenceManager
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.common.constant.Constants
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.gh.common.util.CheckLoginUtils
import com.gh.common.util.HomeBottomBarHelper
import com.gh.common.util.PackageUtils
import com.gh.gamecenter.BuildConfig
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.core.utils.SPUtils
import com.gh.gamecenter.entity.DialogEntity
import com.gh.gamecenter.entity.SimpleGameEntity
@ -23,43 +25,17 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import retrofit2.HttpException
class MainWrapperViewModel(application: Application) : AndroidViewModel(application) {
class MainWrapperViewModel(application: Application, repository: MainWrapperRepository) : AndroidViewModel(application) {
private val mApi = RetrofitManager.getInstance().api
private val mSensitiveApi = RetrofitManager.getInstance().api
val navBar = MutableLiveData<SubjectRecommendEntity?>()
val navBar: MutableLiveData<SubjectRecommendEntity?> = repository.getNavBarLiveData()
// 弹窗优先级: 隐私政策弹窗->启动弹窗->预约弹窗->消息弹窗
val openingDialog = MutableLiveData<WelcomeDialogEntity?>()
val reserveDialog = MutableLiveData<List<SimpleGameEntity>?>()
val privacyPolicyDialog = MutableLiveData<DialogEntity.PrivacyPolicyEntity?>()
init {
getHomeNavBar()
}
@SuppressLint("CheckResult")
private fun getHomeNavBar() {
mSensitiveApi.getHomeNavBar(HaloApp.getInstance().channel, BuildConfig.VERSION_NAME)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : BiResponse<SubjectRecommendEntity>() {
override fun onSuccess(data: SubjectRecommendEntity) {
HomeBottomBarHelper.updateDefaultGameBarData(data)
navBar.postValue(data)
}
override fun onFailure(exception: Exception) {
if (exception is HttpException && exception.code() == 404) {
navBar.postValue(null)
HomeBottomBarHelper.updateDefaultGameBarData(SubjectRecommendEntity())
} else {
navBar.postValue(HomeBottomBarHelper.getDefaultGameBarData())
}
}
})
}
/**
* 获取弹窗
*/
@ -149,6 +125,14 @@ class MainWrapperViewModel(application: Application) : AndroidViewModel(applicat
return if (channelInInteger == null) false else channelInInteger in 1001..1050
}
class Factory(
private val mApplication: Application,
) : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return MainWrapperViewModel(mApplication, MainWrapperRepository.getInstance()) as T
}
}
companion object {
const val SHOULD_SHOW_OPENING_DIALOG = "show_opening_dialog"
}

View File

@ -51,6 +51,8 @@ public class SearchToolWrapperFragment extends LazyFragment {
bundle.putString(EntranceConsts.KEY_LOCATION, "游戏库");
}
mSearchToolbarFragment.setArguments(bundle);
Bundle mContentBundle = (Bundle) requireArguments().clone();
mContentFragment.setArguments(mContentBundle);
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -99,7 +99,7 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
override fun onFragmentPause() {
super.onFragmentPause()
if (mUseAlternativeLayout) {
val rootView = (parentFragment as HomeSearchToolWrapperFragment).view
val rootView = (parentFragment as? HomeSearchToolWrapperFragment)?.view
rootView?.findViewById<ImageView>(R.id.fab)?.visibility = View.GONE
} else {
if (mExposureEventList.isNotEmpty()) ExposureManager.log(mExposureEventList)
@ -109,7 +109,7 @@ class GameCollectionSquareFragment : LazyListFragment<GamesCollectionEntity, Gam
override fun onFragmentResume() {
super.onFragmentResume()
if (mUseAlternativeLayout) {
val rootView = (parentFragment as HomeSearchToolWrapperFragment).view
val rootView = (parentFragment as? HomeSearchToolWrapperFragment)?.view
rootView?.findViewById<ImageView>(R.id.fab)?.visibility = View.VISIBLE
}
}

View File

@ -2355,6 +2355,12 @@ public interface ApiService {
@GET("home/navbar")
Single<SubjectRecommendEntity> getHomeNavBar(@Query("channel") String channel, @Query("version") String version);
/**
* 首页导航栏数据v2
*/
@GET("home/navbar/v2")
Single<SubjectRecommendEntity> getHomeNavBarV2(@Query("channel") String channel, @Query("version") String version);
/**
* 获取我的光环功能列表
*/

View File

@ -28,31 +28,32 @@ import com.gh.base.GlobalActivityLifecycleObserver;
import com.gh.common.FixedRateJobHelper;
import com.gh.common.exposure.ExposureManager;
import com.gh.common.filter.RegionSettingHelper;
import com.gh.gamecenter.common.image.EmptyDecoder;
import com.gh.common.loghub.LoghubUtils;
import com.gh.common.tracker.Tracker;
import com.gh.common.util.DataUtils;
import com.gh.common.util.DownloadNotificationHelper;
import com.gh.common.util.DownloadObserver;
import com.gh.gamecenter.common.utils.EmulatorUtil;
import com.gh.common.util.HomeBottomBarHelper;
import com.gh.gamecenter.common.utils.NightModeUtils;
import com.gh.common.util.PackageHelper;
import com.gh.common.util.PackageUtils;
import com.gh.gamecenter.common.utils.TimestampUtils;
import com.gh.common.videolog.VideoRecordUtils;
import com.gh.gamecenter.BuildConfig;
import com.gh.gamecenter.Injection;
import com.gh.gamecenter.common.constant.Config;
import com.gh.gamecenter.common.constant.Constants;
import com.gh.gamecenter.common.image.EmptyDecoder;
import com.gh.gamecenter.common.utils.DeviceUtils;
import com.gh.gamecenter.common.utils.EmulatorUtil;
import com.gh.gamecenter.common.utils.ExtensionsKt;
import com.gh.gamecenter.common.utils.ImageUtils;
import com.gh.gamecenter.common.utils.NightModeUtils;
import com.gh.gamecenter.common.utils.PackageFlavorHelper;
import com.gh.gamecenter.common.utils.TimestampUtils;
import com.gh.gamecenter.core.AppExecutor;
import com.gh.gamecenter.core.iinterface.IApplication;
import com.gh.gamecenter.core.utils.SPUtils;
import com.gh.gamecenter.entity.SubjectRecommendEntity;
import com.gh.gamecenter.fragment.MainWrapperRepository;
import com.gh.gamecenter.packagehelper.PackageRepository;
import com.gh.gamecenter.receiver.ActivitySkipReceiver;
import com.gh.gamecenter.receiver.DownloadReceiver;
@ -207,6 +208,7 @@ public class HaloApp extends MultiDexApplication implements Configuration.Provid
}
// 异步初始化 SP
SPUtils.getString("");
MainWrapperRepository.Companion.getInstance().getHomeNavBar();
});
RxJavaPlugins.setIoSchedulerHandler(scheduler -> AppExecutor.INSTANCE.getCachedScheduler());