package me.memleak.pomorello;

import android.app.Application;
import android.support.annotation.NonNull;

import me.memleak.pomorello.models.PomorelloUser;

/**
 * Created by jafar_qaddoumi on 9/4/15.
 * <p/>
 * Copyright (c) 2015 memleak.me. All rights reserved.
 */
public class PomorelloApp extends Application {

    private static PomorelloUser sPomorelloUser;

    @NonNull
    public static PomorelloUser getPomorelloUser() {
        return sPomorelloUser;
    }

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

        // by design(Java) this not a correct way to deal with static
        sPomorelloUser = PomorelloUser.getInstance(this);
    }

    @Override
    public void onLowMemory() {
        sPomorelloUser.save(this);

        super.onLowMemory();
    }
}

@@ -100,16 +100,39 @@
 nNull;%0A%0A
+import io.realm.Realm;%0A
 import m
@@ -173,16 +173,16 @@
 loUser;%0A
-
 %0A/**%0A * 
@@ -334,16 +334,49 @@
 tion %7B%0A%0A
+    private static Realm sRealm;%0A
     priv
@@ -513,32 +513,112 @@
 lloUser;%0A    %7D%0A%0A
+    @NonNull%0A    public static Realm getRealm() %7B%0A        return sRealm;%0A    %7D%0A%0A
     @Override%0A  
@@ -741,16 +741,95 @@
  static%0A
+        Realm.deleteRealmFile(this);%0A        sRealm = Realm.getInstance(this);%0A
         
@@ -927,24 +927,48 @@
 wMemory() %7B%0A
+        sRealm.close();%0A
         sPom
@@ -987,24 +987,24 @@
 ave(this);%0A%0A
-
         supe
@@ -1025,11 +1025,153 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public void onTerminate() %7B%0A        sRealm.close();%0A        sPomorelloUser.save(this);%0A%0A        super.onTerminate();%0A    %7D
 %0A%7D%0A

add realm database