package com.lukekorth.pebblelocker;

import android.database.sqlite.SQLiteDatabase;

import com.activeandroid.ActiveAndroid;
import com.activeandroid.app.Application;
import com.lukekorth.pebblelocker.logging.Logger;

public class PebbleLockerApplication extends Application implements Thread.UncaughtExceptionHandler {

    private static SQLiteDatabase mLogDatabase;

    @Override
    public void onCreate() {
        super.onCreate();
        Thread.setDefaultUncaughtExceptionHandler(this);
        ActiveAndroid.initialize(this);
        mLogDatabase = new Logger(this).getWritableDatabase();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        ActiveAndroid.dispose();
        mLogDatabase.close();
    }

    public static SQLiteDatabase getLogDatabase() {
        return mLogDatabase;
    }

    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        Logger logger = new Logger(this, "[EXCEPTION]");

        logger.log("Crashed!");
        logger.log("thread.toString(): " + thread.toString());

        logger.log("Exception string: " + ex.toString());
        logger.log("Exception message: " + ex.getMessage());
        logger.log("Exception stacktrace:");
        for (StackTraceElement trace : ex.getStackTrace()) {
            logger.log(trace.toString());
        }

        System.exit(1);
    }
}

@@ -49,38 +49,125 @@
 oid.
-database.sqlite.SQLiteDatabase
+content.SharedPreferences;%0Aimport android.database.sqlite.SQLiteDatabase;%0Aimport android.preference.PreferenceManager
 ;%0A%0Ai
@@ -298,16 +298,40 @@
 ogger;%0A%0A
+import java.util.Date;%0A%0A
 public c
@@ -632,32 +632,32 @@
 itialize(this);%0A
-
         mLogData
@@ -699,24 +699,604 @@
 Database();%0A
+        init();%0A    %7D%0A%0A    private void init() %7B%0A        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);%0A        SharedPreferences.Editor editor = prefs.edit();%0A        if (BuildConfig.VERSION_CODE %3E prefs.getInt(%22version%22, 0)) %7B%0A            String now = new Date().toString();%0A            if (prefs.getInt(%22version%22, 0) == 0) %7B%0A                editor.putString(%22install_date%22, now);%0A            %7D%0A%0A            editor.putString(%22upgrade_date%22, now);%0A            editor.putInt(%22version%22, BuildConfig.VERSION_CODE);%0A        %7D%0A%0A        editor.apply();%0A
     %7D%0A%0A    @

Add install and upgrade date