Do not start playing after switching tracks by swype

This commit is contained in:
Koitharu 2023-07-14 07:54:01 +03:00
parent 69de9d6f2f
commit 22db781c0b
No known key found for this signature in database
GPG key ID: 676DEE768C17A9D7
8 changed files with 18 additions and 17 deletions

View file

@ -29,6 +29,7 @@ import org.oxycblt.auxio.util.logW
/**
* Manages the state information for [MenuDialogFragment] implementations.
*
* @author Alexander Capehart (OxygenCobalt)
*/
@HiltViewModel

View file

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.playback
import android.content.ActivityNotFoundException
@ -33,6 +33,8 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import dagger.hilt.android.AndroidEntryPoint
import java.lang.reflect.Field
import kotlin.math.abs
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentPlaybackPanelBinding
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.showToast
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
@ -252,8 +252,7 @@ class PlaybackPanelFragment :
is Show.AlbumArtistDecision,
is Show.GenreDetails,
is Show.PlaylistDetails,
null -> {
}
null -> {}
}
}
@ -286,9 +285,8 @@ class PlaybackPanelFragment :
super.onPageScrollStateChanged(state)
if (state == ViewPager2.SCROLL_STATE_IDLE &&
targetPosition != RecyclerView.NO_POSITION &&
targetPosition != viewModel.index.value
) {
viewModel.goto(targetPosition)
targetPosition != viewModel.index.value) {
viewModel.goto(targetPosition, playIfPaused = false)
}
}
}

View file

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.playback.pager
interface PlaybackPageListener {

View file

@ -24,13 +24,13 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import kotlin.jvm.internal.Intrinsics
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.ItemPlaybackSongBinding
import org.oxycblt.auxio.list.adapter.FlexibleListAdapter
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.util.inflater
import kotlin.jvm.internal.Intrinsics
class PlaybackPagerAdapter(
private val listener: PlaybackPageListener,

View file

@ -88,7 +88,7 @@ class QueueFragment : ViewBindingFragment<FragmentQueueBinding>(), EditClickList
}
override fun onClick(item: Song, viewHolder: RecyclerView.ViewHolder) {
queueModel.goto(viewHolder.bindingAdapterPosition)
queueModel.goto(viewHolder.bindingAdapterPosition, playIfPaused = true)
}
override fun onPickUp(viewHolder: RecyclerView.ViewHolder) {

View file

@ -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
* 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) {
return
}
logD("Going to position $adapterIndex in queue")
playbackManager.goto(adapterIndex)
playbackManager.goto(adapterIndex, playIfPaused || playbackManager.playerState.isPlaying)
}
/**

View file

@ -120,8 +120,9 @@ interface PlaybackStateManager {
* Play a [Song] at the given position in the queue.
*
* @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.
@ -426,12 +427,12 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
}
@Synchronized
override fun goto(index: Int) {
override fun goto(index: Int, play: Boolean) {
val internalPlayer = internalPlayer ?: return
if (queue.goto(index)) {
logD("Moving to $index")
notifyIndexMoved()
internalPlayer.loadSong(queue.currentSong, true)
internalPlayer.loadSong(queue.currentSong, play)
} else {
logW("$index was not in bounds, could not move to it")
}

View file

@ -256,7 +256,7 @@ constructor(
}
override fun onSkipToQueueItem(id: Long) {
playbackManager.goto(id.toInt())
playbackManager.goto(id.toInt(), true)
}
override fun onCustomAction(action: String?, extras: Bundle?) {