Do not start playing after switching tracks by swype
This commit is contained in:
parent
69de9d6f2f
commit
22db781c0b
8 changed files with 18 additions and 17 deletions
|
@ -29,6 +29,7 @@ import org.oxycblt.auxio.util.logW
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the state information for [MenuDialogFragment] implementations.
|
* Manages the state information for [MenuDialogFragment] implementations.
|
||||||
|
*
|
||||||
* @author Alexander Capehart (OxygenCobalt)
|
* @author Alexander Capehart (OxygenCobalt)
|
||||||
*/
|
*/
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.oxycblt.auxio.playback
|
package org.oxycblt.auxio.playback
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException
|
import android.content.ActivityNotFoundException
|
||||||
|
@ -33,6 +33,8 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import java.lang.reflect.Field
|
||||||
|
import kotlin.math.abs
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
|
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
|
||||||
import org.oxycblt.auxio.detail.DetailViewModel
|
import org.oxycblt.auxio.detail.DetailViewModel
|
||||||
|
@ -53,8 +55,6 @@ import org.oxycblt.auxio.util.logD
|
||||||
import org.oxycblt.auxio.util.share
|
import org.oxycblt.auxio.util.share
|
||||||
import org.oxycblt.auxio.util.showToast
|
import org.oxycblt.auxio.util.showToast
|
||||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||||
import java.lang.reflect.Field
|
|
||||||
import kotlin.math.abs
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [ViewBindingFragment] more information about the currently playing song, alongside all
|
* A [ViewBindingFragment] more information about the currently playing song, alongside all
|
||||||
|
@ -252,8 +252,7 @@ class PlaybackPanelFragment :
|
||||||
is Show.AlbumArtistDecision,
|
is Show.AlbumArtistDecision,
|
||||||
is Show.GenreDetails,
|
is Show.GenreDetails,
|
||||||
is Show.PlaylistDetails,
|
is Show.PlaylistDetails,
|
||||||
null -> {
|
null -> {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,9 +285,8 @@ class PlaybackPanelFragment :
|
||||||
super.onPageScrollStateChanged(state)
|
super.onPageScrollStateChanged(state)
|
||||||
if (state == ViewPager2.SCROLL_STATE_IDLE &&
|
if (state == ViewPager2.SCROLL_STATE_IDLE &&
|
||||||
targetPosition != RecyclerView.NO_POSITION &&
|
targetPosition != RecyclerView.NO_POSITION &&
|
||||||
targetPosition != viewModel.index.value
|
targetPosition != viewModel.index.value) {
|
||||||
) {
|
viewModel.goto(targetPosition, playIfPaused = false)
|
||||||
viewModel.goto(targetPosition)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.oxycblt.auxio.playback.pager
|
package org.oxycblt.auxio.playback.pager
|
||||||
|
|
||||||
interface PlaybackPageListener {
|
interface PlaybackPageListener {
|
||||||
|
|
|
@ -24,13 +24,13 @@ import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import kotlin.jvm.internal.Intrinsics
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.ItemPlaybackSongBinding
|
import org.oxycblt.auxio.databinding.ItemPlaybackSongBinding
|
||||||
import org.oxycblt.auxio.list.adapter.FlexibleListAdapter
|
import org.oxycblt.auxio.list.adapter.FlexibleListAdapter
|
||||||
import org.oxycblt.auxio.music.Song
|
import org.oxycblt.auxio.music.Song
|
||||||
import org.oxycblt.auxio.music.resolveNames
|
import org.oxycblt.auxio.music.resolveNames
|
||||||
import org.oxycblt.auxio.util.inflater
|
import org.oxycblt.auxio.util.inflater
|
||||||
import kotlin.jvm.internal.Intrinsics
|
|
||||||
|
|
||||||
class PlaybackPagerAdapter(
|
class PlaybackPagerAdapter(
|
||||||
private val listener: PlaybackPageListener,
|
private val listener: PlaybackPageListener,
|
||||||
|
|
|
@ -88,7 +88,7 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), EditClickList
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(item: Song, viewHolder: RecyclerView.ViewHolder) {
|
override fun onClick(item: Song, viewHolder: RecyclerView.ViewHolder) {
|
||||||
queueModel.goto(viewHolder.bindingAdapterPosition)
|
queueModel.goto(viewHolder.bindingAdapterPosition, playIfPaused = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPickUp(viewHolder: RecyclerView.ViewHolder) {
|
override fun onPickUp(viewHolder: RecyclerView.ViewHolder) {
|
||||||
|
|
|
@ -106,13 +106,14 @@ class QueueViewModel @Inject constructor(private val playbackManager: PlaybackSt
|
||||||
*
|
*
|
||||||
* @param adapterIndex The index of the queue item to play. Does nothing if the index is out of
|
* @param adapterIndex The index of the queue item to play. Does nothing if the index is out of
|
||||||
* range.
|
* range.
|
||||||
|
* @param playIfPaused Start playing after switching even if it currently is paused
|
||||||
*/
|
*/
|
||||||
fun goto(adapterIndex: Int) {
|
fun goto(adapterIndex: Int, playIfPaused: Boolean) {
|
||||||
if (adapterIndex !in queue.value.indices) {
|
if (adapterIndex !in queue.value.indices) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logD("Going to position $adapterIndex in queue")
|
logD("Going to position $adapterIndex in queue")
|
||||||
playbackManager.goto(adapterIndex)
|
playbackManager.goto(adapterIndex, playIfPaused || playbackManager.playerState.isPlaying)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -120,8 +120,9 @@ interface PlaybackStateManager {
|
||||||
* Play a [Song] at the given position in the queue.
|
* Play a [Song] at the given position in the queue.
|
||||||
*
|
*
|
||||||
* @param index The position of the [Song] in the queue to start playing.
|
* @param index The position of the [Song] in the queue to start playing.
|
||||||
|
* @param play Whether to start playing after switching to target index
|
||||||
*/
|
*/
|
||||||
fun goto(index: Int)
|
fun goto(index: Int, play: Boolean)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add [Song]s to the top of the queue.
|
* Add [Song]s to the top of the queue.
|
||||||
|
@ -426,12 +427,12 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun goto(index: Int) {
|
override fun goto(index: Int, play: Boolean) {
|
||||||
val internalPlayer = internalPlayer ?: return
|
val internalPlayer = internalPlayer ?: return
|
||||||
if (queue.goto(index)) {
|
if (queue.goto(index)) {
|
||||||
logD("Moving to $index")
|
logD("Moving to $index")
|
||||||
notifyIndexMoved()
|
notifyIndexMoved()
|
||||||
internalPlayer.loadSong(queue.currentSong, true)
|
internalPlayer.loadSong(queue.currentSong, play)
|
||||||
} else {
|
} else {
|
||||||
logW("$index was not in bounds, could not move to it")
|
logW("$index was not in bounds, could not move to it")
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,7 @@ constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSkipToQueueItem(id: Long) {
|
override fun onSkipToQueueItem(id: Long) {
|
||||||
playbackManager.goto(id.toInt())
|
playbackManager.goto(id.toInt(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCustomAction(action: String?, extras: Bundle?) {
|
override fun onCustomAction(action: String?, extras: Bundle?) {
|
||||||
|
|
Loading…
Reference in a new issue