Skip to content

Commit

Permalink
Show thumbnail as background in chat stream info panel
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed May 19, 2024
1 parent d34d552 commit 9e521da
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class StreamInfo(
val title: String,
val author: String,
val shortDescription: String,
val thumbnail: String?,
val isLive: Boolean,
val chatContinuation: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class StreamService @Inject constructor(
title = stream.title,
author = stream.channel.name,
shortDescription = stream.description,
thumbnail = stream.thumbnail,
isLive = stream.isLive,
chatContinuation = chatContinuation,
)
Expand All @@ -43,6 +44,7 @@ class StreamService @Inject constructor(
title = "",
author = "",
shortDescription = "",
thumbnail = null,
isLive = false,
chatContinuation = getChatContinuation(videoId),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.livetl.android.ui.common

import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.blur
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest

@Composable
fun BoxScope.StreamThumbnailBackground(thumbnail: String, modifier: Modifier = Modifier) {
val context = LocalContext.current

AsyncImage(
model = ImageRequest.Builder(context)
.data(thumbnail)
.transformations()
.crossfade(true)
.build(),
contentDescription = null,
modifier = modifier
.matchParentSize()
.alpha(0.1f)
.blur(5.dp),
contentScale = ContentScale.Crop,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.blur
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.livetl.android.R
import com.livetl.android.data.feed.Channel
import com.livetl.android.data.feed.Stream
import com.livetl.android.ui.common.StreamThumbnailBackground
import com.livetl.android.util.escapeHtmlEntities
import com.livetl.android.util.toDate
import com.livetl.android.util.toRelativeString
Expand All @@ -58,19 +55,7 @@ fun Stream(
.fillMaxWidth()
.height(IntrinsicSize.Min),
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(stream.thumbnail)
.transformations()
.crossfade(true)
.build(),
contentDescription = null,
modifier = Modifier
.matchParentSize()
.alpha(0.1f)
.blur(5.dp),
contentScale = ContentScale.Crop,
)
StreamThumbnailBackground(stream.thumbnail)

Row(
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ fun SettingsScreen(onBackPressed: () -> Unit, viewModel: SettingsViewModel = hil
val selectOrganization = { viewModel.prefs.feedOrganization().set(organization) }

Row(
modifier =
Modifier
modifier = Modifier
.requiredHeight(48.dp)
.fillMaxWidth()
.clickable { selectOrganization() },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
package com.livetl.android.ui.screen.player.composable

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.livetl.android.data.stream.StreamInfo
import com.livetl.android.ui.common.LoadingIndicator
import com.livetl.android.ui.common.StreamThumbnailBackground

@Composable
fun StreamInfoPanel(streamInfo: StreamInfo?, modifier: Modifier = Modifier) {
Column(
modifier = modifier.padding(8.dp),
if (streamInfo == null) {
LoadingIndicator()
return
}

Box(
modifier = Modifier
.fillMaxWidth(),
) {
if (streamInfo == null) {
LoadingIndicator()
return
streamInfo.thumbnail?.let {
StreamThumbnailBackground(streamInfo.thumbnail)
}

Text(
text = streamInfo.title,
style = MaterialTheme.typography.headlineSmall,
)
Spacer(modifier = Modifier.requiredHeight(8.dp))
Text(
text = streamInfo.author,
style = MaterialTheme.typography.bodyMedium,
)
Column(
modifier = modifier.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = streamInfo.title,
style = MaterialTheme.typography.titleLarge,
)

Text(
text = streamInfo.author,
style = MaterialTheme.typography.bodyMedium,
)
}
}
}

0 comments on commit 9e521da

Please sign in to comment.