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:
ThanaReka 2024-10-26 16:53:43 -04:00 committed by GitHub
parent f215210ffa
commit b84f266db7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 360 additions and 16 deletions

View file

@ -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)

View file

@ -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 }
}

View file

@ -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(),
)
}

View file

@ -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) {