allow creating playlists from addin

This commit is contained in:
Bnyro 2022-11-19 11:12:26 +01:00
parent 0583f005e8
commit 3105a46e2b
4 changed files with 35 additions and 11 deletions

View File

@ -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()

View File

@ -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())
}

View File

@ -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 {

View File

@ -24,10 +24,23 @@
android:paddingEnd="40dp"
tools:ignore="RtlSymmetry" />
<Button
android:id="@+id/addToPlaylist"
style="@style/CustomDialogButton"
android:layout_marginEnd="16dp"
android:text="@string/addToPlaylist" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:layout_marginEnd="16dp">
<Button
android:id="@+id/create_playlist"
style="@style/CustomDialogButton"
android:text="@string/createPlaylist"
android:layout_marginEnd="8dp"/>
<Button
android:id="@+id/addToPlaylist"
style="@style/CustomDialogButton"
android:text="@string/addToPlaylist" />
</LinearLayout>
</LinearLayout>