mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Add full support for child deletions
This commit is contained in:
parent
f6bfdefe15
commit
201f3a37a1
4 changed files with 162 additions and 19 deletions
app/src/main
java/com/lagradost/cloudstream3/ui/download
res/layout
|
@ -285,7 +285,12 @@ class DownloadAdapter(
|
|||
}
|
||||
|
||||
downloadButton.setDefaultClickListener(data, downloadChildEpisodeTextExtra, mediaClickCallback)
|
||||
downloadButton.isVisible = true
|
||||
downloadButton.isVisible = !isMultiDeleteState
|
||||
|
||||
downloadButton.setOnLongClickListener {
|
||||
multiDeleteStateCallback.invoke(VisualDownloadItem.Child(card))
|
||||
true
|
||||
}
|
||||
|
||||
downloadChildEpisodeText.apply {
|
||||
text = context.getNameFull(data.name, data.episode, data.season)
|
||||
|
@ -295,6 +300,35 @@ class DownloadAdapter(
|
|||
downloadChildEpisodeHolder.setOnClickListener {
|
||||
mediaClickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, data))
|
||||
}
|
||||
|
||||
downloadChildEpisodeHolder.apply {
|
||||
if (isMultiDeleteState) {
|
||||
setOnClickListener {
|
||||
toggleIsChecked(deleteCheckbox, VisualDownloadItem.Child(card))
|
||||
}
|
||||
} else {
|
||||
setOnClickListener {
|
||||
mediaClickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, data))
|
||||
}
|
||||
}
|
||||
|
||||
setOnLongClickListener {
|
||||
multiDeleteStateCallback.invoke(VisualDownloadItem.Child(card))
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
if (isMultiDeleteState) {
|
||||
deleteCheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||
selectedIds[data.id] = isChecked
|
||||
selectedChangedCallback.invoke(VisualDownloadItem.Child(card), isChecked)
|
||||
}
|
||||
} else deleteCheckbox.setOnCheckedChangeListener(null)
|
||||
|
||||
deleteCheckbox.apply {
|
||||
isVisible = isMultiDeleteState
|
||||
isChecked = selectedIds[data.id] == true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.lagradost.cloudstream3.R
|
||||
import com.lagradost.cloudstream3.databinding.FragmentChildDownloadsBinding
|
||||
import com.lagradost.cloudstream3.mvvm.observe
|
||||
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
|
||||
import com.lagradost.cloudstream3.ui.result.FOCUS_SELF
|
||||
import com.lagradost.cloudstream3.ui.result.setLinearListLayout
|
||||
|
@ -86,6 +88,10 @@ class DownloadChildFragment : Fragment() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// We always want fresh selections
|
||||
// when navigating to downloads
|
||||
downloadsViewModel.clearSelectedItems()
|
||||
|
||||
val folder = arguments?.getString("folder")
|
||||
val name = arguments?.getString("name")
|
||||
if (folder == null) {
|
||||
|
@ -105,6 +111,12 @@ class DownloadChildFragment : Fragment() {
|
|||
setAppBarNoScrollFlagsOnTV()
|
||||
}
|
||||
|
||||
observe(downloadsViewModel.selectedItems) {
|
||||
handleSelectedChange(it)
|
||||
binding?.btnDelete?.text =
|
||||
getString(R.string.delete_count).format(it.count())
|
||||
}
|
||||
|
||||
val adapter = DownloadAdapter(
|
||||
{},
|
||||
{ downloadClickEvent ->
|
||||
|
@ -113,8 +125,19 @@ class DownloadChildFragment : Fragment() {
|
|||
setUpDownloadDeleteListener(folder)
|
||||
}
|
||||
},
|
||||
{ _, _ -> },
|
||||
{ _ -> }
|
||||
{ card, isChecked ->
|
||||
if (isChecked) {
|
||||
downloadsViewModel.addSelected(card)
|
||||
} else downloadsViewModel.removeSelected(card)
|
||||
},
|
||||
{ card ->
|
||||
if (card !is VisualDownloadItem.Child) return@DownloadAdapter
|
||||
downloadsViewModel.addSelected(card)
|
||||
(binding?.downloadChildList?.adapter as? DownloadAdapter)?.updateSelectedItem(
|
||||
card.child.data.id,
|
||||
true
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
binding?.downloadChildList?.apply {
|
||||
|
@ -131,6 +154,34 @@ class DownloadChildFragment : Fragment() {
|
|||
updateList(folder)
|
||||
}
|
||||
|
||||
private fun handleSelectedChange(selected: MutableList<VisualDownloadItem>) {
|
||||
val adapter = binding?.downloadChildList?.adapter as? DownloadAdapter
|
||||
if (selected.isNotEmpty()) {
|
||||
binding?.downloadDeleteAppbar?.isVisible = true
|
||||
|
||||
binding?.btnDelete?.setOnClickListener {
|
||||
context?.let { ctx -> downloadsViewModel.handleMultiDelete(ctx) }
|
||||
}
|
||||
|
||||
binding?.btnCancel?.setOnClickListener {
|
||||
adapter?.setIsMultiDeleteState(false)
|
||||
downloadsViewModel.clearSelectedItems()
|
||||
}
|
||||
|
||||
binding?.btnSelectAll?.setOnClickListener {
|
||||
adapter?.selectAllItems()
|
||||
downloadsViewModel.selectAllItems()
|
||||
}
|
||||
|
||||
adapter?.setIsMultiDeleteState(true)
|
||||
} else {
|
||||
binding?.downloadDeleteAppbar?.isVisible = false
|
||||
|
||||
adapter?.setIsMultiDeleteState(false)
|
||||
downloadsViewModel.clearSelectedItems()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpDownloadDeleteListener(folder: String) {
|
||||
downloadDeleteEventListener = { id: Int ->
|
||||
val list = (binding?.downloadChildList?.adapter as? DownloadAdapter)?.currentList
|
||||
|
|
|
@ -2,10 +2,8 @@
|
|||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
||||
android:id="@+id/download_child_episode_holder"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:foreground="@drawable/outline_drawable"
|
||||
|
@ -18,7 +16,6 @@
|
|||
|
||||
<androidx.core.widget.ContentLoadingProgressBar
|
||||
android:id="@+id/download_child_episode_progress"
|
||||
|
||||
style="@android:style/Widget.Material.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="5dp"
|
||||
|
@ -56,12 +53,10 @@
|
|||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
|
||||
android:ellipsize="marquee"
|
||||
android:gravity="center_vertical"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:scrollHorizontally="true"
|
||||
|
||||
android:singleLine="true"
|
||||
android:textColor="?attr/textColor"
|
||||
tools:text="Episode 1 Episode 1 Episode 1 Episode 1 Episode 1 Episode 1 Episode 1" />
|
||||
|
@ -78,7 +73,6 @@
|
|||
tools:text="128MB / 237MB" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<com.lagradost.cloudstream3.ui.download.button.PieFetchButton
|
||||
android:id="@+id/download_button"
|
||||
android:layout_width="@dimen/download_size"
|
||||
|
@ -89,5 +83,16 @@
|
|||
android:focusable="true"
|
||||
android:nextFocusLeft="@id/download_child_episode_holder"
|
||||
android:padding="10dp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/delete_checkbox"
|
||||
android:layout_width="@dimen/download_size"
|
||||
android:layout_height="@dimen/download_size"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:layout_marginStart="-50dp"
|
||||
android:focusable="true"
|
||||
android:nextFocusLeft="@id/download_child_episode_holder"
|
||||
android:padding="10dp"
|
||||
android:visibility="gone" />
|
||||
</GridLayout>
|
||||
</androidx.cardview.widget.CardView>
|
|
@ -14,21 +14,74 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/transparent">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/download_child_toolbar"
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/primaryGrayBackground"
|
||||
android:paddingTop="@dimen/navbar_height"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:navigationIconTint="?attr/iconColor"
|
||||
app:titleTextColor="?attr/textColor"
|
||||
tools:title="Overlord" />
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/download_delete_appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:padding="8dp"
|
||||
android:visibility="gone"
|
||||
android:elevation="100dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btnCancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_baseline_close_24"
|
||||
android:contentDescription="@string/cancel"
|
||||
android:padding="8dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDelete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:text="@string/delete"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSelectAll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:text="@string/select_all"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_marginEnd="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/download_child_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/primaryGrayBackground"
|
||||
android:paddingTop="@dimen/navbar_height"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:navigationIconTint="?attr/iconColor"
|
||||
app:titleTextColor="?attr/textColor"
|
||||
tools:title="Overlord" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/download_child_list"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/primaryBlackBackground"
|
||||
|
|
Loading…
Reference in a new issue