Fix play/pause bug
Possibly fix a bug where the play/pause button would get stuck in the play position when playing from a file intent.
This commit is contained in:
parent
e9abee9f64
commit
af9fac7de2
6 changed files with 35 additions and 21 deletions
|
@ -38,9 +38,6 @@ class MainActivity : AppCompatActivity() {
|
|||
// Apply the theme
|
||||
setTheme(accent.theme)
|
||||
|
||||
// onNewIntent doesnt automatically call on startup, so call it here.
|
||||
onNewIntent(intent)
|
||||
|
||||
if (isEdgeOn()) {
|
||||
doEdgeToEdgeSetup(binding)
|
||||
}
|
||||
|
@ -51,6 +48,9 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
// Start PlaybackService
|
||||
startService(Intent(this, PlaybackService::class.java))
|
||||
|
||||
// onNewIntent doesnt automatically call on startup, so call it here.
|
||||
onNewIntent(intent)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
|
|
|
@ -88,15 +88,17 @@ class MusicStore private constructor() {
|
|||
* Get the song for a file [uri].
|
||||
* @return The corresponding [Song] for this [uri], null if there isnt one.
|
||||
*/
|
||||
suspend fun getSongForUri(uri: Uri, resolver: ContentResolver): Song? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
resolver.query(uri, null, null, null, null)?.use { cursor ->
|
||||
fun getSongForUri(uri: Uri, resolver: ContentResolver): Song? {
|
||||
resolver.query(
|
||||
uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null
|
||||
)?.use { cursor ->
|
||||
cursor.moveToFirst()
|
||||
val fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
|
||||
|
||||
return@withContext songs.find { it.fileName == fileName }
|
||||
}
|
||||
return songs.find { it.fileName == fileName }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -55,8 +55,6 @@ class CompactPlaybackFragment : Fragment() {
|
|||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||
if (song != null) {
|
||||
logD("Updating song display to ${song.name}")
|
||||
|
@ -76,4 +74,10 @@ class CompactPlaybackFragment : Fragment() {
|
|||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.util.AttributeSet
|
|||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.AppCompatImageButton
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.ui.toAnimDrawable
|
||||
|
||||
/**
|
||||
|
@ -45,6 +46,7 @@ class PlayPauseButton @JvmOverloads constructor(
|
|||
setImageDrawable(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
} else {
|
||||
logD("what the FUCK WHY ARENT YOU DOING THIS")
|
||||
setImageResource(R.drawable.ic_play_large)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,9 +77,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
binding.playbackSeekBar.setOnSeekBarChangeListener(this)
|
||||
|
||||
// --- VIEWMODEL SETUP --
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||
if (song != null) {
|
||||
logD("Updating song display to ${song.name}.")
|
||||
|
@ -158,8 +155,13 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
binding.playbackPlayPause.apply {
|
||||
backgroundTintList = if (it) accentColor else controlColor
|
||||
setPlaying(it, playbackModel.canAnimate)
|
||||
if (it) {
|
||||
backgroundTintList = accentColor
|
||||
setPlaying(true, playbackModel.canAnimate)
|
||||
} else {
|
||||
backgroundTintList = controlColor
|
||||
setPlaying(false, playbackModel.canAnimate)
|
||||
}
|
||||
}
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
|
@ -176,6 +178,12 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
}
|
||||
|
||||
// --- SEEK CALLBACKS ---
|
||||
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
|
|
|
@ -181,12 +181,10 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
* This is called after [playWithUri] once its deemed safe to do so.
|
||||
*/
|
||||
private fun playWithUriInternal(uri: Uri, context: Context) {
|
||||
viewModelScope.launch {
|
||||
musicStore.getSongForUri(uri, context.contentResolver)?.let { song ->
|
||||
playSong(song)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffle all songs
|
||||
|
|
Loading…
Reference in a new issue