Fix file intent issue
Fix a problem where the file intent wouldnt work on any fragment that wasnt MainFragment.
This commit is contained in:
parent
7a4b654222
commit
cc14648099
6 changed files with 56 additions and 21 deletions
|
@ -53,6 +53,14 @@ class MainActivity : AppCompatActivity() {
|
||||||
// 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 MainFragment
|
||||||
// can catch any file intents
|
// can catch any file intents
|
||||||
setIntent(intent)
|
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")
|
@Suppress("DEPRECATION")
|
||||||
|
|
|
@ -126,10 +126,6 @@ class MainFragment : Fragment() {
|
||||||
// TODO?: Add an option to view it instead of play it if this becomes too annoying
|
// TODO?: Add an option to view it instead of play it if this becomes too annoying
|
||||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||||
playbackModel.playWithIntent(intent, requireContext())
|
playbackModel.playWithIntent(intent, requireContext())
|
||||||
|
|
||||||
// Clear intent so that this does not fire again
|
|
||||||
// I see no consequences from doing this
|
|
||||||
activity.intent = null
|
|
||||||
} else {
|
} else {
|
||||||
playbackModel.restorePlaybackIfNeeded(requireContext())
|
playbackModel.restorePlaybackIfNeeded(requireContext())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.oxycblt.auxio.playback
|
package org.oxycblt.auxio.playback
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -200,6 +201,13 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||||
|
|
||||||
playbackModel.enableAnimation()
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- SEEK CALLBACKS ---
|
// --- SEEK CALLBACKS ---
|
||||||
|
|
|
@ -160,11 +160,18 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||||
|
|
||||||
/** Play a song using an intent */
|
/** Play a song using an intent */
|
||||||
fun playWithIntent(intent: Intent, context: Context) {
|
fun playWithIntent(intent: Intent, context: Context) {
|
||||||
val uri = intent.data ?: return
|
val fired = intent.getBooleanExtra(KEY_INTENT_PLAY_FIRED, false)
|
||||||
|
|
||||||
viewModelScope.launch {
|
if (!fired) {
|
||||||
musicStore.getSongForUri(uri, context.contentResolver)?.let { song ->
|
// Make sure any intents that are passed here never fire again
|
||||||
playSong(song)
|
intent.putExtra(KEY_INTENT_PLAY_FIRED, true)
|
||||||
|
|
||||||
|
val uri = intent.data ?: return
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
musicStore.getSongForUri(uri, context.contentResolver)?.let { song ->
|
||||||
|
playSong(song)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,4 +427,8 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||||
override fun onInUserQueueUpdate(isInUserQueue: Boolean) {
|
override fun onInUserQueueUpdate(isInUserQueue: Boolean) {
|
||||||
mIsInUserQueue.value = isInUserQueue
|
mIsInUserQueue.value = isInUserQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val KEY_INTENT_PLAY_FIRED = "KEY_PLAY_DONE"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.oxycblt.auxio.playback.queue
|
package org.oxycblt.auxio.playback.queue
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -98,6 +99,17 @@ class QueueFragment : Fragment() {
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the queue data that should be displayed
|
* Create the queue data that should be displayed
|
||||||
* @return The list of headers/songs that should be displayed.
|
* @return The list of headers/songs that should be displayed.
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.content.pm.ServiceInfo
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.Parcelable
|
|
||||||
import android.support.v4.media.MediaMetadataCompat
|
import android.support.v4.media.MediaMetadataCompat
|
||||||
import android.support.v4.media.session.MediaSessionCompat
|
import android.support.v4.media.session.MediaSessionCompat
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
|
@ -73,9 +72,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
private var isForeground = false
|
private var isForeground = false
|
||||||
|
|
||||||
private val serviceJob = Job()
|
private val serviceJob = Job()
|
||||||
private val serviceScope = CoroutineScope(
|
private val serviceScope = CoroutineScope(serviceJob + Dispatchers.Main)
|
||||||
serviceJob + Dispatchers.Main
|
|
||||||
)
|
|
||||||
|
|
||||||
// --- SERVICE OVERRIDES ---
|
// --- SERVICE OVERRIDES ---
|
||||||
|
|
||||||
|
@ -257,13 +254,11 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onShuffleUpdate(isShuffling: Boolean) {
|
override fun onShuffleUpdate(isShuffling: Boolean) {
|
||||||
if (!settingsManager.useAltNotifAction) {
|
if (settingsManager.useAltNotifAction) {
|
||||||
return
|
notification.setShuffle(this, isShuffling)
|
||||||
|
|
||||||
|
startForegroundOrNotify()
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.setShuffle(this, isShuffling)
|
|
||||||
|
|
||||||
startForegroundOrNotify()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSeek(position: Long) {
|
override fun onSeek(position: Long) {
|
||||||
|
@ -312,7 +307,8 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
* Create the [SimpleExoPlayer] instance.
|
* Create the [SimpleExoPlayer] instance.
|
||||||
*/
|
*/
|
||||||
private fun newPlayer(): SimpleExoPlayer {
|
private fun newPlayer(): SimpleExoPlayer {
|
||||||
// Since Auxio is a music player, only specify an audio renderer to save battery/apk size/cache size.
|
// Since Auxio is a music player, only specify an audio renderer to save
|
||||||
|
// battery/apk size/cache size
|
||||||
val audioRenderer = RenderersFactory { handler, _, audioListener, _, _ ->
|
val audioRenderer = RenderersFactory { handler, _, audioListener, _, _ ->
|
||||||
arrayOf(
|
arrayOf(
|
||||||
MediaCodecAudioRenderer(
|
MediaCodecAudioRenderer(
|
||||||
|
@ -445,9 +441,9 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
* Handle a media button intent.
|
* Handle a media button intent.
|
||||||
*/
|
*/
|
||||||
private fun handleMediaButtonEvent(event: Intent): Boolean {
|
private fun handleMediaButtonEvent(event: Intent): Boolean {
|
||||||
val item = event.getParcelableExtra<Parcelable>(Intent.EXTRA_KEY_EVENT) as KeyEvent
|
val item = event.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT)
|
||||||
|
|
||||||
if (item.action == KeyEvent.ACTION_DOWN) {
|
if (item != null && item.action == KeyEvent.ACTION_DOWN) {
|
||||||
return when (item.keyCode) {
|
return when (item.keyCode) {
|
||||||
// Play/Pause if any of the keys are play/pause
|
// Play/Pause if any of the keys are play/pause
|
||||||
KeyEvent.KEYCODE_MEDIA_PAUSE, KeyEvent.KEYCODE_MEDIA_PLAY,
|
KeyEvent.KEYCODE_MEDIA_PAUSE, KeyEvent.KEYCODE_MEDIA_PLAY,
|
||||||
|
@ -518,6 +514,10 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
||||||
stopForegroundAndNotification()
|
stopForegroundAndNotification()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intent.ACTION_VIEW -> {
|
||||||
|
logD("wat this works")
|
||||||
|
}
|
||||||
|
|
||||||
// --- HEADSET CASES ---
|
// --- HEADSET CASES ---
|
||||||
|
|
||||||
BluetoothDevice.ACTION_ACL_CONNECTED -> resumeFromPlug()
|
BluetoothDevice.ACTION_ACL_CONNECTED -> resumeFromPlug()
|
||||||
|
|
Loading…
Reference in a new issue