Playback context switcher now buried behind a long press menu in the

toolbar.
This commit is contained in:
casey langen 2018-01-23 22:00:21 -08:00
parent 0eacb53904
commit ab8517fd89
6 changed files with 61 additions and 20 deletions

View File

@ -177,6 +177,11 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
override fun playFrom(service: IPlaybackService) {
/* we only support switching from a play queue context! */
if (service.queryContext?.type == Messages.Request.QueryPlayQueueTracks) {
val index = service.queuePosition
val offsetMs = (service.currentTime * 1000).toInt()
val context = QueryContext(Messages.Request.PlaySnapshotTracks)
val type = PlayQueueType.Snapshot
val dummyListener: (() -> Unit) = { }
connect(dummyListener)
service.queryContext?.let { _ ->
@ -185,10 +190,6 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
disconnect(dummyListener)
resetPlayContextAndQueryFactory()
val index = service.queuePosition
val offsetMs = (service.currentTime * 1000).toInt()
val context = QueryContext(Messages.Request.PlaySnapshotTracks)
val type = PlayQueueType.Snapshot
snapshotQueryFactory = object: ITrackListQueryFactory {
override fun count(): Observable<Int>? =
@ -200,7 +201,6 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
override fun offline(): Boolean = false
}
service.pause()
loadQueueAndPlay(context, index, offsetMs)
},
onError = {

View File

@ -42,6 +42,8 @@ import io.casey.musikcube.remote.ui.shared.util.UpdateCheck
import io.casey.musikcube.remote.ui.tracks.activity.TrackListActivity
class MainActivity : BaseActivity() {
private enum class SwitchMode { Seamless, Copy, Normal }
private val handler = Handler()
private var updateCheck: UpdateCheck = UpdateCheck()
private var seekbarValue = -1
@ -118,22 +120,32 @@ class MainActivity : BaseActivity() {
val remoteToggle = menu.findItem(R.id.action_remote_toggle)
remoteToggle.setIcon(
remoteToggle.actionView?.findViewById<ImageView>(R.id.icon)?.setImageResource(
if (streaming) R.drawable.ic_toolbar_streaming
else R.drawable.ic_toolbar_remote)
remoteToggle.actionView?.setOnClickListener {
togglePlaybackService()
}
remoteToggle.actionView?.setOnLongClickListener {
showPlaybackTogglePopup()
true
}
return super.onPrepareOptionsMenu(menu)
}
fun showPlaybackTogglePopup() {
private fun showPlaybackTogglePopup() {
val toolbarButton = findViewById<View>(R.id.action_remote_toggle)
val popup = PopupMenu(this, toolbarButton)
popup.inflate(R.menu.playback_toggle_menu)
popup.setOnMenuItemClickListener { it ->
when(it.itemId) {
R.id.menu_switch_seamless -> togglePlaybackService(true)
R.id.menu_switch_normal -> togglePlaybackService()
R.id.menu_switch_seamless -> togglePlaybackService(SwitchMode.Seamless)
R.id.menu_switch_copy -> togglePlaybackService(SwitchMode.Copy)
R.id.menu_switch_normal -> togglePlaybackService(SwitchMode.Normal)
else -> { }
}
true
@ -227,7 +239,7 @@ class MainActivity : BaseActivity() {
Prefs.Key.STREAMING_PLAYBACK,
Prefs.Default.STREAMING_PLAYBACK)
private fun togglePlaybackService(transfer: Boolean = false) {
private fun togglePlaybackService(mode: SwitchMode = SwitchMode.Normal) {
val isStreaming = isStreamingSelected
prefs.edit().putBoolean(Prefs.Key.STREAMING_PLAYBACK, !isStreaming)?.apply()
@ -238,19 +250,27 @@ class MainActivity : BaseActivity() {
showSnackbar(mainLayout, messageId)
if (transfer) {
if (mode == SwitchMode.Normal) {
if (isStreaming) {
playback.service.pause()
}
}
else {
val streaming = PlaybackServiceFactory.streaming(this)
val remote = PlaybackServiceFactory.remote(this)
if (!isStreaming) {
streaming.playFrom(remote)
} else {
remote.playFrom(streaming)
if (mode == SwitchMode.Seamless) {
remote.pause()
}
}
else {
remote.playFrom(streaming)
if (mode == SwitchMode.Seamless) {
streaming.pause()
}
}
}
if (isStreaming) {
playback.service.stop()
}
playback.reload()

View File

@ -0,0 +1,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/actionButtonStyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
android:layout_margin="0dp">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:scaleType="centerInside"
android:src="@drawable/ic_toolbar_remote" />
</RelativeLayout>

View File

@ -6,8 +6,8 @@
<item
android:id="@+id/action_remote_toggle"
app:showAsAction="always"
android:title="@string/menu_remote_toggle"
android:icon="@drawable/ic_toolbar_remote" />
app:actionLayout="@layout/remote_toggle"
android:title="@string/menu_remote_toggle" />
<item
android:id="@+id/action_categories"

View File

@ -4,6 +4,10 @@
android:id="@+id/menu_switch_seamless"
android:title="@string/playback_switch_seamless"/>
<item
android:id="@+id/menu_switch_copy"
android:title="@string/playback_switch_copy"/>
<item
android:id="@+id/menu_switch_normal"
android:title="@string/playback_switch_new"/>

View File

@ -188,6 +188,7 @@
<string name="category_genre">genre</string>
<string name="category_publisher">publisher</string>
<string name="category_year">year</string>
<string name="playback_switch_seamless">seamless switch</string>
<string name="playback_switch_seamless">transfer session</string>
<string name="playback_switch_copy">copy session</string>
<string name="playback_switch_new">new session</string>
</resources>