Compare commits

...

2 Commits

Author SHA1 Message Date
524270dde7 Merge remote-tracking branch 'origin/master' 2025-01-17 21:44:23 +08:00
f80c23c90a refactor(community): 重构社区界面布局和功能
- 移除了底部导航栏
- 优化了推荐页面布局,添加了轮播图和下拉刷新功能- 调整了排名页面布局
- 修复了一些代码注释和未使用变量
2025-01-17 21:44:16 +08:00
6 changed files with 163 additions and 196 deletions

View File

@ -8,7 +8,9 @@ import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.coldmint.rust.pro.R import com.coldmint.rust.pro.R
import com.coldmint.rust.pro.adapters.CommunityAdapter import com.coldmint.rust.pro.adapters.CommunityAdapter
import com.coldmint.rust.pro.tool.Tools
import com.google.android.material.navigation.NavigationBarView import com.google.android.material.navigation.NavigationBarView
import com.google.android.material.navigationrail.NavigationRailView
class CommunityFragment : Fragment() { class CommunityFragment : Fragment() {
@ -19,9 +21,6 @@ class CommunityFragment : Fragment() {
if (!isAdded) { if (!isAdded) {
return return
} }
/* else {
viewBinding.pager.postDelayed({ loadTab() }, MainActivity.linkInterval)
}*/
} }
override fun onCreateView( override fun onCreateView(
@ -29,7 +28,6 @@ class CommunityFragment : Fragment() {
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val inflate = inflater.inflate(R.layout.fragment_community, container, false) val inflate = inflater.inflate(R.layout.fragment_community, container, false)
onViewCreated(inflate) onViewCreated(inflate)
return inflate return inflate
@ -38,6 +36,10 @@ class CommunityFragment : Fragment() {
private fun onViewCreated(view: View) { private fun onViewCreated(view: View) {
val navigationBarView : NavigationBarView = view.findViewById(R.id.bottomnavigationView) val navigationBarView : NavigationBarView = view.findViewById(R.id.bottomnavigationView)
val pager : ViewPager2 = view.findViewById(R.id.pager) val pager : ViewPager2 = view.findViewById(R.id.pager)
if (Tools.isTabletMode(requireContext())) {
// var navigation = navigationBarView as NavigationRailView
// navigation.setonc
}
pager.adapter = CommunityAdapter(this) pager.adapter = CommunityAdapter(this)
pager.isSaveEnabled = false pager.isSaveEnabled = false
pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
@ -76,46 +78,4 @@ class CommunityFragment : Fragment() {
true true
} }
} }
// override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
// viewBinding.pager.adapter = CommunityAdapter(this)
// viewBinding.pager.isSaveEnabled = false
// viewBinding.pager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
// override fun onPageSelected(position: Int) {
// when (position) {
// 0 -> {
// viewBinding.bottomnavigationView.selectedItemId = R.id.action_recommended
// }
// 1 -> {
// viewBinding.bottomnavigationView.selectedItemId = R.id.action_follow
// }
// 2 -> {
// viewBinding.bottomnavigationView.selectedItemId = R.id.action_ranking
// }
// 3 -> {
// viewBinding.bottomnavigationView.selectedItemId = R.id.action_my
// }
// }
// }
// })
// viewBinding.bottomnavigationView.setOnItemSelectedListener {
// when (it.itemId) {
// R.id.action_recommended -> {
// viewBinding.pager.currentItem = 0
// }
// R.id.action_follow -> {
// viewBinding.pager.currentItem = 1
// }
// R.id.action_ranking -> {
// viewBinding.pager.currentItem = 2
// }
// R.id.action_my -> {
// viewBinding.pager.currentItem = 3
// }
// }
// true
// }
//
//
// loadTab()
// }
} }

View File

@ -87,7 +87,6 @@ class RankingFragment : BaseFragment<FragmentRankingBinding>() {
private fun loadMods() { private fun loadMods() {
viewBinding.progressBar.isVisible = true viewBinding.progressBar.isVisible = true
viewBinding.textview.isVisible = false viewBinding.textview.isVisible = false
// viewBinding.swipeRefreshLayout.isVisible = false
WebMod.instance.list(object : ApiCallBack<WebModListData> { WebMod.instance.list(object : ApiCallBack<WebModListData> {
override fun onResponse(t: WebModListData) { override fun onResponse(t: WebModListData) {
if (!isAdded) { if (!isAdded) {

View File

@ -3,8 +3,6 @@ package com.coldmint.rust.pro.fragments
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.coldmint.dialog.CoreDialog import com.coldmint.dialog.CoreDialog
@ -28,6 +26,7 @@ import com.youth.banner.adapter.BannerImageAdapter
import com.youth.banner.holder.BannerImageHolder import com.youth.banner.holder.BannerImageHolder
import com.youth.banner.indicator.CircleIndicator import com.youth.banner.indicator.CircleIndicator
class RecommendedFragment : BaseFragment<FragmentRecommendedBinding>() { class RecommendedFragment : BaseFragment<FragmentRecommendedBinding>() {
/** /**
@ -67,32 +66,34 @@ class RecommendedFragment : BaseFragment<FragmentRecommendedBinding>() {
/** /**
* 加载随机推荐 * 加载随机推荐
*/ */
fun loadRandomRecommended() { private fun loadRandomRecommended() {
viewBinding.randomRecommendedProgressIndicator.isVisible = true viewBinding.randomRecommendedProgressIndicator.isVisible = true
WebMod.instance.randomRecommended(6, object : ApiCallBack<WebModListData> { WebMod.instance.randomRecommended(6, object : ApiCallBack<WebModListData> {
override fun onResponse(t: WebModListData) { override fun onResponse(t: WebModListData) {
val data = t.data?.toMutableList() val data = t.data?.toMutableList()
if (data == null || data.isEmpty()) { if (data.isNullOrEmpty()) {
viewBinding.randomRecommendedProgressIndicator.isVisible = false viewBinding.randomRecommendedProgressIndicator.isVisible = false
viewBinding.swipeRefreshLayout.isRefreshing = false
} else { } else {
viewBinding.randomRecommendedProgressIndicator.isVisible = false viewBinding.randomRecommendedProgressIndicator.isVisible = false
viewBinding.randomRecommendedView.isVisible = true viewBinding.randomRecommendedView.isVisible = true
viewBinding.randomRecommendedView.adapter = createAdapter(data) viewBinding.randomRecommendedView.adapter = createAdapter(data)
viewBinding.swipeRefreshLayout.isRefreshing = false
} }
} }
override fun onFailure(e: Exception) { override fun onFailure(e: Exception) {
e.printStackTrace() e.printStackTrace()
viewBinding.randomRecommendedProgressIndicator.isVisible = false viewBinding.randomRecommendedProgressIndicator.isVisible = false
viewBinding.swipeRefreshLayout.isRefreshing = false
} }
}) })
} }
/** /**
* 加载个性化推荐 * 加载个性化推荐
*/ */
fun loadSoleRecommended() { private fun loadSoleRecommended() {
viewBinding.soleRecommendedCardView.isVisible = false viewBinding.soleRecommendedCardView.isVisible = false
viewBinding.soleRecommendedProgressIndicator.isVisible = true viewBinding.soleRecommendedProgressIndicator.isVisible = true
val account = AppSettings.getValue(AppSettings.Setting.Account, "") val account = AppSettings.getValue(AppSettings.Setting.Account, "")
@ -123,17 +124,17 @@ class RecommendedFragment : BaseFragment<FragmentRecommendedBinding>() {
/** /**
* 加载轮播图数据 * 加载轮播图数据
*/ */
fun loadBannerData() { private fun loadBannerData() {
BannerManager.instance.getItems(object : ApiCallBack<BannerItemDataBean> { BannerManager.instance.getItems(object : ApiCallBack<BannerItemDataBean> {
override fun onResponse(t: BannerItemDataBean) { override fun onResponse(t: BannerItemDataBean) {
if (t.code == ServerConfiguration.Success_Code) { if (t.code == ServerConfiguration.Success_Code) {
val dataList = t.data val dataList = t.data
if (dataList != null && dataList.isNotEmpty()) { if (!dataList.isNullOrEmpty()) {
val forever = val forever =
AppSettings.getValue( AppSettings.getValue(
AppSettings.Setting.ExpirationTime, AppSettings.Setting.ExpirationTime,
0.toLong() 0.toLong()
) == (-2).toLong() ) == (-2).toLong()
val textStyleMaker = TextStyleMaker.instance val textStyleMaker = TextStyleMaker.instance
val showList = dataList.filter { val showList = dataList.filter {
var show = true var show = true
@ -145,31 +146,31 @@ class RecommendedFragment : BaseFragment<FragmentRecommendedBinding>() {
show show
} }
viewBinding.banner.setAdapter(object : viewBinding.banner.setAdapter(object :
BannerImageAdapter<BannerItemDataBean.Data>(showList) { BannerImageAdapter<BannerItemDataBean.Data>(showList) {
override fun onBindView( override fun onBindView(
holder: BannerImageHolder?, holder: BannerImageHolder?,
data: BannerItemDataBean.Data?, data: BannerItemDataBean.Data?,
position: Int, position: Int,
size: Int size: Int
) { ) {
if (holder != null && data != null) { if (holder != null && data != null) {
Glide.with(holder.itemView).load(data.picture) Glide.with(holder.itemView).load(data.picture)
.apply(GlobalMethod.getRequestOptions()) .apply(GlobalMethod.getRequestOptions())
.into(holder.imageView) .into(holder.imageView)
holder.imageView.setOnClickListener { holder.imageView.setOnClickListener {
val type = textStyleMaker.getType(data.link) val type = textStyleMaker.getType(data.link)
val linkData = textStyleMaker.getData(data.link) val linkData = textStyleMaker.getData(data.link)
if (type == null || linkData == null) { if (type == null || linkData == null) {
CoreDialog(requireContext()).setTitle(data.title) CoreDialog(requireContext()).setTitle(data.title)
.setMessage(data.link) .setMessage(data.link)
.setPositiveButton(R.string.dialog_ok) { .setPositiveButton(R.string.dialog_ok) {
}.setCancelable(false).show() }.setCancelable(false).show()
} else { } else {
textStyleMaker.clickEvent( textStyleMaker.clickEvent(
requireContext(), requireContext(),
type, type,
linkData linkData
) )
} }
} }
@ -231,11 +232,16 @@ class RecommendedFragment : BaseFragment<FragmentRecommendedBinding>() {
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
viewBinding.latestReleaseView.layoutManager = ScrollLinearLayoutManager(requireContext()) viewBinding.latestReleaseView.layoutManager = ScrollLinearLayoutManager(requireContext())
viewBinding.soleRecommendedRecyclerView.layoutManager = viewBinding.soleRecommendedRecyclerView.layoutManager =
ScrollLinearLayoutManager(requireContext()) ScrollLinearLayoutManager(requireContext())
viewBinding.randomRecommendedView.layoutManager = ScrollLinearLayoutManager(requireContext()) viewBinding.randomRecommendedView.layoutManager = ScrollLinearLayoutManager(requireContext())
loadRandomRecommended() loadRandomRecommended()
viewBinding.changeRandomRecommended.setOnClickListener { // 下拉刷新随机推荐的模组
viewBinding.swipeRefreshLayout.setOnRefreshListener {
loadRandomRecommended() loadRandomRecommended()
} }
// 动态设置Banner高度
viewBinding.bannerCardView.layoutParams.height = (resources.displayMetrics.heightPixels / 2.5).toInt()
viewBinding.bannerCardView.requestLayout()
} }
} }

View File

@ -15,11 +15,4 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" /> android:layout_weight="1" />
<!-- <com.google.android.material.bottomnavigation.BottomNavigationView-->
<!-- android:id="@+id/bottomnavigationView"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- app:menu="@menu/menu_main_bottom" />-->
</LinearLayout> </LinearLayout>

View File

@ -87,8 +87,7 @@
android:id="@+id/recyclerView" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:overScrollMode="never" android:overScrollMode="ifContentScrolls" />
android:background="#fff" />
<com.scwang.smart.refresh.footer.ClassicsFooter <com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<ProgressBar <ProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -21,142 +22,151 @@
android:text="@string/info" android:text="@string/info"
android:visibility="gone" /> android:visibility="gone" />
<androidx.core.widget.NestedScrollView <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/nestedScrollView" android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp">
android:visibility="visible">
<LinearLayout <androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:visibility="visible">
<com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="200dp"
app:banner_indicator_selected_color="?attr/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="16dp" android:fillViewport="true"
android:orientation="vertical" android:orientation="vertical">
android:padding="8dp">
<com.google.android.material.card.MaterialCardView
android:id="@+id/bannerCardView"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent"
android:layout_height="200dp">
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:banner_indicator_selected_color="?attr/colorPrimary" />
</com.google.android.material.card.MaterialCardView>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:gravity="center_vertical"> android:layout_marginTop="16dp"
android:orientation="vertical"
android:padding="8dp">
<TextView <LinearLayout
style="@style/TextAppearance.Material3.HeadlineSmall" android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:gravity="center_vertical">
android:text="@string/random_recommended" />
<Button <TextView
android:id="@+id/changeRandomRecommended" style="@style/TextAppearance.Material3.HeadlineSmall"
style="@style/Widget.Material3.Button.TextButton" android:layout_width="0dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/random_recommended" />
<!-- <Button-->
<!-- android:id="@+id/changeRandomRecommended"-->
<!-- style="@style/Widget.Material3.Button.TextButton"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/change_random_recommended"-->
<!-- card_view:ignore="RelativeOverlap" />-->
</LinearLayout>
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/randomRecommendedProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/change_random_recommended" android:layout_marginTop="8dp"
card_view:ignore="RelativeOverlap" /> android:indeterminate="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/randomRecommendedView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:focusableInTouchMode="false"
android:nestedScrollingEnabled="false"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
<com.google.android.material.progressindicator.LinearProgressIndicator <LinearLayout
android:id="@+id/randomRecommendedProgressIndicator"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginTop="8dp" android:layout_marginTop="16dp"
android:indeterminate="true" /> android:orientation="vertical"
android:padding="8dp">
<TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/latest_release" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/latestReleaseProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:indeterminate="true" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/randomRecommendedView" android:id="@+id/latestReleaseView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:focusableInTouchMode="false"
android:nestedScrollingEnabled="false" />
</LinearLayout>
<LinearLayout
android:id="@+id/soleRecommendedCardView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginTop="8dp" android:layout_marginTop="16dp"
android:focusableInTouchMode="false" android:orientation="vertical"
android:nestedScrollingEnabled="false" android:padding="8dp">
android:visibility="gone" />
<TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pay_attention_new" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/soleRecommendedProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:indeterminate="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/soleRecommendedRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:focusableInTouchMode="false"
android:nestedScrollingEnabled="false" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:padding="8dp">
<TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/latest_release" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/latestReleaseProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:indeterminate="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/latestReleaseView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:nestedScrollingEnabled="false"
android:layout_marginTop="8dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/soleRecommendedCardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="vertical"
android:padding="8dp">
<TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pay_attention_new" />
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/soleRecommendedProgressIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:indeterminate="true" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/soleRecommendedRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:nestedScrollingEnabled="false"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout> </LinearLayout>