1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Button can be toggled but not all strings have been fed

This commit is contained in:
Samuel Wu 2022-10-24 23:01:02 +11:00
parent 78547b4fa4
commit f37d869ea2
7 changed files with 155 additions and 23 deletions

View File

@ -71,6 +71,7 @@
"service_id", "service_id",
"url" "url"
], ],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_subscriptions_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)" "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_subscriptions_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)"
} }
], ],
@ -78,14 +79,8 @@
}, },
{ {
"tableName": "search_history", "tableName": "search_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `creation_date` INTEGER, `service_id` INTEGER NOT NULL, `search` TEXT)", "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`creation_date` INTEGER, `service_id` INTEGER NOT NULL, `search` TEXT, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
"fields": [ "fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{ {
"fieldPath": "creationDate", "fieldPath": "creationDate",
"columnName": "creation_date", "columnName": "creation_date",
@ -103,6 +98,12 @@
"columnName": "search", "columnName": "search",
"affinity": "TEXT", "affinity": "TEXT",
"notNull": false "notNull": false
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
} }
], ],
"primaryKey": { "primaryKey": {
@ -118,6 +119,7 @@
"columnNames": [ "columnNames": [
"search" "search"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_search_history_search` ON `${TABLE_NAME}` (`search`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_search_history_search` ON `${TABLE_NAME}` (`search`)"
} }
], ],
@ -220,6 +222,7 @@
"service_id", "service_id",
"url" "url"
], ],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_streams_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)" "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_streams_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)"
} }
], ],
@ -262,6 +265,7 @@
"columnNames": [ "columnNames": [
"stream_id" "stream_id"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_stream_history_stream_id` ON `${TABLE_NAME}` (`stream_id`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_stream_history_stream_id` ON `${TABLE_NAME}` (`stream_id`)"
} }
], ],
@ -353,6 +357,7 @@
"columnNames": [ "columnNames": [
"name" "name"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_playlists_name` ON `${TABLE_NAME}` (`name`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_playlists_name` ON `${TABLE_NAME}` (`name`)"
} }
], ],
@ -396,6 +401,7 @@
"playlist_id", "playlist_id",
"join_index" "join_index"
], ],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_playlist_stream_join_playlist_id_join_index` ON `${TABLE_NAME}` (`playlist_id`, `join_index`)" "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_playlist_stream_join_playlist_id_join_index` ON `${TABLE_NAME}` (`playlist_id`, `join_index`)"
}, },
{ {
@ -404,6 +410,7 @@
"columnNames": [ "columnNames": [
"stream_id" "stream_id"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_playlist_stream_join_stream_id` ON `${TABLE_NAME}` (`stream_id`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_playlist_stream_join_stream_id` ON `${TABLE_NAME}` (`stream_id`)"
} }
], ],
@ -492,6 +499,7 @@
"columnNames": [ "columnNames": [
"name" "name"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_remote_playlists_name` ON `${TABLE_NAME}` (`name`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_remote_playlists_name` ON `${TABLE_NAME}` (`name`)"
}, },
{ {
@ -501,6 +509,7 @@
"service_id", "service_id",
"url" "url"
], ],
"orders": [],
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_remote_playlists_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)" "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_remote_playlists_service_id_url` ON `${TABLE_NAME}` (`service_id`, `url`)"
} }
], ],
@ -537,6 +546,7 @@
"columnNames": [ "columnNames": [
"subscription_id" "subscription_id"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_feed_subscription_id` ON `${TABLE_NAME}` (`subscription_id`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_subscription_id` ON `${TABLE_NAME}` (`subscription_id`)"
} }
], ],
@ -607,6 +617,7 @@
"columnNames": [ "columnNames": [
"sort_order" "sort_order"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_feed_group_sort_order` ON `${TABLE_NAME}` (`sort_order`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_group_sort_order` ON `${TABLE_NAME}` (`sort_order`)"
} }
], ],
@ -643,6 +654,7 @@
"columnNames": [ "columnNames": [
"subscription_id" "subscription_id"
], ],
"orders": [],
"createSql": "CREATE INDEX IF NOT EXISTS `index_feed_group_subscription_join_subscription_id` ON `${TABLE_NAME}` (`subscription_id`)" "createSql": "CREATE INDEX IF NOT EXISTS `index_feed_group_subscription_join_subscription_id` ON `${TABLE_NAME}` (`subscription_id`)"
} }
], ],

View File

@ -24,7 +24,7 @@ data class FeedGroupEntity(
var icon: FeedGroupIcon, var icon: FeedGroupIcon,
@ColumnInfo(name = SORT_ORDER) @ColumnInfo(name = SORT_ORDER)
var sortOrder: Long = -1 var sortOrder: Long = -1,
) { ) {
companion object { companion object {
const val FEED_GROUP_TABLE = "feed_group" const val FEED_GROUP_TABLE = "feed_group"

View File

@ -20,6 +20,7 @@ import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.xwray.groupie.Group import com.xwray.groupie.Group
import com.xwray.groupie.GroupAdapter import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.Item import com.xwray.groupie.Item
@ -45,6 +46,7 @@ import org.schabi.newpipe.local.subscription.item.ChannelItem
import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem
import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem
import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem
import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem
import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem
import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem
import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem.Companion.PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM import org.schabi.newpipe.local.subscription.item.HeaderWithMenuItem.Companion.PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM
@ -76,6 +78,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
private val groupAdapter = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>() private val groupAdapter = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>()
private val feedGroupsSection = Section() private val feedGroupsSection = Section()
private var feedGroupsCarousel: FeedGroupCarouselItem? = null private var feedGroupsCarousel: FeedGroupCarouselItem? = null
private var feedGroupsCarouselVertical: FeedGroupCarouselItem? = feedGroupsCarousel
private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem
private val subscriptionsSection = Section() private val subscriptionsSection = Section()
@ -92,6 +95,10 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
@JvmField @JvmField
var feedGroupsListState: Parcelable? = null var feedGroupsListState: Parcelable? = null
@State
@JvmField
var feedGroupsListVerticalState: Parcelable? = null
init { init {
setHasOptionsMenu(true) setHasOptionsMenu(true)
} }
@ -118,6 +125,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
super.onPause() super.onPause()
itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState() itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState()
feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState() feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState()
feedGroupsListVerticalState = feedGroupsCarouselVertical?.onSaveInstanceState()
} }
override fun onDestroy() { override fun onDestroy() {
@ -221,10 +229,6 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
FeedGroupReorderDialog().show(parentFragmentManager, null) FeedGroupReorderDialog().show(parentFragmentManager, null)
} }
private fun temp() {
println("This button is clicked")
}
private fun requestExportResult(result: ActivityResult) { private fun requestExportResult(result: ActivityResult) {
if (result.data != null && result.resultCode == Activity.RESULT_OK) { if (result.data != null && result.resultCode == Activity.RESULT_OK) {
activity.startService( activity.startService(
@ -270,16 +274,16 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
return@setOnItemLongClickListener true return@setOnItemLongClickListener true
} }
feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter) feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.HORIZONTAL)
feedGroupsSortMenuItem = HeaderWithMenuItem( feedGroupsSortMenuItem = HeaderWithMenuItem(
getString(R.string.feed_groups_header_title), getString(R.string.feed_groups_header_title),
R.drawable.ic_list, R.drawable.ic_list,
R.drawable.ic_sort, R.drawable.ic_sort,
listViewOnClickListener = ::temp, listViewOnClickListener = ::changeLayout,
menuItemOnClickListener = ::openReorderDialog menuItemOnClickListener = ::openReorderDialog
) )
add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel)))
groupAdapter.clear()
groupAdapter.add(this) groupAdapter.add(this)
} }
@ -296,6 +300,62 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
) )
} }
private fun changeLayout() {
Section().apply {
val carouselAdapter = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>()
carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS))
carouselAdapter.add(feedGroupsSection)
carouselAdapter.add(FeedGroupAddItem()) // change this button later
carouselAdapter.setOnItemClickListener { item, _ ->
listenerFeedVerticalGroups.selected(item)
}
carouselAdapter.setOnItemLongClickListener { item, _ ->
if (item is FeedGroupCardVerticalItem) {
if (item.groupId == FeedGroupEntity.GROUP_ALL_ID) {
return@setOnItemLongClickListener false
}
}
listenerFeedVerticalGroups.held(item)
return@setOnItemLongClickListener true
}
feedGroupsCarouselVertical = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL)
feedGroupsSortMenuItem = HeaderWithMenuItem(
getString(R.string.feed_groups_header_title),
R.drawable.ic_apps,
R.drawable.ic_sort,
listViewOnClickListener = ::setupInitialLayout,
menuItemOnClickListener = ::openReorderDialog
)
add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarouselVertical)))
groupAdapter.clear()
groupAdapter.add(this)
}
subscriptionsSection.setPlaceholder(EmptyPlaceholderItem())
subscriptionsSection.setHideWhenEmpty(true)
groupAdapter.add(
Section(
HeaderWithMenuItem(
getString(R.string.tab_subscriptions)
),
listOf(subscriptionsSection)
)
)
// TODO: remove this
groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountChannels(context) else 1
binding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply {
spanSizeLookup = groupAdapter.spanSizeLookup
}
binding.itemsList.adapter = groupAdapter
viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java)
viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) }
viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedVerticalGroups) }
}
override fun initViews(rootView: View, savedInstanceState: Bundle?) { override fun initViews(rootView: View, savedInstanceState: Bundle?) {
super.initViews(rootView, savedInstanceState) super.initViews(rootView, savedInstanceState)
_binding = FragmentSubscriptionBinding.bind(rootView) _binding = FragmentSubscriptionBinding.bind(rootView)
@ -367,6 +427,21 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
} }
} }
private val listenerFeedVerticalGroups = object : OnClickGesture<Item<*>> {
override fun selected(selectedItem: Item<*>?) {
when (selectedItem) {
is FeedGroupCardVerticalItem -> NavigationHelper.openFeedFragment(fm, selectedItem.groupId, selectedItem.name)
is FeedGroupAddItem -> FeedGroupDialog.newInstance().show(fm, null)
}
}
override fun held(selectedItem: Item<*>?) {
when (selectedItem) {
is FeedGroupCardVerticalItem -> FeedGroupDialog.newInstance(selectedItem.groupId).show(fm, null)
}
}
}
private val listenerChannelItem = object : OnClickGesture<ChannelInfoItem> { private val listenerChannelItem = object : OnClickGesture<ChannelInfoItem> {
override fun selected(selectedItem: ChannelInfoItem) = NavigationHelper.openChannelFragment( override fun selected(selectedItem: ChannelInfoItem) = NavigationHelper.openChannelFragment(
fm, fm,
@ -420,6 +495,18 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) }
} }
private fun handleFeedVerticalGroups(groups: List<Group>) {
feedGroupsSection.update(groups)
if (feedGroupsListState != null) {
feedGroupsCarouselVertical?.onRestoreInstanceState(feedGroupsListVerticalState)
feedGroupsListVerticalState = null
}
feedGroupsSortMenuItem.showMenuItem = groups.size > 1
binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) }
}
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
// Contract // Contract
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////

View File

@ -10,7 +10,7 @@ import org.schabi.newpipe.local.subscription.FeedGroupIcon
data class FeedGroupCardItem( data class FeedGroupCardItem(
val groupId: Long = FeedGroupEntity.GROUP_ALL_ID, val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
val name: String, val name: String,
val icon: FeedGroupIcon val icon: FeedGroupIcon,
) : BindableItem<FeedGroupCardItemBinding>() { ) : BindableItem<FeedGroupCardItemBinding>() {
constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon) constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon)
@ -21,7 +21,7 @@ data class FeedGroupCardItem(
} }
} }
override fun getLayout(): Int = R.layout.feed_group_list_item override fun getLayout(): Int = R.layout.feed_group_card_item
override fun bind(viewBinding: FeedGroupCardItemBinding, position: Int) { override fun bind(viewBinding: FeedGroupCardItemBinding, position: Int) {
viewBinding.title.text = name viewBinding.title.text = name

View File

@ -0,0 +1,32 @@
package org.schabi.newpipe.local.subscription.item
import android.view.View
import com.xwray.groupie.viewbinding.BindableItem
import org.schabi.newpipe.R
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
import org.schabi.newpipe.databinding.FeedGroupCardVerticalItemBinding
import org.schabi.newpipe.local.subscription.FeedGroupIcon
data class FeedGroupCardVerticalItem(
val groupId: Long = FeedGroupEntity.GROUP_ALL_ID,
val name: String,
val icon: FeedGroupIcon
) : BindableItem<FeedGroupCardVerticalItemBinding>() {
constructor (feedGroupEntity: FeedGroupEntity) : this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon)
override fun getId(): Long {
return when (groupId) {
FeedGroupEntity.GROUP_ALL_ID -> super.getId()
else -> groupId
}
}
override fun getLayout(): Int = R.layout.feed_group_card_vertical_item
override fun bind(viewBinding: FeedGroupCardVerticalItemBinding, position: Int) {
viewBinding.title.text = name
viewBinding.icon.setImageResource(icon.getDrawableRes())
}
override fun initializeViewBinding(view: View) = FeedGroupCardVerticalItemBinding.bind(view)
}

View File

@ -4,7 +4,6 @@ import android.content.Context
import android.os.Parcelable import android.os.Parcelable
import android.view.View import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.xwray.groupie.GroupAdapter import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.viewbinding.BindableItem import com.xwray.groupie.viewbinding.BindableItem
import com.xwray.groupie.viewbinding.GroupieViewHolder import com.xwray.groupie.viewbinding.GroupieViewHolder
@ -14,7 +13,8 @@ import org.schabi.newpipe.local.subscription.decoration.FeedGroupCarouselDecorat
class FeedGroupCarouselItem( class FeedGroupCarouselItem(
context: Context, context: Context,
private val carouselAdapter: GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>> private val carouselAdapter: GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>,
private var listView: Int
) : BindableItem<FeedItemCarouselBinding>() { ) : BindableItem<FeedItemCarouselBinding>() {
private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context) private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context)
@ -36,7 +36,7 @@ class FeedGroupCarouselItem(
override fun initializeViewBinding(view: View): FeedItemCarouselBinding { override fun initializeViewBinding(view: View): FeedItemCarouselBinding {
val viewHolder = FeedItemCarouselBinding.bind(view) val viewHolder = FeedItemCarouselBinding.bind(view)
linearLayoutManager = LinearLayoutManager(view.context, RecyclerView.VERTICAL, false) linearLayoutManager = LinearLayoutManager(view.context, listView, false)
viewHolder.recyclerView.apply { viewHolder.recyclerView.apply {
layoutManager = linearLayoutManager layoutManager = linearLayoutManager

View File

@ -2,7 +2,7 @@
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="388dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:clickable="true" android:clickable="true"
@ -20,7 +20,7 @@
android:layout_width="51dp" android:layout_width="51dp"
android:layout_height="64dp" android:layout_height="64dp"
android:layout_gravity="center" android:layout_gravity="center"
android:paddingTop="2dp" android:paddingTop="8dp"
android:paddingBottom="2dp" android:paddingBottom="2dp"
android:scaleType="centerInside" android:scaleType="centerInside"
tools:ignore="ContentDescription" tools:ignore="ContentDescription"
@ -29,7 +29,7 @@
<org.schabi.newpipe.views.NewPipeTextView <org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:ellipsize="end" android:ellipsize="end"
android:gravity="start" android:gravity="start"
android:maxLines="1" android:maxLines="1"
@ -40,4 +40,5 @@
android:textStyle="bold" android:textStyle="bold"
tools:text="ALL" /> tools:text="ALL" />
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>