Skip to content

Commit c8b01a0

Browse files
committed
Use empty state view in compose
1 parent 414b1a8 commit c8b01a0

5 files changed

Lines changed: 93 additions & 91 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/common/NoItemsMessage.kt

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/src/main/java/org/schabi/newpipe/ui/components/video/RelatedItems.kt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import org.schabi.newpipe.R
2626
import org.schabi.newpipe.extractor.stream.StreamInfo
2727
import org.schabi.newpipe.extractor.stream.StreamType
2828
import org.schabi.newpipe.info_list.ItemViewMode
29-
import org.schabi.newpipe.ui.components.common.NoItemsMessage
3029
import org.schabi.newpipe.ui.components.items.ItemList
3130
import org.schabi.newpipe.ui.components.items.stream.StreamInfoItem
31+
import org.schabi.newpipe.ui.emptystate.EmptyStateComposable
32+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec
3233
import org.schabi.newpipe.ui.theme.AppTheme
3334
import org.schabi.newpipe.util.NO_SERVICE_ID
3435

@@ -41,43 +42,44 @@ fun RelatedItems(info: StreamInfo) {
4142
mutableStateOf(sharedPreferences.getBoolean(key, false))
4243
}
4344

44-
if (info.relatedItems.isEmpty()) {
45-
NoItemsMessage(message = R.string.no_videos)
46-
} else {
47-
ItemList(
48-
items = info.relatedItems,
49-
mode = ItemViewMode.LIST,
50-
listHeader = {
51-
item {
45+
ItemList(
46+
items = info.relatedItems,
47+
mode = ItemViewMode.LIST,
48+
listHeader = {
49+
item {
50+
Row(
51+
modifier = Modifier
52+
.fillMaxWidth()
53+
.padding(start = 12.dp, end = 12.dp),
54+
horizontalArrangement = Arrangement.SpaceBetween,
55+
verticalAlignment = Alignment.CenterVertically,
56+
) {
57+
Text(text = stringResource(R.string.auto_queue_description))
58+
5259
Row(
53-
modifier = Modifier
54-
.fillMaxWidth()
55-
.padding(start = 12.dp, end = 12.dp),
56-
horizontalArrangement = Arrangement.SpaceBetween,
57-
verticalAlignment = Alignment.CenterVertically,
60+
horizontalArrangement = Arrangement.spacedBy(4.dp),
61+
verticalAlignment = Alignment.CenterVertically
5862
) {
59-
Text(text = stringResource(R.string.auto_queue_description))
60-
61-
Row(
62-
horizontalArrangement = Arrangement.spacedBy(4.dp),
63-
verticalAlignment = Alignment.CenterVertically
64-
) {
65-
Text(text = stringResource(R.string.auto_queue_toggle))
66-
Switch(
67-
checked = isAutoQueueEnabled,
68-
onCheckedChange = {
69-
isAutoQueueEnabled = it
70-
sharedPreferences.edit {
71-
putBoolean(key, it)
72-
}
63+
Text(text = stringResource(R.string.auto_queue_toggle))
64+
Switch(
65+
checked = isAutoQueueEnabled,
66+
onCheckedChange = {
67+
isAutoQueueEnabled = it
68+
sharedPreferences.edit {
69+
putBoolean(key, it)
7370
}
74-
)
75-
}
71+
}
72+
)
7673
}
7774
}
7875
}
79-
)
80-
}
76+
if (info.relatedItems.isEmpty()) {
77+
item {
78+
EmptyStateComposable(EmptyStateSpec.NoVideos)
79+
}
80+
}
81+
}
82+
)
8183
}
8284

8385
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.ui.Modifier
2020
import androidx.compose.ui.input.nestedscroll.nestedScroll
2121
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
2222
import androidx.compose.ui.res.pluralStringResource
23+
import androidx.compose.ui.res.stringResource
2324
import androidx.compose.ui.tooling.preview.Preview
2425
import androidx.compose.ui.tooling.preview.datasource.LoremIpsum
2526
import androidx.compose.ui.unit.dp
@@ -38,7 +39,8 @@ import org.schabi.newpipe.extractor.stream.Description
3839
import org.schabi.newpipe.paging.CommentRepliesSource
3940
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
4041
import org.schabi.newpipe.ui.components.common.LoadingIndicator
41-
import org.schabi.newpipe.ui.components.common.NoItemsMessage
42+
import org.schabi.newpipe.ui.emptystate.EmptyStateComposable
43+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec
4244
import org.schabi.newpipe.ui.theme.AppTheme
4345

4446
@Composable
@@ -130,13 +132,17 @@ private fun CommentRepliesDialog(
130132
val refresh = comments.loadState.refresh
131133
if (refresh is LoadState.Loading) {
132134
LoadingIndicator(modifier = Modifier.padding(top = 8.dp))
135+
} else if (refresh is LoadState.Error) {
136+
// TODO use error panel instead
137+
EmptyStateComposable(
138+
EmptyStateSpec.DisabledComments.copy(
139+
descriptionText = {
140+
stringResource(R.string.error_unable_to_load_comments)
141+
}
142+
)
143+
)
133144
} else {
134-
val message = if (refresh is LoadState.Error) {
135-
R.string.error_unable_to_load_comments
136-
} else {
137-
R.string.no_comments
138-
}
139-
NoItemsMessage(message)
145+
EmptyStateComposable(EmptyStateSpec.NoComments)
140146
}
141147
}
142148
} else {

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
1313
import androidx.compose.ui.input.nestedscroll.nestedScroll
1414
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
1515
import androidx.compose.ui.res.pluralStringResource
16+
import androidx.compose.ui.res.stringResource
1617
import androidx.compose.ui.tooling.preview.Preview
1718
import androidx.compose.ui.unit.dp
1819
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -28,7 +29,8 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItem
2829
import org.schabi.newpipe.extractor.stream.Description
2930
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
3031
import org.schabi.newpipe.ui.components.common.LoadingIndicator
31-
import org.schabi.newpipe.ui.components.common.NoItemsMessage
32+
import org.schabi.newpipe.ui.emptystate.EmptyStateComposable
33+
import org.schabi.newpipe.ui.emptystate.EmptyStateSpec
3234
import org.schabi.newpipe.ui.theme.AppTheme
3335
import org.schabi.newpipe.viewmodels.CommentsViewModel
3436
import org.schabi.newpipe.viewmodels.util.Resource
@@ -66,11 +68,11 @@ private fun CommentSection(
6668

6769
if (commentInfo.isCommentsDisabled) {
6870
item {
69-
NoItemsMessage(R.string.comments_are_disabled)
71+
EmptyStateComposable(EmptyStateSpec.DisabledComments)
7072
}
7173
} else if (count == 0) {
7274
item {
73-
NoItemsMessage(R.string.no_comments)
75+
EmptyStateComposable(EmptyStateSpec.NoComments)
7476
}
7577
} else {
7678
// do not show anything if the comment count is unknown
@@ -95,7 +97,14 @@ private fun CommentSection(
9597

9698
is LoadState.Error -> {
9799
item {
98-
NoItemsMessage(R.string.error_unable_to_load_comments)
100+
// TODO use error panel instead
101+
EmptyStateComposable(
102+
EmptyStateSpec.DisabledComments.copy(
103+
descriptionText = {
104+
stringResource(R.string.error_unable_to_load_comments)
105+
}
106+
)
107+
)
99108
}
100109
}
101110

@@ -110,7 +119,14 @@ private fun CommentSection(
110119

111120
is Resource.Error -> {
112121
item {
113-
NoItemsMessage(R.string.error_unable_to_load_comments)
122+
// TODO use error panel instead
123+
EmptyStateComposable(
124+
EmptyStateSpec.DisabledComments.copy(
125+
descriptionText = {
126+
stringResource(R.string.error_unable_to_load_comments)
127+
}
128+
)
129+
)
114130
}
115131
}
116132
}

app/src/main/java/org/schabi/newpipe/ui/emptystate/EmptyStateComposable.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fun EmptyStateComposableGenericErrorPreview() {
6969
@Composable
7070
fun EmptyStateComposableNoCommentPreview() {
7171
AppTheme {
72-
EmptyStateComposable(EmptyStateSpec.NoComment)
72+
EmptyStateComposable(EmptyStateSpec.NoComments)
7373
}
7474
}
7575

@@ -91,15 +91,35 @@ data class EmptyStateSpec(
9191
descriptionText = { stringResource(id = R.string.empty_list_subtitle) },
9292
)
9393

94-
val NoComment =
94+
val NoVideos =
9595
EmptyStateSpec(
96-
modifier = { it.padding(top = 85.dp) },
96+
modifier = {
97+
it
98+
.fillMaxWidth()
99+
.heightIn(min = 128.dp)
100+
},
97101
emojiText = { "(╯°-°)╯" },
102+
descriptionText = { stringResource(id = R.string.no_videos) },
103+
)
104+
105+
val NoComments =
106+
EmptyStateSpec(
107+
modifier = {
108+
it
109+
.fillMaxWidth()
110+
.heightIn(min = 128.dp)
111+
},
112+
emojiText = { "¯\\_(╹x╹)_/¯" },
98113
descriptionText = { stringResource(id = R.string.no_comments) },
99114
)
100115

116+
val DisabledComments =
117+
NoComments.copy(
118+
descriptionText = { stringResource(id = R.string.comments_are_disabled) },
119+
)
120+
101121
val NoSearchResult =
102-
NoComment.copy(
122+
NoComments.copy(
103123
modifier = { it },
104124
emojiText = { "╰(°●°╰)" },
105125
descriptionText = { stringResource(id = R.string.search_no_results) }
@@ -111,7 +131,7 @@ data class EmptyStateSpec(
111131
)
112132

113133
val ContentNotSupported =
114-
NoComment.copy(
134+
NoComments.copy(
115135
modifier = { it.padding(top = 90.dp) },
116136
emojiText = { "(︶︹︺)" },
117137
descriptionText = { stringResource(id = R.string.content_not_supported) },

0 commit comments

Comments
 (0)