mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10: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.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
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.helpers.ImageHelper
|
||||
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.Companion.DELETE_DOWNLOAD_REQUEST_KEY
|
||||
import com.github.libretube.ui.viewholders.DownloadsViewHolder
|
||||
import com.github.libretube.util.TextUtils
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
@ -97,11 +99,19 @@ class DownloadsAdapter(
|
||||
}
|
||||
|
||||
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)
|
||||
}.show(
|
||||
(root.context as AppCompatActivity).supportFragmentManager
|
||||
)
|
||||
}
|
||||
DownloadOptionsBottomSheet()
|
||||
.apply {
|
||||
arguments = bundleOf(
|
||||
IntentData.videoId to download.videoId,
|
||||
IntentData.channelName to download.uploader
|
||||
)
|
||||
}
|
||||
.show(fragmentManager)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.constants.IntentData
|
||||
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.ui.dialogs.ShareDialog
|
||||
|
||||
class DownloadOptionsBottomSheet(
|
||||
private val download: Download,
|
||||
private val onDelete: () -> Unit
|
||||
) : BaseBottomSheet() {
|
||||
class DownloadOptionsBottomSheet : BaseBottomSheet() {
|
||||
private lateinit var videoId: String
|
||||
private lateinit var uploader: String
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
videoId = arguments?.getString(IntentData.videoId)!!
|
||||
uploader = arguments?.getString(IntentData.channelName)!!
|
||||
|
||||
val options = listOf(
|
||||
R.string.playOnBackground,
|
||||
R.string.go_to_video,
|
||||
R.string.share,
|
||||
R.string.delete
|
||||
).map { getString(it) }
|
||||
|
||||
setSimpleItems(options) { selectedIndex ->
|
||||
when (selectedIndex) {
|
||||
0 -> {
|
||||
val playerIntent = Intent(requireContext(), OfflinePlayerService::class.java)
|
||||
.putExtra(IntentData.videoId, download.videoId)
|
||||
.putExtra(IntentData.videoId, videoId)
|
||||
context?.stopService(playerIntent)
|
||||
ContextCompat.startForegroundService(requireContext(), playerIntent)
|
||||
}
|
||||
|
||||
1 -> {
|
||||
NavigationHelper.navigateVideo(requireContext(), videoId = download.videoId)
|
||||
NavigationHelper.navigateVideo(requireContext(), videoId = videoId)
|
||||
}
|
||||
|
||||
2 -> {
|
||||
val shareData = ShareData(currentVideo = download.uploader)
|
||||
val shareData = ShareData(currentVideo = uploader)
|
||||
val bundle = bundleOf(
|
||||
IntentData.id to download.videoId,
|
||||
IntentData.id to videoId,
|
||||
IntentData.shareObjectType to ShareObjectType.CHANNEL,
|
||||
IntentData.shareData to shareData
|
||||
)
|
||||
@ -50,7 +55,7 @@ class DownloadOptionsBottomSheet(
|
||||
}
|
||||
|
||||
3 -> {
|
||||
onDelete.invoke()
|
||||
setFragmentResult(DELETE_DOWNLOAD_REQUEST_KEY, bundleOf())
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
@ -58,4 +63,8 @@ class DownloadOptionsBottomSheet(
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DELETE_DOWNLOAD_REQUEST_KEY = "delete_download_request_key"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user