remove some unused dbhelper functions
This commit is contained in:
parent
a43ec79c40
commit
b6bbdd4b54
1 changed files with 0 additions and 37 deletions
|
@ -8,7 +8,6 @@ import android.database.sqlite.SQLiteOpenHelper
|
|||
import android.provider.MediaStore
|
||||
import android.text.TextUtils
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.extensions.config
|
||||
import com.simplemobiletools.musicplayer.extensions.playlistChanged
|
||||
import com.simplemobiletools.musicplayer.models.Playlist
|
||||
|
@ -36,7 +35,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
override fun onCreate(db: SQLiteDatabase) {
|
||||
db.execSQL("CREATE TABLE $TABLE_NAME_PLAYLISTS ($COL_ID INTEGER PRIMARY KEY, $COL_TITLE TEXT)")
|
||||
createSongsTable(db)
|
||||
addAllSongsPlaylist(db)
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
||||
|
@ -47,21 +45,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
"UNIQUE($COL_PATH, $COL_PLAYLIST_ID) ON CONFLICT IGNORE)")
|
||||
}
|
||||
|
||||
private fun addAllSongsPlaylist(db: SQLiteDatabase) {
|
||||
val allSongs = context.resources.getString(R.string.all_songs)
|
||||
val playlist = Playlist(ALL_SONGS_PLAYLIST_ID, allSongs)
|
||||
addPlaylist(playlist, db)
|
||||
}
|
||||
|
||||
private fun addPlaylist(playlist: Playlist, db: SQLiteDatabase) {
|
||||
insertPlaylist(playlist, db)
|
||||
}
|
||||
|
||||
fun insertPlaylist(playlist: Playlist, db: SQLiteDatabase = mDb): Int {
|
||||
val values = ContentValues().apply { put(COL_TITLE, playlist.title) }
|
||||
return db.insert(TABLE_NAME_PLAYLISTS, null, values).toInt()
|
||||
}
|
||||
|
||||
fun removePlaylists(ids: ArrayList<Int>) {
|
||||
val args = TextUtils.join(", ", ids.filter { it != ALL_SONGS_PLAYLIST_ID })
|
||||
val selection = "$COL_ID IN ($args)"
|
||||
|
@ -110,26 +93,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
mDb.update(TABLE_NAME_SONGS, values, selection, selectionArgs)
|
||||
}
|
||||
|
||||
fun getPlaylists(callback: (types: ArrayList<Playlist>) -> Unit) {
|
||||
val playlists = ArrayList<Playlist>(3)
|
||||
val cols = arrayOf(COL_ID, COL_TITLE)
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = mDb.query(TABLE_NAME_PLAYLISTS, cols, null, null, null, null, "$COL_TITLE ASC")
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val id = cursor.getIntValue(COL_ID)
|
||||
val title = cursor.getStringValue(COL_TITLE)
|
||||
val playlist = Playlist(id, title)
|
||||
playlists.add(playlist)
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
callback(playlists)
|
||||
}
|
||||
|
||||
private fun removeSongFromPlaylist(path: String, playlistId: Int) {
|
||||
removeSongsFromPlaylist(ArrayList<String>().apply { add(path) }, playlistId)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue