From bae671ad231beb776d0267541eaa278dd1f18ea4 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 2 Aug 2023 01:28:48 +0530 Subject: [PATCH] feat(android): switch comments page to a swipe action --- android/build.gradle.kts | 1 + .../claw/android/ui/lists/ListItem.kt | 30 ++++++++++++++----- .../claw/common/posts/LobstersCard.kt | 6 +--- gradle/libs.versions.toml | 1 + 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index c367669f..8a16d649 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -77,6 +77,7 @@ dependencies { implementation(libs.napier) implementation(libs.soloader) implementation(libs.sqldelight.extensions.coroutines) + implementation(libs.swipe) implementation(libs.unfurl) implementation(projects.api) implementation(projects.common) diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/lists/ListItem.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/lists/ListItem.kt index 182d4f71..d6e7e465 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/lists/ListItem.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/lists/ListItem.kt @@ -1,18 +1,24 @@ /* - * Copyright © 2021-2022 Harsh Shandilya. + * Copyright © 2021-2023 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ package dev.msfjarvis.claw.android.ui.lists +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Reply +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.produceState import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.rememberVectorPainter import dev.msfjarvis.claw.common.posts.LobstersCard import dev.msfjarvis.claw.common.posts.PostActions import dev.msfjarvis.claw.database.local.SavedPost +import me.saket.swipe.SwipeAction +import me.saket.swipe.SwipeableActionsBox @Composable fun ListItem( @@ -22,10 +28,20 @@ fun ListItem( modifier: Modifier = Modifier, ) { val saved by produceState(false, item) { value = isSaved(item) } - LobstersCard( - post = item, - isSaved = saved, - postActions = postActions, - modifier = modifier, - ) + val commentsAction = + SwipeAction( + icon = rememberVectorPainter(Icons.Filled.Reply), + background = MaterialTheme.colorScheme.tertiary, + onSwipe = { postActions.viewCommentsPage(item.commentsUrl) }, + ) + SwipeableActionsBox( + endActions = listOf(commentsAction), + ) { + LobstersCard( + post = item, + isSaved = saved, + postActions = postActions, + modifier = modifier, + ) + } } diff --git a/common/src/main/kotlin/dev/msfjarvis/claw/common/posts/LobstersCard.kt b/common/src/main/kotlin/dev/msfjarvis/claw/common/posts/LobstersCard.kt index c13acd09..e4a06dfa 100644 --- a/common/src/main/kotlin/dev/msfjarvis/claw/common/posts/LobstersCard.kt +++ b/common/src/main/kotlin/dev/msfjarvis/claw/common/posts/LobstersCard.kt @@ -7,10 +7,8 @@ package dev.msfjarvis.claw.common.posts import androidx.compose.animation.Crossfade -import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -62,7 +60,6 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList @Composable -@OptIn(ExperimentalFoundationApi::class) fun LobstersCard( post: SavedPost, isSaved: Boolean, @@ -102,10 +99,9 @@ fun LobstersCard( CommentsButton( commentCount = post.commentCount, modifier = - Modifier.combinedClickable( + Modifier.clickable( role = Role.Button, onClick = { postActions.viewComments(post.shortId) }, - onLongClick = { postActions.viewCommentsPage(post.commentsUrl) }, ), ) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 21e20785..9fde1a0f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -91,6 +91,7 @@ sqldelight-extensions-coroutines = { module = "app.cash.sqldelight:coroutines-ex sqldelight-jvmDriver = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" } sqldelight-primitiveAdapters = { module = "app.cash.sqldelight:primitive-adapters", version.ref = "sqldelight" } sqlite-android = "com.github.requery:sqlite-android:3.42.0" +swipe = "me.saket.swipe:swipe:1.2.0" testparameterinjector = "com.google.testparameterinjector:test-parameter-injector:1.12" truth = "com.google.truth:truth:1.1.5" unfurl = "me.saket.unfurl:unfurl:1.7.0"