Fixed IllegalStateException when deleting multiple songs
This commit is contained in:
parent
b2dbfd3083
commit
97c56f9e57
6 changed files with 25 additions and 15 deletions
|
@ -121,7 +121,7 @@ dependencies {
|
|||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
||||
|
||||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||
implementation 'com.google.android.material:material:1.5.0-alpha05'
|
||||
implementation 'com.google.android.material:material:1.5.0-beta01'
|
||||
|
||||
def retrofit_version = '2.9.0'
|
||||
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
|
|
|
@ -281,7 +281,7 @@ class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_playe
|
|||
private fun updatePlayingQueue() {
|
||||
binding.viewPager.apply {
|
||||
adapter = AlbumCoverPagerAdapter(childFragmentManager, MusicPlayerRemote.playingQueue)
|
||||
adapter!!.notifyDataSetChanged()
|
||||
adapter?.notifyDataSetChanged()
|
||||
currentItem = MusicPlayerRemote.position
|
||||
onPageSelected(MusicPlayerRemote.position)
|
||||
}
|
||||
|
|
|
@ -392,6 +392,15 @@ object MusicPlayerRemote : KoinComponent {
|
|||
return false
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun removeFromQueue(songs: List<Song>): Boolean {
|
||||
if (musicService != null) {
|
||||
musicService!!.removeSongs(songs)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun removeFromQueue(position: Int): Boolean {
|
||||
if (musicService != null && position >= 0 && position < playingQueue.size) {
|
||||
musicService!!.removeSong(position)
|
||||
|
|
|
@ -1190,7 +1190,7 @@ public class MusicService extends MediaBrowserServiceCompat
|
|||
notifyChange(QUEUE_CHANGED);
|
||||
}
|
||||
|
||||
public void removeSong(@NonNull Song song) {
|
||||
public void removeSongImpl(@NonNull Song song) {
|
||||
for (int i = 0; i < playingQueue.size(); i++) {
|
||||
if (playingQueue.get(i).getId() == song.getId()) {
|
||||
playingQueue.remove(i);
|
||||
|
@ -1202,6 +1202,17 @@ public class MusicService extends MediaBrowserServiceCompat
|
|||
originalPlayingQueue.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSong(@NonNull Song song) {
|
||||
removeSongImpl(song);
|
||||
notifyChange(QUEUE_CHANGED);
|
||||
}
|
||||
|
||||
public void removeSongs(@NonNull List<Song> songs) {
|
||||
for (Song song : songs) {
|
||||
removeSongImpl(song);
|
||||
}
|
||||
notifyChange(QUEUE_CHANGED);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import code.name.monkey.retromusic.model.Playlist
|
|||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics
|
||||
import code.name.monkey.retromusic.repository.RealPlaylistRepository
|
||||
import code.name.monkey.retromusic.repository.RealSongRepository
|
||||
import code.name.monkey.retromusic.repository.Repository
|
||||
import code.name.monkey.retromusic.repository.SongRepository
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
|
@ -474,16 +473,7 @@ object MusicUtil : KoinComponent {
|
|||
null, null
|
||||
)
|
||||
if (cursor != null) {
|
||||
// Step 1: Remove selected tracks from the current playlist, as well
|
||||
// as from the album art cache
|
||||
cursor.moveToFirst()
|
||||
while (!cursor.isAfterLast) {
|
||||
val id = cursor.getLong(BaseColumns._ID)
|
||||
val song: Song = RealSongRepository(context).song(id)
|
||||
removeFromQueue(song)
|
||||
cursor.moveToNext()
|
||||
}
|
||||
|
||||
removeFromQueue(songs)
|
||||
|
||||
// Step 2: Remove files from card
|
||||
cursor.moveToFirst()
|
||||
|
|
|
@ -24,7 +24,7 @@ android {
|
|||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'com.google.android.material:material:1.5.0-alpha05'
|
||||
implementation 'com.google.android.material:material:1.5.0-beta01'
|
||||
implementation 'androidx.preference:preference-ktx:1.1.1'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
|
||||
|
|
Loading…
Reference in a new issue