From 997267bad1867a12d23d99d54c5ac214995d324f Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 28 Mar 2021 23:17:20 +0200 Subject: [PATCH] Show video metadata below the decription --- .../fragments/detail/DescriptionFragment.java | 103 +++++++++++++++++- .../main/res/layout/fragment_description.xml | 22 +++- app/src/main/res/layout/item_metadata.xml | 44 ++++++++ app/src/main/res/values/strings.xml | 15 ++- 4 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/layout/item_metadata.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java index b4424928f..b44841fdb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/DescriptionFragment.java @@ -4,14 +4,18 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.StringRes; import androidx.core.text.HtmlCompat; import org.schabi.newpipe.BaseFragment; +import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.FragmentDescriptionBinding; +import org.schabi.newpipe.databinding.ItemMetadataBinding; import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.util.Localization; @@ -21,6 +25,8 @@ import icepick.State; import io.reactivex.rxjava3.disposables.Disposable; import static android.text.TextUtils.isEmpty; +import static org.schabi.newpipe.extractor.stream.StreamExtractor.NO_AGE_LIMIT; +import static org.schabi.newpipe.extractor.utils.Utils.isBlank; public class DescriptionFragment extends BaseFragment { @@ -45,6 +51,7 @@ public class DescriptionFragment extends BaseFragment { if (streamInfo != null) { setupUploadDate(binding.detailUploadDateView); setupDescription(binding.detailDescriptionView); + setupMetadata(inflater, binding.detailMetadataLayout); } return binding.getRoot(); } @@ -70,7 +77,7 @@ public class DescriptionFragment extends BaseFragment { final Description description = streamInfo.getDescription(); if (description == null || isEmpty(description.getContent()) || description == Description.emptyDescription) { - descriptionTextView.setText(""); + descriptionTextView.setVisibility(View.GONE); return; } @@ -90,4 +97,98 @@ public class DescriptionFragment extends BaseFragment { break; } } + + private void setupMetadata(final LayoutInflater inflater, + final LinearLayout layout) { + addMetadataItem(inflater, layout, false, + R.string.metadata_category, streamInfo.getCategory()); + + addTagsMetadataItem(inflater, layout); + + addMetadataItem(inflater, layout, false, + R.string.metadata_licence, streamInfo.getLicence()); + + addPrivacyMetadataItem(inflater, layout); + + if (streamInfo.getAgeLimit() != NO_AGE_LIMIT) { + addMetadataItem(inflater, layout, false, + R.string.metadata_age_limit, String.valueOf(streamInfo.getAgeLimit())); + } + + if (streamInfo.getLanguageInfo() != null) { + addMetadataItem(inflater, layout, false, + R.string.metadata_language, streamInfo.getLanguageInfo().getDisplayLanguage()); + } + + addMetadataItem(inflater, layout, true, + R.string.metadata_support, streamInfo.getSupportInfo()); + addMetadataItem(inflater, layout, true, + R.string.metadata_host, streamInfo.getHost()); + addMetadataItem(inflater, layout, true, + R.string.metadata_thumbnail_url, streamInfo.getThumbnailUrl()); + } + + private void addMetadataItem(final LayoutInflater inflater, + final LinearLayout layout, + final boolean linkifyContent, + @StringRes final int type, + @Nullable final String content) { + if (isBlank(content)) { + return; + } + + final ItemMetadataBinding binding = ItemMetadataBinding.inflate(inflater, layout, false); + binding.metadataTypeView.setText(type); + + if (linkifyContent) { + TextLinkifier.createLinksFromPlainText(layout.getContext(), content, + binding.metadataContentView); + } else { + binding.metadataContentView.setText(content); + } + + layout.addView(binding.getRoot()); + } + + private void addTagsMetadataItem(final LayoutInflater inflater, final LinearLayout layout) { + if (streamInfo.getTags() != null && !streamInfo.getTags().isEmpty()) { + final StringBuilder tags = new StringBuilder(); + for (int i = 0; i < streamInfo.getTags().size(); ++i) { + if (i != 0) { + tags.append(", "); + } + tags.append(streamInfo.getTags().get(i)); + } + + addMetadataItem(inflater, layout, false, R.string.metadata_tags, tags.toString()); + } + } + + private void addPrivacyMetadataItem(final LayoutInflater inflater, final LinearLayout layout) { + if (streamInfo.getPrivacy() != null) { + @StringRes final int contentRes; + switch (streamInfo.getPrivacy()) { + case PUBLIC: + contentRes = R.string.metadata_privacy_public; + break; + case UNLISTED: + contentRes = R.string.metadata_privacy_unlisted; + break; + case PRIVATE: + contentRes = R.string.metadata_privacy_private; + break; + case INTERNAL: + contentRes = R.string.metadata_privacy_internal; + break; + case OTHER: default: + contentRes = 0; + break; + } + + if (contentRes != 0) { + addMetadataItem(inflater, layout, false, + R.string.metadata_privacy, layout.getContext().getString(contentRes)); + } + } + } } diff --git a/app/src/main/res/layout/fragment_description.xml b/app/src/main/res/layout/fragment_description.xml index e3845e892..e079e41fe 100644 --- a/app/src/main/res/layout/fragment_description.xml +++ b/app/src/main/res/layout/fragment_description.xml @@ -2,10 +2,10 @@ + android:layout_height="wrap_content" + android:orientation="vertical" + android:scrollbars="vertical"> + + diff --git a/app/src/main/res/layout/item_metadata.xml b/app/src/main/res/layout/item_metadata.xml new file mode 100644 index 000000000..441b916e8 --- /dev/null +++ b/app/src/main/res/layout/item_metadata.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b8ca33c87..f614b6b64 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -716,4 +716,17 @@ Select your favorite night theme — %s You can select your favorite night theme below Download has started - \ No newline at end of file + Category + Tags + Licence + Privacy + Age limit + Language + Support + Host + Thumbnail URL + Public + Unlisted + Private + Internal +