allow changing playlists by clicking on them in the manager

This commit is contained in:
tibbi 2017-03-30 19:58:50 +02:00
parent 6301f447f3
commit c5bf6da7af
5 changed files with 24 additions and 2 deletions

View file

@ -186,6 +186,8 @@ class MainActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListener {
} else {
song_title.text = ""
song_artist.text = ""
progressbar.max = 0
progressbar.progress = 0
}
}

View file

@ -21,7 +21,8 @@ class PlaylistsActivity : SimpleActivity(), RefreshItemsListener {
dbHelper.getPlaylists {
runOnUiThread {
playlists_list.adapter = PlaylistsAdapter(this, it, this) {
getPlaylists()
playlistChanged(it.id)
}
}
}

View file

@ -2,9 +2,21 @@ package com.simplemobiletools.musicplayer.activities
import android.os.Bundle
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.musicplayer.extensions.config
import com.simplemobiletools.musicplayer.extensions.sendIntent
import com.simplemobiletools.musicplayer.helpers.NEXT
import com.simplemobiletools.musicplayer.helpers.PAUSE
import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST
open class SimpleActivity : BaseSimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
fun playlistChanged(newID: Int) {
config.currentPlaylist = newID
sendIntent(PAUSE)
sendIntent(REFRESH_LIST)
sendIntent(NEXT)
}
}

View file

@ -116,6 +116,9 @@ class PlaylistsAdapter(val activity: SimpleActivity, val mItems: List<Playlist>,
if (ids.contains(DBHelper.INITIAL_PLAYLIST_ID)) {
activity.toast(R.string.initial_playlist_cannot_be_deleted)
}
if (ids.contains(activity.config.currentPlaylist)) {
activity.playlistChanged(DBHelper.INITIAL_PLAYLIST_ID)
}
listener?.refreshItems()
}

View file

@ -381,8 +381,12 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
}
fun setSong(songIndex: Int, addNewSong: Boolean) {
if (mSongs!!.isEmpty())
if (mSongs!!.isEmpty()) {
mCurrSong = null
mBus!!.post(Events.SongChanged(null))
songStateChanged(false)
return
}
val wasPlaying = getIsPlaying()
initMediaPlayerIfNeeded()