mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 23:27:04 +05:30
Add tablet specific UI (#686)
Hi @msfjarvis! Please have a look at what I have been able to implement so far. When trying to call the ListDetail version in the MainActivity I realized that the MainActivity is based on the BaseActivity class, and I wasn't exactly sure how to set the parameters for ListDetail. Let me know your thoughts when you get a chance. Thanks! --------- Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
f215210ffa
commit
b84f266db7
14 changed files with 360 additions and 16 deletions
|
@ -48,6 +48,7 @@ dependencies {
|
|||
implementation(libs.androidx.compose.foundation)
|
||||
implementation(libs.androidx.compose.material.icons.extended)
|
||||
implementation(libs.androidx.compose.material3)
|
||||
implementation(libs.androidx.compose.material3.adaptive)
|
||||
implementation(libs.androidx.compose.runtime)
|
||||
implementation(libs.androidx.compose.ui.text)
|
||||
implementation(libs.androidx.core)
|
||||
|
|
|
@ -51,7 +51,7 @@ internal fun CommentsHeader(
|
|||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val linkMetadata by
|
||||
produceState(initialValue = LinkMetadata(post.url, null)) {
|
||||
produceState(initialValue = LinkMetadata(post.url, null), key1 = post) {
|
||||
runSuspendCatching { postActions.getLinkMetadata(post.url) }
|
||||
.onSuccess { metadata -> value = metadata }
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ fun CommentsPage(
|
|||
openUserProfile: (String) -> Unit,
|
||||
) {
|
||||
val postDetails by
|
||||
produceState<NetworkState>(Loading) {
|
||||
produceState<NetworkState>(Loading, key1 = postId) {
|
||||
runSuspendCatching { postActions.getComments(postId) }
|
||||
.fold(
|
||||
success = { details -> value = Success(details) },
|
||||
|
@ -48,7 +48,9 @@ fun CommentsPage(
|
|||
)
|
||||
}
|
||||
val commentState by
|
||||
produceState<PostComments?>(initialValue = null) { value = getSeenComments(postId) }
|
||||
produceState<PostComments?>(initialValue = null, key1 = postId) {
|
||||
value = getSeenComments(postId)
|
||||
}
|
||||
|
||||
when (postDetails) {
|
||||
is Success<*> -> {
|
||||
|
@ -60,7 +62,6 @@ fun CommentsPage(
|
|||
markSeenComments = markSeenComments,
|
||||
openUserProfile = openUserProfile,
|
||||
contentPadding = contentPadding,
|
||||
commentsHandler = CommentsHandler(),
|
||||
modifier = modifier.fillMaxSize(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -64,11 +64,12 @@ internal fun CommentsPageInternal(
|
|||
markSeenComments: (String, List<Comment>) -> Unit,
|
||||
openUserProfile: (String) -> Unit,
|
||||
contentPadding: PaddingValues,
|
||||
commentsHandler: CommentsHandler,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
|
||||
LaunchedEffect(Unit) { commentsHandler.createListNode(details.comments, commentState) }
|
||||
val commentsHandler = CommentsHandler()
|
||||
LaunchedEffect(key1 = details, key2 = commentState) {
|
||||
commentsHandler.createListNode(details.comments, commentState)
|
||||
}
|
||||
|
||||
val onToggleExpandedState = { shortId: String, isExpanded: Boolean ->
|
||||
commentsHandler.updateListNode(shortId, isExpanded)
|
||||
|
@ -77,7 +78,7 @@ internal fun CommentsPageInternal(
|
|||
val context = LocalContext.current
|
||||
val commentNodes by commentsHandler.listItems.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(key1 = commentNodes) {
|
||||
LaunchedEffect(key1 = details, key2 = commentState) {
|
||||
if (details.comments.isNotEmpty() && !commentState?.commentIds.isNullOrEmpty()) {
|
||||
val unreadCount = details.comments.size - (commentState?.commentIds?.size ?: 0)
|
||||
if (unreadCount > 0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue