mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
refactor: remove constructors from PlaybackOptionsSheet
This commit is contained in:
parent
4b8482722f
commit
0ebe784a90
@ -5,7 +5,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -17,7 +17,9 @@ import com.github.libretube.db.obj.DownloadWithItems
|
|||||||
import com.github.libretube.extensions.formatAsFileSize
|
import com.github.libretube.extensions.formatAsFileSize
|
||||||
import com.github.libretube.helpers.ImageHelper
|
import com.github.libretube.helpers.ImageHelper
|
||||||
import com.github.libretube.ui.activities.OfflinePlayerActivity
|
import com.github.libretube.ui.activities.OfflinePlayerActivity
|
||||||
|
import com.github.libretube.ui.base.BaseActivity
|
||||||
import com.github.libretube.ui.sheets.DownloadOptionsBottomSheet
|
import com.github.libretube.ui.sheets.DownloadOptionsBottomSheet
|
||||||
|
import com.github.libretube.ui.sheets.DownloadOptionsBottomSheet.Companion.DELETE_DOWNLOAD_REQUEST_KEY
|
||||||
import com.github.libretube.ui.viewholders.DownloadsViewHolder
|
import com.github.libretube.ui.viewholders.DownloadsViewHolder
|
||||||
import com.github.libretube.util.TextUtils
|
import com.github.libretube.util.TextUtils
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
@ -97,11 +99,19 @@ class DownloadsAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
root.setOnLongClickListener {
|
root.setOnLongClickListener {
|
||||||
DownloadOptionsBottomSheet(download) {
|
val activity = root.context as BaseActivity
|
||||||
|
val fragmentManager = activity.supportFragmentManager
|
||||||
|
fragmentManager.setFragmentResultListener(DELETE_DOWNLOAD_REQUEST_KEY, activity) { _, _ ->
|
||||||
showDeleteDialog(root.context, position)
|
showDeleteDialog(root.context, position)
|
||||||
}.show(
|
}
|
||||||
(root.context as AppCompatActivity).supportFragmentManager
|
DownloadOptionsBottomSheet()
|
||||||
|
.apply {
|
||||||
|
arguments = bundleOf(
|
||||||
|
IntentData.videoId to download.videoId,
|
||||||
|
IntentData.channelName to download.uploader
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
.show(fragmentManager)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
|
import androidx.fragment.app.setFragmentResult
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
import com.github.libretube.db.obj.Download
|
import com.github.libretube.db.obj.Download
|
||||||
@ -13,34 +14,38 @@ import com.github.libretube.obj.ShareData
|
|||||||
import com.github.libretube.services.OfflinePlayerService
|
import com.github.libretube.services.OfflinePlayerService
|
||||||
import com.github.libretube.ui.dialogs.ShareDialog
|
import com.github.libretube.ui.dialogs.ShareDialog
|
||||||
|
|
||||||
class DownloadOptionsBottomSheet(
|
class DownloadOptionsBottomSheet : BaseBottomSheet() {
|
||||||
private val download: Download,
|
private lateinit var videoId: String
|
||||||
private val onDelete: () -> Unit
|
private lateinit var uploader: String
|
||||||
) : BaseBottomSheet() {
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
videoId = arguments?.getString(IntentData.videoId)!!
|
||||||
|
uploader = arguments?.getString(IntentData.channelName)!!
|
||||||
|
|
||||||
val options = listOf(
|
val options = listOf(
|
||||||
R.string.playOnBackground,
|
R.string.playOnBackground,
|
||||||
R.string.go_to_video,
|
R.string.go_to_video,
|
||||||
R.string.share,
|
R.string.share,
|
||||||
R.string.delete
|
R.string.delete
|
||||||
).map { getString(it) }
|
).map { getString(it) }
|
||||||
|
|
||||||
setSimpleItems(options) { selectedIndex ->
|
setSimpleItems(options) { selectedIndex ->
|
||||||
when (selectedIndex) {
|
when (selectedIndex) {
|
||||||
0 -> {
|
0 -> {
|
||||||
val playerIntent = Intent(requireContext(), OfflinePlayerService::class.java)
|
val playerIntent = Intent(requireContext(), OfflinePlayerService::class.java)
|
||||||
.putExtra(IntentData.videoId, download.videoId)
|
.putExtra(IntentData.videoId, videoId)
|
||||||
context?.stopService(playerIntent)
|
context?.stopService(playerIntent)
|
||||||
ContextCompat.startForegroundService(requireContext(), playerIntent)
|
ContextCompat.startForegroundService(requireContext(), playerIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
1 -> {
|
||||||
NavigationHelper.navigateVideo(requireContext(), videoId = download.videoId)
|
NavigationHelper.navigateVideo(requireContext(), videoId = videoId)
|
||||||
}
|
}
|
||||||
|
|
||||||
2 -> {
|
2 -> {
|
||||||
val shareData = ShareData(currentVideo = download.uploader)
|
val shareData = ShareData(currentVideo = uploader)
|
||||||
val bundle = bundleOf(
|
val bundle = bundleOf(
|
||||||
IntentData.id to download.videoId,
|
IntentData.id to videoId,
|
||||||
IntentData.shareObjectType to ShareObjectType.CHANNEL,
|
IntentData.shareObjectType to ShareObjectType.CHANNEL,
|
||||||
IntentData.shareData to shareData
|
IntentData.shareData to shareData
|
||||||
)
|
)
|
||||||
@ -50,7 +55,7 @@ class DownloadOptionsBottomSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
3 -> {
|
3 -> {
|
||||||
onDelete.invoke()
|
setFragmentResult(DELETE_DOWNLOAD_REQUEST_KEY, bundleOf())
|
||||||
dialog?.dismiss()
|
dialog?.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,4 +63,8 @@ class DownloadOptionsBottomSheet(
|
|||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val DELETE_DOWNLOAD_REQUEST_KEY = "delete_download_request_key"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user