-
Notifications
You must be signed in to change notification settings - Fork 25
[Idea Plugin] Add contributors section to About screen #1012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
...n/io/github/composegears/valkyrie/ui/screen/settings/tabs/about/AboutSettingsViewModel.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package io.github.composegears.valkyrie.ui.screen.settings.tabs.about | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.composegears.leviathan.compose.inject | ||
| import io.github.composegears.valkyrie.ui.screen.settings.tabs.about.domain.AvatarByteArray | ||
| import io.github.composegears.valkyrie.ui.screen.settings.tabs.about.domain.ContributorUiModel | ||
| import io.github.composegears.valkyrie.ui.screen.webimport.common.di.NetworkModule | ||
| import io.github.composegears.valkyrie.util.result.runCatchingCancellable | ||
| import io.ktor.client.request.get | ||
| import io.ktor.client.statement.bodyAsBytes | ||
| import kotlinx.coroutines.async | ||
| import kotlinx.coroutines.awaitAll | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| class AboutSettingsViewModel : ViewModel() { | ||
|
|
||
| private val httpClient = inject(NetworkModule.httpClient) | ||
|
|
||
| private val _contributors = MutableStateFlow(initialContributors()) | ||
| val contributors = _contributors.asStateFlow() | ||
|
|
||
| init { | ||
| loadAvatars() | ||
| } | ||
|
|
||
| private fun loadAvatars() { | ||
| viewModelScope.launch { | ||
| val updated = _contributors.value.map { contributor -> | ||
| async { | ||
| val bytes = runCatchingCancellable { | ||
| AvatarByteArray(httpClient.get(contributor.avatarUrl).bodyAsBytes()) | ||
| }.getOrNull() | ||
| contributor.copy(avatarBytes = bytes) | ||
| } | ||
| }.awaitAll() | ||
| _contributors.value = updated | ||
| } | ||
| } | ||
|
|
||
| private fun initialContributors(): List<ContributorUiModel> = listOf( | ||
| ContributorUiModel( | ||
| login = "egorikftp", | ||
| description = "Project creator & core maintainer", | ||
| profileUrl = "https://github.com/egorikftp", | ||
| avatarUrl = "https://github.com/egorikftp.png", | ||
| ), | ||
| ContributorUiModel( | ||
| login = "t-regbs", | ||
| description = "Web import & Figma plugin development, ImageVector to XML conversion, KMP tuning", | ||
| profileUrl = "https://github.com/t-regbs", | ||
| avatarUrl = "https://github.com/t-regbs.png", | ||
| ), | ||
| ContributorUiModel( | ||
| login = "Goooler", | ||
| description = "Build tooling, test infrastructure & dependency management", | ||
| profileUrl = "https://github.com/Goooler", | ||
| avatarUrl = "https://github.com/Goooler.png", | ||
| ), | ||
| ContributorUiModel( | ||
| login = "LennartEgb", | ||
| description = "KMP generator & parser modules, IR restructuring & Compose colors handling", | ||
| profileUrl = "https://github.com/LennartEgb", | ||
| avatarUrl = "https://github.com/LennartEgb.png", | ||
| ), | ||
| ContributorUiModel( | ||
| login = "vkatz", | ||
| description = "Fuzzy search, plugin state persistence & technical support", | ||
| profileUrl = "https://github.com/vkatz", | ||
| avatarUrl = "https://github.com/vkatz.png", | ||
| ), | ||
| ContributorUiModel( | ||
| login = "jonapoul", | ||
| description = "Initial Gradle plugin implementation", | ||
| profileUrl = "https://github.com/jonapoul", | ||
| avatarUrl = "https://github.com/jonapoul.png", | ||
| ), | ||
| ) | ||
| } |
7 changes: 7 additions & 0 deletions
7
...n/io/github/composegears/valkyrie/ui/screen/settings/tabs/about/domain/AvatarByteArray.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package io.github.composegears.valkyrie.ui.screen.settings.tabs.about.domain | ||
|
|
||
| import androidx.compose.runtime.Stable | ||
|
|
||
| @Stable | ||
| @JvmInline | ||
| value class AvatarByteArray(val bytes: ByteArray) | ||
9 changes: 9 additions & 0 deletions
9
...o/github/composegears/valkyrie/ui/screen/settings/tabs/about/domain/ContributorUiModel.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package io.github.composegears.valkyrie.ui.screen.settings.tabs.about.domain | ||
|
|
||
| data class ContributorUiModel( | ||
| val login: String, | ||
| val description: String, | ||
| val profileUrl: String, | ||
| val avatarUrl: String, | ||
| val avatarBytes: AvatarByteArray? = null, | ||
| ) |
73 changes: 73 additions & 0 deletions
73
...otlin/io/github/composegears/valkyrie/ui/screen/settings/tabs/about/ui/ContributorItem.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package io.github.composegears.valkyrie.ui.screen.settings.tabs.about.ui | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.foundation.shape.CircleShape | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.graphics.ImageBitmap | ||
| import androidx.compose.ui.graphics.painter.BitmapPainter | ||
| import androidx.compose.ui.graphics.toComposeImageBitmap | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.unit.dp | ||
| import io.github.composegears.valkyrie.sdk.compose.foundation.animation.Shimmer | ||
| import io.github.composegears.valkyrie.sdk.compose.foundation.animation.shimmer | ||
| import io.github.composegears.valkyrie.ui.screen.settings.tabs.about.domain.ContributorUiModel | ||
| import java.io.ByteArrayInputStream | ||
| import javax.imageio.ImageIO | ||
| import org.jetbrains.jewel.foundation.theme.JewelTheme | ||
| import org.jetbrains.jewel.ui.component.ExternalLink | ||
| import org.jetbrains.jewel.ui.component.Text | ||
| import org.jetbrains.jewel.ui.typography | ||
|
|
||
| @Composable | ||
| fun ContributorItem( | ||
| contributor: ContributorUiModel, | ||
| shimmer: Shimmer, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| val bitmap: ImageBitmap? = remember(contributor.avatarBytes) { | ||
| contributor.avatarBytes?.let { avatar -> | ||
| runCatching { | ||
| ImageIO.read(ByteArrayInputStream(avatar.bytes)).toComposeImageBitmap() | ||
| }.getOrNull() | ||
| } | ||
| } | ||
|
|
||
| Column( | ||
| modifier = modifier.width(160.dp), | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| verticalArrangement = Arrangement.spacedBy(4.dp), | ||
| ) { | ||
| if (bitmap != null) { | ||
| Image( | ||
| modifier = Modifier.size(40.dp).clip(CircleShape), | ||
| painter = BitmapPainter(bitmap), | ||
| contentDescription = contributor.login, | ||
| ) | ||
| } else { | ||
| Spacer( | ||
| modifier = Modifier | ||
| .size(40.dp) | ||
| .clip(CircleShape) | ||
| .shimmer(shimmer = shimmer, cornerRadius = 20.dp), | ||
| ) | ||
| } | ||
| ExternalLink( | ||
| uri = contributor.profileUrl, | ||
| text = contributor.login, | ||
| ) | ||
| Text( | ||
| text = contributor.description, | ||
| style = JewelTheme.typography.small, | ||
| textAlign = TextAlign.Center, | ||
| ) | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...ugin/src/main/kotlin/io/github/composegears/valkyrie/util/result/RunCatchingCancelable.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package io.github.composegears.valkyrie.util.result | ||
|
|
||
| import kotlin.coroutines.cancellation.CancellationException | ||
|
|
||
| inline fun <R> runCatchingCancellable(block: () -> R): Result<R> { | ||
| return try { | ||
| Result.success(block()) | ||
| } catch (c: CancellationException) { | ||
| throw c | ||
| } catch (e: Throwable) { | ||
| Result.failure(e) | ||
| } | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.