From c48e702a50bfcfc6329aa43a26ac9aaac71e2efb Mon Sep 17 00:00:00 2001 From: Stypox Date: Fri, 21 Apr 2023 17:05:28 +0200 Subject: [PATCH] Improve placeholder channel banner handling Now the placeholder gets hidden if there is no banner url or the user disabled images, to save space --- .../fragments/list/channel/ChannelFragment.java | 16 +++++++++++++--- .../org/schabi/newpipe/util/PicassoHelper.java | 6 +----- app/src/main/res/layout/fragment_channel.xml | 7 ++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 46faaf277..f709fc226 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.fragments.list.channel; +import static org.schabi.newpipe.extractor.utils.Utils.isBlank; import static org.schabi.newpipe.ktx.TextViewUtils.animateTextColor; import static org.schabi.newpipe.ktx.ViewUtils.animate; import static org.schabi.newpipe.ktx.ViewUtils.animateBackgroundColor; @@ -146,6 +147,10 @@ public class ChannelFragment extends BaseStateFragment binding.tabLayout.setupWithViewPager(binding.viewPager); binding.channelTitleView.setText(name); + if (!PicassoHelper.getShouldLoadImages()) { + // do not waste space for the banner if it is not going to be loaded + binding.channelBannerImage.setImageDrawable(null); + } } @Override @@ -575,9 +580,14 @@ public class ChannelFragment extends BaseStateFragment currentInfo = result; setInitialData(result.getServiceId(), result.getOriginalUrl(), result.getName()); - binding.getRoot().setVisibility(View.VISIBLE); - PicassoHelper.loadBanner(result.getBannerUrl()).tag(PICASSO_CHANNEL_TAG) - .into(binding.channelBannerImage); + if (PicassoHelper.getShouldLoadImages() && !isBlank(result.getBannerUrl())) { + PicassoHelper.loadBanner(result.getBannerUrl()).tag(PICASSO_CHANNEL_TAG) + .into(binding.channelBannerImage); + } else { + // do not waste space for the banner, if the user disabled images or there is not one + binding.channelBannerImage.setImageDrawable(null); + } + PicassoHelper.loadAvatar(result.getAvatarUrl()).tag(PICASSO_CHANNEL_TAG) .into(binding.channelAvatarView); PicassoHelper.loadAvatar(result.getParentChannelAvatarUrl()).tag(PICASSO_CHANNEL_TAG) diff --git a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java index 750b8e799..ece0c7e87 100644 --- a/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java @@ -109,11 +109,7 @@ public final class PicassoHelper { } public static RequestCreator loadBanner(final String url) { - if (!shouldLoadImages || isBlank(url)) { - return picassoInstance.load((String) null); - } else { - return picassoInstance.load(url); - } + return loadImageDefault(url, R.drawable.placeholder_channel_banner); } public static RequestCreator loadPlaylistThumbnail(final String url) { diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index e1744739c..cd3e371c5 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -28,10 +28,11 @@