-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3fa4c1
commit 05a456b
Showing
16 changed files
with
333 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 15 additions & 105 deletions
120
app/src/main/kotlin/app/fyreplace/fyreplace/ui/screens/SettingsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 27 additions & 16 deletions
43
app/src/main/kotlin/app/fyreplace/fyreplace/ui/views/Avatar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,58 @@ | ||
package app.fyreplace.fyreplace.ui.views | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.twotone.AccountCircle | ||
import androidx.compose.material.icons.filled.AccountCircle | ||
import androidx.compose.material.icons.twotone.Error | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.draw.scale | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.vector.rememberVectorPainter | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import app.fyreplace.api.data.User | ||
import app.fyreplace.fyreplace.R | ||
import app.fyreplace.fyreplace.extensions.composeColor | ||
import app.fyreplace.fyreplace.fakes.placeholder | ||
import coil.compose.AsyncImage | ||
|
||
@Composable | ||
fun Avatar( | ||
user: User?, | ||
tinted: Boolean, | ||
modifier: Modifier = Modifier, | ||
size: Dp | ||
) { | ||
val fallback = rememberVectorPainter(Icons.TwoTone.AccountCircle) | ||
fun Avatar(user: User?, modifier: Modifier = Modifier) { | ||
val fallback = rememberVectorPainter(Icons.Filled.AccountCircle) | ||
val error = rememberVectorPainter(Icons.TwoTone.Error) | ||
val hasAvatar = !user?.avatar.isNullOrEmpty() | ||
AsyncImage( | ||
model = if (hasAvatar) user?.avatar else null, | ||
model = if (hasAvatar) user.avatar else null, | ||
placeholder = fallback, | ||
error = error, | ||
fallback = fallback, | ||
contentDescription = user?.username, | ||
contentScale = ContentScale.Crop, | ||
colorFilter = when { | ||
!tinted || hasAvatar || user == null -> null | ||
else -> ColorFilter.tint(user.tint.composeColor) | ||
hasAvatar -> null | ||
user != null -> ColorFilter.tint(user.tint.composeColor) | ||
else -> ColorFilter.tint(MaterialTheme.colorScheme.onBackground) | ||
}, | ||
modifier = Modifier | ||
.size(size) | ||
.scale(if (hasAvatar) 1f else 1.2f) | ||
modifier = modifier | ||
.clip(CircleShape) | ||
.then(modifier) | ||
.scale(if (hasAvatar) 1f else 1.2f) | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun AvatarPreview() { | ||
Avatar( | ||
user = User.placeholder, | ||
modifier = Modifier | ||
.padding(dimensionResource(R.dimen.spacing_medium)) | ||
.size(128.dp) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.