From a8bedc6c913bf98e4f4e8aacf607fe105fcb978e Mon Sep 17 00:00:00 2001 From: Aleksandar Ilic Date: Mon, 13 Nov 2023 14:23:23 +0100 Subject: [PATCH] Implement DM icon on ProfileScreen --- .../android/navigation/PrimalAppNavigation.kt | 1 + .../android/profile/details/ProfileScreen.kt | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/net/primal/android/navigation/PrimalAppNavigation.kt b/app/src/main/kotlin/net/primal/android/navigation/PrimalAppNavigation.kt index 83b97969..3e1a53b1 100644 --- a/app/src/main/kotlin/net/primal/android/navigation/PrimalAppNavigation.kt +++ b/app/src/main/kotlin/net/primal/android/navigation/PrimalAppNavigation.kt @@ -625,6 +625,7 @@ private fun NavGraphBuilder.profile( onPostQuoteClick = { preFillContent -> navController.navigateToNoteEditor(preFillContent) }, onProfileClick = { profileId -> navController.navigateToProfile(profileId = profileId) }, onEditProfileClick = { navController.navigateToEditProfile() }, + onMessageClick = { profileId -> navController.navigateToChat(profileId = profileId) }, onHashtagClick = { hashtag -> navController.navigateToExploreFeed(query = hashtag) }, onWalletUnavailable = { navController.navigateToWallet() }, ) diff --git a/app/src/main/kotlin/net/primal/android/profile/details/ProfileScreen.kt b/app/src/main/kotlin/net/primal/android/profile/details/ProfileScreen.kt index c867c8bc..f4bad8ef 100644 --- a/app/src/main/kotlin/net/primal/android/profile/details/ProfileScreen.kt +++ b/app/src/main/kotlin/net/primal/android/profile/details/ProfileScreen.kt @@ -33,6 +33,9 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ContentCopy import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.IconButtonDefaults import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState @@ -58,6 +61,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawWithCache import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity @@ -100,6 +104,7 @@ import net.primal.android.core.compose.icons.primaliconpack.ContextMuteUser import net.primal.android.core.compose.icons.primaliconpack.ContextShare import net.primal.android.core.compose.icons.primaliconpack.Key import net.primal.android.core.compose.icons.primaliconpack.Link +import net.primal.android.core.compose.icons.primaliconpack.Message import net.primal.android.core.compose.icons.primaliconpack.More import net.primal.android.core.compose.icons.primaliconpack.UserFeedAdd import net.primal.android.core.compose.isEmpty @@ -129,6 +134,7 @@ fun ProfileScreen( onPostQuoteClick: (String) -> Unit, onProfileClick: (String) -> Unit, onEditProfileClick: () -> Unit, + onMessageClick: (String) -> Unit, onHashtagClick: (String) -> Unit, onWalletUnavailable: () -> Unit, ) { @@ -144,6 +150,7 @@ fun ProfileScreen( onPostQuoteClick = onPostQuoteClick, onProfileClick = onProfileClick, onEditProfileClick = onEditProfileClick, + onMessageClick = onMessageClick, onHashtagClick = onHashtagClick, onWalletUnavailable = onWalletUnavailable, eventPublisher = { viewModel.setEvent(it) }, @@ -160,6 +167,7 @@ fun ProfileScreen( onPostQuoteClick: (String) -> Unit, onProfileClick: (String) -> Unit, onEditProfileClick: () -> Unit, + onMessageClick: (String) -> Unit, onHashtagClick: (String) -> Unit, onWalletUnavailable: () -> Unit, eventPublisher: (ProfileContract.UiEvent) -> Unit, @@ -326,12 +334,15 @@ fun ProfileScreen( profileDetails = state.profileDetails, profileStats = state.profileStats, onEditProfileClick = onEditProfileClick, + onMessageClick = { + onMessageClick(state.profileId) + }, onFollow = { eventPublisher(ProfileContract.UiEvent.FollowAction(state.profileId)) }, onUnfollow = { eventPublisher(ProfileContract.UiEvent.UnfollowAction(state.profileId)) - } + }, ) if (state.isProfileMuted) { @@ -599,6 +610,7 @@ private fun UserProfileDetails( profileDetails: ProfileDetailsUi? = null, profileStats: ProfileStatsUi? = null, onEditProfileClick: () -> Unit, + onMessageClick: () -> Unit, onFollow: () -> Unit, onUnfollow: () -> Unit, ) { @@ -616,6 +628,7 @@ private fun UserProfileDetails( isFollowed = isFollowed, isActiveUser = isActiveUser, onEditProfileClick = onEditProfileClick, + onMessageClick = onMessageClick, onFollow = onFollow, onUnfollow = onUnfollow, ) @@ -752,6 +765,7 @@ private fun ProfileActions( isFollowed: Boolean, isActiveUser: Boolean, onEditProfileClick: () -> Unit, + onMessageClick: () -> Unit, onFollow: () -> Unit, onUnfollow: () -> Unit, ) { @@ -764,6 +778,11 @@ private fun ProfileActions( .background(AppTheme.colorScheme.surfaceVariant), horizontalArrangement = Arrangement.End, ) { + ActionButton( + onClick = onMessageClick, + iconVector = PrimalIcons.Message, + ) + if (!isActiveUser) { when (isFollowed) { true -> UnfollowButton(onClick = onUnfollow) @@ -778,6 +797,30 @@ private fun ProfileActions( } } +@Composable +fun ActionButton( + iconVector: ImageVector, + onClick: () -> Unit, + contentDescription: String? = null, +) { + IconButton( + modifier = Modifier + .padding(horizontal = 8.dp) + .size(36.dp), + onClick = onClick, + colors = IconButtonDefaults.iconButtonColors( + containerColor = AppTheme.extraColorScheme.surfaceVariantAlt1, + contentColor = AppTheme.colorScheme.onSurface, + ), + ) { + Icon( + modifier = Modifier.padding(all = 2.dp), + imageVector = iconVector, + contentDescription = contentDescription, + ) + } +} + @Composable fun FollowButton( onClick: () -> Unit, @@ -988,6 +1031,7 @@ fun PreviewProfileScreen() { onPostQuoteClick = {}, onProfileClick = {}, onEditProfileClick = {}, + onMessageClick = {}, onHashtagClick = {}, onWalletUnavailable = {}, eventPublisher = {},