package cat.xojan.random1;

import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers;
import com.squareup.leakcanary.LeakCanary;

import cat.xojan.random1.injection.component.AppComponent;
import cat.xojan.random1.injection.component.DaggerAppComponent;
import cat.xojan.random1.injection.module.AppModule;
import io.fabric.sdk.android.Fabric;

public class Application extends android.app.Application {

    private AppComponent mComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        initCrashlytics();
        initInjector();
        initLeakDetection();
    }

    public AppComponent getAppComponent() {
        return mComponent;
    }

    private void initInjector() {
        mComponent = DaggerAppComponent.builder()
                .appModule(new AppModule(this))
                .build();
    }

    private void initLeakDetection() {
        if (BuildConfig.DEBUG) {
            LeakCanary.install(this);
        }
    }

    private void initCrashlytics() {
        if (!BuildConfig.DEBUG) {
            Fabric.with(this, new Answers(), new Crashlytics());
        }
    }
}

@@ -21,16 +21,105 @@
 ndom1;%0A%0A
+import android.content.Context;%0Aimport android.os.Environment;%0Aimport android.util.Log;%0A%0A
 import c
@@ -154,16 +154,16 @@
 lytics;%0A
-
 import c
@@ -246,16 +246,38 @@
 anary;%0A%0A
+import java.io.File;%0A%0A
 import c
@@ -543,16 +543,89 @@
 tion %7B%0A%0A
+    private static final String TAG = Application.class.getSimpleName();%0A
     priv
@@ -802,16 +802,61 @@
 ction();
+%0A%0A        removePreviousDownloadedPodcasts();
 %0A    %7D%0A%0A
@@ -1288,32 +1288,32 @@
 Config.DEBUG) %7B%0A
-
             Fabr
@@ -1376,11 +1376,1191 @@
  %7D%0A    %7D
+%0A%0A    private void removePreviousDownloadedPodcasts() %7B%0A        boolean arePodcastsRemoved = getSharedPreferences(%22preferences%22, Context.MODE_PRIVATE)%0A                .getBoolean(%22old_downloaded_podcasts%22, false);%0A        if (!arePodcastsRemoved) %7B%0A            Log.d(TAG, %22removing old podcasts%22);%0A%0A            removeDownloaded();%0A            removeDownloading();%0A%0A            getSharedPreferences(%22preferences%22, Context.MODE_PRIVATE).edit()%0A                    .putBoolean(%22old_downloaded_podcasts%22, true).apply();%0A        %7D%0A    %7D%0A%0A    private void removeDownloaded() %7B%0A        File iternalFileDirectory = getExternalFilesDir(Environment.DIRECTORY_PODCASTS);%0A        for (File podcastFile : iternalFileDirectory.listFiles()) %7B%0A            if (podcastFile.delete()) %7B%0A                Log.d(TAG, %22delete downloaded podcast%22);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private void removeDownloading() %7B%0A        File iternalFileDirectory = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);%0A        for (File podcastFile : iternalFileDirectory.listFiles()) %7B%0A            if (podcastFile.delete()) %7B%0A                Log.d(TAG, %22delete downloading podcast%22);%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

remove old podcasts at first run