Skip to content

Commit

Permalink
Merge pull request #503 from hemang-mishra/Fix-LightthemeFixForListen…
Browse files Browse the repository at this point in the history
…Screen-hemang_mishra

Fix: Light theme on profile screen and ui enhancement.
  • Loading branch information
07jasjeet authored Dec 10, 2024
2 parents 2bc455c + 71a4c35 commit 61ca751
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ fun FollowButton(
fontSize: TextUnit = (height.value/2 - 1).sp,
cornerRadius: Dp = 6.dp,
buttonColor: Color = ListenBrainzTheme.colorScheme.lbSignature,
followedStateTextColor: Color = ListenBrainzTheme.colorScheme.lbSignature,
unfollowedStateTextColor: Color = ListenBrainzTheme.colorScheme.onLbSignature,
onClick: () -> Unit,
) {

Expand Down Expand Up @@ -78,7 +80,7 @@ fun FollowButton(
Box(contentAlignment = Alignment.Center) {
Text(
text = if (isFollowedState) "Following" else "Follow",
color = if (isFollowedState) ListenBrainzTheme.colorScheme.lbSignature else ListenBrainzTheme.colorScheme.onLbSignature,
color = if (isFollowedState) followedStateTextColor else unfollowedStateTextColor,
fontWeight = FontWeight.Medium,
fontSize = fontSize
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import org.listenbrainz.android.R
import org.listenbrainz.android.ui.components.FollowButton
import org.listenbrainz.android.ui.components.LoadingAnimation
import org.listenbrainz.android.ui.screens.brainzplayer.PlaylistScreen
import org.listenbrainz.android.ui.screens.profile.listens.ListensScreen
Expand Down Expand Up @@ -183,18 +184,27 @@ fun BaseProfileScreen(

Row (modifier = Modifier
.align(Alignment.End)
.padding(end = 20.dp)) {
.padding(end = 20.dp, bottom = 4.dp)) {
if(currentTab.value == ProfileScreenTab.LISTENS){
when(isLoggedInUser) {
true -> AddListensButton()
false -> when(uiState.listensTabUiState.isFollowing){
true -> UnFollowButton(username = username, onUnFollowClick = {
onUnfollowClick(it)
})
false -> FollowButton(username = username, onFollowClick = {
onFollowClick(it)
})
}
false->
Box() {
FollowButton(
modifier = Modifier,
isFollowedState = uiState.listensTabUiState.isFollowing,
buttonColor = lb_purple,
followedStateTextColor = new_app_bg_light,
unfollowedStateTextColor = ListenBrainzTheme.colorScheme.text,
onClick = {
if (uiState.listensTabUiState.isFollowing) {
onUnfollowClick(username ?: "")
} else {
onFollowClick(username ?: "")
}
}
)
}
}
Spacer(modifier = Modifier.width(10.dp))
MusicBrainzButton{
Expand Down Expand Up @@ -250,51 +260,11 @@ fun BaseProfileScreen(

}

@Composable
private fun FollowButton(onFollowClick: (String) -> Unit, username: String?) {
IconButton(onClick = {
if(!username.isNullOrEmpty()){
onFollowClick(username)
}

}, modifier = Modifier
.background(lb_purple)
.width(100.dp)
.height(30.dp)) {
Row(modifier = Modifier.padding(horizontal = 8.dp)) {
Icon(painter = painterResource(id = R.drawable.follow_icon), contentDescription = "", tint = app_bg_light, modifier = Modifier
.width(20.dp)
.height(20.dp))
Spacer(modifier = Modifier.width(5.dp))
Text("Follow", color = new_app_bg_light, style = MaterialTheme.typography.bodyMedium)
}
}
}

@Composable
private fun UnFollowButton(onUnFollowClick: (String) -> Unit, username: String?) {
IconButton(onClick = {
if(!username.isNullOrEmpty()){
onUnFollowClick(username)
}

}, modifier = Modifier
.background(lb_purple)
.width(100.dp)
.height(30.dp)) {
Row(modifier = Modifier.padding(horizontal = 8.dp)) {
Icon(painter = painterResource(id = R.drawable.follow_icon), contentDescription = "", tint = new_app_bg_light, modifier = Modifier
.width(20.dp)
.height(20.dp))
Spacer(modifier = Modifier.width(5.dp))
Text("Unfollow", color = new_app_bg_light, style = MaterialTheme.typography.bodyMedium)
}
}
}

@Composable
private fun AddListensButton() {
IconButton(onClick = { /*TODO*/ }, modifier = Modifier
.clip(RoundedCornerShape(4.dp))
.background(Color(0xFF353070))
.width(110.dp)
.height(30.dp)) {
Expand All @@ -311,6 +281,7 @@ private fun AddListensButton() {
@Composable
private fun MusicBrainzButton(onClick: () -> Unit) {
IconButton(onClick = onClick, modifier = Modifier
.clip(RoundedCornerShape(4.dp))
.background(Color(0xFF353070))
.width(140.dp)
.height(30.dp)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ fun ListensScreen(
item {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(top = 30.dp)
.background(ListenBrainzTheme.colorScheme.songsListenedToBG)
) {
Expand Down Expand Up @@ -421,8 +422,8 @@ private fun BuildSimilarArtists(similarArtists: List<Artist>, onArtistClick: (St
similarArtists.isEmpty() -> {
Text(
"You have no common artists",
color = white,
modifier = Modifier.padding(horizontal = 16.dp),
color = ListenBrainzTheme.colorScheme.text,
modifier = Modifier.padding(start = 16.dp, bottom = 8.dp),
style = MaterialTheme.typography.bodyMedium
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.listenbrainz.android.ui.screens.profile.TasteTabUIState
import org.listenbrainz.android.ui.screens.profile.stats.StatsRange
import org.listenbrainz.android.ui.screens.profile.stats.UserGlobal
import org.listenbrainz.android.util.Constants.Strings.STATUS_LOGGED_OUT
import org.listenbrainz.android.util.Resource
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -70,14 +71,22 @@ class UserViewModel @Inject constructor(
fun followUser(username: String?){
if(username.isNullOrEmpty()) return
viewModelScope.launch (ioDispatcher) {
socialRepository.followUser(username)
listenStateFlow.value = listenStateFlow.value.copy(isFollowing = true)
val result = socialRepository.followUser(username)
if (result.status == Resource.Status.FAILED) {
listenStateFlow.value = listenStateFlow.value.copy(isFollowing = false)
}
}
}

fun unfollowUser(username: String?){
if(username.isNullOrEmpty()) return
viewModelScope.launch(ioDispatcher) {
socialRepository.unfollowUser(username)
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)
}
}

}
Expand Down

0 comments on commit 61ca751

Please sign in to comment.