From 75292e099cbb3d63ad038fa4e4da9c74b07bc770 Mon Sep 17 00:00:00 2001 From: Mahendran Date: Sun, 29 Jan 2023 17:44:46 +0530 Subject: [PATCH] Larger channel cards in search results - Thumbnail larger (100dp) than the usual (92dp) throughout the app - Description lint count is 8 (normally 3) --- app/sampledata/channels.json | 19 +++++ .../newpipe/info_list/InfoListAdapter.java | 8 +- .../holder/ChannelCardInfoItemHolder.java | 22 ++++++ .../holder/ChannelMiniInfoItemHolder.java | 16 +++- .../subscription/SubscriptionFragment.kt | 11 ++- .../subscription/SubscriptionViewModel.kt | 28 ++++++- .../res/layout/list_channel_card_item.xml | 74 +++++++++++++++++++ app/src/main/res/values/dimens.xml | 2 + 8 files changed, 170 insertions(+), 10 deletions(-) create mode 100644 app/sampledata/channels.json create mode 100644 app/src/main/java/org/schabi/newpipe/info_list/holder/ChannelCardInfoItemHolder.java create mode 100644 app/src/main/res/layout/list_channel_card_item.xml diff --git a/app/sampledata/channels.json b/app/sampledata/channels.json new file mode 100644 index 000000000..207d78597 --- /dev/null +++ b/app/sampledata/channels.json @@ -0,0 +1,19 @@ +{ + "data": [ + { + "name": "BBC", + "additional": "12K subscribers•233 videos", + "description": "The BBC is the world’s leading public service broadcaster. We’re impartial and independent, and every day we create distinctive, world-class programmes and content which inform, educate and entertain millions of people in the UK and around the world. SUBSCRIBE to our YouTube channel to get the best of BBC entertainment and comedy programmes, stories from science and nature documentaries, and much more! https://bit.ly/2IXqEIn Get ALL your fresh TV, and sofa-hugging box sets on iPlayer https://bbc.in/2J18jYJ" + }, + { + "name": "Linus Tech Tips", + "additional": "1M subscribers•233 videos", + "description": "Looking for a Tech YouTuber?\n\nLinus Tech Tips is a passionate team of \"professionally curious\" experts in consumer technology and video production which aims to inform and educate people of all ages through our entertaining videos. We create product reviews, step-by-step computer build guides, and a variety of other tech-focused content.\n\nSchedule:\nNew videos every Saturday to Thursday @ 10:00am Pacific\nLive WAN Show podcasts every Friday @ ~5:00pm Pacific" + }, + { + "name": "Marques Brownlee", + "additional": "13 subscribers•12K videos", + "description": "MKBHD: Quality Tech Videos | YouTuber | Geek | Consumer Electronics | Tech Head | Internet Personality!\n\nbusiness@MKBHD.com\n\nNYC" + } + ] +} \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index d69db945d..a13f0e5aa 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem; +import org.schabi.newpipe.info_list.holder.ChannelCardInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelGridInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelInfoItemHolder; import org.schabi.newpipe.info_list.holder.ChannelMiniInfoItemHolder; @@ -73,6 +74,7 @@ public class InfoListAdapter extends RecyclerView.Adapter= 0 && item.getSubscriberCount() >= 0) { 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 7146a18d6..bc2f96f73 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 @@ -60,7 +60,6 @@ import org.schabi.newpipe.util.NavigationHelper import org.schabi.newpipe.util.OnClickGesture import org.schabi.newpipe.util.ServiceHelper 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 import java.util.Date @@ -245,7 +244,7 @@ class SubscriptionFragment : BaseStateFragment() { super.initViews(rootView, savedInstanceState) _binding = FragmentSubscriptionBinding.bind(rootView) - groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountChannels(context) else 1 + groupAdapter.spanCount = if (SubscriptionViewModel.shouldUseGridForSubscription(requireContext())) getGridSpanCountChannels(context) else 1 binding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply { spanSizeLookup = groupAdapter.spanSizeLookup } @@ -380,15 +379,15 @@ class SubscriptionFragment : BaseStateFragment() { override fun handleResult(result: SubscriptionState) { super.handleResult(result) - val shouldUseGridLayout = shouldUseGridLayout(context) when (result) { is SubscriptionState.LoadedState -> { result.subscriptions.forEach { if (it is ChannelItem) { it.gesturesListener = listenerChannelItem - it.itemVersion = when { - shouldUseGridLayout -> ChannelItem.ItemVersion.GRID - else -> ChannelItem.ItemVersion.MINI + it.itemVersion = if (SubscriptionViewModel.shouldUseGridForSubscription(requireContext())) { + ChannelItem.ItemVersion.GRID + } else { + ChannelItem.ItemVersion.MINI } } } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt index 914299c78..dfad60c3f 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionViewModel.kt @@ -1,6 +1,7 @@ package org.schabi.newpipe.local.subscription import android.app.Application +import android.content.Context import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -8,12 +9,13 @@ import com.xwray.groupie.Group import io.reactivex.rxjava3.core.Flowable import io.reactivex.rxjava3.processors.BehaviorProcessor import io.reactivex.rxjava3.schedulers.Schedulers +import org.schabi.newpipe.info_list.ItemViewMode import org.schabi.newpipe.local.feed.FeedDatabaseManager import org.schabi.newpipe.local.subscription.item.ChannelItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardGridItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem import org.schabi.newpipe.util.DEFAULT_THROTTLE_TIMEOUT -import org.schabi.newpipe.util.ThemeHelper +import org.schabi.newpipe.util.ThemeHelper.getItemViewMode import java.util.concurrent.TimeUnit class SubscriptionViewModel(application: Application) : AndroidViewModel(application) { @@ -22,7 +24,7 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica // true -> list view, false -> grid view private val listViewMode = BehaviorProcessor.createDefault( - !ThemeHelper.shouldUseGridLayout(application) + !shouldUseGridForSubscription(application) ) private val listViewModeFlowable = listViewMode.distinctUntilChanged() @@ -77,4 +79,26 @@ class SubscriptionViewModel(application: Application) : AndroidViewModel(applica data class LoadedState(val subscriptions: List) : SubscriptionState() data class ErrorState(val error: Throwable? = null) : SubscriptionState() } + + companion object { + + /** + * Returns whether to use GridLayout mode for Subscription Fragment. + * + * ### Current mapping: + * + * | ItemViewMode | ItemVersion | Span count | + * |---|---|---| + * | AUTO | MINI | 1 | + * | LIST | MINI | 1 | + * | CARD | GRID | > 1 (ThemeHelper defined) | + * | GRID | GRID | > 1 (ThemeHelper defined) | + * + * @see [SubscriptionViewModel.shouldUseGridForSubscription] to modify Layout Manager + */ + fun shouldUseGridForSubscription(context: Context): Boolean { + val itemViewMode = getItemViewMode(context) + return itemViewMode == ItemViewMode.GRID || itemViewMode == ItemViewMode.CARD + } + } } diff --git a/app/src/main/res/layout/list_channel_card_item.xml b/app/src/main/res/layout/list_channel_card_item.xml new file mode 100644 index 000000000..09696ff38 --- /dev/null +++ b/app/src/main/res/layout/list_channel_card_item.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 679dc05eb..e35b3c2e5 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,6 +4,7 @@ 16dp 8dp 32dp + 12dp 8dp 4dp 2dp @@ -38,6 +39,7 @@ 164dp 92dp + 100dp 92dp 128dp