From 644396149b2d4505ca0dd2b78d6528cf1f7ff8b7 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 31 Jul 2021 10:51:59 +0200 Subject: [PATCH] Fix channel item span count for SubscriptionFragment --- .../schabi/newpipe/local/feed/FeedFragment.kt | 4 +- .../subscription/SubscriptionFragment.kt | 4 +- .../org/schabi/newpipe/util/ThemeHelper.java | 39 +++++++++++++++---- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 03d39b13c..61ac3cb77 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -73,7 +73,7 @@ import org.schabi.newpipe.player.helper.PlayerHolder import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.NavigationHelper import org.schabi.newpipe.util.StreamDialogEntry -import org.schabi.newpipe.util.ThemeHelper.getGridSpanCount +import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountStreams import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout import java.time.OffsetDateTime import java.util.ArrayList @@ -160,7 +160,7 @@ class FeedFragment : BaseStateFragment() { fun setupListViewMode() { // does everything needed to setup the layouts for grid or list modes - groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCount(context) else 1 + groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountStreams(context) else 1 feedBinding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply { spanSizeLookup = groupAdapter.spanSizeLookup } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index c6f6cc73c..e2248e742 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -58,7 +58,7 @@ import org.schabi.newpipe.local.subscription.services.SubscriptionsImportService import org.schabi.newpipe.streams.io.StoredFileHelper import org.schabi.newpipe.util.NavigationHelper import org.schabi.newpipe.util.OnClickGesture -import org.schabi.newpipe.util.ThemeHelper.getGridSpanCount +import org.schabi.newpipe.util.ThemeHelper.getGridSpanCountChannels import org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout import org.schabi.newpipe.util.external_communication.ShareUtils import java.text.SimpleDateFormat @@ -267,7 +267,7 @@ class SubscriptionFragment : BaseStateFragment() { super.initViews(rootView, savedInstanceState) _binding = FragmentSubscriptionBinding.bind(rootView) - groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCount(context) else 1 + groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountChannels(context) else 1 binding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply { spanSizeLookup = groupAdapter.spanSizeLookup } diff --git a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java index f3ae002dd..7c47d387f 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java @@ -324,17 +324,40 @@ public final class ThemeHelper { } /** - * Calculates the number of grid items that can fit horizontally on the screen. The width of a - * grid item is obtained from the thumbnail width plus the right and left paddings. + * Calculates the number of grid channel info items that can fit horizontally on the screen. * * @param context the context to use + * @return the span count of grid channel info items + */ + public static int getGridSpanCountChannels(final Context context) { + return getGridSpanCount(context, + context.getResources().getDimensionPixelSize(R.dimen.channel_item_grid_min_width)); + } + + /** + * Calculates the number of grid stream info items that can fit horizontally on the screen. The + * width of a grid stream info item is obtained from the thumbnail width plus the right and left + * paddings. + * + * @param context the context to use + * @return the span count of grid stream info items + */ + public static int getGridSpanCountStreams(final Context context) { + final Resources res = context.getResources(); + return getGridSpanCount(context, + res.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width) + + res.getDimensionPixelSize(R.dimen.video_item_search_padding) * 2); + } + + /** + * Calculates the number of grid items that can fit horizontally on the screen based on the + * minimum width. + * + * @param context the context to use + * @param minWidth the minimum width of items in the grid * @return the span count of grid list items */ - public static int getGridSpanCount(final Context context) { - final Resources res = context.getResources(); - final int minWidth - = res.getDimensionPixelSize(R.dimen.video_item_grid_thumbnail_image_width) - + res.getDimensionPixelSize(R.dimen.video_item_search_padding) * 2; - return Math.max(1, res.getDisplayMetrics().widthPixels / minWidth); + public static int getGridSpanCount(final Context context, final int minWidth) { + return Math.max(1, context.getResources().getDisplayMetrics().widthPixels / minWidth); } }