feat: 回复按钮点击跳转回复

This commit is contained in:
HuanCheng65 2023-07-20 18:34:01 +08:00
parent 0a86dffd8e
commit 11fb0b7e1a
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
8 changed files with 83 additions and 35 deletions

View File

@ -136,6 +136,7 @@ private fun ThreadList(
goodClassifyId: Int?, goodClassifyId: Int?,
goodClassifyHoldersProvider: () -> List<ImmutableHolder<Classify>>, goodClassifyHoldersProvider: () -> List<ImmutableHolder<Classify>>,
onItemClicked: (ThreadInfo) -> Unit, onItemClicked: (ThreadInfo) -> Unit,
onItemReplyClicked: (ThreadInfo) -> Unit,
onAgree: (ThreadInfo) -> Unit, onAgree: (ThreadInfo) -> Unit,
onClassifySelected: (Int) -> Unit onClassifySelected: (Int) -> Unit
) { ) {
@ -219,12 +220,9 @@ private fun ThreadList(
} }
FeedCard( FeedCard(
item = holder, item = holder,
onClick = { onClick = onItemClicked,
onItemClicked(item) onReplyClick = onItemReplyClicked,
}, onAgree = onAgree,
onAgree = {
onAgree(item)
},
) )
} }
} }
@ -338,10 +336,20 @@ fun ForumThreadListPage(
navigator.navigate( navigator.navigate(
ThreadPageDestination( ThreadPageDestination(
it.threadId, it.threadId,
forumId = it.forumId,
threadInfo = it threadInfo = it
) )
) )
}, },
onItemReplyClicked = {
navigator.navigate(
ThreadPageDestination(
it.threadId,
forumId = it.forumId,
scrollToReply = true
)
)
},
onAgree = { onAgree = {
viewModel.send( viewModel.send(
ForumThreadListUiIntent.Agree( ForumThreadListUiIntent.Agree(

View File

@ -115,7 +115,8 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
1, 1,
1, 1,
sortType.takeIf { type == ForumThreadListType.Latest } ?: -1, sortType.takeIf { type == ForumThreadListType.Latest } ?: -1,
goodClassifyId.takeIf { type == ForumThreadListType.Good } goodClassifyId.takeIf { type == ForumThreadListType.Good },
forceNew = true
) )
.map<FrsPageResponse, ForumThreadListPartialChange.Refresh> { response -> .map<FrsPageResponse, ForumThreadListPartialChange.Refresh> { response ->
if (response.data_?.page == null) throw TiebaUnknownException if (response.data_?.page == null) throw TiebaUnknownException

View File

@ -17,6 +17,7 @@ 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.unit.dp import androidx.compose.ui.unit.dp
import com.huanchengfly.tieba.post.api.hasAgree
import com.huanchengfly.tieba.post.arch.BaseComposeActivity import com.huanchengfly.tieba.post.arch.BaseComposeActivity
import com.huanchengfly.tieba.post.arch.CommonUiEvent.ScrollToTop.bindScrollToTopEvent import com.huanchengfly.tieba.post.arch.CommonUiEvent.ScrollToTop.bindScrollToTopEvent
import com.huanchengfly.tieba.post.arch.collectPartialAsState import com.huanchengfly.tieba.post.arch.collectPartialAsState
@ -102,19 +103,27 @@ fun ConcernPage(
onClick = { onClick = {
navigator.navigate( navigator.navigate(
ThreadPageDestination( ThreadPageDestination(
item.threadList.threadId, it.threadId,
item.threadList.forumId, it.forumId,
threadInfo = item.threadList threadInfo = it
)
)
},
onReplyClick = {
navigator.navigate(
ThreadPageDestination(
it.threadId,
it.forumId,
scrollToReply = true
) )
) )
}, },
onAgree = { onAgree = {
viewModel.send( viewModel.send(
ConcernUiIntent.Agree( ConcernUiIntent.Agree(
item.threadList.threadId, it.threadId,
item.threadList.firstPostId, it.firstPostId,
item.threadList.agree?.hasAgree ?: 0 it.hasAgree
) )
) )
}, },

View File

@ -283,6 +283,14 @@ fun HotPage(
) )
) )
}, },
onReplyClick = {
navigator.navigate(
ThreadPageDestination(
threadId = it.id,
scrollToReply = true
)
)
},
onAgree = { onAgree = {
viewModel.send( viewModel.send(
HotUiIntent.Agree( HotUiIntent.Agree(

View File

@ -157,21 +157,30 @@ fun PersonalizedPage(
personalizedDataProvider = { threadPersonalizedData }, personalizedDataProvider = { threadPersonalizedData },
refreshPositionProvider = { refreshPosition }, refreshPositionProvider = { refreshPosition },
hiddenThreadIdsProvider = { hiddenThreadIds }, hiddenThreadIdsProvider = { hiddenThreadIds },
onItemClick = { threadInfo -> onItemClick = {
navigator.navigate( navigator.navigate(
ThreadPageDestination( ThreadPageDestination(
threadInfo.id, it.id,
threadInfo.forumId, it.forumId,
threadInfo = threadInfo threadInfo = it
) )
) )
}, },
onAgree = { item -> onItemReplyClick = {
navigator.navigate(
ThreadPageDestination(
it.id,
it.forumId,
scrollToReply = true
)
)
},
onAgree = {
viewModel.send( viewModel.send(
PersonalizedUiIntent.Agree( PersonalizedUiIntent.Agree(
item.threadId, it.threadId,
item.firstPostId, it.firstPostId,
item.agree?.hasAgree ?: 0 it.agree?.hasAgree ?: 0
) )
) )
}, },
@ -232,6 +241,7 @@ private fun FeedList(
refreshPositionProvider: () -> Int, refreshPositionProvider: () -> Int,
hiddenThreadIdsProvider: () -> List<Long>, hiddenThreadIdsProvider: () -> List<Long>,
onItemClick: (ThreadInfo) -> Unit, onItemClick: (ThreadInfo) -> Unit,
onItemReplyClick: (ThreadInfo) -> Unit,
onAgree: (ThreadInfo) -> Unit, onAgree: (ThreadInfo) -> Unit,
onDislike: (ThreadInfo, Long, List<ImmutableHolder<DislikeReason>>) -> Unit, onDislike: (ThreadInfo, Long, List<ImmutableHolder<DislikeReason>>) -> Unit,
onRefresh: () -> Unit, onRefresh: () -> Unit,
@ -274,14 +284,11 @@ private fun FeedList(
) { ) {
FeedCard( FeedCard(
item = item, item = item,
onClick = { onClick = onItemClick,
onItemClick(item.get()) onReplyClick = onItemReplyClick,
}, onAgree = onAgree,
onAgree = {
onAgree(item.get())
},
onClickForum = { onClickForum = {
onOpenForum(item.get { forumInfo?.name ?: "" }) onOpenForum(it.name)
} }
) { ) {
val personalized = threadPersonalizedData.getOrNull(index) val personalized = threadPersonalizedData.getOrNull(index)

View File

@ -397,6 +397,7 @@ fun ThreadPage(
from: String = "", from: String = "",
extra: ThreadPageExtra = ThreadPageNoExtra, extra: ThreadPageExtra = ThreadPageNoExtra,
threadInfo: ThreadInfo? = null, threadInfo: ThreadInfo? = null,
scrollToReply: Boolean = false,
viewModel: ThreadViewModel = pageViewModel() viewModel: ThreadViewModel = pageViewModel()
) { ) {
LazyLoad(loaded = viewModel.initialized) { LazyLoad(loaded = viewModel.initialized) {
@ -528,6 +529,8 @@ fun ThreadPage(
val curForumId = remember(forumId, forum) { val curForumId = remember(forumId, forum) {
forumId ?: forum?.get { id } forumId ?: forum?.get { id }
} }
var waitLoadSuccessAndScrollToFirstReply by remember { mutableStateOf(scrollToReply) }
val lazyListState = rememberLazyListState() val lazyListState = rememberLazyListState()
val bottomSheetState = rememberModalBottomSheetState( val bottomSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden, initialValue = ModalBottomSheetValue.Hidden,
@ -571,6 +574,12 @@ fun ThreadPage(
viewModel.onEvent<ThreadUiEvent.ScrollToFirstReply> { viewModel.onEvent<ThreadUiEvent.ScrollToFirstReply> {
lazyListState.animateScrollToItem(3) lazyListState.animateScrollToItem(3)
} }
viewModel.onEvent<ThreadUiEvent.LoadSuccess> {
if (it.page > 1 || waitLoadSuccessAndScrollToFirstReply) {
waitLoadSuccessAndScrollToFirstReply = false
lazyListState.animateScrollToItem(3)
}
}
viewModel.onEvent<ThreadUiEvent.AddFavoriteSuccess> { viewModel.onEvent<ThreadUiEvent.AddFavoriteSuccess> {
scaffoldState.snackbarHostState.showSnackbar( scaffoldState.snackbarHostState.showSnackbar(
context.getString(R.string.message_add_favorite_success, it.floor) context.getString(R.string.message_add_favorite_success, it.floor)
@ -1050,7 +1059,7 @@ fun ThreadPage(
) )
) )
} }
} },
) )
} }
if (data.isEmpty()) { if (data.isEmpty()) {

View File

@ -74,7 +74,7 @@ class ThreadViewModel @Inject constructor() :
) )
ThreadPartialChange.RemoveFavorite.Success -> ThreadUiEvent.RemoveFavoriteSuccess ThreadPartialChange.RemoveFavorite.Success -> ThreadUiEvent.RemoveFavoriteSuccess
is ThreadPartialChange.Load.Success -> if (partialChange.currentPage > 1) ThreadUiEvent.ScrollToFirstReply else null is ThreadPartialChange.Load.Success -> ThreadUiEvent.LoadSuccess(partialChange.currentPage)
else -> null else -> null
} }
} }
@ -895,6 +895,10 @@ data class ThreadUiState(
sealed interface ThreadUiEvent : UiEvent { sealed interface ThreadUiEvent : UiEvent {
object ScrollToFirstReply : ThreadUiEvent object ScrollToFirstReply : ThreadUiEvent
data class LoadSuccess(
val page: Int
) : ThreadUiEvent
data class AddFavoriteSuccess(val floor: Int) : ThreadUiEvent data class AddFavoriteSuccess(val floor: Int) : ThreadUiEvent
object RemoveFavoriteSuccess : ThreadUiEvent object RemoveFavoriteSuccess : ThreadUiEvent

View File

@ -62,6 +62,7 @@ import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.activities.UserActivity import com.huanchengfly.tieba.post.activities.UserActivity
import com.huanchengfly.tieba.post.api.abstractText import com.huanchengfly.tieba.post.api.abstractText
import com.huanchengfly.tieba.post.api.models.protos.Media import com.huanchengfly.tieba.post.api.models.protos.Media
import com.huanchengfly.tieba.post.api.models.protos.SimpleForum
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.User import com.huanchengfly.tieba.post.api.models.protos.User
import com.huanchengfly.tieba.post.arch.ImmutableHolder import com.huanchengfly.tieba.post.arch.ImmutableHolder
@ -383,7 +384,7 @@ private fun ThreadMedia(
@Composable @Composable
private fun ThreadForumInfo( private fun ThreadForumInfo(
item: ImmutableHolder<ThreadInfo>, item: ImmutableHolder<ThreadInfo>,
onClick: () -> Unit onClick: (SimpleForum) -> Unit
) { ) {
val hasForumInfo = remember(item) { item.isNotNull { forumInfo } } val hasForumInfo = remember(item) { item.isNotNull { forumInfo } }
if (hasForumInfo) { if (hasForumInfo) {
@ -392,7 +393,7 @@ private fun ThreadForumInfo(
ForumInfoChip( ForumInfoChip(
imageUriProvider = { StringUtil.getAvatarUrl(forumInfo.get { avatar }) }, imageUriProvider = { StringUtil.getAvatarUrl(forumInfo.get { avatar }) },
nameProvider = { forumInfo.get { name } }, nameProvider = { forumInfo.get { name } },
onClick = onClick onClick = { onClick(forumInfo.get()) }
) )
} }
} }
@ -486,7 +487,8 @@ fun FeedCard(
item: ImmutableHolder<ThreadInfo>, item: ImmutableHolder<ThreadInfo>,
onClick: (ThreadInfo) -> Unit, onClick: (ThreadInfo) -> Unit,
onAgree: (ThreadInfo) -> Unit, onAgree: (ThreadInfo) -> Unit,
onClickForum: () -> Unit = {}, onReplyClick: (ThreadInfo) -> Unit = {},
onClickForum: (SimpleForum) -> Unit = {},
dislikeAction: @Composable () -> Unit = {}, dislikeAction: @Composable () -> Unit = {},
) { ) {
Card( Card(
@ -519,7 +521,7 @@ fun FeedCard(
Row(modifier = Modifier.fillMaxWidth()) { Row(modifier = Modifier.fillMaxWidth()) {
ThreadReplyBtn( ThreadReplyBtn(
replyNum = item.get { replyNum }, replyNum = item.get { replyNum },
onClick = { onClick(item.get()) }, onClick = { onReplyClick(item.get()) },
modifier = Modifier.weight(1f) modifier = Modifier.weight(1f)
) )