Fix rewinding issues

Fix a problem where rewinding wouldnt cause the playback to start again.
This commit is contained in:
OxygenCobalt 2021-01-15 19:36:56 -07:00
parent d86e5f1414
commit 929ef0a1b4
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 7 additions and 47 deletions

View file

@ -17,7 +17,6 @@ import org.oxycblt.auxio.databinding.FragmentPlaybackBinding
import org.oxycblt.auxio.detail.DetailViewModel import org.oxycblt.auxio.detail.DetailViewModel
import org.oxycblt.auxio.logD import org.oxycblt.auxio.logD
import org.oxycblt.auxio.playback.state.LoopMode import org.oxycblt.auxio.playback.state.LoopMode
import org.oxycblt.auxio.settings.SettingsManager
import org.oxycblt.auxio.ui.accent import org.oxycblt.auxio.ui.accent
import org.oxycblt.auxio.ui.memberBinding import org.oxycblt.auxio.ui.memberBinding
import org.oxycblt.auxio.ui.toColor import org.oxycblt.auxio.ui.toColor
@ -63,7 +62,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
) )
val queueMenuItem: MenuItem val queueMenuItem: MenuItem
val showCoverArt = SettingsManager.getInstance().showCovers
// --- UI SETUP --- // --- UI SETUP ---
@ -100,10 +98,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
binding.song = it binding.song = it
binding.playbackSeekBar.max = it.seconds.toInt() binding.playbackSeekBar.max = it.seconds.toInt()
if (!showCoverArt) {
binding.playbackCover.setImageResource(R.drawable.ic_album)
}
} else { } else {
logD("No song is being played, leaving.") logD("No song is being played, leaving.")

View file

@ -501,7 +501,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
// Rewind if the key is rewind // Rewind if the key is rewind
KeyEvent.KEYCODE_MEDIA_REWIND -> { KeyEvent.KEYCODE_MEDIA_REWIND -> {
player.seekTo(0) playbackManager.rewind()
true true
} }

View file

@ -322,7 +322,7 @@ class PlaybackStateManager private constructor() {
fun prev() { fun prev() {
// If enabled, rewind before skipping back if the position is past 3 seconds [3000ms] // If enabled, rewind before skipping back if the position is past 3 seconds [3000ms]
if (settingsManager.rewindWithPrev && mPosition >= 3000) { if (settingsManager.rewindWithPrev && mPosition >= 3000) {
seekTo(0) rewind()
} else { } else {
// Only decrement the index if there's a song to move back to AND if we are not exiting // Only decrement the index if there's a song to move back to AND if we are not exiting
// the user queue. // the user queue.
@ -593,6 +593,11 @@ class PlaybackStateManager private constructor() {
} }
} }
fun rewind() {
seekTo(0)
setPlayingStatus(true)
}
/** /**
* Set the [LoopMode] * Set the [LoopMode]
* @param mode The [LoopMode] to be used * @param mode The [LoopMode] to be used

View file

@ -8,13 +8,9 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.Album
import org.oxycblt.auxio.music.Artist
import org.oxycblt.auxio.music.BaseModel import org.oxycblt.auxio.music.BaseModel
import org.oxycblt.auxio.music.Genre
import org.oxycblt.auxio.music.Header import org.oxycblt.auxio.music.Header
import org.oxycblt.auxio.music.MusicStore import org.oxycblt.auxio.music.MusicStore
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.recycler.DisplayMode import org.oxycblt.auxio.recycler.DisplayMode
import org.oxycblt.auxio.settings.SettingsManager import org.oxycblt.auxio.settings.SettingsManager
@ -99,16 +95,6 @@ class SearchViewModel : ViewModel() {
return if (filtered.isNotEmpty()) filtered else null return if (filtered.isNotEmpty()) filtered else null
} }
private fun List<BaseModel>.filterByDisplayMode(mode: DisplayMode): List<BaseModel> {
return when (mode) {
DisplayMode.SHOW_ALL -> this
DisplayMode.SHOW_SONGS -> filterIsInstance<Song>()
DisplayMode.SHOW_ALBUMS -> filterIsInstance<Album>()
DisplayMode.SHOW_ARTISTS -> filterIsInstance<Artist>()
DisplayMode.SHOW_GENRES -> filterIsInstance<Genre>()
}
}
/** /**
* Update the current navigation status * Update the current navigation status
* @param value Whether LibraryFragment is navigating or not * @param value Whether LibraryFragment is navigating or not

View file

@ -3,8 +3,6 @@ package org.oxycblt.auxio.ui
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import android.text.Spanned import android.text.Spanned
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -96,29 +94,6 @@ fun Int.toColor(context: Context): Int {
} }
} }
/**
* Resolve an attribute into a color.
* @param context [Context] required
* @param attr The Resource ID for the attribute
* @return The resolved color for that attribute. Black if the process failed.
*/
@ColorInt
fun resolveAttr(context: Context, @AttrRes attr: Int): Int {
// Convert the attribute into its color
val resolvedAttr = TypedValue().apply {
context.theme.resolveAttribute(attr, this, true)
}
// Then convert it to a proper color
val color = if (resolvedAttr.resourceId != 0) {
resolvedAttr.resourceId
} else {
resolvedAttr.data
}
return color.toColor(context)
}
/** /**
* Get the name of an accent. * Get the name of an accent.
* @param context [Context] required * @param context [Context] required