From 10d15a900a0da2293b899d1843b2a5350de6e85e Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 17 Jun 2022 17:03:17 +0200 Subject: [PATCH] default selection downloads --- .../com/github/libretube/DownloadService.kt | 2 +- .../libretube/dialogs/DownloadDialog.kt | 72 ++++++++----------- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index db52515d6..e13b766b5 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -152,7 +152,7 @@ class DownloadService : Service() { if (downloadId == id) { if (downloadType == "mux") { downloadManagerRequest( - getString(R.string.video), + getString(R.string.audio), getString(R.string.downloading), audioUrl, audioDir 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 7e71a21e7..1cffd8858 100644 --- a/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/DownloadDialog.kt @@ -10,7 +10,6 @@ import android.os.Environment import android.util.Log import android.util.TypedValue import android.view.View -import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Button import android.widget.Spinner @@ -26,18 +25,23 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder class DownloadDialog : DialogFragment() { private val TAG = "DownloadDialog" - var streams: Streams = Streams() - var selectedVideo = 0 - var selectedAudio = 0 - var duration = 0 + + private lateinit var streams: Streams private lateinit var videoId: String + private var duration = 0 + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { streams = arguments?.getParcelable("streams")!! videoId = arguments?.getString("video_id")!! val mainActivity = activity as MainActivity - Log.e(TAG, "download button clicked!") + val builder = MaterialAlertDialogBuilder(it) + // Get the layout inflater + val inflater = requireActivity().layoutInflater + var view: View = inflater.inflate(R.layout.dialog_download, null) + + // request storage permissions if not granted yet if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { Log.d("myz", "" + Build.VERSION.SDK_INT) if (!Environment.isExternalStorageManager()) { @@ -70,50 +74,46 @@ class DownloadDialog : DialogFragment() { ) } } + + var vidName = arrayListOf() - vidName.add(getString(R.string.no_video)) var vidUrl = arrayListOf() + + // add empty selection + vidName.add(getString(R.string.no_video)) vidUrl.add("") + + // add all available video streams for (vid in streams.videoStreams!!) { val name = vid.quality + " " + vid.format vidName.add(name) vidUrl.add(vid.url!!) } + var audioName = arrayListOf() - audioName.add(getString(R.string.no_audio)) var audioUrl = arrayListOf() + + // add empty selection + audioName.add(getString(R.string.no_audio)) audioUrl.add("") + + // add all available audio streams for (audio in streams.audioStreams!!) { val name = audio.quality + " " + audio.format audioName.add(name) audioUrl.add(audio.url!!) } - val builder = MaterialAlertDialogBuilder(it) - // Get the layout inflater - val inflater = requireActivity().layoutInflater - var view: View = inflater.inflate(R.layout.dialog_download, null) val videoSpinner = view.findViewById(R.id.video_spinner) - val videoArrayAdapter = ArrayAdapter( + val videoArrayAdapter = ArrayAdapter( requireContext(), android.R.layout.simple_spinner_item, vidName ) videoArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) videoSpinner.adapter = videoArrayAdapter - videoSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parent: AdapterView<*>, - view: View, - position: Int, - id: Long - ) { - selectedVideo = position - Log.d(TAG, selectedVideo.toString()) - } + videoSpinner.setSelection(1) - override fun onNothingSelected(parent: AdapterView<*>?) {} - } val audioSpinner = view.findViewById(R.id.audio_spinner) val audioArrayAdapter = ArrayAdapter( requireContext(), @@ -122,27 +122,17 @@ class DownloadDialog : DialogFragment() { ) audioArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) audioSpinner.adapter = audioArrayAdapter - audioSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { - override fun onItemSelected( - parent: AdapterView<*>, - view: View, - position: Int, - id: Long - ) { - selectedAudio = position - Log.d(TAG, selectedAudio.toString()) - } - - override fun onNothingSelected(parent: AdapterView<*>?) {} - } + audioSpinner.setSelection(1) view.findViewById