diff --git a/app/src/main/java/com/yizhuan/erban/home/MeViewModel.kt b/app/src/main/java/com/yizhuan/erban/home/MeViewModel.kt new file mode 100644 index 000000000..f2130e747 --- /dev/null +++ b/app/src/main/java/com/yizhuan/erban/home/MeViewModel.kt @@ -0,0 +1,85 @@ +package com.yizhuan.erban.home + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import com.yizhuan.erban.base.BaseViewModel +import com.yizhuan.xchat_android_core.home.bean.BannerInfo +import com.yizhuan.xchat_android_core.home.model.HomeModel +import com.yizhuan.xchat_android_core.room.bean.MeCenterInfo +import com.yizhuan.xchat_android_core.room.game.GameInfo + +class MeViewModel : BaseViewModel() { + + private val _bannerLiveData = MutableLiveData>() + val bannerLiveData: LiveData> = _bannerLiveData + + private val _meCenterInfoLiveData = MutableLiveData>>() + val meCenterInfoLiveData: LiveData>> = _meCenterInfoLiveData + + private val _gameInfoListLiveData = MutableLiveData>>() + val gameInfoListLiveData: LiveData>> = _gameInfoListLiveData + + init { + getBannerInfo() + requestMeCenterInfoList() + getGameList() + } + + fun getBannerInfo() { + safeLaunch( + block = { + _bannerLiveData.value = HomeModel.getHomeBanner("10") + }, + onError = { + _bannerLiveData.value = null + } + ) + } + + fun requestMeCenterInfoList() { + safeLaunch( + block = { + _meCenterInfoLiveData.value = transformList(HomeModel.requestMeCenterInfoList(), 4) + }, + onError = { + _meCenterInfoLiveData.value = null + } + ) + } + + fun getGameList() { + safeLaunch( + block = { + _gameInfoListLiveData.value = transformList(HomeModel.getGameList(), 4) + }, + onError = { + _gameInfoListLiveData.value = null + } + ) + } + + private fun transformList( + data: List?, + pageSize: Int + ): List> { + val result: MutableList> = ArrayList() + if (data.isNullOrEmpty()) { + return result + } + for (i in data.indices) { + var page: MutableList? = null + if (i % pageSize == 0) { + page = ArrayList() + result.add(page) + } else { + if (result.size > 0) { + page = result[result.size - 1] + } + } + page?.add(data[i]) + } + return result + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/yizhuan/erban/home/adapter/MeCenterAdapter.kt b/app/src/main/java/com/yizhuan/erban/home/adapter/MeCenterAdapter.kt new file mode 100644 index 000000000..e6659c0a6 --- /dev/null +++ b/app/src/main/java/com/yizhuan/erban/home/adapter/MeCenterAdapter.kt @@ -0,0 +1,24 @@ +package com.yizhuan.erban.home.adapter + +import android.widget.ImageView +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.yizhuan.erban.R +import com.yizhuan.erban.ui.utils.load +import com.yizhuan.xchat_android_core.room.bean.MeCenterInfo + + +class MeCenterAdapter : + BaseQuickAdapter(R.layout.item_me_center) { + + override fun convert(helper: BaseViewHolder, item: MeCenterInfo) { + + helper.getView(R.id.iv_pic).load(item.centerPic) + helper.setText(R.id.tv_name, item.centerName) + helper.itemView.setOnClickListener { + + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/yizhuan/erban/home/adapter/MeGameAdapter.kt b/app/src/main/java/com/yizhuan/erban/home/adapter/MeGameAdapter.kt new file mode 100644 index 000000000..9b0b4da2d --- /dev/null +++ b/app/src/main/java/com/yizhuan/erban/home/adapter/MeGameAdapter.kt @@ -0,0 +1,19 @@ +package com.yizhuan.erban.home.adapter + +import android.widget.ImageView +import com.chad.library.adapter.base.BaseQuickAdapter +import com.chad.library.adapter.base.BaseViewHolder +import com.yizhuan.erban.R +import com.yizhuan.erban.ui.utils.load +import com.yizhuan.xchat_android_core.room.game.GameInfo + + +class MeGameAdapter : + BaseQuickAdapter(R.layout.item_me_game) { + + override fun convert(helper: BaseViewHolder, item: GameInfo) { + helper.getView(R.id.iv_pic).load(item.pic) + helper.setText(R.id.tv_name, item.name) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/yizhuan/erban/home/fragment/MeFragment.kt b/app/src/main/java/com/yizhuan/erban/home/fragment/MeFragment.kt index d7d093ded..a56ccb7ee 100644 --- a/app/src/main/java/com/yizhuan/erban/home/fragment/MeFragment.kt +++ b/app/src/main/java/com/yizhuan/erban/home/fragment/MeFragment.kt @@ -1,376 +1,374 @@ -package com.yizhuan.erban.home.fragment; +package com.yizhuan.erban.home.fragment -import static com.yizhuan.erban.skill.activity.SkillHomeActivity.PAGE_TYPE_SELF; -import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_HADEXPIRE; -import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_OPENNOBLE; -import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_SUB_RENEWNOBLE; - -import android.annotation.SuppressLint; -import android.content.Intent; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.View; - -import androidx.annotation.Nullable; -import androidx.databinding.DataBindingUtil; - -import com.yizhuan.erban.MainActivity; -import com.yizhuan.erban.R; -import com.yizhuan.erban.UIHelper; -import com.yizhuan.erban.base.BaseFragment; -import com.yizhuan.erban.databinding.FragmentMeBinding; -import com.yizhuan.erban.decoration.view.MyDecorationActivity; -import com.yizhuan.erban.fansteam.FansTeamListActivity; -import com.yizhuan.erban.home.activity.CollectionRoomActivity; -import com.yizhuan.erban.home.activity.VisitorListActivity; -import com.yizhuan.erban.home.helper.OpenRoomHelper; -import com.yizhuan.erban.module_hall.HallDataManager; -import com.yizhuan.erban.module_hall.hall.activity.ModuleClanActivity; -import com.yizhuan.erban.module_hall.hall.activity.ModuleHallActivity; -import com.yizhuan.erban.relation.cp.activity.CpHomeActivity; -import com.yizhuan.erban.skill.activity.SkillHomeActivity; -import com.yizhuan.erban.ui.patriarch.PatriarchModeActivity; -import com.yizhuan.erban.ui.pay.ChargeActivity; -import com.yizhuan.erban.ui.relation.AttentionListActivity; -import com.yizhuan.erban.ui.relation.FansListActivity; -import com.yizhuan.erban.ui.setting.ScheduleManageActivity; -import com.yizhuan.erban.ui.utils.ImageLoadUtils; -import com.yizhuan.erban.ui.webview.CommonWebViewActivity; -import com.yizhuan.erban.ui.widget.higuide.TuTuGuideHelper; -import com.yizhuan.erban.vip.VipHelper; -import com.yizhuan.erban.vip.VipMainActivity; -import com.yizhuan.xchat_android_core.DemoCache; -import com.yizhuan.xchat_android_core.UriProvider; -import com.yizhuan.xchat_android_core.auth.AuthModel; -import com.yizhuan.xchat_android_core.decoration.headwear.bean.HeadWearInfo; -import com.yizhuan.xchat_android_core.home.event.VisitorUnreadCountEvent; -import com.yizhuan.xchat_android_core.level.UserLevelVo; -import com.yizhuan.xchat_android_core.manager.IMNetEaseManager; -import com.yizhuan.xchat_android_core.manager.RelationShipEvent; -import com.yizhuan.xchat_android_core.noble.NobleInfo; -import com.yizhuan.xchat_android_core.noble.NobleProtocol; -import com.yizhuan.xchat_android_core.noble.NobleUtil; -import com.yizhuan.xchat_android_core.statistic.StatisticManager; -import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol; -import com.yizhuan.xchat_android_core.user.UserModel; -import com.yizhuan.xchat_android_core.user.bean.UserInfo; -import com.yizhuan.xchat_android_core.user.event.LoginUserInfoUpdateEvent; -import com.yizhuan.xchat_android_core.utils.SharedPreferenceUtils; -import com.yizhuan.xchat_android_core.utils.StarUtils; -import com.yizhuan.xchat_android_library.rxbus.RxBusHelper; - -import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; -import org.greenrobot.eventbus.ThreadMode; - -import java.util.Date; -import java.util.Locale; +import android.annotation.SuppressLint +import android.content.Intent +import android.text.TextUtils +import android.util.SparseArray +import android.view.View +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.viewModels +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import androidx.viewpager.widget.PagerAdapter +import com.yizhuan.erban.R +import com.yizhuan.erban.UIHelper +import com.yizhuan.erban.base.BaseFragment +import com.yizhuan.erban.databinding.FragmentMeBinding +import com.yizhuan.erban.home.MeViewModel +import com.yizhuan.erban.home.adapter.MeCenterAdapter +import com.yizhuan.erban.home.adapter.MeGameAdapter +import com.yizhuan.erban.home.helper.BannerHelper +import com.yizhuan.erban.skill.activity.SkillHomeActivity +import com.yizhuan.erban.skill.activity.SkillHomeActivity.Companion.start +import com.yizhuan.erban.ui.relation.AttentionListActivity +import com.yizhuan.erban.ui.relation.FansListActivity +import com.yizhuan.erban.ui.utils.ImageLoadUtils +import com.yizhuan.erban.ui.widget.OnPageSelectedListener +import com.yizhuan.erban.vip.VipHelper +import com.yizhuan.erban.vip.VipMainActivity.Companion.start +import com.yizhuan.xchat_android_core.auth.AuthModel +import com.yizhuan.xchat_android_core.home.event.VisitorUnreadCountEvent +import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment +import com.yizhuan.xchat_android_core.level.UserLevelVo +import com.yizhuan.xchat_android_core.manager.IMNetEaseManager +import com.yizhuan.xchat_android_core.manager.RelationShipEvent +import com.yizhuan.xchat_android_core.noble.NobleProtocol +import com.yizhuan.xchat_android_core.noble.NobleUtil +import com.yizhuan.xchat_android_core.room.bean.MeCenterInfo +import com.yizhuan.xchat_android_core.room.game.GameInfo +import com.yizhuan.xchat_android_core.statistic.StatisticManager +import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol +import com.yizhuan.xchat_android_core.user.UserModel +import com.yizhuan.xchat_android_core.user.bean.UserInfo +import com.yizhuan.xchat_android_core.user.event.LoginUserInfoUpdateEvent +import com.yizhuan.xchat_android_core.utils.StarUtils +import com.yizhuan.xchat_android_library.rxbus.RxBusHelper +import com.yizhuan.xchat_android_library.utils.ListUtils +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode +import java.util.* /** * @description: 我的 界面 * @author: hewenhao * @date: 2018/9/4 16:53 */ -public class MeFragment extends BaseFragment implements View.OnClickListener { +class MeFragment : BaseFragment(), View.OnClickListener { - public static final String TAG = "MeFragment"; - private static final String HAS_SHOW_GUIDE = "has_show_guide"; - - private UserInfo mUserInfo; - private FragmentMeBinding mBinding; - - @Override - public int getRootLayoutId() { - return R.layout.fragment_me; + companion object { + const val TAG = "MeFragment" } - @Override - public void onSetListener() { - mBinding = DataBindingUtil.bind(mView); - if (mBinding != null) { - mBinding.setClick(this); - } + private var mUserInfo: UserInfo? = null + private lateinit var mBinding: FragmentMeBinding + private val meViewModel: MeViewModel by viewModels() + override fun getRootLayoutId(): Int { + return R.layout.fragment_me } - @Override - public void onDestroy() { - super.onDestroy(); - EventBus.getDefault().unregister(this); + override fun onSetListener() { + mBinding = DataBindingUtil.bind(mView)!! + mBinding.click = this } - @Override - public void initiate() { - EventBus.getDefault().register(this); - RxBusHelper.doOnMainThread(NobleProtocol.class, mCompositeDisposable, nobleProtocol -> { - int second = nobleProtocol.getSecond(); - if (second == CUSTOM_MESS_SUB_OPENNOBLE || second == CUSTOM_MESS_SUB_RENEWNOBLE) { - requestUpdateUserInfo(); - } else if (second == CUSTOM_MESS_SUB_HADEXPIRE) { - mBinding.ivUserNobleLevel.setVisibility(View.GONE); - mBinding.ivAvatarHeadWear.setVisibility(View.GONE); + override fun onDestroy() { + super.onDestroy() + EventBus.getDefault().unregister(this) + } + + @SuppressLint("CheckResult") + override fun initiate() { + EventBus.getDefault().register(this) + RxBusHelper.doOnMainThread( + NobleProtocol::class.java, + mCompositeDisposable + ) { nobleProtocol: NobleProtocol -> + val second = nobleProtocol.second + if (second == CustomAttachment.CUSTOM_MESS_SUB_OPENNOBLE || second == CustomAttachment.CUSTOM_MESS_SUB_RENEWNOBLE) { + requestUpdateUserInfo() + } else if (second == CustomAttachment.CUSTOM_MESS_SUB_HADEXPIRE) { + mBinding.ivUserNobleLevel.visibility = View.GONE + mBinding.ivAvatarHeadWear.visibility = View.GONE } - }); - + } mCompositeDisposable.add( - IMNetEaseManager.get().getRelationShipEventObservable().subscribe(e -> onGetRelationShipEvent(e)) - ); - - //模厅 - HallDataManager.get().registerHallExist(this, hallExist -> { - if (HallDataManager.get().isClanElder()) { - mBinding.meItemLinkRoom.setVisibility(View.VISIBLE); - } else { - mBinding.meItemLinkRoom.setVisibility(View.GONE); - } - if ((hallExist != null && hallExist) || HallDataManager.get().isHasClan()) { - mBinding.meItemUnion.setText("我的公会"); - mBinding.meItemUnion.setVisibility(View.VISIBLE); - } else { - mBinding.meItemUnion.setVisibility(View.GONE); - } - }); - - if (TuTuGuideHelper.isNeedHiGuide(TuTuGuideHelper.KEY_GUIDE_ME_TAB)) { - mBinding.meItemRadish.post(() -> { - if (getActivity() != null && getActivity() instanceof MainActivity) { - if (!((MainActivity) getActivity()).isShowMeTab()) { - return; - } - TuTuGuideHelper helper = new TuTuGuideHelper(mContext); - helper.createHiGuide(() -> helper.createMeTabOverLayer(mBinding.meItemRadish)); - TuTuGuideHelper.setNoNeedHiGuide(TuTuGuideHelper.KEY_GUIDE_ME_TAB); + IMNetEaseManager.get() + .relationShipEventObservable + .subscribe { e: RelationShipEvent -> + onGetRelationShipEvent(e) } - }); + ) + + meViewModel.bannerLiveData.observe(viewLifecycleOwner) { + BannerHelper.setBanner(mBinding.rollView, it) } - showGuideView(); - - if (DemoCache.readBoolean(DemoCache.KEY_VIP_RED_POINT, true)) { - mBinding.viewVipRedPoint.setVisibility(View.VISIBLE); + meViewModel.gameInfoListLiveData.observe(viewLifecycleOwner) { + setGameInfoData(it) } + + meViewModel.meCenterInfoLiveData.observe(viewLifecycleOwner) { + setCenterInfoData(it) + } + } - private void showGuideView() { - final boolean hasShowGuid = (boolean) SharedPreferenceUtils.get(HAS_SHOW_GUIDE, false); - if (!hasShowGuid) { - SharedPreferenceUtils.put(HAS_SHOW_GUIDE, true); - mBinding.groupGuide.setVisibility(View.VISIBLE); - mBinding.ivOverlayGuide.setOnClickListener(v -> { - mBinding.groupGuide.setVisibility(View.GONE); - } - ); + private fun setCenterInfoData(pagerList: List?>) { + if (ListUtils.isListEmpty(pagerList)) { + return } + mBinding.magicIndicatorEntrance.initIndicator(pagerList.size) + mBinding.magicIndicatorEntrance.setSelectedPage(0) + mBinding.magicIndicatorEntrance.visibility = + if (pagerList.size > 1) View.VISIBLE else View.INVISIBLE + val cacheItemView = SparseArray() + mBinding.viewPagerEntrance.adapter = object : PagerAdapter() { + override fun getCount(): Int { + return pagerList.size + } + + override fun isViewFromObject(view: View, any: Any): Boolean { + return view === any + } + + override fun instantiateItem(container: ViewGroup, pagePos: Int): Any { + val recyclerView: RecyclerView + val giftAdapter: MeCenterAdapter? + if (cacheItemView[pagePos] == null) { + recyclerView = RecyclerView(requireContext()) + recyclerView.layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + recyclerView.layoutManager = GridLayoutManager(context, 4) + giftAdapter = MeCenterAdapter() + recyclerView.adapter = giftAdapter + cacheItemView.put(pagePos, recyclerView) + } else { + recyclerView = cacheItemView[pagePos] + giftAdapter = recyclerView.adapter as MeCenterAdapter + } + giftAdapter.setNewData(pagerList[pagePos]) + container.addView(recyclerView) + return recyclerView + } + + override fun destroyItem(container: ViewGroup, position: Int, any: Any) { + val recyclerView = cacheItemView[position] + container.removeView(recyclerView) + } + } + mBinding.viewPagerEntrance.addOnPageChangeListener(object : OnPageSelectedListener() { + override fun onPageSelected(position: Int) { + if (pagerList.size > 1) { + mBinding.magicIndicatorEntrance.setSelectedPage(position) + } + } + }) } - private void onGetRelationShipEvent(RelationShipEvent event) { + private fun setGameInfoData(pagerList: List?>) { + if (ListUtils.isListEmpty(pagerList)) { + return + } + mBinding.magicIndicatorGame.initIndicator(pagerList.size) + mBinding.magicIndicatorGame.setSelectedPage(0) + mBinding.magicIndicatorGame.visibility = + if (pagerList.size > 1) View.VISIBLE else View.INVISIBLE + val cacheItemView = SparseArray() + mBinding.viewPagerGame.adapter = object : PagerAdapter() { + override fun getCount(): Int { + return pagerList.size + } + + override fun isViewFromObject(view: View, any: Any): Boolean { + return view === any + } + + override fun instantiateItem(container: ViewGroup, pagePos: Int): Any { + val recyclerView: RecyclerView + val giftAdapter: MeGameAdapter? + if (cacheItemView[pagePos] == null) { + recyclerView = RecyclerView(requireContext()) + recyclerView.layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + recyclerView.layoutManager = GridLayoutManager(context, 4) + giftAdapter = MeGameAdapter() + recyclerView.adapter = giftAdapter + cacheItemView.put(pagePos, recyclerView) + } else { + recyclerView = cacheItemView[pagePos] + giftAdapter = recyclerView.adapter as MeGameAdapter + } + giftAdapter.setNewData(pagerList[pagePos]) + container.addView(recyclerView) + return recyclerView + } + + override fun destroyItem(container: ViewGroup, position: Int, any: Any) { + val recyclerView = cacheItemView[position] + container.removeView(recyclerView) + } + } + mBinding.viewPagerGame.addOnPageChangeListener(object : OnPageSelectedListener() { + override fun onPageSelected(position: Int) { + if (pagerList.size > 1) { + mBinding.magicIndicatorGame.setSelectedPage(position) + } + } + }) + } + + + private fun onGetRelationShipEvent(event: RelationShipEvent) { if (event.event == RelationShipEvent.EVENT_FRIEND_UPDATE) { - requestUpdateUserInfo(); + requestUpdateUserInfo() } } - @Override - public void onResume() { - super.onResume(); - initUserDate(); + override fun onResume() { + super.onResume() + initUserDate() // 每次页面重新可见的时候,如果处于审核状态,都尝试刷新拿取最新信息 // 不算是一个多好的做法,但是 it works // 不算频繁,可以接受 - if (mUserInfo != null && mUserInfo.isReview()) { - requestUpdateUserInfo(); + if (mUserInfo?.isReview == true) { + requestUpdateUserInfo() } } - private void initUserDate() { - mUserInfo = UserModel.get().getCacheLoginUserInfo(); - setUserData(); + private fun initUserDate() { + mUserInfo = UserModel.get().cacheLoginUserInfo + setUserData() } - private void setUserData() { - if (mUserInfo != null) { - mBinding.setUserInfo(mUserInfo); - - mBinding.tvUserId.setText(String.format(Locale.getDefault(), - getString(R.string.text_user_id), String.valueOf(mUserInfo.getErbanNo()))); - - NobleInfo nobleInfo = mUserInfo.getNobleInfo(); - HeadWearInfo headWearInfo = mUserInfo.getUserHeadwear(); + private fun setUserData() { + mUserInfo?.let { + mBinding.userInfo = mUserInfo + mBinding.tvUserId.text = String.format( + Locale.getDefault(), + getString(R.string.text_user_id), it.erbanNo.toString() + ) + val nobleInfo = it.nobleInfo + val headWearInfo = it.userHeadwear if (headWearInfo != null) { - mBinding.ivAvatarHeadWear.setImageDrawable(null); + mBinding.ivAvatarHeadWear.setImageDrawable(null) if (nobleInfo != null) { - mBinding.ivUserNobleLevel.setVisibility(View.VISIBLE); - NobleUtil.loadResource(NobleUtil.getBadgeByLevel(nobleInfo.getLevel()), mBinding.ivUserNobleLevel); + mBinding.ivUserNobleLevel.visibility = View.VISIBLE + NobleUtil.loadResource( + NobleUtil.getBadgeByLevel(nobleInfo.level), + mBinding.ivUserNobleLevel + ) } else { - mBinding.ivUserNobleLevel.setVisibility(View.GONE); + mBinding.ivUserNobleLevel.visibility = View.GONE } - - NobleUtil.loadHeadWear(headWearInfo.getEffect() != null ? headWearInfo.getEffect() : headWearInfo.getPic(), mBinding.ivAvatarHeadWear); + NobleUtil.loadHeadWear( + if (headWearInfo.effect != null) headWearInfo.effect else headWearInfo.pic, + mBinding.ivAvatarHeadWear + ) } else if (nobleInfo != null) { - mBinding.ivUserNobleLevel.setVisibility(View.VISIBLE); - NobleUtil.loadResource(NobleUtil.getBadgeByLevel(nobleInfo.getLevel()), mBinding.ivUserNobleLevel); - mBinding.ivAvatarHeadWear.setImageDrawable(null); - NobleUtil.loadResource(nobleInfo.getHeadWear(), mBinding.ivAvatarHeadWear); + mBinding.ivUserNobleLevel.visibility = View.VISIBLE + NobleUtil.loadResource( + NobleUtil.getBadgeByLevel(nobleInfo.level), + mBinding.ivUserNobleLevel + ) + mBinding.ivAvatarHeadWear.setImageDrawable(null) + NobleUtil.loadResource(nobleInfo.headWear, mBinding.ivAvatarHeadWear) } else { - mBinding.ivAvatarHeadWear.setImageDrawable(null); - mBinding.ivUserNobleLevel.setVisibility(View.GONE); + mBinding.ivAvatarHeadWear.setImageDrawable(null) + mBinding.ivUserNobleLevel.visibility = View.GONE } - - String star = StarUtils.getConstellation(new Date(mUserInfo.getBirth())); - mBinding.tvConstellation.setText(star); - setUserLevel(mUserInfo.getUserLevelVo()); - - VipHelper.loadVipIcon(mBinding.ivVipIcon, mUserInfo.getUserVipInfoVO()); - if (mUserInfo.getUserVipInfoVO() == null || mUserInfo.getUserVipInfoVO().getVipLevel() == 0) { - mBinding.meItemVip.setText("开通贵族立享各项特权>>"); + val star = StarUtils.getConstellation(Date(it.birth)) + mBinding.tvConstellation.text = star + setUserLevel(it.userLevelVo) + VipHelper.loadVipIcon(mBinding.ivVipIcon, it.userVipInfoVO) + if (it.userVipInfoVO == null || it.userVipInfoVO.vipLevel == 0) { + mBinding.tvVipDesc.text = "开通贵族立享各项特权>>" } else { - mBinding.meItemVip.setText("查看我的特权>>"); + mBinding.tvVipDesc.text = "查看我的特权>>" } } + } - private void setUserLevel(UserLevelVo userLevelVo) { - mBinding.ivUserCharm.setVisibility(View.GONE); - mBinding.ivUserLevel.setVisibility(View.GONE); + private fun setUserLevel(userLevelVo: UserLevelVo?) { + mBinding.ivUserCharm.visibility = View.GONE + mBinding.ivUserLevel.visibility = View.GONE if (userLevelVo != null) { - String userLevelUrl = userLevelVo.getExperUrl(); - String userCharmUrl = userLevelVo.getCharmUrl(); + val userLevelUrl = userLevelVo.getExperUrl() + val userCharmUrl = userLevelVo.getCharmUrl() if (!TextUtils.isEmpty(userLevelUrl)) { - mBinding.ivUserLevel.setVisibility(View.VISIBLE); - ImageLoadUtils.loadImage(mContext, userLevelUrl, mBinding.ivUserLevel); + mBinding.ivUserLevel.visibility = View.VISIBLE + ImageLoadUtils.loadImage(mContext, userLevelUrl, mBinding.ivUserLevel) } if (!TextUtils.isEmpty(userCharmUrl)) { - mBinding.ivUserCharm.setVisibility(View.VISIBLE); - ImageLoadUtils.loadImage(mContext, userCharmUrl, mBinding.ivUserCharm); + mBinding.ivUserCharm.visibility = View.VISIBLE + ImageLoadUtils.loadImage(mContext, userCharmUrl, mBinding.ivUserCharm) } } } - @Subscribe(threadMode = ThreadMode.MAIN) - public void onLoginUserInfoUpdateEvent(LoginUserInfoUpdateEvent event) { - mUserInfo = UserModel.get().getCacheLoginUserInfo(); - setUserData(); + fun onLoginUserInfoUpdateEvent(event: LoginUserInfoUpdateEvent?) { + mUserInfo = UserModel.get().cacheLoginUserInfo + setUserData() } @SuppressLint("SetTextI18n") @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) - public void onVisitorUnreadCountEvent(VisitorUnreadCountEvent event) { - if (mBinding == null) return; + fun onVisitorUnreadCountEvent(event: VisitorUnreadCountEvent?) { + /* if (mBinding == null) return; if (event.getVisitNum() == 0) { mBinding.tvRedDot.setVisibility(View.GONE); } else { mBinding.tvRedDot.setVisibility(View.VISIBLE); mBinding.tvRedDot.setText(event.getVisitNum() > 99 ? "99+" : String.valueOf(event.getVisitNum())); - } + }*/ } - private void requestUpdateUserInfo() { + private fun requestUpdateUserInfo() { if (mUserInfo != null) { - UserModel.get().updateCurrentUserInfo().subscribe(); + UserModel.get().updateCurrentUserInfo().subscribe() } } - @Override - public void onClick(View v) { - int id = v.getId(); - switch (id) { - case R.id.iv_user_head: - case R.id.rl_user_info: - if (mUserInfo != null) { - UIHelper.showUserInfoAct(mContext, mUserInfo.getUid()); - } - break; + override fun onClick(v: View) { + val id = v.id + when (id) { + R.id.iv_user_head, R.id.rl_user_info -> + mUserInfo?.let { UIHelper.showUserInfoAct(mContext, it.uid) } + R.id.iv_edit -> + mUserInfo?.let { UIHelper.showUserInfoModifyAct(mContext, it.uid) } - case R.id.iv_edit: - if (mUserInfo != null) { - UIHelper.showUserInfoModifyAct(mContext, mUserInfo.getUid()); - } - break; - - case R.id.tv_user_attentions: - case R.id.tv_user_attention_text: - startActivity(new Intent(mContext, AttentionListActivity.class)); - break; - - case R.id.tv_user_fans: - case R.id.tv_user_fan_text: - startActivity(new Intent(mContext, FansListActivity.class)); - break; - - case R.id.ll_my_room: - StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_ME_INTO_MY_ROOM_CLICK, "我页_进入我的房间"); - OpenRoomHelper.openRoom(getBaseActivity()); - break; - case R.id.ll_collect_room: - CollectionRoomActivity.start(mContext); - break; - - case R.id.me_item_radish: - startActivity(new Intent(mContext, ChargeActivity.class)); - break; - case R.id.me_item_level: - CommonWebViewActivity.start(mContext, UriProvider.getUserLevelUrl()); - break; - - case R.id.me_item_decoration_store: - startActivity(new Intent(mContext, MyDecorationActivity.class)); - break; - - case R.id.me_item_union: - if (HallDataManager.get().isHasClan()) { - ModuleClanActivity.start(mContext); - } else { - ModuleHallActivity.start(mContext); - } - break; - - case R.id.me_item_patriarch: - startActivity(new Intent(getActivity(), PatriarchModeActivity.class)); - break; - - case R.id.me_item_certification: - // 跳去实名认证页面 - CommonWebViewActivity.start(mContext, - UriProvider.getTutuRealNamePage()); - break; - - case R.id.me_item_setting: - UIHelper.showSettingAct(mContext); - break; - - case R.id.me_item_invite: - CommonWebViewActivity.start(mContext, UriProvider.getGameShareUrl()); - break; - case R.id.me_item_link_room: - CommonWebViewActivity.start(mContext, UriProvider.getLinkRoomUrl()); - break; - case R.id.me_item_vip: - VipMainActivity.start(mContext); + R.id.tv_user_attentions, R.id.tv_user_attention_text -> startActivity( + Intent( + mContext, + AttentionListActivity::class.java + ) + ) + R.id.tv_user_fans, R.id.tv_user_fan_text -> startActivity( + Intent( + mContext, + FansListActivity::class.java + ) + ) + R.id.me_item_setting -> UIHelper.showSettingAct(mContext) + R.id.me_item_vip -> { + start(mContext) StatisticManager.Instance() - .onEvent(StatisticsProtocol.EVENT_VIP_ENTRANCE_ME_CLICK, "贵族我的入口点击事件"); - if (mBinding.viewVipRedPoint.getVisibility() == View.VISIBLE) { - DemoCache.saveBoolean(DemoCache.KEY_VIP_RED_POINT, false); - mBinding.viewVipRedPoint.setVisibility(View.GONE); - } - break; - case R.id.me_item_schedule: - ScheduleManageActivity.Companion.start(mContext); - break; - case R.id.me_item_skill: - SkillHomeActivity.Companion.start(mContext, PAGE_TYPE_SELF, AuthModel.get().getCurrentUid()); - break; - case R.id.me_item_visitor: - EventBus.getDefault().postSticky(new VisitorUnreadCountEvent(0)); - VisitorListActivity.start(mContext); - break; - case R.id.me_item_relation: - CpHomeActivity.Companion.start(mContext); - break; - case R.id.me_item_fans_team: - FansTeamListActivity.start(mContext); - break; - default: - break; + .onEvent(StatisticsProtocol.EVENT_VIP_ENTRANCE_ME_CLICK, "贵族我的入口点击事件") + } + R.id.me_item_skill -> start( + mContext, + SkillHomeActivity.PAGE_TYPE_SELF, + AuthModel.get().currentUid + ) + else -> {} } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/yizhuan/erban/home/widget/MePageIndicatorView.java b/app/src/main/java/com/yizhuan/erban/home/widget/MePageIndicatorView.java new file mode 100644 index 000000000..f660c34da --- /dev/null +++ b/app/src/main/java/com/yizhuan/erban/home/widget/MePageIndicatorView.java @@ -0,0 +1,133 @@ +package com.yizhuan.erban.home.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.LinearLayout; + +import com.yizhuan.erban.R; +import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by shichaohui on 2015/7/10 0010. + *

+ * 页码指示器类,获得此类实例后,可通过{@link MePageIndicatorView#initIndicator(int)}方法初始化指示器 + *

+ */ +public class MePageIndicatorView extends LinearLayout { + + private Context mContext = null; + private int dotSize = 12; // 指示器的大小(dp) + private int height = 4; // 指示器的大小(dp) + private double margins = 0; // 指示器间距(dp) + private List indicatorViews = null; // 存放指示器 + private int selectRes = R.drawable.shape_me_indicator_visible; + private int noSelectRes = R.drawable.shape_me_indicator_invisible; + + public void setSelectRes(int selectRes) { + this.selectRes = selectRes; + } + + public void setNoSelectRes(int noSelectRes) { + this.noSelectRes = noSelectRes; + } + + public MePageIndicatorView(Context context) { + this(context, null); + } + + public MePageIndicatorView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public MePageIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + private void init(Context context) { + this.mContext = context; + + setGravity(Gravity.CENTER); + setOrientation(HORIZONTAL); + + dotSize = UIUtil.dip2px(context, dotSize); + height = UIUtil.dip2px(context, height); + margins = UIUtil.dip2px(context, (float) margins); + } + + public void setDotSize(int dotSize) { + this.dotSize = dotSize; + } + + public void setHeight(int height) { + this.height = height; + } + + /** + * 初始化指示器,默认选中第一页 + * + * @param count 指示器数量,即页数 + */ + public void initIndicator(int count) { + if (indicatorViews == null) { + indicatorViews = new ArrayList<>(); + } + indicatorViews.clear(); + removeAllViews(); + View view; + LayoutParams params = new LayoutParams(dotSize, height); + int margins = (int) this.margins; + params.setMargins(margins, margins, margins, margins); + for (int i = 0; i < count; i++) { + view = new View(mContext); + view.setBackgroundResource(noSelectRes); + addView(view, params); + indicatorViews.add(view); + } + if (indicatorViews.size() > 0) { + indicatorViews.get(0).setBackgroundResource(selectRes); + } + } + + /** + * 设置选中页 + * + * @param selected 页下标,从0开始 + */ + public void setSelectedPage(int selected) { + for (int i = 0; i < indicatorViews.size(); i++) { + if (i == selected) { + indicatorViews.get(i).setBackgroundResource(selectRes); + } else { + indicatorViews.get(i).setBackgroundResource(noSelectRes); + } + } + } + + /** + * 设置选中页 + * + * @param selected 页下标,从0开始 + */ + public void setDifSelectedPage(int selected) { + for (int i = 0; i < indicatorViews.size(); i++) { + if (i == selected) { + LayoutParams params = new LayoutParams(dotSize, height); + int margins = (int) this.margins; + params.setMargins(margins, margins, margins, margins); + indicatorViews.get(i).setLayoutParams(params); + indicatorViews.get(i).setBackgroundResource(selectRes); + } else { + LayoutParams params = new LayoutParams(height, height); + indicatorViews.get(i).setLayoutParams(params); + indicatorViews.get(i).setBackgroundResource(noSelectRes); + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable-xhdpi/bg_me_wallet_entrance.png b/app/src/main/res/drawable-xhdpi/bg_me_wallet_entrance.png new file mode 100644 index 000000000..3470d4c49 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/bg_me_wallet_entrance.png differ diff --git a/app/src/main/res/drawable-xhdpi/bg_vip_me_entrance.png b/app/src/main/res/drawable-xhdpi/bg_vip_me_entrance.png index 47d67fd03..9f30d805a 100644 Binary files a/app/src/main/res/drawable-xhdpi/bg_vip_me_entrance.png and b/app/src/main/res/drawable-xhdpi/bg_vip_me_entrance.png differ diff --git a/app/src/main/res/drawable/shape_1a000_left_100dp.xml b/app/src/main/res/drawable/shape_1a000_left_100dp.xml new file mode 100644 index 000000000..ee41b2f95 --- /dev/null +++ b/app/src/main/res/drawable/shape_1a000_left_100dp.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_me_indicator_bg.xml b/app/src/main/res/drawable/shape_me_indicator_bg.xml new file mode 100644 index 000000000..0f2be7482 --- /dev/null +++ b/app/src/main/res/drawable/shape_me_indicator_bg.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_me_indicator_invisible.xml b/app/src/main/res/drawable/shape_me_indicator_invisible.xml new file mode 100644 index 000000000..9d397afd3 --- /dev/null +++ b/app/src/main/res/drawable/shape_me_indicator_invisible.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/shape_me_indicator_visible.xml b/app/src/main/res/drawable/shape_me_indicator_visible.xml new file mode 100644 index 000000000..ae656f321 --- /dev/null +++ b/app/src/main/res/drawable/shape_me_indicator_visible.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_me.xml b/app/src/main/res/layout/fragment_me.xml index 34a5f1e07..1e0246ec4 100644 --- a/app/src/main/res/layout/fragment_me.xml +++ b/app/src/main/res/layout/fragment_me.xml @@ -18,7 +18,7 @@ - + android:layout_height="wrap_content"> + + + + + + + + + - - - - - - - + app:layout_constraintTop_toBottomOf="@id/me_item_setting"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + - + android:layout_marginStart="10dp" + android:layout_marginTop="20dp" + android:layout_marginEnd="10dp" + android:gravity="bottom" + android:orientation="horizontal" + android:weightSum="4" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/rl_user_info"> + android:textSize="@dimen/sp_20" + android:textStyle="bold" + tools:text="999" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:text="@string/attention" + android:textColor="@color/color_999999" + android:textSize="@dimen/sp_12" /> + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + android:layout_marginStart="15dp" + android:layout_marginTop="16dp" + android:background="@drawable/bg_me_wallet_entrance" + android:gravity="center_vertical" + android:onClick="@{click}" + android:orientation="vertical" + app:layout_constraintDimensionRatio="328:128" + app:layout_constraintEnd_toStartOf="@id/me_item_vip" + app:layout_constraintHorizontal_chainStyle="packed" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/ll_user_relation"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/app/src/main/res/layout/item_me_center.xml b/app/src/main/res/layout/item_me_center.xml new file mode 100644 index 000000000..2c177844f --- /dev/null +++ b/app/src/main/res/layout/item_me_center.xml @@ -0,0 +1,35 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_me_game.xml b/app/src/main/res/layout/item_me_game.xml new file mode 100644 index 000000000..30f2bf81c --- /dev/null +++ b/app/src/main/res/layout/item_me_game.xml @@ -0,0 +1,35 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xhdpi/icon_skill_card.png b/app/src/main/res/mipmap-xhdpi/icon_skill_card.png index 95bf2e610..9244bab9a 100644 Binary files a/app/src/main/res/mipmap-xhdpi/icon_skill_card.png and b/app/src/main/res/mipmap-xhdpi/icon_skill_card.png differ diff --git a/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/home/model/HomeModel.kt b/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/home/model/HomeModel.kt index 1af53f332..50bceafc0 100644 --- a/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/home/model/HomeModel.kt +++ b/core/src/diff_src_erban/java/com/yizhuan/xchat_android_core/home/model/HomeModel.kt @@ -7,7 +7,9 @@ import com.yizhuan.xchat_android_core.community.CommunityConstant import com.yizhuan.xchat_android_core.community.bean.UnReadCountInfo import com.yizhuan.xchat_android_core.home.bean.* import com.yizhuan.xchat_android_core.room.bean.HomeLiveTopInfo +import com.yizhuan.xchat_android_core.room.bean.MeCenterInfo import com.yizhuan.xchat_android_core.room.bean.SingleRoomSortInfo +import com.yizhuan.xchat_android_core.room.game.GameInfo import com.yizhuan.xchat_android_core.user.bean.UserInfo import com.yizhuan.xchat_android_core.utils.net.RxHelper import com.yizhuan.xchat_android_core.utils.net.launchRequest @@ -162,6 +164,16 @@ object HomeModel : BaseModel() { api.requestHomeLiveTopInfo() } + suspend fun requestMeCenterInfoList(): List? = + launchRequest { + api.requestMeCenterInfoList() + } + + suspend fun getGameList(): List? = + launchRequest { + api.getGameList() + } + private interface Api { /** @@ -339,6 +351,22 @@ object HomeModel : BaseModel() { @GET("single/broadcast/onceLook") suspend fun requestHomeLiveTopInfo(): ServiceResult + /** + * @return + */ + @GET("personal/center/list") + suspend fun requestMeCenterInfoList(): ServiceResult> + + /** + * + * + * @param uid + * @return + */ + @POST("/miniGame/record/miniGameList") + suspend fun getGameList( + ): ServiceResult> + } } \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/room/bean/MeCenterInfo.kt b/core/src/main/java/com/yizhuan/xchat_android_core/room/bean/MeCenterInfo.kt new file mode 100644 index 000000000..1b7abcb2a --- /dev/null +++ b/core/src/main/java/com/yizhuan/xchat_android_core/room/bean/MeCenterInfo.kt @@ -0,0 +1,12 @@ +package com.yizhuan.xchat_android_core.room.bean + +data class MeCenterInfo( + val centerBadge: String = "", + val centerId: Int = 0, + val centerName: String = "", + val centerPic: String = "", + val centerSeq: Int = 0, + val centerStatus: Int = 0, + val centerUrl: String = "", + val skipType: Int = 0, +) \ No newline at end of file diff --git a/core/src/main/java/com/yizhuan/xchat_android_core/room/game/GameModel.kt b/core/src/main/java/com/yizhuan/xchat_android_core/room/game/GameModel.kt index 102aec156..b10f8ba57 100644 --- a/core/src/main/java/com/yizhuan/xchat_android_core/room/game/GameModel.kt +++ b/core/src/main/java/com/yizhuan/xchat_android_core/room/game/GameModel.kt @@ -28,17 +28,6 @@ object GameModel : BaseModel() { .compose(RxHelper.handleSchAndExce()) } - suspend fun getHomeBanner(type: String): List? = - launchRequest { - api.apiHomeBanner( - type, AuthModel.get().currentUid.toString(), - CommunityConstant.VERSION_VALID_TYPE, - AuthModel.get().ticket - ) - } - - - private interface Api { /** @@ -63,24 +52,6 @@ object GameModel : BaseModel() { @Field("uid") uid: Long ): Single> - - /** - * 首页Banner - * - * @param type - * @param uid - * @param types - * @param ticket - * @return - */ - @GET("/home/banner") - suspend fun apiHomeBanner( - @Query("type") type: String, - @Query("uid") uid: String, - @Query("types") types: String, - @Query("ticket") ticket: String - ): ServiceResult> - } } \ No newline at end of file