// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/AppDatabase.java
// @Database(entities = {Station.class}, version = 3)
// public abstract class AppDatabase extends RoomDatabase {
// 
//     private static AppDatabase INSTANCE;
// 
//     public abstract StationDaoRoom stationDao();
// 
//     public static AppDatabase getAppDatabase(Context context, boolean force) {
//         if (INSTANCE == null || force) {
// 
//             INSTANCE =
//                     Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "justintrain.db")
//                             // allow queries on the main thread.
//                             // Don't do\ this on a real app! See PersistenceBasicSample for an example.
//                             .openHelperFactory(new AssetSQLiteOpenHelperFactory())
// //                            .addMigrations(MIGRATION_1_2)
//                             .allowMainThreadQueries()
//                             .build();
//         }
//         return INSTANCE;
//     }
// 
//     public static void destroyInstance() {
//         INSTANCE = null;
//     }
// 
// //    private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
// //        @Override
// //        public void migrate(SupportSQLiteDatabase database) {
// //            database.execSQL("ALTER TABLE station "
// //                    + " ADD COLUMN name_fancy TEXT");
// //        }
// //    };
// 
// }


import com.google.firebase.crash.FirebaseCrash;
import android.app.Application;
import com.jaus.albertogiunta.justintrain_oraritreni.db.AppDatabase;
import net.danlew.android.joda.JodaTimeAndroid;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
package com.jaus.albertogiunta.justintrain_oraritreni;






//import com.facebook.stetho.Stetho;

public class MyApplication extends Application {

    public static AppDatabase database;

    @Override
    public void onCreate() {
        super.onCreate();
        JodaTimeAndroid.init(this);

        String fontPath = "fonts/rooneysans-medium.ttf";
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath(fontPath)
                .setFontAttrId(R.attr.fontPath)
                .build()
        );

//        this.deleteDatabase("justintrain.db");
        if (database == null) {
            database = AppDatabase.getAppDatabase(getBaseContext(), false);
        }

        try {
            if (database.stationDao().getAll().size() == 0) {
                this.deleteDatabase("justintrain.db");
                database = AppDatabase.getAppDatabase(getBaseContext(), true);
            }
        } catch (Exception e) {
            this.deleteDatabase("justintrain.db");
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/db/AppDatabase.java
// @Database(entities = {Station.class}, version = 3)
// public abstract class AppDatabase extends RoomDatabase {
// 
//     private static AppDatabase INSTANCE;
// 
//     public abstract StationDaoRoom stationDao();
// 
//     public static AppDatabase getAppDatabase(Context context, boolean force) {
//         if (INSTANCE == null || force) {
// 
//             INSTANCE =
//                     Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, "justintrain.db")
//                             // allow queries on the main thread.
//                             // Don't do\ this on a real app! See PersistenceBasicSample for an example.
//                             .openHelperFactory(new AssetSQLiteOpenHelperFactory())
// //                            .addMigrations(MIGRATION_1_2)
//                             .allowMainThreadQueries()
//                             .build();
//         }
//         return INSTANCE;
//     }
// 
//     public static void destroyInstance() {
//         INSTANCE = null;
//     }
// 
// //    private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
// //        @Override
// //        public void migrate(SupportSQLiteDatabase database) {
// //            database.execSQL("ALTER TABLE station "
// //                    + " ADD COLUMN name_fancy TEXT");
// //        }
// //    };
// 
// }


// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/MyApplication.java
import com.google.firebase.crash.FirebaseCrash;
import android.app.Application;
import com.jaus.albertogiunta.justintrain_oraritreni.db.AppDatabase;
import net.danlew.android.joda.JodaTimeAndroid;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

package com.jaus.albertogiunta.justintrain_oraritreni;






//import com.facebook.stetho.Stetho;

public class MyApplication extends Application {

    public static AppDatabase database;

    @Override
    public void onCreate() {
        super.onCreate();
        JodaTimeAndroid.init(this);

        String fontPath = "fonts/rooneysans-medium.ttf";
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath(fontPath)
                .setFontAttrId(R.attr.fontPath)
                .build()
        );

//        this.deleteDatabase("justintrain.db");
        if (database == null) {
            database = AppDatabase.getAppDatabase(getBaseContext(), false);
        }

        try {
            if (database.stationDao().getAll().size() == 0) {
                this.deleteDatabase("justintrain.db");
                database = AppDatabase.getAppDatabase(getBaseContext(), true);
            }
        } catch (Exception e) {
            this.deleteDatabase("justintrain.db");
            database = AppDatabase.getAppDatabase(getBaseContext(), true);