mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
commit
3642eea7e4
@ -13,4 +13,7 @@ object Globals {
|
|||||||
|
|
||||||
// for downloads
|
// for downloads
|
||||||
var IS_DOWNLOAD_RUNNING = false
|
var IS_DOWNLOAD_RUNNING = false
|
||||||
|
|
||||||
|
// for playlists
|
||||||
|
var SELECTED_PLAYLIST_ID: String? = null
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,13 @@ class PlaylistsAdapter(
|
|||||||
override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) {
|
||||||
val playlist = playlists[position]
|
val playlist = playlists[position]
|
||||||
holder.binding.apply {
|
holder.binding.apply {
|
||||||
ConnectionHelper.loadImage(playlist.thumbnail, playlistThumbnail)
|
|
||||||
// set imageview drawable as empty playlist if imageview empty
|
// set imageview drawable as empty playlist if imageview empty
|
||||||
if (playlistThumbnail.drawable == null) {
|
Log.e(TAG, playlist.thumbnail.toString())
|
||||||
|
if (playlist.thumbnail!!.split("/").size <= 4) {
|
||||||
playlistThumbnail.setImageResource(R.drawable.ic_empty_playlist)
|
playlistThumbnail.setImageResource(R.drawable.ic_empty_playlist)
|
||||||
playlistThumbnail.setBackgroundColor(R.attr.colorSurface)
|
playlistThumbnail.setBackgroundColor(R.attr.colorSurface)
|
||||||
|
} else {
|
||||||
|
ConnectionHelper.loadImage(playlist.thumbnail, playlistThumbnail)
|
||||||
}
|
}
|
||||||
playlistTitle.text = playlist.name
|
playlistTitle.text = playlist.name
|
||||||
deletePlaylist.setOnClickListener {
|
deletePlaylist.setOnClickListener {
|
||||||
@ -56,8 +58,8 @@ class PlaylistsAdapter(
|
|||||||
builder.setTitle(R.string.deletePlaylist)
|
builder.setTitle(R.string.deletePlaylist)
|
||||||
builder.setMessage(R.string.areYouSure)
|
builder.setMessage(R.string.areYouSure)
|
||||||
builder.setPositiveButton(R.string.yes) { _, _ ->
|
builder.setPositiveButton(R.string.yes) { _, _ ->
|
||||||
val token = PreferenceHelper.getToken()
|
PreferenceHelper.getToken()
|
||||||
deletePlaylist(playlist.id!!, token, position)
|
deletePlaylist(playlist.id!!, position)
|
||||||
}
|
}
|
||||||
builder.setNegativeButton(R.string.cancel, null)
|
builder.setNegativeButton(R.string.cancel, null)
|
||||||
builder.show()
|
builder.show()
|
||||||
@ -68,11 +70,14 @@ class PlaylistsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deletePlaylist(id: String, token: String, position: Int) {
|
private fun deletePlaylist(id: String, position: Int) {
|
||||||
fun run() {
|
fun run() {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.authApi.deletePlaylist(token, PlaylistId(id))
|
RetrofitInstance.authApi.deletePlaylist(
|
||||||
|
PreferenceHelper.getToken(),
|
||||||
|
PlaylistId(id)
|
||||||
|
)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
println(e)
|
println(e)
|
||||||
Log.e(TAG, "IOException, you might not have internet connection")
|
Log.e(TAG, "IOException, you might not have internet connection")
|
||||||
@ -83,9 +88,7 @@ class PlaylistsAdapter(
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (response.message == "ok") {
|
if (response.message == "ok") {
|
||||||
Log.d(TAG, "deleted!")
|
|
||||||
playlists.removeAt(position)
|
playlists.removeAt(position)
|
||||||
// FIXME: This needs to run on UI thread?
|
|
||||||
activity.runOnUiThread { notifyDataSetChanged() }
|
activity.runOnUiThread { notifyDataSetChanged() }
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -8,6 +8,7 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import com.github.libretube.Globals
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.DialogAddtoplaylistBinding
|
import com.github.libretube.databinding.DialogAddtoplaylistBinding
|
||||||
import com.github.libretube.obj.PlaylistId
|
import com.github.libretube.obj.PlaylistId
|
||||||
@ -18,7 +19,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class AddtoPlaylistDialog : DialogFragment() {
|
class AddToPlaylistDialog : DialogFragment() {
|
||||||
private val TAG = "AddToPlaylistDialog"
|
private val TAG = "AddToPlaylistDialog"
|
||||||
private lateinit var binding: DialogAddtoplaylistBinding
|
private lateinit var binding: DialogAddtoplaylistBinding
|
||||||
|
|
||||||
@ -59,24 +60,29 @@ class AddtoPlaylistDialog : DialogFragment() {
|
|||||||
return@launchWhenCreated
|
return@launchWhenCreated
|
||||||
}
|
}
|
||||||
if (response.isNotEmpty()) {
|
if (response.isNotEmpty()) {
|
||||||
var names = emptyList<String>().toMutableList()
|
val names = response.map { it.name }
|
||||||
for (playlist in response) {
|
|
||||||
names.add(playlist.name!!)
|
|
||||||
}
|
|
||||||
val arrayAdapter =
|
val arrayAdapter =
|
||||||
ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, names)
|
ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, names)
|
||||||
arrayAdapter.setDropDownViewResource(
|
arrayAdapter.setDropDownViewResource(
|
||||||
android.R.layout.simple_spinner_dropdown_item
|
android.R.layout.simple_spinner_dropdown_item
|
||||||
)
|
)
|
||||||
binding.playlistsSpinner.adapter = arrayAdapter
|
binding.playlistsSpinner.adapter = arrayAdapter
|
||||||
|
if (Globals.SELECTED_PLAYLIST_ID != null) {
|
||||||
|
var selectionIndex = 0
|
||||||
|
response.forEachIndexed { index, playlist ->
|
||||||
|
if (playlist.id == Globals.SELECTED_PLAYLIST_ID) selectionIndex = index
|
||||||
|
}
|
||||||
|
binding.playlistsSpinner.setSelection(selectionIndex)
|
||||||
|
}
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
binding.addToPlaylist.setOnClickListener {
|
binding.addToPlaylist.setOnClickListener {
|
||||||
|
val index = binding.playlistsSpinner.selectedItemPosition
|
||||||
|
Globals.SELECTED_PLAYLIST_ID = response[index].id!!
|
||||||
addToPlaylist(
|
addToPlaylist(
|
||||||
response[binding.playlistsSpinner.selectedItemPosition].id!!
|
response[index].id!!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -50,7 +50,7 @@ class VideoOptionsDialog(private val videoId: String, context: Context) : Dialog
|
|||||||
context?.getString(R.string.addToPlaylist) -> {
|
context?.getString(R.string.addToPlaylist) -> {
|
||||||
val token = PreferenceHelper.getToken()
|
val token = PreferenceHelper.getToken()
|
||||||
if (token != "") {
|
if (token != "") {
|
||||||
val newFragment = AddtoPlaylistDialog()
|
val newFragment = AddToPlaylistDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString("videoId", videoId)
|
bundle.putString("videoId", videoId)
|
||||||
newFragment.arguments = bundle
|
newFragment.arguments = bundle
|
||||||
|
@ -46,7 +46,7 @@ import com.github.libretube.adapters.TrendingAdapter
|
|||||||
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
import com.github.libretube.databinding.DoubleTapOverlayBinding
|
||||||
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
import com.github.libretube.databinding.ExoStyledPlayerControlViewBinding
|
||||||
import com.github.libretube.databinding.FragmentPlayerBinding
|
import com.github.libretube.databinding.FragmentPlayerBinding
|
||||||
import com.github.libretube.dialogs.AddtoPlaylistDialog
|
import com.github.libretube.dialogs.AddToPlaylistDialog
|
||||||
import com.github.libretube.dialogs.DownloadDialog
|
import com.github.libretube.dialogs.DownloadDialog
|
||||||
import com.github.libretube.dialogs.ShareDialog
|
import com.github.libretube.dialogs.ShareDialog
|
||||||
import com.github.libretube.obj.ChapterSegment
|
import com.github.libretube.obj.ChapterSegment
|
||||||
@ -1097,7 +1097,7 @@ class PlayerFragment : Fragment() {
|
|||||||
if (token != "") {
|
if (token != "") {
|
||||||
isSubscribed()
|
isSubscribed()
|
||||||
binding.relPlayerSave.setOnClickListener {
|
binding.relPlayerSave.setOnClickListener {
|
||||||
val newFragment = AddtoPlaylistDialog()
|
val newFragment = AddToPlaylistDialog()
|
||||||
val bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString("videoId", videoId)
|
bundle.putString("videoId", videoId)
|
||||||
newFragment.arguments = bundle
|
newFragment.arguments = bundle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user