|
1 |
| -package org.schabi.newpipe.fragments.detail; |
2 |
| - |
3 |
| -import static org.schabi.newpipe.extractor.stream.StreamExtractor.NO_AGE_LIMIT; |
4 |
| -import static org.schabi.newpipe.util.Localization.getAppLocale; |
5 |
| - |
6 |
| -import android.view.LayoutInflater; |
7 |
| -import android.view.View; |
8 |
| -import android.widget.LinearLayout; |
9 |
| - |
10 |
| -import androidx.annotation.NonNull; |
11 |
| -import androidx.annotation.Nullable; |
12 |
| -import androidx.annotation.StringRes; |
13 |
| - |
14 |
| -import org.schabi.newpipe.R; |
15 |
| -import org.schabi.newpipe.extractor.StreamingService; |
16 |
| -import org.schabi.newpipe.extractor.stream.Description; |
17 |
| -import org.schabi.newpipe.extractor.stream.StreamInfo; |
18 |
| -import org.schabi.newpipe.util.Localization; |
19 |
| - |
20 |
| -import java.util.List; |
21 |
| - |
22 |
| -import icepick.State; |
23 |
| - |
24 |
| -public class DescriptionFragment extends BaseDescriptionFragment { |
25 |
| - |
26 |
| - @State |
27 |
| - StreamInfo streamInfo; |
28 |
| - |
29 |
| - public DescriptionFragment(final StreamInfo streamInfo) { |
30 |
| - this.streamInfo = streamInfo; |
31 |
| - } |
32 |
| - |
33 |
| - public DescriptionFragment() { |
34 |
| - // keep empty constructor for IcePick when resuming fragment from memory |
35 |
| - } |
36 |
| - |
37 |
| - |
38 |
| - @Nullable |
39 |
| - @Override |
40 |
| - protected Description getDescription() { |
41 |
| - return streamInfo.getDescription(); |
42 |
| - } |
43 |
| - |
44 |
| - @NonNull |
45 |
| - @Override |
46 |
| - protected StreamingService getService() { |
47 |
| - return streamInfo.getService(); |
48 |
| - } |
49 |
| - |
50 |
| - @Override |
51 |
| - protected int getServiceId() { |
52 |
| - return streamInfo.getServiceId(); |
53 |
| - } |
54 |
| - |
55 |
| - @NonNull |
56 |
| - @Override |
57 |
| - protected String getStreamUrl() { |
58 |
| - return streamInfo.getUrl(); |
59 |
| - } |
60 |
| - |
61 |
| - @NonNull |
62 |
| - @Override |
63 |
| - public List<String> getTags() { |
64 |
| - return streamInfo.getTags(); |
65 |
| - } |
66 |
| - |
67 |
| - @Override |
68 |
| - protected void setupMetadata(final LayoutInflater inflater, |
69 |
| - final LinearLayout layout) { |
70 |
| - if (streamInfo != null && streamInfo.getUploadDate() != null) { |
71 |
| - binding.detailUploadDateView.setText(Localization |
72 |
| - .localizeUploadDate(activity, streamInfo.getUploadDate().offsetDateTime())); |
73 |
| - } else { |
74 |
| - binding.detailUploadDateView.setVisibility(View.GONE); |
75 |
| - } |
76 |
| - |
77 |
| - if (streamInfo == null) { |
78 |
| - return; |
79 |
| - } |
80 |
| - |
81 |
| - addMetadataItem(inflater, layout, false, R.string.metadata_category, |
82 |
| - streamInfo.getCategory()); |
83 |
| - |
84 |
| - addMetadataItem(inflater, layout, false, R.string.metadata_licence, |
85 |
| - streamInfo.getLicence()); |
86 |
| - |
87 |
| - addPrivacyMetadataItem(inflater, layout); |
88 |
| - |
89 |
| - if (streamInfo.getAgeLimit() != NO_AGE_LIMIT) { |
90 |
| - addMetadataItem(inflater, layout, false, R.string.metadata_age_limit, |
91 |
| - String.valueOf(streamInfo.getAgeLimit())); |
92 |
| - } |
93 |
| - |
94 |
| - if (streamInfo.getLanguageInfo() != null) { |
95 |
| - addMetadataItem(inflater, layout, false, R.string.metadata_language, |
96 |
| - streamInfo.getLanguageInfo().getDisplayLanguage(getAppLocale(getContext()))); |
| 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.MaterialTheme |
| 7 | +import androidx.compose.material3.Surface |
| 8 | +import androidx.core.os.bundleOf |
| 9 | +import androidx.fragment.app.Fragment |
| 10 | +import androidx.fragment.compose.content |
| 11 | +import org.schabi.newpipe.extractor.stream.StreamInfo |
| 12 | +import org.schabi.newpipe.ktx.serializable |
| 13 | +import org.schabi.newpipe.ui.components.video.VideoDescriptionSection |
| 14 | +import org.schabi.newpipe.ui.theme.AppTheme |
| 15 | +import org.schabi.newpipe.util.KEY_INFO |
| 16 | + |
| 17 | +class DescriptionFragment : Fragment() { |
| 18 | + override fun onCreateView( |
| 19 | + inflater: LayoutInflater, |
| 20 | + container: ViewGroup?, |
| 21 | + savedInstanceState: Bundle? |
| 22 | + ) = content { |
| 23 | + AppTheme { |
| 24 | + Surface(color = MaterialTheme.colorScheme.background) { |
| 25 | + VideoDescriptionSection(requireArguments().serializable(KEY_INFO)!!) |
| 26 | + } |
97 | 27 | }
|
98 |
| - |
99 |
| - addMetadataItem(inflater, layout, true, R.string.metadata_support, |
100 |
| - streamInfo.getSupportInfo()); |
101 |
| - addMetadataItem(inflater, layout, true, R.string.metadata_host, |
102 |
| - streamInfo.getHost()); |
103 |
| - |
104 |
| - addImagesMetadataItem(inflater, layout, R.string.metadata_thumbnails, |
105 |
| - streamInfo.getThumbnails()); |
106 |
| - addImagesMetadataItem(inflater, layout, R.string.metadata_uploader_avatars, |
107 |
| - streamInfo.getUploaderAvatars()); |
108 |
| - addImagesMetadataItem(inflater, layout, R.string.metadata_subchannel_avatars, |
109 |
| - streamInfo.getSubChannelAvatars()); |
110 | 28 | }
|
111 | 29 |
|
112 |
| - private void addPrivacyMetadataItem(final LayoutInflater inflater, final LinearLayout layout) { |
113 |
| - if (streamInfo.getPrivacy() != null) { |
114 |
| - @StringRes final int contentRes; |
115 |
| - switch (streamInfo.getPrivacy()) { |
116 |
| - case PUBLIC: |
117 |
| - contentRes = R.string.metadata_privacy_public; |
118 |
| - break; |
119 |
| - case UNLISTED: |
120 |
| - contentRes = R.string.metadata_privacy_unlisted; |
121 |
| - break; |
122 |
| - case PRIVATE: |
123 |
| - contentRes = R.string.metadata_privacy_private; |
124 |
| - break; |
125 |
| - case INTERNAL: |
126 |
| - contentRes = R.string.metadata_privacy_internal; |
127 |
| - break; |
128 |
| - case OTHER: |
129 |
| - default: |
130 |
| - contentRes = 0; |
131 |
| - break; |
132 |
| - } |
133 |
| - |
134 |
| - if (contentRes != 0) { |
135 |
| - addMetadataItem(inflater, layout, false, R.string.metadata_privacy, |
136 |
| - getString(contentRes)); |
137 |
| - } |
| 30 | + companion object { |
| 31 | + @JvmStatic |
| 32 | + fun getInstance(streamInfo: StreamInfo) = DescriptionFragment().apply { |
| 33 | + arguments = bundleOf(KEY_INFO to streamInfo) |
138 | 34 | }
|
139 | 35 | }
|
140 | 36 | }
|
0 commit comments