Skip to content

Commit

Permalink
Merge pull request #3733 from Bnyro/master
Browse files Browse the repository at this point in the history
Various subscription group improvements
  • Loading branch information
Bnyro authored May 8, 2023
2 parents 843b5b6 + 01b98a0 commit 33ccb1a
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.github.libretube.databinding.SubscriptionGroupChannelRowBinding
import com.github.libretube.db.obj.SubscriptionGroup
import com.github.libretube.extensions.toID
import com.github.libretube.helpers.ImageHelper
import com.github.libretube.helpers.NavigationHelper
import com.github.libretube.ui.viewholders.SubscriptionGroupChannelRowViewHolder

class SubscriptionGroupChannelsAdapter(
Expand All @@ -30,6 +31,9 @@ class SubscriptionGroupChannelsAdapter(
val channel = channels[position]
val channelId = channel.url.toID()
holder.binding.apply {
root.setOnClickListener {
NavigationHelper.navigateChannel(root.context, channelId)
}
subscriptionChannelName.text = channel.name
ImageHelper.loadImage(channel.avatar, subscriptionChannelImage)
channelIncluded.setOnCheckedChangeListener(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.SubscriptionGroupRowBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SubscriptionGroup
import com.github.libretube.ui.dialogs.EditChannelGroupDialog
import com.github.libretube.ui.sheets.EditChannelGroupSheet
import com.github.libretube.ui.viewholders.SubscriptionGroupsViewHolder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -44,7 +44,7 @@ class SubscriptionGroupsAdapter(
notifyItemRangeChanged(position, itemCount)
}
editGroup.setOnClickListener {
EditChannelGroupDialog(subscriptionGroup) {
EditChannelGroupSheet(subscriptionGroup) {
groups[position] = it
runBlocking(Dispatchers.IO) {
// delete the old one as it might have a different name
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import com.github.libretube.helpers.PreferenceHelper
import com.github.libretube.ui.adapters.LegacySubscriptionAdapter
import com.github.libretube.ui.adapters.SubscriptionChannelAdapter
import com.github.libretube.ui.adapters.VideosAdapter
import com.github.libretube.ui.dialogs.ChannelGroupsDialog
import com.github.libretube.ui.models.SubscriptionsViewModel
import com.github.libretube.ui.sheets.BaseBottomSheet
import com.github.libretube.ui.sheets.ChannelGroupsSheet
import com.google.android.material.chip.Chip
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -197,7 +197,7 @@ class SubscriptionsFragment : Fragment() {
}

binding.editGroups.setOnClickListener {
ChannelGroupsDialog(channelGroups.toMutableList()) {
ChannelGroupsSheet(channelGroups.toMutableList()) {
lifecycleScope.launch { initChannelGroups() }
}.show(childFragmentManager, null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.libretube.ui.sheets

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.databinding.DialogSubscriptionGroupsBinding
import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.SubscriptionGroup
import com.github.libretube.ui.adapters.SubscriptionGroupsAdapter
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking

class ChannelGroupsSheet(
private val groups: MutableList<SubscriptionGroup>,
private val onGroupsChanged: (List<SubscriptionGroup>) -> Unit
) : ExpandedBottomSheet() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val binding = DialogSubscriptionGroupsBinding.inflate(layoutInflater)

binding.groupsRV.layoutManager = LinearLayoutManager(context)
val adapter = SubscriptionGroupsAdapter(
groups.toMutableList(),
parentFragmentManager,
onGroupsChanged
)
binding.groupsRV.adapter = adapter

binding.newGroup.setOnClickListener {
EditChannelGroupSheet(SubscriptionGroup("", mutableListOf())) {
runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.subscriptionGroupsDao().createGroup(it)
}
groups.add(it)
adapter.insertItem(it)
onGroupsChanged(groups)
}.show(parentFragmentManager, null)
}

binding.confirm.setOnClickListener {
dismiss()
}

return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
package com.github.libretube.ui.dialogs
package com.github.libretube.ui.sheets

import android.app.Dialog
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.api.SubscriptionHelper
import com.github.libretube.api.obj.Subscription
import com.github.libretube.databinding.DialogEditChannelGroupBinding
import com.github.libretube.db.obj.SubscriptionGroup
import com.github.libretube.ui.adapters.SubscriptionGroupChannelsAdapter
import com.github.libretube.ui.models.SubscriptionsViewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class EditChannelGroupDialog(
class EditChannelGroupSheet(
private var group: SubscriptionGroup,
private val onGroupChanged: (SubscriptionGroup) -> Unit
) : DialogFragment() {
) : ExpandedBottomSheet() {
private val subscriptionsModel: SubscriptionsViewModel by activityViewModels()
private lateinit var binding: DialogEditChannelGroupBinding
private var channels: List<Subscription> = listOf()

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DialogEditChannelGroupBinding.inflate(layoutInflater)
binding.groupName.setText(group.name)

Expand All @@ -39,16 +42,18 @@ class EditChannelGroupDialog(
showChannels(channels, it?.toString())
}

return MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.edit_group)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.okay) { _, _ ->
group.name = binding.groupName.text.toString()
if (group.name.isBlank()) return@setPositiveButton
onGroupChanged(group)
}
.setView(binding.root)
.create()
binding.cancel.setOnClickListener {
dismiss()
}

binding.confirm.setOnClickListener {
group.name = binding.groupName.text.toString()
if (group.name.isBlank()) return@setOnClickListener
onGroupChanged(group)
dismiss()
}

return binding.root
}

private fun fetchSubscriptions() {
Expand Down
39 changes: 31 additions & 8 deletions app/src/main/res/layout/dialog_edit_channel_group.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
Expand All @@ -16,7 +16,7 @@
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/group_name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

Expand All @@ -37,15 +37,38 @@
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/search_input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/channelsRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
android:layout_marginTop="10dp"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="end"
android:paddingVertical="10dp"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:id="@+id/cancel"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_width="wrap_content"
android:text="@string/cancel"
android:layout_height="wrap_content"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/confirm"
style="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="wrap_content"
android:text="@string/okay"
android:layout_marginHorizontal="16dp"
android:layout_height="wrap_content"/>

</LinearLayout>

</LinearLayout>

Expand All @@ -54,6 +77,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="200dp" />
android:layout_marginVertical="20dp"/>

</LinearLayout>
39 changes: 36 additions & 3 deletions app/src/main/res/layout/dialog_subscription_groups.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:text="@string/channel_groups"
android:textStyle="bold"
android:textSize="24sp"
android:layout_marginTop="18dp"
android:layout_marginStart="18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/groupsRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />
android:layout_marginTop="20dp"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="end"
android:paddingVertical="10dp"
android:layout_height="wrap_content">

<com.google.android.material.button.MaterialButton
android:id="@+id/new_group"
android:layout_width="wrap_content"
android:text="@string/new_group"
style="@style/Widget.Material3.Button.OutlinedButton"
android:layout_height="wrap_content"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/confirm"
style="@style/Widget.Material3.Button.ElevatedButton"
android:layout_width="wrap_content"
android:text="@string/okay"
android:layout_marginHorizontal="16dp"
android:layout_height="wrap_content"/>

</LinearLayout>

</LinearLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/subscription_group_channel_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:paddingHorizontal="20dp" >
android:background="@drawable/rounded_ripple"
android:paddingHorizontal="10dp" >

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/subscription_channel_image"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/subscription_group_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingHorizontal="25dp"
android:paddingHorizontal="5dp"
android:paddingVertical="10dp">

<TextView
Expand Down

0 comments on commit 33ccb1a

Please sign in to comment.