@@ -48,71 +48,69 @@ private fun CommentSection(
4848 val nestedScrollInterop = rememberNestedScrollInteropConnection()
4949 val state = rememberLazyListState()
5050
51- Surface (color = MaterialTheme .colorScheme.background) {
52- LazyColumnThemedScrollbar (state = state) {
53- LazyColumn (
54- modifier = Modifier .nestedScroll(nestedScrollInterop),
55- state = state
56- ) {
57- when (uiState) {
58- is Resource .Loading -> {
59- item {
60- LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
61- }
51+ LazyColumnThemedScrollbar (state = state) {
52+ LazyColumn (
53+ modifier = Modifier .nestedScroll(nestedScrollInterop),
54+ state = state
55+ ) {
56+ when (uiState) {
57+ is Resource .Loading -> {
58+ item {
59+ LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
6260 }
61+ }
6362
64- is Resource .Success -> {
65- val commentInfo = uiState.data
66- val count = commentInfo.commentCount
63+ is Resource .Success -> {
64+ val commentInfo = uiState.data
65+ val count = commentInfo.commentCount
6766
68- if (commentInfo.isCommentsDisabled) {
69- item {
70- NoItemsMessage (R .string.comments_are_disabled)
71- }
72- } else if (count == 0 ) {
67+ if (commentInfo.isCommentsDisabled) {
68+ item {
69+ NoItemsMessage (R .string.comments_are_disabled)
70+ }
71+ } else if (count == 0 ) {
72+ item {
73+ NoItemsMessage (R .string.no_comments)
74+ }
75+ } else {
76+ // do not show anything if the comment count is unknown
77+ if (count >= 0 ) {
7378 item {
74- NoItemsMessage (R .string.no_comments)
79+ Text (
80+ modifier = Modifier
81+ .padding(start = 12 .dp, end = 12 .dp, bottom = 4 .dp),
82+ text = pluralStringResource(R .plurals.comments, count, count),
83+ maxLines = 1 ,
84+ style = MaterialTheme .typography.titleMedium
85+ )
7586 }
76- } else {
77- // do not show anything if the comment count is unknown
78- if (count >= 0 ) {
87+ }
88+
89+ when (comments.loadState.refresh) {
90+ is LoadState .Loading -> {
7991 item {
80- Text (
81- modifier = Modifier
82- .padding(start = 12 .dp, end = 12 .dp, bottom = 4 .dp),
83- text = pluralStringResource(R .plurals.comments, count, count),
84- maxLines = 1 ,
85- style = MaterialTheme .typography.titleMedium
86- )
92+ LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
8793 }
8894 }
8995
90- when (comments.loadState.refresh) {
91- is LoadState .Loading -> {
92- item {
93- LoadingIndicator (modifier = Modifier .padding(top = 8 .dp))
94- }
95- }
96-
97- is LoadState .Error -> {
98- item {
99- NoItemsMessage (R .string.error_unable_to_load_comments)
100- }
96+ is LoadState .Error -> {
97+ item {
98+ NoItemsMessage (R .string.error_unable_to_load_comments)
10199 }
100+ }
102101
103- else -> {
104- items(comments.itemCount) {
105- Comment (comment = comments[it]!! ) {}
106- }
102+ else -> {
103+ items(comments.itemCount) {
104+ Comment (comment = comments[it]!! ) {}
107105 }
108106 }
109107 }
110108 }
109+ }
111110
112- is Resource .Error -> {
113- item {
114- NoItemsMessage (R .string.error_unable_to_load_comments)
115- }
111+ is Resource .Error -> {
112+ item {
113+ NoItemsMessage (R .string.error_unable_to_load_comments)
116114 }
117115 }
118116 }
0 commit comments