1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-06-27 15:43:07 +00:00

Merge pull request #12217 from SttApollo/Update-EmptyStateComposable

This commit is contained in:
Stypox 2025-06-06 15:49:13 +02:00 committed by GitHub
commit f16becc872
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 63 additions and 35 deletions

View File

@ -4,6 +4,7 @@ import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
@ -74,7 +75,12 @@ fun RelatedItems(info: StreamInfo) {
} }
if (info.relatedItems.isEmpty()) { if (info.relatedItems.isEmpty()) {
item { item {
EmptyStateComposable(EmptyStateSpec.NoVideos) EmptyStateComposable(
spec = EmptyStateSpec.NoVideos,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
)
} }
} }
} }

View File

@ -1,6 +1,8 @@
package org.schabi.newpipe.ui.components.video.comment package org.schabi.newpipe.ui.components.video.comment
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
@ -126,14 +128,22 @@ private fun CommentRepliesDialog(
} else if (refresh is LoadState.Error) { } else if (refresh is LoadState.Error) {
// TODO use error panel instead // TODO use error panel instead
EmptyStateComposable( EmptyStateComposable(
EmptyStateSpec.DisabledComments.copy( spec = EmptyStateSpec.DisabledComments.copy(
descriptionText = { descriptionText = {
stringResource(R.string.error_unable_to_load_comments) stringResource(R.string.error_unable_to_load_comments)
}, },
), ),
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
) )
} else { } else {
EmptyStateComposable(EmptyStateSpec.NoComments) EmptyStateComposable(
spec = EmptyStateSpec.NoComments,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
)
} }
} }
} else { } else {

View File

@ -1,6 +1,8 @@
package org.schabi.newpipe.ui.components.video.comment package org.schabi.newpipe.ui.components.video.comment
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
@ -68,11 +70,22 @@ private fun CommentSection(
if (commentInfo.isCommentsDisabled) { if (commentInfo.isCommentsDisabled) {
item { item {
EmptyStateComposable(EmptyStateSpec.DisabledComments) EmptyStateComposable(
spec = EmptyStateSpec.DisabledComments,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
)
} }
} else if (count == 0) { } else if (count == 0) {
item { item {
EmptyStateComposable(EmptyStateSpec.NoComments) EmptyStateComposable(
spec = EmptyStateSpec.NoComments,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
)
} }
} else { } else {
// do not show anything if the comment count is unknown // do not show anything if the comment count is unknown
@ -121,11 +134,14 @@ private fun CommentSection(
item { item {
// TODO use error panel instead // TODO use error panel instead
EmptyStateComposable( EmptyStateComposable(
EmptyStateSpec.DisabledComments.copy( spec = EmptyStateSpec.DisabledComments.copy(
descriptionText = { descriptionText = {
stringResource(R.string.error_unable_to_load_comments) stringResource(R.string.error_unable_to_load_comments)
} }
) ),
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
) )
} }
} }

View File

@ -3,7 +3,6 @@ package org.schabi.newpipe.ui.emptystate
import android.graphics.Color import android.graphics.Color
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
@ -24,9 +23,9 @@ fun EmptyStateComposable(
spec: EmptyStateSpec, spec: EmptyStateSpec,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) = EmptyStateComposable( ) = EmptyStateComposable(
modifier = spec.modifier(modifier),
emojiText = spec.emojiText(), emojiText = spec.emojiText(),
descriptionText = spec.descriptionText(), descriptionText = spec.descriptionText(),
modifier = modifier
) )
@Composable @Composable
@ -61,7 +60,12 @@ private fun EmptyStateComposable(
@Composable @Composable
fun EmptyStateComposableGenericErrorPreview() { fun EmptyStateComposableGenericErrorPreview() {
AppTheme { AppTheme {
EmptyStateComposable(EmptyStateSpec.GenericError) EmptyStateComposable(
spec = EmptyStateSpec.GenericError,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
)
} }
} }
@ -69,12 +73,16 @@ fun EmptyStateComposableGenericErrorPreview() {
@Composable @Composable
fun EmptyStateComposableNoCommentPreview() { fun EmptyStateComposableNoCommentPreview() {
AppTheme { AppTheme {
EmptyStateComposable(EmptyStateSpec.NoComments) EmptyStateComposable(
spec = EmptyStateSpec.NoComments,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
)
} }
} }
data class EmptyStateSpec( data class EmptyStateSpec(
val modifier: (Modifier) -> Modifier,
val emojiText: @Composable () -> String, val emojiText: @Composable () -> String,
val descriptionText: @Composable () -> String, val descriptionText: @Composable () -> String,
) { ) {
@ -82,33 +90,19 @@ data class EmptyStateSpec(
val GenericError = val GenericError =
EmptyStateSpec( EmptyStateSpec(
modifier = {
it
.fillMaxWidth()
.heightIn(min = 128.dp)
},
emojiText = { "¯\\_(ツ)_/¯" }, emojiText = { "¯\\_(ツ)_/¯" },
descriptionText = { stringResource(id = R.string.empty_list_subtitle) }, descriptionText = { stringResource(id = R.string.empty_list_subtitle) },
) )
val NoVideos = val NoVideos =
EmptyStateSpec( EmptyStateSpec(
modifier = {
it
.fillMaxWidth()
.heightIn(min = 128.dp)
},
emojiText = { "(╯°-°)╯" }, emojiText = { "(╯°-°)╯" },
descriptionText = { stringResource(id = R.string.no_videos) }, descriptionText = { stringResource(id = R.string.no_videos) },
) )
val NoComments = val NoComments =
EmptyStateSpec( EmptyStateSpec(
modifier = {
it
.fillMaxWidth()
.heightIn(min = 128.dp)
},
emojiText = { "¯\\_(╹x╹)_/¯" }, emojiText = { "¯\\_(╹x╹)_/¯" },
descriptionText = { stringResource(id = R.string.no_comments) }, descriptionText = { stringResource(id = R.string.no_comments) },
) )
@ -120,33 +114,27 @@ data class EmptyStateSpec(
val NoSearchResult = val NoSearchResult =
NoComments.copy( NoComments.copy(
modifier = { it },
emojiText = { "╰(°●°╰)" }, emojiText = { "╰(°●°╰)" },
descriptionText = { stringResource(id = R.string.search_no_results) } descriptionText = { stringResource(id = R.string.search_no_results) }
) )
val NoSearchMaxSizeResult = val NoSearchMaxSizeResult =
NoSearchResult.copy( NoSearchResult
modifier = { it.fillMaxSize() },
)
val ContentNotSupported = val ContentNotSupported =
NoComments.copy( NoComments.copy(
modifier = { it.padding(top = 90.dp) },
emojiText = { "(︶︹︺)" }, emojiText = { "(︶︹︺)" },
descriptionText = { stringResource(id = R.string.content_not_supported) }, descriptionText = { stringResource(id = R.string.content_not_supported) },
) )
val NoBookmarkedPlaylist = val NoBookmarkedPlaylist =
EmptyStateSpec( EmptyStateSpec(
modifier = { it },
emojiText = { "(╥﹏╥)" }, emojiText = { "(╥﹏╥)" },
descriptionText = { stringResource(id = R.string.no_playlist_bookmarked_yet) }, descriptionText = { stringResource(id = R.string.no_playlist_bookmarked_yet) },
) )
val NoSubscriptionsHint = val NoSubscriptionsHint =
EmptyStateSpec( EmptyStateSpec(
modifier = { it },
emojiText = { "(꩜ᯅ꩜)" }, emojiText = { "(꩜ᯅ꩜)" },
descriptionText = { stringResource(id = R.string.import_subscriptions_hint) }, descriptionText = { stringResource(id = R.string.import_subscriptions_hint) },
) )

View File

@ -2,12 +2,16 @@
package org.schabi.newpipe.ui.emptystate package org.schabi.newpipe.ui.emptystate
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.material3.LocalContentColor import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.contentColorFor import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.compose.ui.unit.dp
import org.schabi.newpipe.ui.theme.AppTheme import org.schabi.newpipe.ui.theme.AppTheme
@JvmOverloads @JvmOverloads
@ -22,7 +26,11 @@ fun ComposeView.setEmptyStateComposable(
LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background) LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background)
) { ) {
EmptyStateComposable( EmptyStateComposable(
spec = spec spec = spec,
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 128.dp)
) )
} }
} }