mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
add download to video options dialog
This commit is contained in:
parent
a12f3ee210
commit
02f48be45c
@ -22,16 +22,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class DownloadDialog : DialogFragment() {
|
class DownloadDialog(
|
||||||
|
private val videoId: String
|
||||||
|
) : DialogFragment() {
|
||||||
private lateinit var binding: DialogDownloadBinding
|
private lateinit var binding: DialogDownloadBinding
|
||||||
|
|
||||||
private lateinit var videoId: String
|
|
||||||
private var duration = 0
|
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
return activity?.let {
|
return activity?.let {
|
||||||
videoId = arguments?.getString("video_id")!!
|
|
||||||
|
|
||||||
val builder = MaterialAlertDialogBuilder(it)
|
val builder = MaterialAlertDialogBuilder(it)
|
||||||
binding = DialogDownloadBinding.inflate(layoutInflater)
|
binding = DialogDownloadBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class VideoOptionsDialog(
|
|||||||
val optionsList = mutableListOf(
|
val optionsList = mutableListOf(
|
||||||
context?.getString(R.string.playOnBackground),
|
context?.getString(R.string.playOnBackground),
|
||||||
context?.getString(R.string.addToPlaylist),
|
context?.getString(R.string.addToPlaylist),
|
||||||
|
context?.getString(R.string.download),
|
||||||
context?.getString(R.string.share)
|
context?.getString(R.string.share)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -81,6 +82,10 @@ class VideoOptionsDialog(
|
|||||||
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, R.string.login_first, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
context?.getString(R.string.download) -> {
|
||||||
|
val downloadDialog = DownloadDialog(videoId)
|
||||||
|
downloadDialog.show(parentFragmentManager, DownloadDialog::class.java.name)
|
||||||
|
}
|
||||||
context?.getString(R.string.share) -> {
|
context?.getString(R.string.share) -> {
|
||||||
val shareDialog = ShareDialog(videoId, false)
|
val shareDialog = ShareDialog(videoId, false)
|
||||||
// using parentFragmentManager is important here
|
// using parentFragmentManager is important here
|
||||||
|
@ -1121,10 +1121,7 @@ class PlayerFragment : BaseFragment() {
|
|||||||
// download clicked
|
// download clicked
|
||||||
binding.relPlayerDownload.setOnClickListener {
|
binding.relPlayerDownload.setOnClickListener {
|
||||||
if (!Globals.IS_DOWNLOAD_RUNNING) {
|
if (!Globals.IS_DOWNLOAD_RUNNING) {
|
||||||
val newFragment = DownloadDialog()
|
val newFragment = DownloadDialog(videoId!!)
|
||||||
val bundle = Bundle()
|
|
||||||
bundle.putString("video_id", videoId)
|
|
||||||
newFragment.arguments = bundle
|
|
||||||
newFragment.show(childFragmentManager, DownloadDialog::class.java.name)
|
newFragment.show(childFragmentManager, DownloadDialog::class.java.name)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, R.string.dlisinprogress, Toast.LENGTH_SHORT)
|
Toast.makeText(context, R.string.dlisinprogress, Toast.LENGTH_SHORT)
|
||||||
@ -1294,7 +1291,15 @@ class PlayerFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeChapters() {
|
private fun initializeChapters() {
|
||||||
if (chapters.isEmpty()) return
|
if (chapters.isEmpty()) {
|
||||||
|
binding.chaptersRecView.visibility = View.GONE
|
||||||
|
playerBinding.chapterLL.visibility = View.GONE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// show the chapter layouts
|
||||||
|
binding.chaptersRecView.visibility = View.VISIBLE
|
||||||
|
playerBinding.chapterLL.visibility = View.VISIBLE
|
||||||
|
|
||||||
// enable chapters in the video description
|
// enable chapters in the video description
|
||||||
binding.chaptersRecView.layoutManager =
|
binding.chaptersRecView.layoutManager =
|
||||||
LinearLayoutManager(
|
LinearLayoutManager(
|
||||||
@ -1303,21 +1308,20 @@ class PlayerFragment : BaseFragment() {
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
|
binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer)
|
||||||
binding.chaptersRecView.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
// enable the chapters dialog in the player
|
// enable the chapters dialog in the player
|
||||||
val titles = mutableListOf<String>()
|
val titles = mutableListOf<String>()
|
||||||
chapters.forEach {
|
chapters.forEach {
|
||||||
titles += it.title!!
|
titles += it.title!!
|
||||||
}
|
}
|
||||||
playerBinding.chapterLL.visibility = View.VISIBLE
|
|
||||||
playerBinding.chapterLL.setOnClickListener {
|
playerBinding.chapterLL.setOnClickListener {
|
||||||
if (viewModel.isFullscreen.value!!) {
|
if (viewModel.isFullscreen.value!!) {
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(R.string.chapters)
|
.setTitle(R.string.chapters)
|
||||||
.setItems(titles.toTypedArray()) { _, index ->
|
.setItems(titles.toTypedArray()) { _, index ->
|
||||||
val position = chapters[index].start!! * 1000
|
exoPlayer.seekTo(
|
||||||
exoPlayer.seekTo(position)
|
chapters[index].start!! * 1000
|
||||||
|
)
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
} else {
|
} else {
|
||||||
@ -1329,14 +1333,14 @@ class PlayerFragment : BaseFragment() {
|
|||||||
|
|
||||||
// set the name of the video chapter in the exoPlayerView
|
// set the name of the video chapter in the exoPlayerView
|
||||||
private fun setCurrentChapterName() {
|
private fun setCurrentChapterName() {
|
||||||
// return if chapters are ampty to avoid crashes
|
// return if chapters are empty to avoid crashes
|
||||||
if (chapters.isEmpty()) return
|
if (chapters.isEmpty()) return
|
||||||
|
|
||||||
// call the function again in 100ms
|
// call the function again in 100ms
|
||||||
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)
|
exoPlayerView.postDelayed(this::setCurrentChapterName, 100)
|
||||||
|
|
||||||
val chapterIndex = getCurrentChapterIndex()
|
val chapterIndex = getCurrentChapterIndex()
|
||||||
val chapterName = chapters[chapterIndex].title
|
val chapterName = chapters[chapterIndex].title?.trim()
|
||||||
|
|
||||||
// change the chapter name textView text to the chapterName
|
// change the chapter name textView text to the chapterName
|
||||||
if (chapterName != playerBinding.chapterName.text) {
|
if (chapterName != playerBinding.chapterName.text) {
|
||||||
|
Loading…
Reference in New Issue
Block a user