mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-29 03:32:42 +00:00
Playback context switcher now buried behind a long press menu in the
toolbar.
This commit is contained in:
parent
0eacb53904
commit
ab8517fd89
@ -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 = {
|
||||
|
@ -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()
|
||||
|
16
src/musikdroid/app/src/main/res/layout/remote_toggle.xml
Normal file
16
src/musikdroid/app/src/main/res/layout/remote_toggle.xml
Normal 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>
|
@ -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"
|
||||
|
@ -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"/>
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user