Increasing performance of the follow/follower count
This commit is contained in:
@@ -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.AccountBackupDialog
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -229,39 +230,57 @@ fun ProfileContent(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun FollowingAndFollowerCounts(baseAccountUser: User) {
|
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 followingCount by remember { mutableStateOf("--") }
|
||||||
var followerCount by remember { mutableStateOf("--") }
|
var followerCount by remember { mutableStateOf("--") }
|
||||||
|
|
||||||
LaunchedEffect(key1 = accountUserFollowsState, key2 = accountUserFollowersState) {
|
WatchFollow(baseAccountUser = baseAccountUser) { newFollowing ->
|
||||||
launch(Dispatchers.IO) {
|
if (followingCount != newFollowing) {
|
||||||
val newFollowing = accountUserFollowsState?.user?.cachedFollowCount()?.toString() ?: "--"
|
followingCount = newFollowing
|
||||||
val newFollower = accountUserFollowersState?.user?.cachedFollowerCount()?.toString() ?: "--"
|
|
||||||
|
|
||||||
if (followingCount != newFollowing) {
|
|
||||||
followingCount = newFollowing
|
|
||||||
}
|
|
||||||
if (followerCount != newFollower) {
|
|
||||||
followerCount = newFollower
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row() {
|
WatchFollower(baseAccountUser = baseAccountUser) { newFollower ->
|
||||||
Text(
|
if (followerCount != newFollower) {
|
||||||
text = followingCount,
|
followerCount = newFollower
|
||||||
fontWeight = FontWeight.Bold
|
}
|
||||||
)
|
|
||||||
Text(stringResource(R.string.following))
|
|
||||||
}
|
}
|
||||||
Row(modifier = Modifier.padding(start = 10.dp)) {
|
|
||||||
Text(
|
Text(
|
||||||
text = followerCount,
|
text = followingCount,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(stringResource(R.string.followers))
|
|
||||||
|
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() ?: "--")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -385,9 +385,11 @@ private fun FollowersTabHeader(baseUser: User) {
|
|||||||
val userState by baseUser.live().followers.observeAsState()
|
val userState by baseUser.live().followers.observeAsState()
|
||||||
var followerCount by remember { mutableStateOf("--") }
|
var followerCount by remember { mutableStateOf("--") }
|
||||||
|
|
||||||
|
val text = stringResource(R.string.followers)
|
||||||
|
|
||||||
LaunchedEffect(key1 = userState) {
|
LaunchedEffect(key1 = userState) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
val newFollower = userState?.user?.transientFollowerCount()?.toString() ?: "--"
|
val newFollower = (userState?.user?.transientFollowerCount()?.toString() ?: "--") + " " + text
|
||||||
|
|
||||||
if (followerCount != newFollower) {
|
if (followerCount != newFollower) {
|
||||||
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
|
@Composable
|
||||||
@@ -403,9 +405,11 @@ private fun FollowTabHeader(baseUser: User) {
|
|||||||
val userState by baseUser.live().follows.observeAsState()
|
val userState by baseUser.live().follows.observeAsState()
|
||||||
var followCount by remember { mutableStateOf("--") }
|
var followCount by remember { mutableStateOf("--") }
|
||||||
|
|
||||||
|
val text = stringResource(R.string.follows)
|
||||||
|
|
||||||
LaunchedEffect(key1 = userState) {
|
LaunchedEffect(key1 = userState) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
val newFollow = userState?.user?.transientFollowCount()?.toString() ?: "--"
|
val newFollow = (userState?.user?.transientFollowCount()?.toString() ?: "--") + " " + text
|
||||||
|
|
||||||
if (followCount != newFollow) {
|
if (followCount != newFollow) {
|
||||||
followCount = newFollow
|
followCount = newFollow
|
||||||
@@ -413,7 +417,7 @@ private fun FollowTabHeader(baseUser: User) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(text = "$followCount ${stringResource(R.string.follows)}")
|
Text(text = followCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -21,3 +21,4 @@ val ChatBubbleShapeThem = RoundedCornerShape(3.dp, 15.dp, 15.dp, 15.dp)
|
|||||||
|
|
||||||
val StdButtonSizeModifier = Modifier.size(20.dp)
|
val StdButtonSizeModifier = Modifier.size(20.dp)
|
||||||
val StdHorzSpacer = Modifier.width(5.dp)
|
val StdHorzSpacer = Modifier.width(5.dp)
|
||||||
|
val DoubleHorzSpacer = Modifier.width(10.dp)
|
||||||
|
|||||||
Reference in New Issue
Block a user