Fix another file intent bug
Fix another bug where PlaybackService wouldn't show its notification/go into foreground if a song was played by a file intent.
This commit is contained in:
parent
cc14648099
commit
00e7af8f3d
6 changed files with 32 additions and 38 deletions
|
@ -50,17 +50,10 @@ class MainActivity : AppCompatActivity() {
|
|||
super.onNewIntent(intent)
|
||||
|
||||
// Since the activity is set to singleInstance [Given that there's only MainActivity]
|
||||
// We have to manually push the intent whenever we get one so that MainFragment
|
||||
// We have to manually push the intent whenever we get one so that the fragments
|
||||
// can catch any file intents
|
||||
// FIXME: Centralize the file intent code in MainActivity, if thats even possible
|
||||
setIntent(intent)
|
||||
|
||||
// TODO: Idea Needed
|
||||
// Move to all non-loading fragments
|
||||
// Use ext fun
|
||||
// Apply bool to intent to make sure it doesnt fire again???
|
||||
// Need it to
|
||||
// - Run everywhere except loading
|
||||
// - Dont fire after the first go
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.oxycblt.auxio
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
|
@ -22,6 +21,7 @@ import org.oxycblt.auxio.music.Song
|
|||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.fixAnimInfoLeak
|
||||
import org.oxycblt.auxio.ui.handleFileIntent
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
import org.oxycblt.auxio.ui.isTablet
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
@ -119,14 +119,7 @@ class MainFragment : Fragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val activity = requireActivity()
|
||||
val intent = activity.intent
|
||||
|
||||
// If the intent of the activity is a file intent, then play it.
|
||||
// TODO?: Add an option to view it instead of play it if this becomes too annoying
|
||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||
playbackModel.playWithIntent(intent, requireContext())
|
||||
} else {
|
||||
if (!handleFileIntent(playbackModel)) {
|
||||
playbackModel.restorePlaybackIfNeeded(requireContext())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
|
@ -18,6 +17,7 @@ import org.oxycblt.auxio.detail.DetailViewModel
|
|||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.playback.state.LoopMode
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.handleFileIntent
|
||||
import org.oxycblt.auxio.ui.memberBinding
|
||||
import org.oxycblt.auxio.ui.toStateList
|
||||
|
||||
|
@ -202,12 +202,7 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
playbackModel.enableAnimation()
|
||||
}
|
||||
|
||||
val intent = requireActivity().intent
|
||||
|
||||
// If the intent of the activity is a file intent, then play it.
|
||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||
playbackModel.playWithIntent(intent, requireContext())
|
||||
}
|
||||
handleFileIntent(playbackModel)
|
||||
}
|
||||
|
||||
// --- SEEK CALLBACKS ---
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.oxycblt.auxio.playback.queue
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
|
@ -19,6 +18,7 @@ import org.oxycblt.auxio.music.Genre
|
|||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.ui.handleFileIntent
|
||||
import org.oxycblt.auxio.ui.isEdgeOn
|
||||
import org.oxycblt.auxio.ui.isIrregularLandscape
|
||||
|
||||
|
@ -102,12 +102,7 @@ class QueueFragment : Fragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val intent = requireActivity().intent
|
||||
|
||||
// If the intent of the activity is a file intent, then play it.
|
||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||
playbackModel.playWithIntent(intent, requireContext())
|
||||
}
|
||||
handleFileIntent(playbackModel)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -213,7 +213,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
pushMetadataToSession(song)
|
||||
|
||||
notification.setMetadata(
|
||||
this, song, settingsManager.colorizeNotif, ::startForegroundOrNotify
|
||||
this, song, settingsManager.colorizeNotif, { startForegroundOrNotify() }
|
||||
)
|
||||
|
||||
return
|
||||
|
@ -270,7 +270,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
override fun onColorizeNotifUpdate(doColorize: Boolean) {
|
||||
playbackManager.song?.let { song ->
|
||||
notification.setMetadata(
|
||||
this, song, settingsManager.colorizeNotif, ::startForegroundOrNotify
|
||||
this, song, settingsManager.colorizeNotif, {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
override fun onShowCoverUpdate(showCovers: Boolean) {
|
||||
playbackManager.song?.let { song ->
|
||||
notification.setMetadata(
|
||||
this, song, settingsManager.colorizeNotif, ::startForegroundOrNotify
|
||||
this, song, settingsManager.colorizeNotif, { startForegroundOrNotify() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
override fun onQualityCoverUpdate(doQualityCovers: Boolean) {
|
||||
playbackManager.song?.let { song ->
|
||||
notification.setMetadata(
|
||||
this, song, settingsManager.colorizeNotif, ::startForegroundOrNotify
|
||||
this, song, settingsManager.colorizeNotif, { startForegroundOrNotify() }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
* Bring the service into the foreground and show the notification, or refresh the notification.
|
||||
*/
|
||||
private fun startForegroundOrNotify() {
|
||||
if (playbackManager.hasPlayed && playbackManager.isRestored && playbackManager.song != null) {
|
||||
if (playbackManager.hasPlayed && playbackManager.song != null) {
|
||||
logD("Starting foreground/notifying")
|
||||
|
||||
if (!isForeground) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.oxycblt.auxio.ui
|
|||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
|
@ -26,6 +27,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.google.android.material.button.MaterialButton
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logE
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
|
||||
// --- VIEW CONFIGURATION ---
|
||||
|
||||
|
@ -225,7 +227,7 @@ private fun isSystemBarOnBottom(activity: Activity): Boolean {
|
|||
return (!canMove || width < height)
|
||||
}
|
||||
|
||||
// --- HACKY NIGHTMARES ---
|
||||
// --- FRAGMENT NONSENSE ---
|
||||
|
||||
/**
|
||||
* Use reflection to fix a memory leak in the [Fragment] source code where the focused view will
|
||||
|
@ -241,3 +243,19 @@ fun Fragment.fixAnimInfoLeak() {
|
|||
logE("mAnimationInfo leak fix failed.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut for handling a file intent.
|
||||
* @return True if the file intent was pushed to [playbackModel], false if not
|
||||
*/
|
||||
fun Fragment.handleFileIntent(playbackModel: PlaybackViewModel): Boolean {
|
||||
val intent = requireActivity().intent
|
||||
|
||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||
playbackModel.playWithIntent(intent, requireContext())
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue