Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 26 | Rev 43 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 gabriel 1
package com.cesams.twogetskills.dao;
2
 
3
import android.content.Context;
4
 
5
import androidx.room.Room;
19 gabriel 6
import androidx.room.migration.Migration;
7
import androidx.sqlite.db.SupportSQLiteDatabase;
1 gabriel 8
 
9
import com.cesams.twogetskills.Constants;
19 gabriel 10
import com.cesams.twogetskills.entity.NotificationCenter;
1 gabriel 11
 
12
public class DatabaseHelper {
13
 
14
    //Control de cambio de capsula
3 gabriel 15
    //public static String CambioSlide = "NO"; // SI o NO
16
    //public static String ResumenVisores ="NO";
17
    //public static String imagenviewerontrol= "NO";
1 gabriel 18
 
19
    private static DatabaseHelper _INSTANCE = null;
20
    private AppDatabase appDatabase;
21
 
22
    // other instance variables can be here
23
 
24
    private DatabaseHelper(Context context) {
25
        appDatabase = Room.databaseBuilder(
26
                context.getApplicationContext(),
27
                AppDatabase.class, Constants.DATABASE_FILENAME
19 gabriel 28
        ).allowMainThreadQueries().addMigrations(MIGRATION_1_2).fallbackToDestructiveMigration()
29
                .build();
1 gabriel 30
    };
31
 
19 gabriel 32
    static final Migration MIGRATION_1_2 = new Migration(1, 2) {
33
        @Override
34
        public void migrate(SupportSQLiteDatabase database) {
35
            database.execSQL("CREATE TABLE `tb_notification` (`id` INTEGER NOT NULL, "
39 gabriel 36
                    + "`title` TEXT,`date` TEXT,`description` TEXT, viewed TEXT, url TEXT, PRIMARY KEY(`id`))");
21 gabriel 37
 
38
            database.execSQL("ALTER TABLE `tb_capsules`"
39
                    + "ADD COLUMN added_on TEXT");
40
 
41
            database.execSQL("ALTER TABLE `tb_capsules`"
42
                    + "ADD COLUMN updated_on TEXT");
43
 
44
            database.execSQL("ALTER TABLE `tb_topics`"
45
                    + "ADD COLUMN updated_on TEXT");
46
 
47
            database.execSQL("ALTER TABLE `tb_topics`"
48
                    + "ADD COLUMN updated_on TEXT");
49
 
50
 
26 gabriel 51
 
19 gabriel 52
        }
53
    };
54
 
1 gabriel 55
    public static DatabaseHelper getInstance(Context context) {
56
        if (_INSTANCE == null) {
57
            _INSTANCE = new DatabaseHelper(context);
58
        }
59
        return(_INSTANCE);
60
    }
61
 
62
    public AppDatabase getAppDatabase() {
63
        return appDatabase;
64
    }
65
}