Change file intent to play
Change the file intent to play instead of view. I may add the view option back in at some point however if the play functionality angers me enough.
This commit is contained in:
parent
2dfd916736
commit
ca4cabedbc
3 changed files with 23 additions and 18 deletions
|
@ -111,8 +111,6 @@ class MainFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
playbackModel.restorePlaybackIfNeeded(requireContext())
|
||||
|
||||
logD("Fragment Created.")
|
||||
|
||||
return binding.root
|
||||
|
@ -121,11 +119,17 @@ class MainFragment : Fragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
val intent = requireActivity().intent
|
||||
val activity = requireActivity()
|
||||
val intent = activity.intent
|
||||
|
||||
if (intent != null && intent.action == Intent.ACTION_VIEW) {
|
||||
logD("Attempting to navigate from file intent")
|
||||
detailModel.navigateWithIntent(intent, requireActivity().application)
|
||||
playbackModel.playWithIntent(intent, requireContext())
|
||||
|
||||
// Clear intent so that this does not fire again
|
||||
// I see no consequences from doing this
|
||||
activity.intent = null
|
||||
} else {
|
||||
playbackModel.restorePlaybackIfNeeded(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package org.oxycblt.auxio.detail
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
|
@ -114,13 +110,4 @@ class DetailViewModel : ViewModel() {
|
|||
fun doneWithNavToItem() {
|
||||
mNavToItem.value = null
|
||||
}
|
||||
|
||||
/** Navigate to an item using a file [Intent] */
|
||||
fun navigateWithIntent(intent: Intent, app: Application) {
|
||||
val uri = intent.data ?: return
|
||||
|
||||
viewModelScope.launch {
|
||||
mNavToItem.value = musicStore.getSongForUri(uri, app.contentResolver)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
|
@ -13,6 +14,7 @@ import org.oxycblt.auxio.logE
|
|||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.music.Parent
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.toDuration
|
||||
|
@ -93,6 +95,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
|
||||
private val playbackManager = PlaybackStateManager.getInstance()
|
||||
private val settingsManager = SettingsManager.getInstance()
|
||||
private val musicStore = MusicStore.getInstance()
|
||||
|
||||
init {
|
||||
playbackManager.addCallback(this)
|
||||
|
@ -155,6 +158,17 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
playbackManager.shuffleAll()
|
||||
}
|
||||
|
||||
/** Play a song using an intent */
|
||||
fun playWithIntent(intent: Intent, context: Context) {
|
||||
val uri = intent.data ?: return
|
||||
|
||||
viewModelScope.launch {
|
||||
musicStore.getSongForUri(uri, context.contentResolver)?.let { song ->
|
||||
playSong(song)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- POSITION FUNCTIONS ---
|
||||
|
||||
/** Update the position and push it to [PlaybackStateManager] */
|
||||
|
|
Loading…
Reference in a new issue