diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt
index bf86d8577..492f423fa 100644
--- a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt
+++ b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt
@@ -38,6 +38,14 @@ class AddToPlaylistDialog : DialogFragment() {
binding = DialogAddtoplaylistBinding.inflate(layoutInflater)
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
+ binding.createPlaylist.setOnClickListener {
+ parentFragment?.childFragmentManager?.let {
+ CreatePlaylistDialog {
+ fetchPlaylists()
+ }.show(it, null)
+ }
+ }
+
token = PreferenceHelper.getToken()
if (token != "") fetchPlaylists()
diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt
index 087cfbf8c..6ea9e2936 100644
--- a/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt
+++ b/app/src/main/java/com/github/libretube/ui/dialogs/CreatePlaylistDialog.kt
@@ -8,16 +8,18 @@ import androidx.fragment.app.DialogFragment
import androidx.lifecycle.lifecycleScope
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance
+import com.github.libretube.api.obj.Playlists
import com.github.libretube.databinding.DialogCreatePlaylistBinding
import com.github.libretube.extensions.TAG
-import com.github.libretube.ui.fragments.LibraryFragment
import com.github.libretube.util.PreferenceHelper
import com.github.libretube.util.ThemeHelper
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import retrofit2.HttpException
import java.io.IOException
-class CreatePlaylistDialog : DialogFragment() {
+class CreatePlaylistDialog(
+ private val onSuccess: () -> Unit = {}
+) : DialogFragment() {
private var token: String = ""
private lateinit var binding: DialogCreatePlaylistBinding
@@ -53,7 +55,7 @@ class CreatePlaylistDialog : DialogFragment() {
val response = try {
RetrofitInstance.authApi.createPlaylist(
token,
- com.github.libretube.api.obj.Playlists(name = name)
+ Playlists(name = name)
)
} catch (e: IOException) {
println(e)
@@ -73,8 +75,7 @@ class CreatePlaylistDialog : DialogFragment() {
}
// refresh the playlists in the library
try {
- val parent = parentFragment as LibraryFragment
- parent.fetchPlaylists()
+ onSuccess.invoke()
} catch (e: Exception) {
Log.e(TAG(), e.toString())
}
diff --git a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt
index 33047a666..d217feb83 100644
--- a/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt
+++ b/app/src/main/java/com/github/libretube/ui/fragments/LibraryFragment.kt
@@ -82,7 +82,9 @@ class LibraryFragment : BaseFragment() {
fetchPlaylists()
}
binding.createPlaylist.setOnClickListener {
- val newFragment = CreatePlaylistDialog()
+ val newFragment = CreatePlaylistDialog {
+ fetchPlaylists()
+ }
newFragment.show(childFragmentManager, CreatePlaylistDialog::class.java.name)
}
} else {
diff --git a/app/src/main/res/layout/dialog_addtoplaylist.xml b/app/src/main/res/layout/dialog_addtoplaylist.xml
index eae3855cb..f2611e6b3 100644
--- a/app/src/main/res/layout/dialog_addtoplaylist.xml
+++ b/app/src/main/res/layout/dialog_addtoplaylist.xml
@@ -24,10 +24,23 @@
android:paddingEnd="40dp"
tools:ignore="RtlSymmetry" />
-
+
+
+
+
+
+
+