Browse Source

Allow downloading whole albums.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
4127421132
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 26
      app/src/main/java/com/github/apognu/otter/fragments/PlaylistTracksFragment.kt
  2. 28
      app/src/main/java/com/github/apognu/otter/fragments/TracksFragment.kt
  3. 37
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  4. 1
      app/src/main/java/com/github/apognu/otter/utils/EventBus.kt
  5. 16
      app/src/main/res/layout-land/fragment_tracks.xml
  6. 16
      app/src/main/res/layout/fragment_tracks.xml
  7. 12
      app/src/main/res/menu/album.xml

26
app/src/main/java/com/github/apognu/otter/fragments/PlaylistTracksFragment.kt

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
package com.github.apognu.otter.fragments
import android.os.Bundle
import android.view.Gravity
import android.view.View
import androidx.appcompat.widget.PopupMenu
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import com.github.apognu.otter.R
@ -84,10 +86,28 @@ class PlaylistTracksFragment : FunkwhaleFragment<PlaylistTrack, PlaylistTracksAd @@ -84,10 +86,28 @@ class PlaylistTracksFragment : FunkwhaleFragment<PlaylistTrack, PlaylistTracksAd
context.toast("All tracks were added to your queue")
}
queue.setOnClickListener {
CommandBus.send(Command.AddToQueue(adapter.data.map { it.track }))
context?.let { context ->
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()
}
}
}
}

28
app/src/main/java/com/github/apognu/otter/fragments/TracksFragment.kt

@ -1,7 +1,11 @@ @@ -1,7 +1,11 @@
package com.github.apognu.otter.fragments
import android.os.Bundle
import android.view.Gravity
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import androidx.appcompat.widget.PopupMenu
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import com.github.apognu.otter.R
@ -89,10 +93,28 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() { @@ -89,10 +93,28 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() {
context.toast("All tracks were added to your queue")
}
queue.setOnClickListener {
CommandBus.send(Command.AddToQueue(adapter.data))
context?.let { context ->
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()
}
}
}
}

37
app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

@ -193,23 +193,8 @@ class PlayerService : Service() { @@ -193,23 +193,8 @@ class PlayerService : Service() {
is Command.SetRepeatMode -> player.repeatMode = message.mode
is Command.PinTrack -> {
message.track.bestUpload()?.let { upload ->
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)
}
}
}
is Command.PinTrack -> download(message.track)
is Command.PinTracks -> message.tracks.forEach { download(it) }
}
if (player.playWhenReady) {
@ -355,6 +340,24 @@ class PlayerService : Service() { @@ -355,6 +340,24 @@ class PlayerService : Service() {
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 {
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
super.onPlayerStateChanged(playWhenReady, playbackState)

1
app/src/main/java/com/github/apognu/otter/utils/EventBus.kt

@ -31,6 +31,7 @@ sealed class Command { @@ -31,6 +31,7 @@ sealed class Command {
class PlayTrack(val index: Int) : Command()
class PinTrack(val track: Track) : Command()
class PinTracks(val tracks: List<Track>) : Command()
}
sealed class Event {

16
app/src/main/res/layout-land/fragment_tracks.xml

@ -180,16 +180,14 @@ @@ -180,16 +180,14 @@
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/queue"
style="@style/AppTheme.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
<ImageButton
android:id="@+id/actions"
style="@style/IconButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:text="@string/playback_queue"
app:icon="@drawable/add" />
android:contentDescription="@string/alt_more_options"
android:src="@drawable/more" />
</LinearLayout>

16
app/src/main/res/layout/fragment_tracks.xml

@ -183,16 +183,14 @@ @@ -183,16 +183,14 @@
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/queue"
style="@style/AppTheme.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="16dp"
<ImageButton
android:id="@+id/actions"
style="@style/IconButton"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="16dp"
android:text="@string/playback_queue"
app:icon="@drawable/add" />
android:contentDescription="@string/alt_more_options"
android:src="@drawable/more" />
</LinearLayout>

12
app/src/main/res/menu/album.xml

@ -0,0 +1,12 @@ @@ -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…
Cancel
Save