mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 03:39:50 +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) {
|
override fun playFrom(service: IPlaybackService) {
|
||||||
/* we only support switching from a play queue context! */
|
/* we only support switching from a play queue context! */
|
||||||
if (service.queryContext?.type == Messages.Request.QueryPlayQueueTracks) {
|
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) = { }
|
val dummyListener: (() -> Unit) = { }
|
||||||
connect(dummyListener)
|
connect(dummyListener)
|
||||||
service.queryContext?.let { _ ->
|
service.queryContext?.let { _ ->
|
||||||
@ -185,10 +190,6 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
|
|||||||
disconnect(dummyListener)
|
disconnect(dummyListener)
|
||||||
|
|
||||||
resetPlayContextAndQueryFactory()
|
resetPlayContextAndQueryFactory()
|
||||||
val index = service.queuePosition
|
|
||||||
val offsetMs = (service.currentTime * 1000).toInt()
|
|
||||||
val context = QueryContext(Messages.Request.PlaySnapshotTracks)
|
|
||||||
val type = PlayQueueType.Snapshot
|
|
||||||
|
|
||||||
snapshotQueryFactory = object: ITrackListQueryFactory {
|
snapshotQueryFactory = object: ITrackListQueryFactory {
|
||||||
override fun count(): Observable<Int>? =
|
override fun count(): Observable<Int>? =
|
||||||
@ -200,7 +201,6 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
|
|||||||
override fun offline(): Boolean = false
|
override fun offline(): Boolean = false
|
||||||
}
|
}
|
||||||
|
|
||||||
service.pause()
|
|
||||||
loadQueueAndPlay(context, index, offsetMs)
|
loadQueueAndPlay(context, index, offsetMs)
|
||||||
},
|
},
|
||||||
onError = {
|
onError = {
|
||||||
|
@ -42,6 +42,8 @@ import io.casey.musikcube.remote.ui.shared.util.UpdateCheck
|
|||||||
import io.casey.musikcube.remote.ui.tracks.activity.TrackListActivity
|
import io.casey.musikcube.remote.ui.tracks.activity.TrackListActivity
|
||||||
|
|
||||||
class MainActivity : BaseActivity() {
|
class MainActivity : BaseActivity() {
|
||||||
|
private enum class SwitchMode { Seamless, Copy, Normal }
|
||||||
|
|
||||||
private val handler = Handler()
|
private val handler = Handler()
|
||||||
private var updateCheck: UpdateCheck = UpdateCheck()
|
private var updateCheck: UpdateCheck = UpdateCheck()
|
||||||
private var seekbarValue = -1
|
private var seekbarValue = -1
|
||||||
@ -118,22 +120,32 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
val remoteToggle = menu.findItem(R.id.action_remote_toggle)
|
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
|
if (streaming) R.drawable.ic_toolbar_streaming
|
||||||
else R.drawable.ic_toolbar_remote)
|
else R.drawable.ic_toolbar_remote)
|
||||||
|
|
||||||
|
remoteToggle.actionView?.setOnClickListener {
|
||||||
|
togglePlaybackService()
|
||||||
|
}
|
||||||
|
|
||||||
|
remoteToggle.actionView?.setOnLongClickListener {
|
||||||
|
showPlaybackTogglePopup()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
return super.onPrepareOptionsMenu(menu)
|
return super.onPrepareOptionsMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showPlaybackTogglePopup() {
|
private fun showPlaybackTogglePopup() {
|
||||||
val toolbarButton = findViewById<View>(R.id.action_remote_toggle)
|
val toolbarButton = findViewById<View>(R.id.action_remote_toggle)
|
||||||
val popup = PopupMenu(this, toolbarButton)
|
val popup = PopupMenu(this, toolbarButton)
|
||||||
popup.inflate(R.menu.playback_toggle_menu)
|
popup.inflate(R.menu.playback_toggle_menu)
|
||||||
|
|
||||||
popup.setOnMenuItemClickListener { it ->
|
popup.setOnMenuItemClickListener { it ->
|
||||||
when(it.itemId) {
|
when(it.itemId) {
|
||||||
R.id.menu_switch_seamless -> togglePlaybackService(true)
|
R.id.menu_switch_seamless -> togglePlaybackService(SwitchMode.Seamless)
|
||||||
R.id.menu_switch_normal -> togglePlaybackService()
|
R.id.menu_switch_copy -> togglePlaybackService(SwitchMode.Copy)
|
||||||
|
R.id.menu_switch_normal -> togglePlaybackService(SwitchMode.Normal)
|
||||||
else -> { }
|
else -> { }
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@ -227,7 +239,7 @@ class MainActivity : BaseActivity() {
|
|||||||
Prefs.Key.STREAMING_PLAYBACK,
|
Prefs.Key.STREAMING_PLAYBACK,
|
||||||
Prefs.Default.STREAMING_PLAYBACK)
|
Prefs.Default.STREAMING_PLAYBACK)
|
||||||
|
|
||||||
private fun togglePlaybackService(transfer: Boolean = false) {
|
private fun togglePlaybackService(mode: SwitchMode = SwitchMode.Normal) {
|
||||||
val isStreaming = isStreamingSelected
|
val isStreaming = isStreamingSelected
|
||||||
prefs.edit().putBoolean(Prefs.Key.STREAMING_PLAYBACK, !isStreaming)?.apply()
|
prefs.edit().putBoolean(Prefs.Key.STREAMING_PLAYBACK, !isStreaming)?.apply()
|
||||||
|
|
||||||
@ -238,19 +250,27 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
showSnackbar(mainLayout, messageId)
|
showSnackbar(mainLayout, messageId)
|
||||||
|
|
||||||
if (transfer) {
|
if (mode == SwitchMode.Normal) {
|
||||||
|
if (isStreaming) {
|
||||||
|
playback.service.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
val streaming = PlaybackServiceFactory.streaming(this)
|
val streaming = PlaybackServiceFactory.streaming(this)
|
||||||
val remote = PlaybackServiceFactory.remote(this)
|
val remote = PlaybackServiceFactory.remote(this)
|
||||||
|
|
||||||
if (!isStreaming) {
|
if (!isStreaming) {
|
||||||
streaming.playFrom(remote)
|
streaming.playFrom(remote)
|
||||||
} else {
|
if (mode == SwitchMode.Seamless) {
|
||||||
remote.playFrom(streaming)
|
remote.pause()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
remote.playFrom(streaming)
|
||||||
|
if (mode == SwitchMode.Seamless) {
|
||||||
|
streaming.pause()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (isStreaming) {
|
|
||||||
playback.service.stop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
playback.reload()
|
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
|
<item
|
||||||
android:id="@+id/action_remote_toggle"
|
android:id="@+id/action_remote_toggle"
|
||||||
app:showAsAction="always"
|
app:showAsAction="always"
|
||||||
android:title="@string/menu_remote_toggle"
|
app:actionLayout="@layout/remote_toggle"
|
||||||
android:icon="@drawable/ic_toolbar_remote" />
|
android:title="@string/menu_remote_toggle" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_categories"
|
android:id="@+id/action_categories"
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
android:id="@+id/menu_switch_seamless"
|
android:id="@+id/menu_switch_seamless"
|
||||||
android:title="@string/playback_switch_seamless"/>
|
android:title="@string/playback_switch_seamless"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_switch_copy"
|
||||||
|
android:title="@string/playback_switch_copy"/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_switch_normal"
|
android:id="@+id/menu_switch_normal"
|
||||||
android:title="@string/playback_switch_new"/>
|
android:title="@string/playback_switch_new"/>
|
||||||
|
@ -188,6 +188,7 @@
|
|||||||
<string name="category_genre">genre</string>
|
<string name="category_genre">genre</string>
|
||||||
<string name="category_publisher">publisher</string>
|
<string name="category_publisher">publisher</string>
|
||||||
<string name="category_year">year</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>
|
<string name="playback_switch_new">new session</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user