diff --git a/app/src/main/java/org/listenbrainz/android/ui/screens/profile/BaseProfileScreen.kt b/app/src/main/java/org/listenbrainz/android/ui/screens/profile/BaseProfileScreen.kt index d9821369..e49ee5f5 100644 --- a/app/src/main/java/org/listenbrainz/android/ui/screens/profile/BaseProfileScreen.kt +++ b/app/src/main/java/org/listenbrainz/android/ui/screens/profile/BaseProfileScreen.kt @@ -194,8 +194,8 @@ fun BaseProfileScreen( modifier = Modifier, isFollowedState = uiState.listensTabUiState.isFollowing, buttonColor = lb_purple, - followedStateTextColor = new_app_bg_light, - unfollowedStateTextColor = ListenBrainzTheme.colorScheme.text, + followedStateTextColor = ListenBrainzTheme.colorScheme.text, + unfollowedStateTextColor = new_app_bg_light, onClick = { if (uiState.listensTabUiState.isFollowing) { onUnfollowClick(username ?: "") diff --git a/app/src/main/java/org/listenbrainz/android/ui/screens/profile/listens/ListensScreen.kt b/app/src/main/java/org/listenbrainz/android/ui/screens/profile/listens/ListensScreen.kt index 9c77045e..3a9866f8 100644 --- a/app/src/main/java/org/listenbrainz/android/ui/screens/profile/listens/ListensScreen.kt +++ b/app/src/main/java/org/listenbrainz/android/ui/screens/profile/listens/ListensScreen.kt @@ -68,6 +68,7 @@ import org.listenbrainz.android.model.TrackMetadata import org.listenbrainz.android.model.feed.ReviewEntityType import org.listenbrainz.android.model.user.Artist import org.listenbrainz.android.ui.components.ErrorBar +import org.listenbrainz.android.ui.components.FollowButton import org.listenbrainz.android.ui.components.ListenCardSmallDefault import org.listenbrainz.android.ui.components.SimilarUserCard import org.listenbrainz.android.ui.components.SuccessBar @@ -84,6 +85,7 @@ import org.listenbrainz.android.ui.theme.app_bg_mid import org.listenbrainz.android.ui.theme.compatibilityMeterColor import org.listenbrainz.android.ui.theme.lb_purple import org.listenbrainz.android.ui.theme.lb_purple_night +import org.listenbrainz.android.ui.theme.new_app_bg_light import org.listenbrainz.android.util.Utils.getCoverArtUrl import org.listenbrainz.android.viewmodel.FeedViewModel import org.listenbrainz.android.viewmodel.ListensViewModel @@ -389,7 +391,7 @@ private fun BuildSimilarArtists(similarArtists: List, onArtistClick: (St similarArtists.size > 5 -> { val topSimilarArtists = similarArtists.take(5) val text = buildAnnotatedString { - withStyle(style = SpanStyle(color = white)) { + withStyle(style = SpanStyle(color = lb_purple_night)) { append("You both listen to ") } topSimilarArtists.forEachIndexed { index, artist -> @@ -401,10 +403,13 @@ private fun BuildSimilarArtists(similarArtists: List, onArtistClick: (St } pop() if (index < topSimilarArtists.size - 1) { - append(", ") + withStyle(style = SpanStyle(color = lb_purple_night)) { + append(", ") + } + } } - withStyle(style = SpanStyle(color = white)) { + withStyle(style = SpanStyle(color = lb_purple_night)) { append(" and more.") } } @@ -734,29 +739,19 @@ private fun FollowCard(username: String?, onFollowButtonClick: (String?, Boolean goToUserPage(username) } ) - TextButton( - onClick = { - onFollowButtonClick(username, followStatus) - }, colors = ButtonDefaults.buttonColors( - containerColor = when (followStatus) { - true -> ListenBrainzTheme.colorScheme.followingButtonColor - false -> lb_purple - } - ), modifier = Modifier - .width(90.dp) - .height(40.dp), shape = RoundedCornerShape(10.dp), - border = ListenBrainzTheme.colorScheme.followingButtonBorder - ) { - Text( - when (followStatus) { - true -> "Following" - false -> "Follow" - }, color = when(followStatus){ - true -> ListenBrainzTheme.colorScheme.followerCardTextColor - false -> Color.White + Box(){ + FollowButton( + modifier = Modifier, + isFollowedState = followStatus, + buttonColor = lb_purple, + followedStateTextColor = ListenBrainzTheme.colorScheme.lbSignature, + unfollowedStateTextColor = new_app_bg_light, + onClick = { + onFollowButtonClick(username, followStatus) } ) } + } } } diff --git a/app/src/main/java/org/listenbrainz/android/viewmodel/UserViewModel.kt b/app/src/main/java/org/listenbrainz/android/viewmodel/UserViewModel.kt index af5261b5..20c06dd3 100644 --- a/app/src/main/java/org/listenbrainz/android/viewmodel/UserViewModel.kt +++ b/app/src/main/java/org/listenbrainz/android/viewmodel/UserViewModel.kt @@ -68,27 +68,42 @@ class UserViewModel @Inject constructor( return similarArtists.distinct() } - fun followUser(username: String?){ - if(username.isNullOrEmpty()) return - viewModelScope.launch (ioDispatcher) { - listenStateFlow.value = listenStateFlow.value.copy(isFollowing = true) + fun followUser(username: String?) { + if (username.isNullOrEmpty()) return + updateFollowState(username, true) + + viewModelScope.launch(ioDispatcher) { val result = socialRepository.followUser(username) if (result.status == Resource.Status.FAILED) { - listenStateFlow.value = listenStateFlow.value.copy(isFollowing = false) + updateFollowState(username, false) } } } - fun unfollowUser(username: String?){ - if(username.isNullOrEmpty()) return + fun unfollowUser(username: String?) { + if (username.isNullOrEmpty()) return + updateFollowState(username, false) + viewModelScope.launch(ioDispatcher) { - listenStateFlow.value = listenStateFlow.value.copy(isFollowing = false) val result = socialRepository.unfollowUser(username) if (result.status == Resource.Status.FAILED) { - listenStateFlow.value = listenStateFlow.value.copy(isFollowing = true) + updateFollowState(username, true) } } + } + private fun updateFollowState(username: String, isFollowing: Boolean) { + val updatedFollowers = listenStateFlow.value.followers?.map { (user, status) -> + if (user == username) user to isFollowing else user to status + } + val updatedFollowing = listenStateFlow.value.following?.map { (user, status) -> + if (user == username) user to isFollowing else user to status + } + listenStateFlow.value = listenStateFlow.value.copy( + followers = updatedFollowers, + following = updatedFollowing, + isFollowing = isFollowing + ) } suspend fun getUserDataFromRemote(