Moving channels to the local version of RoboHash

This commit is contained in:
Vitor Pamplona 2023-02-10 17:29:10 -05:00
parent e6153e7ef5
commit 8a65f3fbe7
6 changed files with 39 additions and 22 deletions

View File

@ -34,9 +34,9 @@ class Channel(val id: ByteArray) {
live.refresh()
}
fun profilePicture(): String {
fun profilePicture(): String? {
if (info.picture.isNullOrBlank()) info.picture = null
return info.picture ?: "https://robohash.org/${idHex}.png"
return info.picture
}
fun anyNameStartsWith(prefix: String): Boolean {

View File

@ -40,6 +40,7 @@ import coil.compose.AsyncImage
import coil.compose.rememberAsyncImagePainter
import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.NotificationCache
import com.vitorpamplona.amethyst.RoboHashCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
@ -85,7 +86,7 @@ fun ChatroomCompose(baseNote: Note, accountViewModel: AccountViewModel, navContr
ChannelName(
channelPicture = channel.profilePicture(),
channelPicturePlaceholder = null,
channelPicturePlaceholder = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
channelTitle = {
Text(
"${channel.info.name}",
@ -138,7 +139,7 @@ fun ChatroomCompose(baseNote: Note, accountViewModel: AccountViewModel, navContr
@Composable
fun ChannelName(
channelPicture: String,
channelPicture: String?,
channelPicturePlaceholder: Painter?,
channelTitle: @Composable (Modifier) -> Unit,
channelLastTime: Long?,
@ -151,6 +152,8 @@ fun ChannelName(
AsyncImage(
model = channelPicture,
placeholder = channelPicturePlaceholder,
fallback = channelPicturePlaceholder,
error = channelPicturePlaceholder,
contentDescription = "Channel Image",
modifier = Modifier
.width(55.dp)

View File

@ -191,7 +191,9 @@ fun NoteCompose(
.align(Alignment.BottomEnd)) {
AsyncImage(
model = channel.profilePicture(),
placeholder = null,
placeholder = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
fallback = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
error = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
contentDescription = "Group Picture",
modifier = Modifier
.width(30.dp)

View File

@ -55,6 +55,7 @@ import androidx.navigation.NavController
import coil.compose.AsyncImage
import coil.compose.rememberAsyncImagePainter
import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.RoboHashCache
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.Note
@ -147,15 +148,19 @@ fun ChannelScreen(channelId: String?, accountViewModel: AccountViewModel, accoun
@Composable
fun ChannelHeader(baseChannel: Channel, account: Account, accountStateViewModel: AccountStateViewModel, navController: NavController) {
val channelState by baseChannel.live.observeAsState()
val channel = channelState?.channel
val channel = channelState?.channel ?: return
val context = LocalContext.current.applicationContext
Column() {
Column(modifier = Modifier.padding(12.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
AsyncImage(
model = channel?.profilePicture(),
placeholder = null,
model = channel.profilePicture(),
placeholder = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
fallback = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
error = rememberAsyncImagePainter(RoboHashCache.get(context, channel.idHex)),
contentDescription = "Profile Image",
modifier = Modifier
.width(35.dp)
@ -168,14 +173,14 @@ fun ChannelHeader(baseChannel: Channel, account: Account, accountStateViewModel:
.weight(1f)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
"${channel?.info?.name}",
"${channel.info.name}",
fontWeight = FontWeight.Bold,
)
}
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
"${channel?.info?.about}",
"${channel.info.about}",
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
maxLines = 2,
overflow = TextOverflow.Ellipsis,
@ -185,19 +190,18 @@ fun ChannelHeader(baseChannel: Channel, account: Account, accountStateViewModel:
}
Row(modifier = Modifier.height(35.dp).padding(bottom = 3.dp)) {
channel?.let { NoteCopyButton(it) }
NoteCopyButton(channel)
channel?.let {
if (channel.creator == account.userProfile()) {
EditButton(account, it)
}
if (account.followingChannels.contains(channel.idHex)) {
LeaveButton(account, channel, navController)
} else {
JoinButton(account, channel, navController)
}
if (channel.creator == account.userProfile()) {
EditButton(account, channel)
}
if (account.followingChannels.contains(channel.idHex)) {
LeaveButton(account, channel, navController)
} else {
JoinButton(account, channel, navController)
}
}
}
}

View File

@ -24,10 +24,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.TextFieldValue
@ -38,6 +40,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import coil.compose.AsyncImage
import coil.compose.rememberAsyncImagePainter
import com.vitorpamplona.amethyst.RoboHashCache
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.NostrChatRoomDataSource
import com.vitorpamplona.amethyst.ui.actions.PostButton

View File

@ -36,6 +36,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardCapitalization
@ -43,7 +44,9 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import coil.compose.rememberAsyncImagePainter
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.RoboHashCache
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.LocalCache
@ -95,6 +98,8 @@ private fun SearchBar(accountViewModel: AccountViewModel, navController: NavCont
val onlineSearch = NostrSearchEventOrUserDataSource
val ctx = LocalContext.current.applicationContext
val isTrailingIconVisible by remember {
derivedStateOf {
searchValue.isNotBlank()
@ -210,7 +215,7 @@ private fun SearchBar(accountViewModel: AccountViewModel, navController: NavCont
itemsIndexed(searchResultsChannels.value, key = { _, item -> "c"+item.idHex }) { index, item ->
ChannelName(
channelPicture = item.profilePicture(),
channelPicturePlaceholder = null,
channelPicturePlaceholder = rememberAsyncImagePainter(RoboHashCache.get(ctx, item.idHex)),
channelTitle = {
Text(
"${item.info.name}",