package com.github.libretube import android.app.Dialog import android.content.Intent import android.os.Bundle import android.util.Log import android.util.TypedValue import android.view.View import android.widget.* import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import com.google.android.material.dialog.MaterialAlertDialogBuilder class DownloadDialog : DialogFragment() { private val TAG = "DownloadDialog" var vidName = arrayListOf() var vidUrl = arrayListOf() var audioName = arrayListOf() var audioUrl = arrayListOf() var selectedVideo = 0 var selectedAudio = 0 var extension = ".mkv" var duration = 0 private lateinit var videoId: String override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { vidName = arguments?.getStringArrayList("videoName") as ArrayList vidUrl = arguments?.getStringArrayList("videoUrl") as ArrayList audioName = arguments?.getStringArrayList("audioName") as ArrayList audioUrl = arguments?.getStringArrayList("audioUrl") as ArrayList duration = arguments?.getInt("duration")!! videoId = arguments?.getString("videoId")!! 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(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()) } override fun onNothingSelected(parent: AdapterView<*>?) {} } val audioSpinner = view.findViewById(R.id.audio_spinner) val audioArrayAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, audioName) 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<*>?) {} } val radioGroup = view.findViewById(R.id.radioGp) radioGroup.setOnCheckedChangeListener { group, checkedId -> val radio: RadioButton = view.findViewById(checkedId) extension = radio.text.toString() Log.d(TAG, extension) } view.findViewById