Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit a8c2bcd3 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Saalim Quadri
Browse files

feat: Use existing dbhelper

parent ee2f2f75
Loading
Loading
Loading
Loading
+2 −15
Original line number Diff line number Diff line
@@ -54,25 +54,18 @@ object BlissDbUtils {
    private const val folderType = 2

    @JvmStatic
    fun migrateDataFromDb(context: Context): Boolean {
    fun migrateDataFromDb(context: Context, dbHelper: DatabaseHelper): Boolean {
        // Check if old database exists
        val oldFile = context.getDatabasePath(oldDbName)
        if (!oldFile.exists()) return false

        // Current database details
        val currentDbName = InvariantDeviceProfile.INSTANCE[context].dbFile
        val rowCount = InvariantDeviceProfile.INSTANCE[context].numRows
        val columnCount = InvariantDeviceProfile.INSTANCE[context].numColumns
        val numFolderRows = InvariantDeviceProfile.INSTANCE[context].numFolderRows
        val numFolderColumns = InvariantDeviceProfile.INSTANCE[context].numFolderColumns

        // Init database helper classes
        val dbHelper =
            DatabaseHelper(
                context,
                currentDbName,
                UserCache.INSTANCE.get(context)::getSerialNumberForUser
            ) {}
        val oldDbHelper = BlissDbHelper(context, oldDbName)

        // Retrieve data from the old table
@@ -233,10 +226,6 @@ object BlissDbUtils {
            }
        }

        // Update item id after migrating
        dbHelper.updateItemId()
        dbHelper.close()

        // Rename the database to old
        val newFile = context.getDatabasePath(oldDbName + "_old")
        oldFile.renameTo(newFile)
@@ -276,14 +265,12 @@ object BlissDbUtils {
                        val widgetInfo = appWidgetManager.getAppWidgetInfo(id)

                        if (widgetInfo != null) {
                            var provider: ComponentName = widgetInfo.provider

                            widgetsInfoList.add(
                                WidgetItems(
                                    id,
                                    height,
                                    order,
                                    provider,
                                    widgetInfo.provider,
                                )
                            )
                        }
+4 −3
Original line number Diff line number Diff line
@@ -640,10 +640,11 @@ public class ModelDbController {
     */
    @WorkerThread
    public synchronized void loadDefaultFavoritesIfNecessary() {
        if (BlissDbUtils.migrateDataFromDb(mContext)) {
        if (BlissDbUtils.migrateDataFromDb(mContext, mOpenHelper)) {
            SQLiteDatabase db = mOpenHelper.getWritableDatabase();
            copyTable(db, Favorites.E_TABLE_NAME,
                    db, Favorites.E_TABLE_NAME_ALL, mContext);
            copyTable(db, Favorites.E_TABLE_NAME_ALL,
                    db, Favorites.E_TABLE_NAME, mContext);
            mOpenHelper.updateItemId();
            clearFlagEmptyDbCreated();
            return;
        }