add a helper function for getting current playlist song paths
This commit is contained in:
parent
d3d10217ba
commit
f3e352e6b4
3 changed files with 29 additions and 1 deletions
|
@ -3,6 +3,7 @@ package com.simplemobiletools.musicplayer.extensions
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.simplemobiletools.musicplayer.helpers.Config
|
||||
import com.simplemobiletools.musicplayer.helpers.DBHelper
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
|
||||
fun Context.sendIntent(action: String) {
|
||||
|
@ -13,3 +14,5 @@ fun Context.sendIntent(action: String) {
|
|||
}
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
|
||||
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(this)
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.simplemobiletools.musicplayer.helpers
|
|||
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import com.simplemobiletools.commons.extensions.getStringValue
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.models.Playlist
|
||||
|
@ -69,4 +71,24 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCurrentPlaylistPaths(): ArrayList<String> {
|
||||
val paths = ArrayList<String>()
|
||||
val cols = arrayOf(COL_PATH)
|
||||
val selection = "$COL_PLAYLIST_ID = ?"
|
||||
val selectionArgs = arrayOf(context.config.currentPlaylist.toString())
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = mDb.query(TABLE_NAME_SONGS, cols, selection, selectionArgs, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val path = cursor.getStringValue(COL_PATH)
|
||||
paths.add(path)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
return paths
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.simplemobiletools.commons.extensions.toast
|
|||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.activities.MainActivity
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.extensions.dbHelper
|
||||
import com.simplemobiletools.musicplayer.helpers.*
|
||||
import com.simplemobiletools.musicplayer.models.Events
|
||||
import com.simplemobiletools.musicplayer.models.Song
|
||||
|
@ -200,7 +201,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
cursor?.close()
|
||||
}
|
||||
|
||||
DBHelper.newInstance(this).addSongsToPlaylist(paths)
|
||||
dbHelper.addSongsToPlaylist(paths)
|
||||
}
|
||||
|
||||
private fun getSortedSongs() {
|
||||
|
@ -209,6 +210,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
config.wasInitialPlaylistFilled = true
|
||||
}
|
||||
|
||||
val songPaths = dbHelper.getCurrentPlaylistPaths()
|
||||
|
||||
Song.sorting = mConfig!!.sorting
|
||||
mSongs?.sort()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue