package com.ardraw.ardrawinggallery;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.ardraw.ardrawinggallery.util.ArDataInsert;

public class MyApplication extends Application {
    public static MyApplication application;
    private static final String PREF_NAME = "preferences";
    private static final String KEY_INITIALIZED = "initRoom";

    @Override
    public void onCreate() {
        super.onCreate();

        application = this;

        SharedPreferences preferences = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
        boolean init = preferences.getBoolean(KEY_INITIALIZED, false);

        if (!init) {
            initDatabase();
            preferences.edit().putBoolean(KEY_INITIALIZED, true).apply();
        }
    }

    private void initDatabase() {
        ArDataInsert arDataInsert = new ArDataInsert(getContext());
        arDataInsert.insertImagesToDatabase();
        Log.d("MyApplication", "Database initialized");
    }

    public static Context getContext() {
        return application.getApplicationContext();
    }
}
