Skip to content

Commit fa57160

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
VideoDetailFragment: coposfiy views and thumbs chunck
1 parent 3a42827 commit fa57160

5 files changed

Lines changed: 220 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
@@ -1423,48 +1424,9 @@ class VideoDetailFragment :
14231424
displayBothUploaderAndSubChannel(info)
14241425
}
14251426

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

14691431
if (info.duration > 0) {
14701432
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: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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.font.FontWeight
20+
import androidx.compose.ui.tooling.preview.Preview
21+
import androidx.compose.ui.unit.dp
22+
import androidx.compose.ui.unit.sp
23+
import org.schabi.newpipe.R
24+
import org.schabi.newpipe.extractor.stream.StreamInfo
25+
import org.schabi.newpipe.extractor.stream.StreamType
26+
import org.schabi.newpipe.ui.theme.AppTheme
27+
import org.schabi.newpipe.util.Localization
28+
import org.schabi.newpipe.util.NO_SERVICE_ID
29+
30+
@Composable
31+
fun ViewAndThumbs(info: StreamInfo) {
32+
Column(
33+
modifier = Modifier.padding(start = 6.dp)
34+
) {
35+
if (info.viewCount >= 0) {
36+
// View count
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+
Text(
51+
text = viewCount,
52+
style = MaterialTheme.typography.titleMedium,
53+
maxLines = 1,
54+
modifier = Modifier
55+
.padding(top = 5.dp, bottom = 4.dp)
56+
.align(Alignment.CenterHorizontally)
57+
)
58+
}
59+
60+
Row(verticalAlignment = Alignment.CenterVertically) {
61+
val showLikes = info.likeCount >= 0
62+
val showDislikes = info.dislikeCount >= 0
63+
val showDisabled = !showLikes && !showDislikes
64+
65+
// Like icon
66+
if (showLikes || showDisabled) {
67+
Icon(
68+
painter = painterResource(R.drawable.ic_thumb_up),
69+
contentDescription = stringResource(R.string.detail_likes_img_view_description),
70+
modifier = Modifier.size(16.dp)
71+
)
72+
}
73+
if (showLikes) {
74+
Text(
75+
text = Localization.shortCount(LocalContext.current, info.likeCount),
76+
fontSize = 16.sp,
77+
maxLines = 1,
78+
modifier = Modifier.padding(start = 5.dp)
79+
)
80+
}
81+
82+
if (showLikes || showDisabled) {
83+
Spacer(Modifier.size(8.dp))
84+
}
85+
86+
// Dislike icon
87+
if (showDislikes || showDisabled) {
88+
Icon(
89+
painter = painterResource(R.drawable.ic_thumb_down),
90+
contentDescription = stringResource(R.string.detail_dislikes_img_view_description),
91+
modifier = Modifier.size(16.dp)
92+
)
93+
}
94+
95+
if (showDislikes) {
96+
Text(
97+
text = Localization.shortCount(LocalContext.current, info.dislikeCount),
98+
fontSize = 16.sp,
99+
maxLines = 1,
100+
modifier = Modifier.padding(start = 5.dp)
101+
)
102+
}
103+
104+
if (showDisabled) {
105+
Text(
106+
text = "Disabled",
107+
style = MaterialTheme.typography.titleMedium,
108+
fontWeight = FontWeight.Bold,
109+
modifier = Modifier.padding(start = 8.dp)
110+
)
111+
}
112+
}
113+
}
114+
}
115+
116+
@Composable
117+
fun Preview(info: StreamInfo) {
118+
AppTheme {
119+
Surface {
120+
ViewAndThumbs(info)
121+
}
122+
}
123+
}
124+
125+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
126+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
127+
@Composable
128+
fun PreviewNormal() {
129+
Preview(
130+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
131+
viewCount = 1247
132+
likeCount = 1290
133+
dislikeCount = 327
134+
}
135+
)
136+
}
137+
138+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
139+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
140+
@Composable
141+
fun PreviewLikes() {
142+
Preview(
143+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
144+
viewCount = 1247
145+
likeCount = 1290
146+
dislikeCount = -1
147+
}
148+
)
149+
}
150+
151+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
152+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
153+
@Composable
154+
fun PreviewDislikes() {
155+
Preview(
156+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
157+
viewCount = 1247
158+
likeCount = -1
159+
dislikeCount = 327
160+
}
161+
)
162+
}
163+
164+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
165+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
166+
@Composable
167+
fun PreviewDisabled() {
168+
Preview(
169+
StreamInfo(NO_SERVICE_ID, "", "", StreamType.VIDEO_STREAM, "", "", 0).apply {
170+
viewCount = -1
171+
likeCount = -1
172+
dislikeCount = -1
173+
}
174+
)
175+
}

app/src/main/res/layout-large-land/fragment_video_detail.xml

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
android:background="?attr/windowBackground">
99

1010
<LinearLayout
11-
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
1313
android:baselineAligned="false"
1414
android:focusableInTouchMode="true"
1515
android:orientation="horizontal"
@@ -325,91 +325,11 @@
325325
</LinearLayout>
326326

327327
<!-- VIEW & THUMBS -->
328-
<RelativeLayout
328+
<androidx.fragment.app.FragmentContainerView
329329
android:id="@+id/details_panel"
330330
android:layout_width="wrap_content"
331331
android:layout_height="match_parent"
332-
android:layout_alignParentEnd="true"
333-
android:layout_alignParentRight="true"
334-
android:paddingLeft="6dp"
335-
android:paddingRight="6dp">
336-
337-
<org.schabi.newpipe.views.NewPipeTextView
338-
android:id="@+id/detail_view_count_view"
339-
android:layout_width="wrap_content"
340-
android:layout_height="wrap_content"
341-
android:layout_centerHorizontal="true"
342-
android:layout_marginTop="6dp"
343-
android:layout_marginBottom="6dp"
344-
android:lines="1"
345-
android:textAppearance="?android:attr/textAppearanceLarge"
346-
android:textSize="@dimen/video_item_detail_views_text_size"
347-
tools:ignore="RtlHardcoded"
348-
tools:text="2,816,821,505 views" />
349-
350-
<ImageView
351-
android:id="@+id/detail_thumbs_up_img_view"
352-
android:layout_width="@dimen/video_item_detail_like_image_width"
353-
android:layout_height="@dimen/video_item_detail_like_image_height"
354-
android:layout_below="@id/detail_view_count_view"
355-
android:contentDescription="@string/detail_likes_img_view_description"
356-
android:src="@drawable/ic_thumb_up" />
357-
358-
<org.schabi.newpipe.views.NewPipeTextView
359-
android:id="@+id/detail_thumbs_up_count_view"
360-
android:layout_width="wrap_content"
361-
android:layout_height="@dimen/video_item_detail_like_image_height"
362-
android:layout_below="@id/detail_view_count_view"
363-
android:layout_marginLeft="@dimen/video_item_detail_like_margin"
364-
android:layout_toRightOf="@id/detail_thumbs_up_img_view"
365-
android:gravity="center_vertical"
366-
android:lines="1"
367-
android:textAppearance="?android:attr/textAppearanceMedium"
368-
android:textSize="@dimen/video_item_detail_likes_text_size"
369-
tools:ignore="RtlHardcoded"
370-
tools:text="12M" />
371-
372-
<ImageView
373-
android:id="@+id/detail_thumbs_down_img_view"
374-
android:layout_width="@dimen/video_item_detail_like_image_width"
375-
android:layout_height="@dimen/video_item_detail_like_image_height"
376-
android:layout_below="@id/detail_view_count_view"
377-
android:layout_marginLeft="12dp"
378-
android:layout_toRightOf="@id/detail_thumbs_up_count_view"
379-
android:contentDescription="@string/detail_dislikes_img_view_description"
380-
android:src="@drawable/ic_thumb_down"
381-
tools:ignore="RtlHardcoded" />
382-
383-
<org.schabi.newpipe.views.NewPipeTextView
384-
android:id="@+id/detail_thumbs_down_count_view"
385-
android:layout_width="wrap_content"
386-
android:layout_height="@dimen/video_item_detail_like_image_height"
387-
android:layout_below="@id/detail_view_count_view"
388-
android:layout_marginLeft="@dimen/video_item_detail_like_margin"
389-
android:layout_toRightOf="@id/detail_thumbs_down_img_view"
390-
android:gravity="center_vertical"
391-
android:lines="1"
392-
android:textAppearance="?android:attr/textAppearanceMedium"
393-
android:textSize="@dimen/video_item_detail_likes_text_size"
394-
tools:ignore="RtlHardcoded"
395-
tools:text="10K" />
396-
397-
<org.schabi.newpipe.views.NewPipeTextView
398-
android:id="@+id/detail_thumbs_disabled_view"
399-
android:layout_width="wrap_content"
400-
android:layout_height="@dimen/video_item_detail_like_image_height"
401-
android:layout_below="@id/detail_view_count_view"
402-
android:layout_marginLeft="12dp"
403-
android:layout_toRightOf="@id/detail_thumbs_down_img_view"
404-
android:gravity="center_vertical"
405-
android:text="@string/disabled"
406-
android:textAppearance="?android:attr/textAppearanceLarge"
407-
android:textSize="@dimen/video_item_detail_likes_text_size"
408-
android:textStyle="bold"
409-
android:visibility="gone"
410-
tools:ignore="RtlHardcoded"
411-
tools:visibility="visible" />
412-
</RelativeLayout>
332+
android:layout_alignParentEnd="true"/>
413333
</RelativeLayout>
414334

415335
<!-- CONTROLS -->
@@ -590,7 +510,6 @@
590510
android:layout_marginLeft="8dp"
591511
android:layout_marginRight="8dp"
592512
android:background="?attr/separator_color" />
593-
594513
</LinearLayout>
595514
</RelativeLayout>
596515
</com.google.android.material.appbar.AppBarLayout>

0 commit comments

Comments
 (0)