diff --git a/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt b/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt index cabc0826b..0cc9119ad 100644 --- a/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/AddtoPlaylistDialog.kt @@ -4,17 +4,14 @@ import android.app.Dialog import android.os.Bundle import android.util.Log import android.util.TypedValue -import android.view.View import android.widget.ArrayAdapter -import android.widget.Button -import android.widget.Spinner -import android.widget.TextView import android.widget.Toast import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.github.libretube.R +import com.github.libretube.databinding.DialogAddtoplaylistBinding import com.github.libretube.obj.PlaylistId import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.RetrofitInstance @@ -24,23 +21,22 @@ import java.io.IOException class AddtoPlaylistDialog : DialogFragment() { private val TAG = "AddToPlaylistDialog" + private lateinit var binding: DialogAddtoplaylistBinding + private lateinit var videoId: String private lateinit var token: String - private lateinit var spinner: Spinner - private lateinit var button: Button + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { videoId = arguments?.getString("videoId")!! val builder = MaterialAlertDialogBuilder(it) // Get the layout inflater - val inflater = requireActivity().layoutInflater + binding = DialogAddtoplaylistBinding.inflate(layoutInflater) + token = PreferenceHelper.getToken(requireContext()) - var view: View = inflater.inflate(R.layout.dialog_addtoplaylist, null) - spinner = view.findViewById(R.id.playlists_spinner) - button = view.findViewById(R.id.addToPlaylist) - if (token != "") { - fetchPlaylists() - } + + if (token != "") fetchPlaylists() + val typedValue = TypedValue() this.requireActivity().theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true) val hexColor = String.format("#%06X", (0xFFFFFF and typedValue.data)) @@ -48,9 +44,9 @@ class AddtoPlaylistDialog : DialogFragment() { "LibreTube", HtmlCompat.FROM_HTML_MODE_COMPACT ) - view.findViewById(R.id.title).text = appName + binding.title.text = appName - builder.setView(view) + builder.setView(binding.root) builder.create() } ?: throw IllegalStateException("Activity cannot be null") } @@ -80,10 +76,12 @@ class AddtoPlaylistDialog : DialogFragment() { arrayAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item ) - spinner.adapter = arrayAdapter + binding.playlistsSpinner.adapter = arrayAdapter runOnUiThread { - button.setOnClickListener { - addToPlaylist(response[spinner.selectedItemPosition].id!!) + binding.addToPlaylist.setOnClickListener { + addToPlaylist( + response[binding.playlistsSpinner.selectedItemPosition].id!! + ) } } } else { diff --git a/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt index d08256704..c08a9096a 100644 --- a/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/dialogs/CreatePlaylistDialog.kt @@ -4,32 +4,29 @@ import android.app.Dialog import android.os.Bundle import android.util.Log import android.util.TypedValue -import android.view.View -import android.widget.Button -import android.widget.TextView import android.widget.Toast import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope import com.github.libretube.R +import com.github.libretube.databinding.DialogCreatePlaylistBinding import com.github.libretube.fragments.Library import com.github.libretube.obj.Playlists import com.github.libretube.util.PreferenceHelper import com.github.libretube.util.RetrofitInstance import com.google.android.material.dialog.MaterialAlertDialogBuilder -import com.google.android.material.textfield.TextInputEditText import retrofit2.HttpException import java.io.IOException class CreatePlaylistDialog : DialogFragment() { val TAG = "CreatePlaylistDialog" private var token: String = "" + private lateinit var binding: DialogCreatePlaylistBinding override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { val builder = MaterialAlertDialogBuilder(it) - val inflater = requireActivity().layoutInflater - val view: View = inflater.inflate(R.layout.dialog_create_playlist, null) + binding = DialogCreatePlaylistBinding.inflate(layoutInflater) val typedValue = TypedValue() this.requireActivity().theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true) @@ -38,21 +35,18 @@ class CreatePlaylistDialog : DialogFragment() { "LibreTube", HtmlCompat.FROM_HTML_MODE_COMPACT ) - view.findViewById(R.id.title).text = appName + binding.title.text = appName - val cancelBtn = view.findViewById