diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt index 320cb3df2..3ba5a23e8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt @@ -67,6 +67,7 @@ import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountBackupDialog import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog +import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -229,39 +230,57 @@ fun ProfileContent( @Composable private fun FollowingAndFollowerCounts(baseAccountUser: User) { - val accountUserFollowsState by baseAccountUser.live().follows.observeAsState() - val accountUserFollowersState by baseAccountUser.live().followers.observeAsState() - var followingCount by remember { mutableStateOf("--") } var followerCount by remember { mutableStateOf("--") } - LaunchedEffect(key1 = accountUserFollowsState, key2 = accountUserFollowersState) { - launch(Dispatchers.IO) { - val newFollowing = accountUserFollowsState?.user?.cachedFollowCount()?.toString() ?: "--" - val newFollower = accountUserFollowersState?.user?.cachedFollowerCount()?.toString() ?: "--" - - if (followingCount != newFollowing) { - followingCount = newFollowing - } - if (followerCount != newFollower) { - followerCount = newFollower - } + WatchFollow(baseAccountUser = baseAccountUser) { newFollowing -> + if (followingCount != newFollowing) { + followingCount = newFollowing } } - Row() { - Text( - text = followingCount, - fontWeight = FontWeight.Bold - ) - Text(stringResource(R.string.following)) + WatchFollower(baseAccountUser = baseAccountUser) { newFollower -> + if (followerCount != newFollower) { + followerCount = newFollower + } } - Row(modifier = Modifier.padding(start = 10.dp)) { - Text( - text = followerCount, - fontWeight = FontWeight.Bold - ) - Text(stringResource(R.string.followers)) + + Text( + text = followingCount, + fontWeight = FontWeight.Bold + ) + + Text(stringResource(R.string.following)) + + Spacer(modifier = DoubleHorzSpacer) + + Text( + text = followerCount, + fontWeight = FontWeight.Bold + ) + + Text(stringResource(R.string.followers)) +} + +@Composable +fun WatchFollow(baseAccountUser: User, onReady: (String) -> Unit) { + val accountUserFollowsState by baseAccountUser.live().follows.observeAsState() + + LaunchedEffect(key1 = accountUserFollowsState) { + launch(Dispatchers.IO) { + onReady(accountUserFollowsState?.user?.cachedFollowCount()?.toString() ?: "--") + } + } +} + +@Composable +fun WatchFollower(baseAccountUser: User, onReady: (String) -> Unit) { + val accountUserFollowersState by baseAccountUser.live().followers.observeAsState() + + LaunchedEffect(key1 = accountUserFollowersState) { + launch(Dispatchers.IO) { + onReady(accountUserFollowersState?.user?.cachedFollowerCount()?.toString() ?: "--") + } } } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt index dd045fd75..b848d22c8 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileScreen.kt @@ -385,9 +385,11 @@ private fun FollowersTabHeader(baseUser: User) { val userState by baseUser.live().followers.observeAsState() var followerCount by remember { mutableStateOf("--") } + val text = stringResource(R.string.followers) + LaunchedEffect(key1 = userState) { launch(Dispatchers.IO) { - val newFollower = userState?.user?.transientFollowerCount()?.toString() ?: "--" + val newFollower = (userState?.user?.transientFollowerCount()?.toString() ?: "--") + " " + text if (followerCount != newFollower) { followerCount = newFollower @@ -395,7 +397,7 @@ private fun FollowersTabHeader(baseUser: User) { } } - Text(text = "$followerCount ${stringResource(id = R.string.followers)}") + Text(text = followerCount) } @Composable @@ -403,9 +405,11 @@ private fun FollowTabHeader(baseUser: User) { val userState by baseUser.live().follows.observeAsState() var followCount by remember { mutableStateOf("--") } + val text = stringResource(R.string.follows) + LaunchedEffect(key1 = userState) { launch(Dispatchers.IO) { - val newFollow = userState?.user?.transientFollowCount()?.toString() ?: "--" + val newFollow = (userState?.user?.transientFollowCount()?.toString() ?: "--") + " " + text if (followCount != newFollow) { followCount = newFollow @@ -413,7 +417,7 @@ private fun FollowTabHeader(baseUser: User) { } } - Text(text = "$followCount ${stringResource(R.string.follows)}") + Text(text = followCount) } @Composable diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt index 574ed5da0..c78f3eb8f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/theme/Shape.kt @@ -21,3 +21,4 @@ val ChatBubbleShapeThem = RoundedCornerShape(3.dp, 15.dp, 15.dp, 15.dp) val StdButtonSizeModifier = Modifier.size(20.dp) val StdHorzSpacer = Modifier.width(5.dp) +val DoubleHorzSpacer = Modifier.width(10.dp)