package com.marverenic.music;

import android.app.Application;
import android.content.Context;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;

import com.bumptech.glide.Glide;
import com.crashlytics.android.Crashlytics;
import com.marverenic.music.data.inject.JockeyComponentFactory;
import com.marverenic.music.data.inject.JockeyGraph;
import com.marverenic.music.utils.CrashlyticsTree;
import com.marverenic.music.utils.compat.JockeyPreferencesCompat;

import io.fabric.sdk.android.Fabric;
import timber.log.Timber;

public class JockeyApplication extends Application {

    private JockeyGraph mComponent;

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

        setupCrashlytics();
        setupTimber();

        mComponent = createDaggerComponent();
        JockeyPreferencesCompat.upgradeSharedPreferences(this);
    }

    @NonNull
    protected JockeyGraph createDaggerComponent() {
        return JockeyComponentFactory.create(this);
    }

    private void setupStrictMode() {
        if (BuildConfig.DEBUG) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads()
                    .detectDiskWrites()
                    .detectAll()
                    .penaltyLog()
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .build());
        }
    }

    private void setupCrashlytics() {
        Fabric.with(this, new Crashlytics());
    }

    private void setupTimber() {
        if (BuildConfig.DEBUG) {
            Timber.plant(new Timber.DebugTree());
        } else {
            Timber.plant(new CrashlyticsTree());
        }
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        Glide.with(this).onTrimMemory(level);
    }

    public static JockeyGraph getComponent(Fragment fragment) {
        return getComponent(fragment.getContext());
    }

    public static JockeyGraph getComponent(Context context) {
        return ((JockeyApplication) context.getApplicationContext()).mComponent;
    }
}

@@ -92,38 +92,8 @@
 xt;%0A
-import android.os.StrictMode;%0A
 impo
@@ -131,16 +131,16 @@
 onNull;%0A
+
 import a
@@ -686,35 +686,8 @@
 ) %7B%0A
-        setupStrictMode();%0A
     
@@ -939,24 +939,24 @@
 mponent() %7B%0A
+
         retu
@@ -1006,584 +1006,8 @@
  %7D%0A%0A
-    private void setupStrictMode() %7B%0A        if (BuildConfig.DEBUG) %7B%0A            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()%0A                    .detectDiskReads()%0A                    .detectDiskWrites()%0A                    .detectAll()%0A                    .penaltyLog()%0A                    .build());%0A            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()%0A                    .detectLeakedSqlLiteObjects()%0A                    .detectLeakedClosableObjects()%0A                    .penaltyLog()%0A                    .build());%0A        %7D%0A    %7D%0A%0A
     

Disable strict mode