Performance Improvements when rendering a channel creation note
This commit is contained in:
@@ -162,7 +162,7 @@ fun NoteCompose(
|
|||||||
val noteForReports = remember(noteReportsState) { noteReportsState?.note } ?: return
|
val noteForReports = remember(noteReportsState) { noteReportsState?.note } ?: return
|
||||||
|
|
||||||
val noteEvent = remember(noteState) { note.event }
|
val noteEvent = remember(noteState) { note.event }
|
||||||
val baseChannel = remember(noteState) { note.channel() }
|
val channelHex = remember(noteState) { note.channelHex() }
|
||||||
val isSensitive = remember(noteState) { note.event?.isSensitive() ?: false }
|
val isSensitive = remember(noteState) { note.event?.isSensitive() ?: false }
|
||||||
|
|
||||||
var popupExpanded by remember { mutableStateOf(false) }
|
var popupExpanded by remember { mutableStateOf(false) }
|
||||||
@@ -212,8 +212,8 @@ fun NoteCompose(
|
|||||||
nav,
|
nav,
|
||||||
onClick = { showHiddenNote = true }
|
onClick = { showHiddenNote = true }
|
||||||
)
|
)
|
||||||
} else if ((noteEvent is ChannelCreateEvent || noteEvent is ChannelMetadataEvent) && baseChannel != null) {
|
} else if ((noteEvent is ChannelCreateEvent || noteEvent is ChannelMetadataEvent) && channelHex != null) {
|
||||||
ChannelHeader(baseChannel = baseChannel, account = account, nav = nav)
|
ChannelHeader(channelHex = channelHex, account = account, nav = nav)
|
||||||
} else if (noteEvent is BadgeDefinitionEvent) {
|
} else if (noteEvent is BadgeDefinitionEvent) {
|
||||||
BadgeDisplay(baseNote = note)
|
BadgeDisplay(baseNote = note)
|
||||||
} else if (noteEvent is FileHeaderEvent) {
|
} else if (noteEvent is FileHeaderEvent) {
|
||||||
@@ -581,14 +581,15 @@ private fun RenderPrivateMessage(
|
|||||||
val noteEvent = note.event as? PrivateDmEvent ?: return
|
val noteEvent = note.event as? PrivateDmEvent ?: return
|
||||||
|
|
||||||
val withMe = remember { noteEvent.with(accountViewModel.userProfile().pubkeyHex) }
|
val withMe = remember { noteEvent.with(accountViewModel.userProfile().pubkeyHex) }
|
||||||
val tags = remember(note.event?.id()) { note.event?.tags() }
|
|
||||||
val hashtags = remember(note.event?.id()) { note.event?.hashtags() ?: emptyList() }
|
|
||||||
val modifier = remember(note.event?.id()) { Modifier.fillMaxWidth() }
|
|
||||||
val isAuthorTheLoggedUser = remember(note.event?.id()) { accountViewModel.isLoggedUser(note.author) }
|
|
||||||
|
|
||||||
if (withMe) {
|
if (withMe) {
|
||||||
val eventContent = remember { accountViewModel.decrypt(note) }
|
val eventContent = remember { accountViewModel.decrypt(note) }
|
||||||
|
|
||||||
|
val hashtags = remember(note.event?.id()) { note.event?.hashtags() ?: emptyList() }
|
||||||
|
val modifier = remember(note.event?.id()) { Modifier.fillMaxWidth() }
|
||||||
|
val isAuthorTheLoggedUser = remember(note.event?.id()) { accountViewModel.isLoggedUser(note.author) }
|
||||||
|
val tags = remember(note.event?.id()) { note.event?.tags() }
|
||||||
|
|
||||||
if (eventContent != null) {
|
if (eventContent != null) {
|
||||||
if (makeItShort && isAuthorTheLoggedUser) {
|
if (makeItShort && isAuthorTheLoggedUser) {
|
||||||
Text(
|
Text(
|
||||||
@@ -628,7 +629,7 @@ private fun RenderPrivateMessage(
|
|||||||
),
|
),
|
||||||
canPreview = !makeItShort,
|
canPreview = !makeItShort,
|
||||||
Modifier.fillMaxWidth(),
|
Modifier.fillMaxWidth(),
|
||||||
noteEvent.tags(),
|
emptyList(),
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav
|
nav
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -63,6 +64,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.Channel
|
import com.vitorpamplona.amethyst.model.Channel
|
||||||
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
|
||||||
import com.vitorpamplona.amethyst.ui.actions.NewChannelView
|
import com.vitorpamplona.amethyst.ui.actions.NewChannelView
|
||||||
@@ -77,6 +79,8 @@ import com.vitorpamplona.amethyst.ui.navigation.Route
|
|||||||
import com.vitorpamplona.amethyst.ui.note.ChatroomMessageCompose
|
import com.vitorpamplona.amethyst.ui.note.ChatroomMessageCompose
|
||||||
import com.vitorpamplona.amethyst.ui.screen.ChatroomFeedView
|
import com.vitorpamplona.amethyst.ui.screen.ChatroomFeedView
|
||||||
import com.vitorpamplona.amethyst.ui.screen.NostrChannelFeedViewModel
|
import com.vitorpamplona.amethyst.ui.screen.NostrChannelFeedViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChannelScreen(
|
fun ChannelScreen(
|
||||||
@@ -158,7 +162,12 @@ fun ChannelScreen(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(10.dp))
|
Spacer(modifier = Modifier.height(10.dp))
|
||||||
|
|
||||||
Row(Modifier.padding(horizontal = 10.dp).animateContentSize(), verticalAlignment = Alignment.CenterVertically) {
|
Row(
|
||||||
|
Modifier
|
||||||
|
.padding(horizontal = 10.dp)
|
||||||
|
.animateContentSize(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
val replyingNote = replyTo.value
|
val replyingNote = replyTo.value
|
||||||
if (replyingNote != null) {
|
if (replyingNote != null) {
|
||||||
Column(Modifier.weight(1f)) {
|
Column(Modifier.weight(1f)) {
|
||||||
@@ -182,7 +191,9 @@ fun ChannelScreen(
|
|||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Cancel,
|
imageVector = Icons.Default.Cancel,
|
||||||
null,
|
null,
|
||||||
modifier = Modifier.padding(end = 5.dp).size(30.dp),
|
modifier = Modifier
|
||||||
|
.padding(end = 5.dp)
|
||||||
|
.size(30.dp),
|
||||||
tint = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
tint = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -192,7 +203,9 @@ fun ChannelScreen(
|
|||||||
|
|
||||||
// LAST ROW
|
// LAST ROW
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp, bottom = 10.dp, top = 5.dp).fillMaxWidth(),
|
modifier = Modifier
|
||||||
|
.padding(start = 10.dp, end = 10.dp, bottom = 10.dp, top = 5.dp)
|
||||||
|
.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
@@ -246,10 +259,26 @@ fun ChannelScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ChannelHeader(channelHex: String, account: Account, nav: (String) -> Unit) {
|
||||||
|
var baseChannel by remember { mutableStateOf<Channel?>(null) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
LaunchedEffect(key1 = channelHex) {
|
||||||
|
scope.launch(Dispatchers.IO) {
|
||||||
|
baseChannel = LocalCache.checkGetOrCreateChannel(channelHex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
baseChannel?.let {
|
||||||
|
ChannelHeader(it, account, nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChannelHeader(baseChannel: Channel, account: Account, nav: (String) -> Unit) {
|
fun ChannelHeader(baseChannel: Channel, account: Account, nav: (String) -> Unit) {
|
||||||
val channelState by baseChannel.live.observeAsState()
|
val channelState by baseChannel.live.observeAsState()
|
||||||
val channel = channelState?.channel ?: return
|
val channel = remember(channelState) { channelState?.channel } ?: return
|
||||||
|
|
||||||
val context = LocalContext.current.applicationContext
|
val context = LocalContext.current.applicationContext
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user