mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-27 22:46:22 +02:00
Implements a faster AuthorGallery for notifications
This commit is contained in:
@@ -26,11 +26,15 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.compositeOver
|
import androidx.compose.ui.graphics.compositeOver
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.google.accompanist.flowlayout.FlowRow
|
import com.google.accompanist.flowlayout.FlowRow
|
||||||
import com.vitorpamplona.amethyst.NotificationCache
|
import com.vitorpamplona.amethyst.NotificationCache
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
||||||
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
import com.vitorpamplona.amethyst.ui.screen.MultiSetCard
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
@@ -114,18 +118,7 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(start = 10.dp)) {
|
AuthorGallery(multiSetCard.zapEvents.keys, navController, account)
|
||||||
FlowRow() {
|
|
||||||
multiSetCard.zapEvents.forEach {
|
|
||||||
NoteAuthorPicture(
|
|
||||||
note = it.key,
|
|
||||||
navController = navController,
|
|
||||||
userAccount = account.userProfile(),
|
|
||||||
size = 35.dp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,18 +139,7 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(start = 10.dp)) {
|
AuthorGallery(multiSetCard.boostEvents, navController, account)
|
||||||
FlowRow() {
|
|
||||||
multiSetCard.boostEvents.forEach {
|
|
||||||
NoteAuthorPicture(
|
|
||||||
note = it,
|
|
||||||
navController = navController,
|
|
||||||
userAccount = account.userProfile(),
|
|
||||||
size = 35.dp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,18 +160,7 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(start = 10.dp)) {
|
AuthorGallery(multiSetCard.likeEvents, navController, account)
|
||||||
FlowRow() {
|
|
||||||
multiSetCard.likeEvents.forEach {
|
|
||||||
NoteAuthorPicture(
|
|
||||||
note = it,
|
|
||||||
navController = navController,
|
|
||||||
userAccount = account.userProfile(),
|
|
||||||
size = 35.dp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,3 +189,54 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AuthorGallery(
|
||||||
|
authorNotes: Collection<Note>,
|
||||||
|
navController: NavController,
|
||||||
|
account: Account
|
||||||
|
) {
|
||||||
|
val accountState by account.userProfile().live().follows.observeAsState()
|
||||||
|
val accountUser = accountState?.user ?: return
|
||||||
|
|
||||||
|
Column(modifier = Modifier.padding(start = 10.dp)) {
|
||||||
|
FlowRow() {
|
||||||
|
authorNotes.forEach {
|
||||||
|
FastNoteAuthorPicture(
|
||||||
|
note = it,
|
||||||
|
navController = navController,
|
||||||
|
userAccount = accountUser,
|
||||||
|
size = 35.dp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FastNoteAuthorPicture(
|
||||||
|
note: Note,
|
||||||
|
navController: NavController,
|
||||||
|
userAccount: User,
|
||||||
|
size: Dp,
|
||||||
|
pictureModifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
// can't be null if here
|
||||||
|
val author = note.author ?: return
|
||||||
|
|
||||||
|
val userState by author.live().metadata.observeAsState()
|
||||||
|
val user = userState?.user ?: return
|
||||||
|
|
||||||
|
val showFollowingMark = userAccount.isFollowingCached(user) || user == userAccount
|
||||||
|
|
||||||
|
UserPicture(
|
||||||
|
userHex = user.pubkeyHex,
|
||||||
|
userPicture = user.profilePicture(),
|
||||||
|
showFollowingMark = showFollowingMark,
|
||||||
|
size = size,
|
||||||
|
modifier = pictureModifier,
|
||||||
|
onClick = {
|
||||||
|
navController.navigate("User/${user.pubkeyHex}")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
@@ -720,14 +720,49 @@ fun UserPicture(
|
|||||||
val userState by baseUser.live().metadata.observeAsState()
|
val userState by baseUser.live().metadata.observeAsState()
|
||||||
val user = userState?.user ?: return
|
val user = userState?.user ?: return
|
||||||
|
|
||||||
|
val accountState by baseUserAccount.live().follows.observeAsState()
|
||||||
|
val accountUser = accountState?.user ?: return
|
||||||
|
|
||||||
|
val showFollowingMark = accountUser.isFollowingCached(user) || user == accountUser
|
||||||
|
|
||||||
|
UserPicture(
|
||||||
|
userHex = user.pubkeyHex,
|
||||||
|
userPicture = user.profilePicture(),
|
||||||
|
showFollowingMark = showFollowingMark,
|
||||||
|
size = size,
|
||||||
|
modifier = modifier,
|
||||||
|
onClick = {
|
||||||
|
if (onClick != null) {
|
||||||
|
onClick(user)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongClick = {
|
||||||
|
if (onLongClick != null) {
|
||||||
|
onLongClick(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun UserPicture(
|
||||||
|
userHex: String,
|
||||||
|
userPicture: String?,
|
||||||
|
showFollowingMark: Boolean,
|
||||||
|
size: Dp,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onClick: (() -> Unit)? = null,
|
||||||
|
onLongClick: (() -> Unit)? = null
|
||||||
|
) {
|
||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
.width(size)
|
.width(size)
|
||||||
.height(size)
|
.height(size)
|
||||||
) {
|
) {
|
||||||
RobohashAsyncImageProxy(
|
RobohashAsyncImageProxy(
|
||||||
robot = user.pubkeyHex,
|
robot = userHex,
|
||||||
model = ResizeImage(user.profilePicture(), size),
|
model = ResizeImage(userPicture, size),
|
||||||
contentDescription = stringResource(id = R.string.profile_image),
|
contentDescription = stringResource(id = R.string.profile_image),
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.width(size)
|
.width(size)
|
||||||
@@ -736,9 +771,9 @@ fun UserPicture(
|
|||||||
.background(MaterialTheme.colors.background)
|
.background(MaterialTheme.colors.background)
|
||||||
.run {
|
.run {
|
||||||
if (onClick != null && onLongClick != null) {
|
if (onClick != null && onLongClick != null) {
|
||||||
this.combinedClickable(onClick = { onClick(user) }, onLongClick = { onLongClick(user) })
|
this.combinedClickable(onClick = onClick, onLongClick = onLongClick)
|
||||||
} else if (onClick != null) {
|
} else if (onClick != null) {
|
||||||
this.clickable(onClick = { onClick(user) })
|
this.clickable(onClick = onClick)
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
@@ -746,10 +781,7 @@ fun UserPicture(
|
|||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val accountState by baseUserAccount.live().follows.observeAsState()
|
if (showFollowingMark) {
|
||||||
val accountUser = accountState?.user ?: return
|
|
||||||
|
|
||||||
if (accountUser.isFollowingCached(user) || user == accountUser) {
|
|
||||||
Box(
|
Box(
|
||||||
Modifier
|
Modifier
|
||||||
.width(size.div(3.5f))
|
.width(size.div(3.5f))
|
||||||
|
Reference in New Issue
Block a user