mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
allow creating playlists from addin
This commit is contained in:
parent
0583f005e8
commit
3105a46e2b
@ -38,6 +38,14 @@ class AddToPlaylistDialog : DialogFragment() {
|
|||||||
binding = DialogAddtoplaylistBinding.inflate(layoutInflater)
|
binding = DialogAddtoplaylistBinding.inflate(layoutInflater)
|
||||||
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
|
binding.title.text = ThemeHelper.getStyledAppName(requireContext())
|
||||||
|
|
||||||
|
binding.createPlaylist.setOnClickListener {
|
||||||
|
parentFragment?.childFragmentManager?.let {
|
||||||
|
CreatePlaylistDialog {
|
||||||
|
fetchPlaylists()
|
||||||
|
}.show(it, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
token = PreferenceHelper.getToken()
|
token = PreferenceHelper.getToken()
|
||||||
|
|
||||||
if (token != "") fetchPlaylists()
|
if (token != "") fetchPlaylists()
|
||||||
|
@ -8,16 +8,18 @@ import androidx.fragment.app.DialogFragment
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
|
import com.github.libretube.api.obj.Playlists
|
||||||
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
||||||
import com.github.libretube.extensions.TAG
|
import com.github.libretube.extensions.TAG
|
||||||
import com.github.libretube.ui.fragments.LibraryFragment
|
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import com.github.libretube.util.ThemeHelper
|
import com.github.libretube.util.ThemeHelper
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class CreatePlaylistDialog : DialogFragment() {
|
class CreatePlaylistDialog(
|
||||||
|
private val onSuccess: () -> Unit = {}
|
||||||
|
) : DialogFragment() {
|
||||||
private var token: String = ""
|
private var token: String = ""
|
||||||
private lateinit var binding: DialogCreatePlaylistBinding
|
private lateinit var binding: DialogCreatePlaylistBinding
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
|||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.authApi.createPlaylist(
|
RetrofitInstance.authApi.createPlaylist(
|
||||||
token,
|
token,
|
||||||
com.github.libretube.api.obj.Playlists(name = name)
|
Playlists(name = name)
|
||||||
)
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
@ -73,8 +75,7 @@ class CreatePlaylistDialog : DialogFragment() {
|
|||||||
}
|
}
|
||||||
// refresh the playlists in the library
|
// refresh the playlists in the library
|
||||||
try {
|
try {
|
||||||
val parent = parentFragment as LibraryFragment
|
onSuccess.invoke()
|
||||||
parent.fetchPlaylists()
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG(), e.toString())
|
Log.e(TAG(), e.toString())
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,9 @@ class LibraryFragment : BaseFragment() {
|
|||||||
fetchPlaylists()
|
fetchPlaylists()
|
||||||
}
|
}
|
||||||
binding.createPlaylist.setOnClickListener {
|
binding.createPlaylist.setOnClickListener {
|
||||||
val newFragment = CreatePlaylistDialog()
|
val newFragment = CreatePlaylistDialog {
|
||||||
|
fetchPlaylists()
|
||||||
|
}
|
||||||
newFragment.show(childFragmentManager, CreatePlaylistDialog::class.java.name)
|
newFragment.show(childFragmentManager, CreatePlaylistDialog::class.java.name)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,10 +24,23 @@
|
|||||||
android:paddingEnd="40dp"
|
android:paddingEnd="40dp"
|
||||||
tools:ignore="RtlSymmetry" />
|
tools:ignore="RtlSymmetry" />
|
||||||
|
|
||||||
|
<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
|
<Button
|
||||||
android:id="@+id/addToPlaylist"
|
android:id="@+id/addToPlaylist"
|
||||||
style="@style/CustomDialogButton"
|
style="@style/CustomDialogButton"
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
android:text="@string/addToPlaylist" />
|
android:text="@string/addToPlaylist" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user