diff --git a/app/src/main/java/com/github/libretube/Constants.kt b/app/src/main/java/com/github/libretube/Constants.kt index cc6ffe739..05c68ed41 100644 --- a/app/src/main/java/com/github/libretube/Constants.kt +++ b/app/src/main/java/com/github/libretube/Constants.kt @@ -59,4 +59,4 @@ const val DATABASE_NAME = "LibreTubeDatabase" /** * New Streams notifications */ -const val NOTIFICATION_WORK_NAME = "NotificationService" \ No newline at end of file +const val NOTIFICATION_WORK_NAME = "NotificationService" diff --git a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt index 28a249a48..17bd96864 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt @@ -22,16 +22,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import retrofit2.HttpException import java.io.IOException -class DownloadDialog : DialogFragment() { +class DownloadDialog( + private val videoId: String +) : DialogFragment() { private lateinit var binding: DialogDownloadBinding - private lateinit var videoId: String - private var duration = 0 - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { - videoId = arguments?.getString("video_id")!! - val builder = MaterialAlertDialogBuilder(it) binding = DialogDownloadBinding.inflate(layoutInflater) diff --git a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt index 688e76a95..9eb7e221b 100644 --- a/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/VideoOptionsDialog.kt @@ -33,6 +33,7 @@ class VideoOptionsDialog( val optionsList = mutableListOf( context?.getString(R.string.playOnBackground), context?.getString(R.string.addToPlaylist), + context?.getString(R.string.download), context?.getString(R.string.share) ) @@ -81,6 +82,10 @@ class VideoOptionsDialog( 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) -> { val shareDialog = ShareDialog(videoId, false) // using parentFragmentManager is important here diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 4a79e0ae7..969d32e00 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -1121,10 +1121,7 @@ class PlayerFragment : BaseFragment() { // download clicked binding.relPlayerDownload.setOnClickListener { if (!Globals.IS_DOWNLOAD_RUNNING) { - val newFragment = DownloadDialog() - val bundle = Bundle() - bundle.putString("video_id", videoId) - newFragment.arguments = bundle + val newFragment = DownloadDialog(videoId!!) newFragment.show(childFragmentManager, DownloadDialog::class.java.name) } else { Toast.makeText(context, R.string.dlisinprogress, Toast.LENGTH_SHORT) @@ -1294,7 +1291,15 @@ class PlayerFragment : BaseFragment() { } 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 binding.chaptersRecView.layoutManager = LinearLayoutManager( @@ -1303,21 +1308,20 @@ class PlayerFragment : BaseFragment() { false ) binding.chaptersRecView.adapter = ChaptersAdapter(chapters, exoPlayer) - binding.chaptersRecView.visibility = View.VISIBLE // enable the chapters dialog in the player val titles = mutableListOf() chapters.forEach { titles += it.title!! } - playerBinding.chapterLL.visibility = View.VISIBLE playerBinding.chapterLL.setOnClickListener { if (viewModel.isFullscreen.value!!) { MaterialAlertDialogBuilder(requireContext()) .setTitle(R.string.chapters) .setItems(titles.toTypedArray()) { _, index -> - val position = chapters[index].start!! * 1000 - exoPlayer.seekTo(position) + exoPlayer.seekTo( + chapters[index].start!! * 1000 + ) } .show() } else { @@ -1329,14 +1333,14 @@ class PlayerFragment : BaseFragment() { // set the name of the video chapter in the exoPlayerView private fun setCurrentChapterName() { - // return if chapters are ampty to avoid crashes + // return if chapters are empty to avoid crashes if (chapters.isEmpty()) return // call the function again in 100ms exoPlayerView.postDelayed(this::setCurrentChapterName, 100) val chapterIndex = getCurrentChapterIndex() - val chapterName = chapters[chapterIndex].title + val chapterName = chapters[chapterIndex].title?.trim() // change the chapter name textView text to the chapterName if (chapterName != playerBinding.chapterName.text) {