-
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.
Added all the client-side implementations, with no support for image …
…avatars yet
- Loading branch information
1 parent
b361470
commit 8e8b9bc
Showing
6 changed files
with
199 additions
and
68 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
57 changes: 57 additions & 0 deletions
57
minchat-client/src/main/kotlin/io/minchat/client/ui/chat/UserAvatarElement.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.minchat.client.ui.chat | ||
|
||
import arc.Core | ||
import arc.scene.style.TextureRegionDrawable | ||
import io.minchat.client.Minchat | ||
import io.minchat.client.ui.AsyncImage | ||
import io.minchat.common.entity.User | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
class UserAvatarElement( | ||
userId: Long, | ||
avatar: User.Avatar?, | ||
val full: Boolean, | ||
parentScope: CoroutineScope | ||
) : AsyncImage(parentScope) { | ||
var userId = userId | ||
set(value) { | ||
field = value | ||
updateAvatar() | ||
} | ||
var avatar = avatar | ||
set(value) { | ||
field = value | ||
updateAvatar() | ||
} | ||
|
||
init { | ||
updateAvatar() | ||
} | ||
|
||
fun updateAvatar() { | ||
val avatar = avatar ?: User.Avatar.defaultAvatar | ||
when (avatar) { | ||
is User.Avatar.IconAvatar -> { | ||
setDrawableAsync(avatar.iconName) { | ||
val region = Core.atlas.find(avatar.iconName).takeIf { Core.atlas.isFound(it) } | ||
?: error("No region found for icon avatar ${avatar.iconName}!") | ||
|
||
TextureRegionDrawable(region) | ||
} | ||
} | ||
|
||
is User.Avatar.ImageAvatar, is User.Avatar.LocalAvatar -> { | ||
setFileAsync { | ||
Minchat.client.getCacheableAvatar(userId, avatar, full) {} | ||
?: error("No avatar found for user ${userId} and avatar ${avatar}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun CoroutineScope.UserAvatarElement( | ||
userId: Long, | ||
avatar: User.Avatar?, | ||
full: Boolean | ||
) = UserAvatarElement(userId, avatar, full, this) |
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