diff --git a/app/src/main/java/com/gh/common/constant/Constants.java b/app/src/main/java/com/gh/common/constant/Constants.java index 7e335dd8e9..935745f26a 100644 --- a/app/src/main/java/com/gh/common/constant/Constants.java +++ b/app/src/main/java/com/gh/common/constant/Constants.java @@ -318,6 +318,10 @@ public class Constants { public static final String WITHDRAW_INFO_ADDRESS_DEV = "https://static-web.ghzs.com/shop-dev/index.html#/cash?from=ghzs"; public static final String WITHDRAW_INFO_ADDRESS = "https://static-web.ghzs.com/shop/index.html#/cash?from=ghzs"; + // 活动详情 + public static final String ACTIVITY_DETAIL_ADDRESS_DEV = "https://static-web.ghzs.com/ghzs_activity_dev/common.html?from=ghzs"; + public static final String ACTIVITY_DETAIL_ADDRESS = "https://static-web.ghzs.com/ghzs_activity_prod/common.html?from=ghzs"; + //最少需要多少数据才能上传 public static final int DATA_AMOUNT = 20; diff --git a/app/src/main/java/com/gh/common/util/DirectUtils.kt b/app/src/main/java/com/gh/common/util/DirectUtils.kt index 54b04c3dd7..b7b57b6d72 100644 --- a/app/src/main/java/com/gh/common/util/DirectUtils.kt +++ b/app/src/main/java/com/gh/common/util/DirectUtils.kt @@ -1461,4 +1461,19 @@ object DirectUtils { url = String.format(Locale.CHINA, "%s×tamp=%d", url, (Date().time / 1000 / 1000.toFloat()).roundToInt()) directToFullScreenWebPage(context, url, true) } + + /** + * 跳转至活动详情 + */ + @JvmStatic + fun directToActivityDetail(context: Context, activityId: String, entrance: String) { + var url: String = if (isPublishEnv()) { + Constants.ACTIVITY_DETAIL_ADDRESS + } else { + Constants.ACTIVITY_DETAIL_ADDRESS + } + + url = String.format(Locale.CHINA, "%s&id=%s×tamp=%d", url, activityId, (Date().time / 1000 / 1000.toFloat()).roundToInt()) + directToWebView(context, url, entrance) + } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/entity/ForumActivityEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/ForumActivityEntity.kt new file mode 100644 index 0000000000..56f361d081 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/entity/ForumActivityEntity.kt @@ -0,0 +1,40 @@ +package com.gh.gamecenter.entity + +import com.google.gson.annotations.SerializedName + +data class ForumActivityCategoryEntity( + @SerializedName("_id") + var id: String = "", + var name: String = "" +) + +data class ForumActivityEntity( + @SerializedName("_id") + val id: String = "", + val title: String = "", + @SerializedName("tag_activity_id") + val activityId: String = "", //活动标签ID + @SerializedName("tag_activity_name") + val activityName: String = "", //活动标签名 + @SerializedName("game_id") + val gameId: String = "", + @SerializedName("game_name") + val gameName: String = "", + @SerializedName("effect_time") + val effectTime: ActivityTime = ActivityTime(), + @SerializedName("award_time") + val awardTime: ActivityTime = ActivityTime(), + val image: ActivityImage = ActivityImage(), + val name: String = "", + val unread: Boolean = false +) { + + data class ActivityTime( + val start: Long = 0, + val end: Long = 0 + ) + + data class ActivityImage( + val cover: String = "" + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/CommunityHomeFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/home/CommunityHomeFragment.kt index d9e821ce6c..209dd4e804 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/CommunityHomeFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/CommunityHomeFragment.kt @@ -33,7 +33,7 @@ class CommunityHomeFragment : LazyFragment() { private var mBinding: FragmentCommunityHomeBinding? = null private var mFragmentList = arrayListOf() - private var mTitleList = arrayListOf("推荐", "论坛") + private var mTitleList = arrayListOf("推荐", "论坛", "活动") private var mTabList = arrayListOf() override fun getRealLayoutId(): Int { @@ -85,6 +85,10 @@ class CommunityHomeFragment : LazyFragment() { ?: ForumFragment().with(bundleOf(EntranceUtils.KEY_ENTRANCE to "社区")) mFragmentList.add(forumFragment) + val activityFragment = childFragmentManager.findFragmentByTag("${tag}2") + ?: ForumActivityFragment().with(bundleOf(EntranceUtils.KEY_ENTRANCE to "活动")) + mFragmentList.add(activityFragment) + viewPager.run { offscreenPageLimit = mFragmentList.size adapter = FragmentAdapter(childFragmentManager, mFragmentList, mTitleList) diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityAdapter.kt b/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityAdapter.kt new file mode 100644 index 0000000000..8769eac174 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityAdapter.kt @@ -0,0 +1,113 @@ +package com.gh.gamecenter.forum.home + +import android.content.Context +import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.recyclerview.widget.RecyclerView +import com.gh.base.BaseRecyclerViewHolder +import com.gh.common.constant.ItemViewType +import com.gh.common.exposure.time.TimeUtil +import com.gh.common.util.* +import com.gh.gamecenter.R +import com.gh.gamecenter.adapter.viewholder.FooterViewHolder +import com.gh.gamecenter.baselist.ListAdapter +import com.gh.gamecenter.databinding.ForumActivityItemBinding +import com.gh.gamecenter.entity.ForumActivityEntity + +class ForumActivityAdapter(context: Context, + val mViewModel: ForumActivityViewModel, + val mEntrance: String) : ListAdapter(context) { + + override fun getItemViewType(position: Int): Int { + if (position == itemCount - 1) return ItemViewType.ITEM_FOOTER + return ItemViewType.ITEM_BODY + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return when (viewType) { + ItemViewType.ITEM_FOOTER -> { + val view = mLayoutInflater.inflate(R.layout.refresh_footerview, parent, false) + FooterViewHolder(view) + } + + else -> { + ForumActivityViewHolder(DataBindingUtil.inflate(mLayoutInflater, R.layout.forum_activity_item, parent, false)) + } + } + } + + override fun getItemCount(): Int { + return if (mEntityList.isNotEmpty()) mEntityList.size + FOOTER_ITEM_COUNT else 0 + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + when (holder) { + is ForumActivityViewHolder -> { + holder.binding.run { + val activityEntity = mEntityList[position] + entity = activityEntity + executePendingBindings() + + line.goneIf(position == 0) + + var status = "" + val currentTime = TimeUtil.currentTime() + when { + // 进行中 + currentTime > activityEntity.effectTime.start + && (currentTime < activityEntity.effectTime.end + || activityEntity.effectTime.end == null + || activityEntity.effectTime.end == 0L) -> { + status = "进行中" + statusTv.text = "进行中" + statusTv.setTextColor(R.color.theme_font.toColor()) + statusTv.setBackgroundResource(R.drawable.bg_forum_activity_status_blue) + if (activityEntity.effectTime.end == null || activityEntity.effectTime.end == 0L) { + timeTv.text = "长期有效" + } else { + val startTime = TimeUtils.getFormatTime(activityEntity.effectTime.start, "yyyy.MM.dd") + val endTime = TimeUtils.getFormatTime(activityEntity.effectTime.end, "yyyy.MM.dd") + timeTv.text = "$startTime 至 $endTime" + } + } + + // 奖励发放中 + currentTime > activityEntity.awardTime.start + && currentTime < activityEntity.awardTime.end -> { + status = "发放中" + statusTv.text = "发放中" + statusTv.setTextColor(R.color.theme_font.toColor()) + statusTv.setBackgroundResource(R.drawable.bg_forum_activity_status_blue) + val startTime = TimeUtils.getFormatTime(activityEntity.awardTime.start, "yyyy.MM.dd") + val endTime = TimeUtils.getFormatTime(activityEntity.awardTime.end, "yyyy.MM.dd") + timeTv.text = "$startTime 至 $endTime" + } + + // 已结束 + else -> { + status = "已结束" + statusTv.text = "已结束" + statusTv.setTextColor(R.color.white.toColor()) + statusTv.setBackgroundResource(R.drawable.bg_forum_activity_status_gray) + val startTime = TimeUtils.getFormatTime(activityEntity.effectTime.start, "yyyy.MM.dd") + val endTime = TimeUtils.getFormatTime(activityEntity.effectTime.end, "yyyy.MM.dd") + timeTv.text = "$startTime 至 $endTime" + } + } + + root.setOnClickListener { + if (status == "发放中") ToastUtils.toast("活动奖励发放中~") + if (status == "已结束") ToastUtils.toast("活动已结束~") + DirectUtils.directToActivityDetail(mContext, activityEntity.id, mEntrance) + } + } + } + + is FooterViewHolder -> { + holder.initFooterViewHolder(mViewModel, mIsLoading, mIsNetworkError, mIsOver) + } + } + } + + inner class ForumActivityViewHolder(val binding: ForumActivityItemBinding): BaseRecyclerViewHolder(binding.root) +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityFragment.kt new file mode 100644 index 0000000000..1a0d16496b --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityFragment.kt @@ -0,0 +1,83 @@ +package com.gh.gamecenter.forum.home + +import android.view.View +import android.view.ViewGroup +import android.widget.CheckedTextView +import com.gh.common.util.dip2px +import com.gh.common.util.observeNonNull +import com.gh.common.util.viewModelProvider +import com.gh.gamecenter.R +import com.gh.gamecenter.baselist.LazyListFragment +import com.gh.gamecenter.databinding.FragmentForumActivityBinding +import com.gh.gamecenter.databinding.LayoutForumActivityCategoryItemBinding +import com.gh.gamecenter.entity.ForumActivityCategoryEntity +import com.gh.gamecenter.entity.ForumActivityEntity +import com.google.android.flexbox.FlexboxLayout + +class ForumActivityFragment: LazyListFragment() { + + private var mBinding: FragmentForumActivityBinding? = null + private var mAdapter: ForumActivityAdapter? = null + + override fun getRealLayoutId() = R.layout.fragment_forum_activity + + override fun provideListAdapter() = + mAdapter ?: ForumActivityAdapter(requireContext(), mListViewModel, "论坛-活动").apply { mAdapter = this } + + override fun provideListViewModel(): ForumActivityViewModel { + return viewModelProvider() + } + + override fun onRealLayoutInflated(inflatedView: View) { + mBinding = FragmentForumActivityBinding.bind(inflatedView) + } + + override fun initRealView() { + super.initRealView() + + mListViewModel.categories.observeNonNull(viewLifecycleOwner) { + initCategoryView(ArrayList(it)) + } + } + + override fun getItemDecoration() = null + + private fun initCategoryView(list: ArrayList) { + if (list.isEmpty()) return + + mBinding?.categoryContainer?.visibility = View.VISIBLE + + list.add(0, ForumActivityCategoryEntity(id = "all", name = "全部")) + list.forEachIndexed { index, entity -> + val binding = LayoutForumActivityCategoryItemBinding.inflate(layoutInflater).apply { + val params = FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) + params.setMargins(0, 8F.dip2px(), 8F.dip2px(), 0) + params.height = 24F.dip2px() + root.layoutParams = params + + name.text = entity.name + name.isChecked = index == 0 + root.setOnClickListener { + updateCategory(index, entity) + } + } + + mBinding?.categoryContainer?.addView(binding.root) + } + } + + private fun updateCategory(index: Int, entity: ForumActivityCategoryEntity) { + updateCategoryView(index) + mListViewModel.categoryId = entity.id + onRefresh() + } + + private fun updateCategoryView(index: Int) { + mBinding?.categoryContainer?.run { + for (i in 0 until childCount) { + val categoryView = getChildAt(i) as CheckedTextView + categoryView.isChecked = index == i + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityViewModel.kt b/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityViewModel.kt new file mode 100644 index 0000000000..dc5fb1af9e --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/forum/home/ForumActivityViewModel.kt @@ -0,0 +1,48 @@ +package com.gh.gamecenter.forum.home + +import android.annotation.SuppressLint +import android.app.Application +import androidx.lifecycle.MutableLiveData +import com.gh.common.util.UrlFilterUtils +import com.gh.common.util.singleToMain +import com.gh.gamecenter.baselist.ListViewModel +import com.gh.gamecenter.entity.ForumActivityCategoryEntity +import com.gh.gamecenter.entity.ForumActivityEntity +import com.gh.gamecenter.retrofit.BiResponse +import com.gh.gamecenter.retrofit.RetrofitManager +import io.reactivex.Single + +class ForumActivityViewModel(application: Application) : ListViewModel(application) { + + var categoryId = "all" + var categories = MutableLiveData>() + + init { + getActivityCategories() + } + + @SuppressLint("CheckResult") + fun getActivityCategories() { + RetrofitManager.getInstance(getApplication()) + .api + .forumActivityCategories + .compose(singleToMain()) + .subscribe(object : BiResponse>() { + override fun onSuccess(data: List) { + categories.postValue(data) + } + }) + } + + override fun provideDataObservable(page: Int) = null + + override fun provideDataSingle(page: Int): Single> { + return RetrofitManager.getInstance(getApplication()) + .api.getForumActivities(UrlFilterUtils.getFilterQuery("category_id", categoryId), page) + } + + override fun mergeResultLiveData() { + mResultLiveData.addSource(mListLiveData) { mResultLiveData.postValue(it) } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleListFragment.kt b/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleListFragment.kt index 7d3a3d2112..652535e672 100644 --- a/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleListFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/forum/home/ForumArticleListFragment.kt @@ -46,8 +46,6 @@ class ForumArticleListFragment : LazyListFragment() var sort: String = "time.comment"//排序 time.edit 最新发布 time.comment 最新回复 + init { + getRecordForums() + } + override fun provideDataObservable(page: Int): Observable>? { return RetrofitManager.getInstance(getApplication()) .api.getForumRecommendsArticle(UrlFilterUtils.getFilterQuery(sort, "-1"), page) diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 41a2f9cc1f..fb10a3a504 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -21,6 +21,8 @@ import com.gh.gamecenter.entity.ConcernEntity; import com.gh.gamecenter.entity.DeviceDialogEntity; import com.gh.gamecenter.entity.EnergyTaskCompleteEntity; import com.gh.gamecenter.entity.FollowersOrFansEntity; +import com.gh.gamecenter.entity.ForumActivityCategoryEntity; +import com.gh.gamecenter.entity.ForumActivityEntity; import com.gh.gamecenter.entity.ForumCategoryEntity; import com.gh.gamecenter.entity.ForumDetailEntity; import com.gh.gamecenter.entity.ForumEntity; @@ -3130,4 +3132,16 @@ public interface ApiService { */ @POST("bbses/questions/{question_id}/comments/{comment_id}:unset-top") Observable postQuestionCommentUnTop(@Path("question_id") String questionId, @Path("comment_id") String commentId); + + /** + * 获取社区活动分类列表 + */ + @GET("videos/activities/category") + Single> getForumActivityCategories(); + + /** + * 获取社区活动列表 + */ + @GET("videos/activities") + Single> getForumActivities(@Query("filter") String filter, @Query("page") int page); } \ No newline at end of file diff --git a/app/src/main/res/color/forum_category_selector.xml b/app/src/main/res/color/forum_category_selector.xml new file mode 100644 index 0000000000..fafdf93fce --- /dev/null +++ b/app/src/main/res/color/forum_category_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-xxxhdpi/bg_forum_activity_status_blue.webp b/app/src/main/res/drawable-xxxhdpi/bg_forum_activity_status_blue.webp new file mode 100644 index 0000000000..29486af370 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/bg_forum_activity_status_blue.webp differ diff --git a/app/src/main/res/drawable-xxxhdpi/bg_forum_activity_status_gray.webp b/app/src/main/res/drawable-xxxhdpi/bg_forum_activity_status_gray.webp new file mode 100644 index 0000000000..f57479b90f Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/bg_forum_activity_status_gray.webp differ diff --git a/app/src/main/res/drawable/bg_forum_category_selected.xml b/app/src/main/res/drawable/bg_forum_category_selected.xml new file mode 100644 index 0000000000..0ab8d3be01 --- /dev/null +++ b/app/src/main/res/drawable/bg_forum_category_selected.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_forum_category_unselect.xml b/app/src/main/res/drawable/bg_forum_category_unselect.xml new file mode 100644 index 0000000000..834a7cf6aa --- /dev/null +++ b/app/src/main/res/drawable/bg_forum_category_unselect.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/selector_bg_forum_activity_category.xml b/app/src/main/res/drawable/selector_bg_forum_activity_category.xml new file mode 100644 index 0000000000..70b14ba06f --- /dev/null +++ b/app/src/main/res/drawable/selector_bg_forum_activity_category.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/forum_activity_item.xml b/app/src/main/res/layout/forum_activity_item.xml new file mode 100644 index 0000000000..abd7e21f15 --- /dev/null +++ b/app/src/main/res/layout/forum_activity_item.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_forum_activity.xml b/app/src/main/res/layout/fragment_forum_activity.xml new file mode 100644 index 0000000000..55550afaeb --- /dev/null +++ b/app/src/main/res/layout/fragment_forum_activity.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_forum_activity_category_item.xml b/app/src/main/res/layout/layout_forum_activity_category_item.xml new file mode 100644 index 0000000000..f0bc95b6bf --- /dev/null +++ b/app/src/main/res/layout/layout_forum_activity_category_item.xml @@ -0,0 +1,14 @@ + + + \ No newline at end of file