package com.fun.originalityprank;

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

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.fun.originalityprank.data.AllData;
import com.fun.originalityprank.data.MydataBase;
import com.fun.originalityprank.tool.Mytools;

import java.util.ArrayList;
import java.util.List;


public class PrankSkin extends Application {

    public static final String DB_Name = "prank_database";
    public static final String Table_Name = "prank_table";
    public static final int DB_Version = 1;
    private static Context context;
    private List<AllData> allData = new ArrayList<>();
    private SharedPreferences sp;
    private static boolean isinsert;
    private SharedPreferences.Editor editor;
    public static final String AD_BROADCAST = "ON_SUCCESS";
    private static final String PREFS_NAME = "MyPrefs";
    private static final String KEY_IS_INSERTED = "isinserted";

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();

        allData = Mytools.parseJsonToList("prank.json");
        sp = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
        isinsert = sp.getBoolean(KEY_IS_INSERTED, false);
        if (!isinsert) {
            Mytools.runIO(new Runnable() {
                @Override
                public void run() {
                    MydataBase.getInstance().likeDAO().insertAll(allData);
                    editor = sp.edit();
                    editor.putBoolean(KEY_IS_INSERTED, true);
                    editor.commit();
                }
            });
        }

    }


    public static Context getContext() {

        return context;
    }
}
