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