feat: 精华贴分类
This commit is contained in:
parent
2f6e64452c
commit
0a834c81ab
|
|
@ -2,6 +2,7 @@ package com.huanchengfly.tieba.post.ui.page.forum.threadlist
|
|||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -12,6 +13,8 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Divider
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.MaterialTheme
|
||||
|
|
@ -25,6 +28,7 @@ import androidx.compose.runtime.LaunchedEffect
|
|||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
|
|
@ -174,6 +178,14 @@ fun ForumThreadListPage(
|
|||
prop1 = ForumThreadListUiState::threadListIds,
|
||||
initial = emptyList()
|
||||
)
|
||||
val goodClassifyId by viewModel.uiState.collectPartialAsState(
|
||||
prop1 = ForumThreadListUiState::goodClassifyId,
|
||||
initial = null
|
||||
)
|
||||
val goodClassifies by viewModel.uiState.collectPartialAsState(
|
||||
prop1 = ForumThreadListUiState::goodClassifies,
|
||||
initial = emptyList()
|
||||
)
|
||||
val pullRefreshState = rememberPullRefreshState(
|
||||
refreshing = isRefreshing,
|
||||
onRefresh = { viewModel.send(getRefreshIntent(context, forumName, isGood)) }
|
||||
|
|
@ -200,6 +212,35 @@ fun ForumThreadListPage(
|
|||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
if (isGood) {
|
||||
item(key = "GoodClassifyHeader") {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.horizontalScroll(rememberScrollState())
|
||||
.padding(vertical = 8.dp, horizontal = 16.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
goodClassifies.forEach {
|
||||
Chip(
|
||||
text = it.class_name,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(100))
|
||||
.clickable {
|
||||
viewModel.send(
|
||||
getRefreshIntent(
|
||||
context,
|
||||
forumName,
|
||||
true,
|
||||
goodClassifyId = it.class_id
|
||||
)
|
||||
)
|
||||
},
|
||||
invertColor = goodClassifyId == it.class_id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
itemsIndexed(
|
||||
items = threadList,
|
||||
key = { index, item -> "${index}_${item.id}" },
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.huanchengfly.tieba.post.ui.page.forum.threadlist
|
|||
import com.huanchengfly.tieba.post.api.TiebaApi
|
||||
import com.huanchengfly.tieba.post.api.models.AgreeBean
|
||||
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
||||
import com.huanchengfly.tieba.post.api.models.protos.frsPage.Classify
|
||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||
import com.huanchengfly.tieba.post.api.updateAgreeStatus
|
||||
|
|
@ -99,6 +100,8 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
|
|||
ForumThreadListPartialChange.FirstLoad.Success(
|
||||
threadList,
|
||||
response.data_.thread_id_list,
|
||||
response.data_.forum?.good_classify ?: emptyList(),
|
||||
goodClassifyId.takeIf { type == ForumThreadListType.Good },
|
||||
response.data_.page.has_more == 1
|
||||
)
|
||||
}
|
||||
|
|
@ -126,6 +129,8 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
|
|||
ForumThreadListPartialChange.Refresh.Success(
|
||||
threadList,
|
||||
response.data_.thread_id_list,
|
||||
response.data_.forum?.good_classify ?: emptyList(),
|
||||
goodClassifyId.takeIf { type == ForumThreadListType.Good },
|
||||
response.data_.page.has_more == 1
|
||||
)
|
||||
}
|
||||
|
|
@ -250,6 +255,8 @@ sealed interface ForumThreadListPartialChange : PartialChange<ForumThreadListUiS
|
|||
isRefreshing = false,
|
||||
threadList = threadList,
|
||||
threadListIds = threadListIds,
|
||||
goodClassifies = goodClassifies,
|
||||
goodClassifyId = goodClassifyId,
|
||||
currentPage = 1,
|
||||
hasMore = hasMore
|
||||
)
|
||||
|
|
@ -262,6 +269,8 @@ sealed interface ForumThreadListPartialChange : PartialChange<ForumThreadListUiS
|
|||
data class Success(
|
||||
val threadList: List<ThreadInfo>,
|
||||
val threadListIds: List<Long>,
|
||||
val goodClassifies: List<Classify>,
|
||||
val goodClassifyId: Int?,
|
||||
val hasMore: Boolean,
|
||||
) : FirstLoad()
|
||||
|
||||
|
|
@ -278,6 +287,8 @@ sealed interface ForumThreadListPartialChange : PartialChange<ForumThreadListUiS
|
|||
isRefreshing = false,
|
||||
threadList = threadList,
|
||||
threadListIds = threadListIds,
|
||||
goodClassifies = goodClassifies,
|
||||
goodClassifyId = goodClassifyId,
|
||||
currentPage = 1,
|
||||
hasMore = hasMore
|
||||
)
|
||||
|
|
@ -290,6 +301,8 @@ sealed interface ForumThreadListPartialChange : PartialChange<ForumThreadListUiS
|
|||
data class Success(
|
||||
val threadList: List<ThreadInfo>,
|
||||
val threadListIds: List<Long>,
|
||||
val goodClassifies: List<Classify>,
|
||||
val goodClassifyId: Int? = null,
|
||||
val hasMore: Boolean,
|
||||
) : Refresh()
|
||||
|
||||
|
|
@ -394,6 +407,7 @@ data class ForumThreadListUiState(
|
|||
val goodClassifyId: Int? = null,
|
||||
val threadList: List<ThreadInfo> = emptyList(),
|
||||
val threadListIds: List<Long> = emptyList(),
|
||||
val goodClassifies: List<Classify> = emptyList(),
|
||||
val currentPage: Int = 1,
|
||||
val hasMore: Boolean = true,
|
||||
) : UiState
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ private fun Header(
|
|||
invert: Boolean = false,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Chip(text = text, invertColor = invert, modifier = modifier)
|
||||
Chip(text = text, modifier = modifier.padding(start = 16.dp), invertColor = invert)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ import com.huanchengfly.tieba.post.utils.ThemeUtil
|
|||
@Composable
|
||||
fun Chip(
|
||||
text: String,
|
||||
invertColor: Boolean = false,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
invertColor: Boolean = false
|
||||
) {
|
||||
Text(
|
||||
color = if (invertColor)
|
||||
|
|
@ -27,10 +27,8 @@ fun Chip(
|
|||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
text = text,
|
||||
modifier = Modifier
|
||||
.padding(start = 16.dp)
|
||||
modifier = modifier
|
||||
.clip(RoundedCornerShape(100))
|
||||
.then(modifier)
|
||||
.background(
|
||||
color = if (invertColor)
|
||||
if (ThemeUtil.isNightMode()) MaterialTheme.colors.secondary.copy(alpha = 0.3f) else MaterialTheme.colors.secondary
|
||||
|
|
|
|||
Loading…
Reference in New Issue