Improves rendering time of the Channel header
This commit is contained in:
@@ -517,11 +517,10 @@ fun ChannelHeader(
|
|||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
var baseChannel by remember { mutableStateOf<Channel?>(LocalCache.channels[channelHex]) }
|
var baseChannel by remember { mutableStateOf<Channel?>(LocalCache.channels[channelHex]) }
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
if (baseChannel == null) {
|
if (baseChannel == null) {
|
||||||
LaunchedEffect(key1 = channelHex) {
|
LaunchedEffect(key1 = channelHex) {
|
||||||
scope.launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
baseChannel = LocalCache.checkGetOrCreateChannel(channelHex)
|
baseChannel = LocalCache.checkGetOrCreateChannel(channelHex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -548,30 +547,26 @@ fun ChannelHeader(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val channelState by baseChannel.live.observeAsState()
|
|
||||||
val channel = remember(channelState) { channelState?.channel } ?: return
|
|
||||||
|
|
||||||
val context = LocalContext.current.applicationContext
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
Modifier.clickable {
|
Modifier.fillMaxWidth().clickable {
|
||||||
nav("Channel/${baseChannel.idHex}")
|
nav("Channel/${baseChannel.idHex}")
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (channel is LiveActivitiesChannel) {
|
val channelState by baseChannel.live.observeAsState()
|
||||||
val streamingUrl by remember(channelState) {
|
val channel = remember(channelState) { channelState?.channel } ?: return
|
||||||
derivedStateOf {
|
|
||||||
channel.info?.streaming()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (streamingUrl != null && showVideo) {
|
val streamingUrl by remember(channelState) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.heightIn(max = 300.dp)) {
|
derivedStateOf {
|
||||||
VideoView(
|
(channel as? LiveActivitiesChannel)?.info?.streaming()
|
||||||
videoUri = streamingUrl!!,
|
}
|
||||||
description = null
|
}
|
||||||
)
|
|
||||||
}
|
if (streamingUrl != null && showVideo) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically, modifier = remember { Modifier.heightIn(max = 300.dp) }) {
|
||||||
|
VideoView(
|
||||||
|
videoUri = streamingUrl!!,
|
||||||
|
description = null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,7 +575,7 @@ fun ChannelHeader(
|
|||||||
RobohashAsyncImageProxy(
|
RobohashAsyncImageProxy(
|
||||||
robot = channel.idHex,
|
robot = channel.idHex,
|
||||||
model = channel.profilePicture(),
|
model = channel.profilePicture(),
|
||||||
contentDescription = context.getString(R.string.profile_image),
|
contentDescription = stringResource(R.string.profile_image),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(Size35dp)
|
.width(Size35dp)
|
||||||
.height(Size35dp)
|
.height(Size35dp)
|
||||||
@@ -681,35 +676,25 @@ private fun LiveChannelActionOptions(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val isMe by remember(accountViewModel) {
|
|
||||||
derivedStateOf {
|
|
||||||
channel.creator == accountViewModel.account.userProfile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val isLive by remember(channel) {
|
val isLive by remember(channel) {
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
channel.info?.status() == "live"
|
channel.info?.status() == "live"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMe) {
|
val note = remember(channel.idHex) {
|
||||||
// EditButton(accountViewModel, channel)
|
LocalCache.getNoteIfExists(channel.idHex)
|
||||||
} else {
|
}
|
||||||
val note = remember(channel.idHex) {
|
|
||||||
LocalCache.getNoteIfExists(channel.idHex)
|
|
||||||
}
|
|
||||||
|
|
||||||
note?.let {
|
note?.let {
|
||||||
if (isLive) {
|
if (isLive) {
|
||||||
LiveFlag()
|
LiveFlag()
|
||||||
Spacer(modifier = StdHorzSpacer)
|
|
||||||
}
|
|
||||||
|
|
||||||
LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
|
|
||||||
Spacer(modifier = StdHorzSpacer)
|
Spacer(modifier = StdHorzSpacer)
|
||||||
ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LikeReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
|
||||||
|
Spacer(modifier = StdHorzSpacer)
|
||||||
|
ZapReaction(baseNote = it, grayTint = MaterialTheme.colors.onSurface, accountViewModel = accountViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user