diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt index 7f9b8fed..6b060035 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt @@ -236,29 +236,6 @@ class MainActivity : SimpleActivity(), SongListListener { } } - private fun handleSongMigration() { - dbHelper.getAllSongs { - if (it.isEmpty()) { - config.wereSongsMigrated = true - return@getAllSongs - } - - val songs = it - dbHelper.getAllPlaylists { - it.forEach { - val playlist = it - val newPlaylistId = if (playlist.id == ALL_SONGS_PLAYLIST_ID) ALL_SONGS_PLAYLIST_ID else playlistDAO.insert(playlist.copy(id = 0)).toInt() - val playlistSongPaths = songs.filter { it.playListId == newPlaylistId }.map { it.path } as ArrayList - RoomHelper(applicationContext).addSongsToPlaylist(playlistSongPaths, newPlaylistId) - } - - playlistChanged(ALL_SONGS_PLAYLIST_ID) - config.wereSongsMigrated = true - dbHelper.clearDatabase() - } - } - } - private fun setTopArtHeight() { topArtHeight = if (config.showAlbumCover) resources.getDimensionPixelSize(R.dimen.top_art_height) else 0 artView!!.setPadding(0, topArtHeight, 0, 0) @@ -505,12 +482,6 @@ class MainActivity : SimpleActivity(), SongListListener { } private fun initializePlayer() { - if (!config.wereSongsMigrated) { - Thread { - handleSongMigration() - }.start() - } - if (isThirdPartyIntent) { initThirdPartyIntent() } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/extensions/Context.kt index 63e9916e..7ee84338 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/extensions/Context.kt @@ -5,7 +5,10 @@ import android.content.Intent import android.util.TypedValue import com.simplemobiletools.musicplayer.R import com.simplemobiletools.musicplayer.databases.SongsDatabase -import com.simplemobiletools.musicplayer.helpers.* +import com.simplemobiletools.musicplayer.helpers.CALL_SETUP_AFTER +import com.simplemobiletools.musicplayer.helpers.Config +import com.simplemobiletools.musicplayer.helpers.PAUSE +import com.simplemobiletools.musicplayer.helpers.REFRESH_LIST import com.simplemobiletools.musicplayer.interfaces.PlaylistsDao import com.simplemobiletools.musicplayer.interfaces.SongsDao import com.simplemobiletools.musicplayer.models.Playlist @@ -25,8 +28,6 @@ fun Context.sendIntent(action: String) { val Context.config: Config get() = Config.newInstance(applicationContext) -val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext) - val Context.playlistDAO: PlaylistsDao get() = getSongsDB().PlaylistsDao() val Context.songsDAO: SongsDao get() = getSongsDB().SongsDao() diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt index 47448798..a7e2354e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt @@ -47,10 +47,6 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(SHOW_FILENAME, SHOW_FILENAME_IF_UNAVAILABLE) set(showFilename) = prefs.edit().putInt(SHOW_FILENAME, showFilename).apply() - var wereSongsMigrated: Boolean - get() = prefs.getBoolean(WERE_SONGS_MIGRATED, false) - set(wereSongsMigrated) = prefs.edit().putBoolean(WERE_SONGS_MIGRATED, wereSongsMigrated).apply() - var swapPrevNext: Boolean get() = prefs.getBoolean(SWAP_PREV_NEXT, false) set(swapPrevNext) = prefs.edit().putBoolean(SWAP_PREV_NEXT, swapPrevNext).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt index a8e12457..0ff4a4a8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Constants.kt @@ -37,7 +37,6 @@ const val IGNORED_PATHS = "ignored_paths" const val CURRENT_PLAYLIST = "current_playlist" const val SHOW_FILENAME = "show_filename" const val SHOW_ALBUM_COVER = "show_album_cover" -const val WERE_SONGS_MIGRATED = "were_songs_migrated" // check migration from old sqlite to Room const val SWAP_PREV_NEXT = "swap_prev_next" const val LIST_HEADERS_COUNT = 2 diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/DBHelper.kt deleted file mode 100644 index 98f15873..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/DBHelper.kt +++ /dev/null @@ -1,87 +0,0 @@ -package com.simplemobiletools.musicplayer.helpers - -import android.content.Context -import android.database.Cursor -import android.database.sqlite.SQLiteDatabase -import android.database.sqlite.SQLiteOpenHelper -import com.simplemobiletools.commons.extensions.getIntValue -import com.simplemobiletools.commons.extensions.getStringValue -import com.simplemobiletools.musicplayer.models.Playlist -import com.simplemobiletools.musicplayer.models.Song - -class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { - private val TABLE_NAME_PLAYLISTS = "playlists" - private val COL_ID = "id" - private val COL_TITLE = "title" - - private val TABLE_NAME_SONGS = "songs" - private val COL_PATH = "path" - private val COL_PLAYLIST_ID = "playlist_id" - - private val mDb = writableDatabase - - companion object { - private const val DB_VERSION = 1 - const val DB_NAME = "playlists.db" - - fun newInstance(context: Context) = DBHelper(context) - } - - override fun onCreate(db: SQLiteDatabase) { - db.execSQL("CREATE TABLE $TABLE_NAME_PLAYLISTS ($COL_ID INTEGER PRIMARY KEY, $COL_TITLE TEXT)") - createSongsTable(db) - } - - override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { - } - - private fun createSongsTable(db: SQLiteDatabase) { - db.execSQL("CREATE TABLE $TABLE_NAME_SONGS ($COL_ID INTEGER PRIMARY KEY, $COL_PATH TEXT, $COL_PLAYLIST_ID INTEGER, " + - "UNIQUE($COL_PATH, $COL_PLAYLIST_ID) ON CONFLICT IGNORE)") - } - - fun getAllPlaylists(callback: (types: ArrayList) -> Unit) { - val playlists = ArrayList(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) - } - - fun getAllSongs(callback: (songs: ArrayList) -> Unit) { - val songs = ArrayList() - val cols = arrayOf(COL_PATH, COL_PLAYLIST_ID) - var cursor: Cursor? = null - try { - cursor = mDb.query(TABLE_NAME_SONGS, cols, null, null, null, null, null) - if (cursor?.moveToFirst() == true) { - do { - val path = cursor.getStringValue(COL_PATH) - val playlistId = cursor.getIntValue(COL_PLAYLIST_ID) - val song = Song(0, "", "", path, 0, "", playlistId, TYPE_FILE) - songs.add(song) - } while (cursor.moveToNext()) - } - } finally { - cursor?.close() - } - callback(songs) - } - - fun clearDatabase() { - mDb.execSQL("DELETE FROM $TABLE_NAME_PLAYLISTS") - mDb.execSQL("DELETE FROM $TABLE_NAME_SONGS") - } -}