mirror of
https://github.com/apognu/otter
synced 2025-02-17 11:20:34 +01:00
Allow downloading whole albums.
This commit is contained in:
parent
00fb833cfa
commit
4127421132
@ -1,7 +1,9 @@
|
|||||||
package com.github.apognu.otter.fragments
|
package com.github.apognu.otter.fragments
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Gravity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.apognu.otter.R
|
import com.github.apognu.otter.R
|
||||||
@ -84,10 +86,28 @@ class PlaylistTracksFragment : FunkwhaleFragment<PlaylistTrack, PlaylistTracksAd
|
|||||||
context.toast("All tracks were added to your queue")
|
context.toast("All tracks were added to your queue")
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.setOnClickListener {
|
context?.let { context ->
|
||||||
CommandBus.send(Command.AddToQueue(adapter.data.map { it.track }))
|
actions.setOnClickListener {
|
||||||
|
PopupMenu(context, actions, Gravity.START, R.attr.actionOverflowMenuStyle, 0).apply {
|
||||||
|
inflate(R.menu.album)
|
||||||
|
|
||||||
context.toast("All tracks were added to your queue")
|
setOnMenuItemClickListener {
|
||||||
|
when (it.itemId) {
|
||||||
|
R.id.add_to_queue -> {
|
||||||
|
CommandBus.send(Command.AddToQueue(adapter.data.map { it.track }))
|
||||||
|
|
||||||
|
context.toast("All tracks were added to your queue")
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.download -> CommandBus.send(Command.PinTracks(adapter.data.map { it.track }))
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package com.github.apognu.otter.fragments
|
package com.github.apognu.otter.fragments
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.appcompat.widget.PopupMenu
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.apognu.otter.R
|
import com.github.apognu.otter.R
|
||||||
@ -89,10 +93,28 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() {
|
|||||||
context.toast("All tracks were added to your queue")
|
context.toast("All tracks were added to your queue")
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.setOnClickListener {
|
context?.let { context ->
|
||||||
CommandBus.send(Command.AddToQueue(adapter.data))
|
actions.setOnClickListener {
|
||||||
|
PopupMenu(context, actions, Gravity.START, R.attr.actionOverflowMenuStyle, 0).apply {
|
||||||
|
inflate(R.menu.album)
|
||||||
|
|
||||||
context.toast("All tracks were added to your queue")
|
setOnMenuItemClickListener {
|
||||||
|
when (it.itemId) {
|
||||||
|
R.id.add_to_queue -> {
|
||||||
|
CommandBus.send(Command.AddToQueue(adapter.data))
|
||||||
|
|
||||||
|
context.toast("All tracks were added to your queue")
|
||||||
|
}
|
||||||
|
|
||||||
|
R.id.download -> CommandBus.send(Command.PinTracks(adapter.data))
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,23 +193,8 @@ class PlayerService : Service() {
|
|||||||
|
|
||||||
is Command.SetRepeatMode -> player.repeatMode = message.mode
|
is Command.SetRepeatMode -> player.repeatMode = message.mode
|
||||||
|
|
||||||
is Command.PinTrack -> {
|
is Command.PinTrack -> download(message.track)
|
||||||
message.track.bestUpload()?.let { upload ->
|
is Command.PinTracks -> message.tracks.forEach { download(it) }
|
||||||
val url = mustNormalizeUrl(upload.listen_url)
|
|
||||||
val data = Gson().toJson(
|
|
||||||
DownloadInfo(
|
|
||||||
url,
|
|
||||||
message.track.title,
|
|
||||||
message.track.artist.name,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
).toByteArray()
|
|
||||||
|
|
||||||
DownloadRequest(url, DownloadRequest.TYPE_PROGRESSIVE, Uri.parse(url), Collections.emptyList(), null, data).also {
|
|
||||||
sendAddDownload(this@PlayerService, PinService::class.java, it, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.playWhenReady) {
|
if (player.playWhenReady) {
|
||||||
@ -355,6 +340,24 @@ class PlayerService : Service() {
|
|||||||
player.seekTo(duration.toLong())
|
player.seekTo(duration.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun download(track: Track) {
|
||||||
|
track.bestUpload()?.let { upload ->
|
||||||
|
val url = mustNormalizeUrl(upload.listen_url)
|
||||||
|
val data = Gson().toJson(
|
||||||
|
DownloadInfo(
|
||||||
|
url,
|
||||||
|
track.title,
|
||||||
|
track.artist.name,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
).toByteArray()
|
||||||
|
|
||||||
|
DownloadRequest(url, DownloadRequest.TYPE_PROGRESSIVE, Uri.parse(url), Collections.emptyList(), null, data).also {
|
||||||
|
sendAddDownload(this@PlayerService, PinService::class.java, it, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inner class PlayerEventListener : Player.EventListener {
|
inner class PlayerEventListener : Player.EventListener {
|
||||||
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
|
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
|
||||||
super.onPlayerStateChanged(playWhenReady, playbackState)
|
super.onPlayerStateChanged(playWhenReady, playbackState)
|
||||||
|
@ -31,6 +31,7 @@ sealed class Command {
|
|||||||
|
|
||||||
class PlayTrack(val index: Int) : Command()
|
class PlayTrack(val index: Int) : Command()
|
||||||
class PinTrack(val track: Track) : Command()
|
class PinTrack(val track: Track) : Command()
|
||||||
|
class PinTracks(val tracks: List<Track>) : Command()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Event {
|
sealed class Event {
|
||||||
|
@ -180,16 +180,14 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<ImageButton
|
||||||
android:id="@+id/queue"
|
android:id="@+id/actions"
|
||||||
style="@style/AppTheme.OutlinedButton"
|
style="@style/IconButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="24dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:text="@string/playback_queue"
|
android:contentDescription="@string/alt_more_options"
|
||||||
app:icon="@drawable/add" />
|
android:src="@drawable/more" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -183,16 +183,14 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<ImageButton
|
||||||
android:id="@+id/queue"
|
android:id="@+id/actions"
|
||||||
style="@style/AppTheme.OutlinedButton"
|
style="@style/IconButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="24dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:text="@string/playback_queue"
|
android:contentDescription="@string/alt_more_options"
|
||||||
app:icon="@drawable/add" />
|
android:src="@drawable/more" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
12
app/src/main/res/menu/album.xml
Normal file
12
app/src/main/res/menu/album.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/add_to_queue"
|
||||||
|
android:title="@string/playback_queue" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/download"
|
||||||
|
android:title="@string/playback_queue_download" />
|
||||||
|
|
||||||
|
</menu>
|
Loading…
x
Reference in New Issue
Block a user