Skip to content

Commit 1b950c6

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
VideoDetailFragment: coposfiy views and thumbs chunck
1 parent 8b28bd1 commit 1b950c6

5 files changed

Lines changed: 243 additions & 209 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import org.schabi.newpipe.fragments.BackPressable
8484
import org.schabi.newpipe.fragments.BaseStateFragment
8585
import org.schabi.newpipe.fragments.EmptyFragment
8686
import org.schabi.newpipe.fragments.MainFragment
87+
import org.schabi.newpipe.fragments.detail.ViewAndThumbsFragment
8788
import org.schabi.newpipe.fragments.list.comments.CommentsFragment.Companion.getInstance
8889
import org.schabi.newpipe.fragments.list.videos.RelatedItemsFragment.Companion.getInstance
8990
import org.schabi.newpipe.ktx.AnimationType
@@ -1424,48 +1425,9 @@ class VideoDetailFragment :
14241425
displayBothUploaderAndSubChannel(info)
14251426
}
14261427

1427-
if (info.viewCount >= 0) {
1428-
binding.detailViewCountView.text =
1429-
if (info.streamType == StreamType.AUDIO_LIVE_STREAM) {
1430-
Localization.listeningCount(activity, info.viewCount)
1431-
} else if (info.streamType == StreamType.LIVE_STREAM) {
1432-
Localization.localizeWatchingCount(activity, info.viewCount)
1433-
} else {
1434-
Localization.localizeViewCount(activity, info.viewCount)
1435-
}
1436-
binding.detailViewCountView.visibility = View.VISIBLE
1437-
} else {
1438-
binding.detailViewCountView.visibility = View.GONE
1439-
}
1440-
1441-
if (info.dislikeCount == -1L && info.likeCount == -1L) {
1442-
binding.detailThumbsDownImgView.visibility = View.VISIBLE
1443-
binding.detailThumbsUpImgView.visibility = View.VISIBLE
1444-
binding.detailThumbsUpCountView.visibility = View.GONE
1445-
binding.detailThumbsDownCountView.visibility = View.GONE
1446-
binding.detailThumbsDisabledView.visibility = View.VISIBLE
1447-
} else {
1448-
if (info.dislikeCount >= 0) {
1449-
binding.detailThumbsDownCountView.text =
1450-
Localization.shortCount(activity, info.dislikeCount)
1451-
binding.detailThumbsDownCountView.visibility = View.VISIBLE
1452-
binding.detailThumbsDownImgView.visibility = View.VISIBLE
1453-
} else {
1454-
binding.detailThumbsDownCountView.visibility = View.GONE
1455-
binding.detailThumbsDownImgView.visibility = View.GONE
1456-
}
1457-
1458-
if (info.likeCount >= 0) {
1459-
binding.detailThumbsUpCountView.text =
1460-
Localization.shortCount(activity, info.likeCount)
1461-
binding.detailThumbsUpCountView.visibility = View.VISIBLE
1462-
binding.detailThumbsUpImgView.visibility = View.VISIBLE
1463-
} else {
1464-
binding.detailThumbsUpCountView.visibility = View.GONE
1465-
binding.detailThumbsUpImgView.visibility = View.GONE
1466-
}
1467-
binding.detailThumbsDisabledView.visibility = View.GONE
1468-
}
1428+
getChildFragmentManager().beginTransaction()
1429+
.replace(R.id.details_panel, ViewAndThumbsFragment.getInstance(info))
1430+
.commitAllowingStateLoss()
14691431

14701432
if (info.duration > 0) {
14711433
binding.detailDurationView.text = Localization.getDurationString(info.duration)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.schabi.newpipe.fragments.detail
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.ViewGroup
6+
import androidx.compose.material3.Surface
7+
import androidx.core.os.bundleOf
8+
import androidx.fragment.app.Fragment
9+
import androidx.fragment.compose.content
10+
import org.schabi.newpipe.extractor.stream.StreamInfo
11+
import org.schabi.newpipe.ktx.serializable
12+
import org.schabi.newpipe.ui.components.video.ViewAndThumbs
13+
import org.schabi.newpipe.ui.theme.AppTheme
14+
import org.schabi.newpipe.util.KEY_INFO
15+
16+
class ViewAndThumbsFragment : Fragment() {
17+
18+
override fun onCreateView(
19+
inflater: LayoutInflater,
20+
container: ViewGroup?,
21+
savedInstanceState: Bundle?
22+
) = content {
23+
AppTheme {
24+
Surface {
25+
ViewAndThumbs(requireArguments().serializable<StreamInfo>(KEY_INFO)!!)
26+
}
27+
}
28+
}
29+
30+
companion object {
31+
fun getInstance(info: StreamInfo) = ViewAndThumbsFragment().apply {
32+
arguments = bundleOf(KEY_INFO to info)
33+
}
34+
}
35+
}
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
package org.schabi.newpipe.ui.components.video
2+
3+
import android.content.res.Configuration
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.Row
6+
import androidx.compose.foundation.layout.Spacer
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.layout.size
9+
import androidx.compose.material3.Icon
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Surface
12+
import androidx.compose.material3.Text
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.platform.LocalContext
17+
import androidx.compose.ui.res.painterResource
18+
import androidx.compose.ui.res.stringResource
19+
import androidx.compose.ui.text.TextStyle
20+
import androidx.compose.ui.text.font.FontWeight
21+
import androidx.compose.ui.text.style.LineHeightStyle
22+
import androidx.compose.ui.tooling.preview.Preview
23+
import androidx.compose.ui.unit.dp
24+
import org.schabi.newpipe.R
25+
import org.schabi.newpipe.extractor.stream.StreamInfo
26+
import org.schabi.newpipe.extractor.stream.StreamType
27+
import org.schabi.newpipe.ui.theme.AppTheme
28+
import org.schabi.newpipe.util.Localization
29+
import org.schabi.newpipe.util.NO_SERVICE_ID
30+
31+
@Composable
32+
fun ViewAndThumbs(info: StreamInfo) {
33+
Column(
34+
modifier = Modifier.padding(start = 6.dp)
35+
) {
36+
if (info.viewCount >= 0) {
37+
val viewCount = when (info.streamType) {
38+
StreamType.AUDIO_LIVE_STREAM -> {
39+
Localization.listeningCount(LocalContext.current, info.viewCount)
40+
}
41+
42+
StreamType.LIVE_STREAM -> {
43+
Localization.localizeWatchingCount(LocalContext.current, info.viewCount)
44+
}
45+
46+
else -> {
47+
Localization.localizeViewCount(LocalContext.current, info.viewCount)
48+
}
49+
}
50+
// View count
51+
Text(
52+
text = viewCount,
53+
style = MaterialTheme.typography.labelLarge,
54+
maxLines = 1,
55+
modifier = Modifier
56+
.padding(top = 5.dp, bottom = 4.dp)
57+
.align(Alignment.CenterHorizontally)
58+
59+
)
60+
}
61+
62+
Row {
63+
val showLikes = info.likeCount >= 0
64+
val showDislikes = info.dislikeCount >= 0
65+
val showDisabled = !showLikes && !showDislikes
66+
67+
// Like icon
68+
if (showLikes || showDisabled) {
69+
Icon(
70+
painter = painterResource(R.drawable.ic_thumb_up),
71+
contentDescription = stringResource(R.string.detail_likes_img_view_description),
72+
modifier = Modifier
73+
.align(Alignment.CenterVertically)
74+
.size(16.dp)
75+
76+
)
77+
}
78+
if (showLikes) {
79+
Text(
80+
text = Localization.shortCount(LocalContext.current, info.likeCount),
81+
style = MaterialTheme.typography.bodyMedium.merge(
82+
TextStyle(
83+
lineHeightStyle = LineHeightStyle(
84+
alignment = LineHeightStyle.Alignment.Proportional,
85+
trim = LineHeightStyle.Trim.LastLineBottom
86+
)
87+
)
88+
),
89+
fontWeight = FontWeight.Light,
90+
maxLines = 1,
91+
modifier = Modifier.padding(start = 6.dp)
92+
)
93+
}
94+
95+
if ((showLikes && showDislikes) || showDisabled) {
96+
Spacer(Modifier.size(8.dp))
97+
}
98+
99+
// Dislike icon
100+
if (showDislikes || showDisabled) {
101+
Icon(
102+
painter = painterResource(R.drawable.ic_thumb_down),
103+
contentDescription = stringResource(R.string.detail_dislikes_img_view_description),
104+
modifier = Modifier
105+
.align(Alignment.CenterVertically)
106+
.size(16.dp)
107+
)
108+
}
109+
110+
if (showDislikes) {
111+
Text(
112+
text = Localization.shortCount(LocalContext.current, info.dislikeCount),
113+
style = MaterialTheme.typography.bodyMedium.merge(
114+
TextStyle(
115+
lineHeightStyle = LineHeightStyle(
116+
alignment = LineHeightStyle.Alignment.Proportional,
117+
trim = LineHeightStyle.Trim.LastLineBottom
118+
)
119+
)
120+
),
121+
fontWeight = FontWeight.Light,
122+
maxLines = 1,
123+
modifier = Modifier.padding(start = 6.dp)
124+
)
125+
}
126+
127+
if (showDisabled) {
128+
Text(
129+
text = "Disabled",
130+
style = MaterialTheme.typography.titleMedium,
131+
fontWeight = FontWeight.Bold,
132+
modifier = Modifier.padding(start = 8.dp)
133+
)
134+
}
135+
}
136+
}
137+
}
138+
139+
@Composable
140+
fun Preview(info: StreamInfo) {
141+
AppTheme {
142+
Surface {
143+
ViewAndThumbs(info)
144+
}
145+
}
146+
}
147+
148+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
149+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
150+
@Composable
151+
fun PreviewNormal() {
152+
Preview(
153+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
154+
viewCount = 1247
155+
likeCount = 1290
156+
dislikeCount = 327
157+
}
158+
)
159+
}
160+
161+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
162+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
163+
@Composable
164+
fun PreviewLikes() {
165+
Preview(
166+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
167+
viewCount = 1247
168+
likeCount = 1290
169+
dislikeCount = -1
170+
}
171+
)
172+
}
173+
174+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
175+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
176+
@Composable
177+
fun PreviewDislikes() {
178+
Preview(
179+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
180+
viewCount = 1247
181+
likeCount = -1
182+
dislikeCount = 327
183+
}
184+
)
185+
}
186+
187+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
188+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
189+
@Composable
190+
fun PreviewDisabled() {
191+
Preview(
192+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
193+
viewCount = -1
194+
likeCount = -1
195+
dislikeCount = -1
196+
}
197+
)
198+
}

0 commit comments

Comments
 (0)