Add PicassoInitializer and CrashlyticsInitializer
authorDa Risk <da_risk@geekorum.com>
Wed, 06 Feb 2019 08:46:59 -0800
changeset 73 f11f469d15a9
parent 72 9ca00cb1e5b8
child 74 55ebf5f3088b
Add PicassoInitializer and CrashlyticsInitializer
app/src/google/java/com/geekorum/ttrss/logging/CrashlyticsInitializer.kt
app/src/google/java/com/geekorum/ttrss/logging/CrashlyticsLoggingModule.kt
app/src/main/java/com/geekorum/ttrss/di/NetworkModule.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/src/google/java/com/geekorum/ttrss/logging/CrashlyticsInitializer.kt	Wed Feb 06 08:46:59 2019 -0800
@@ -0,0 +1,41 @@
+/*
+ * Geekttrss is a RSS feed reader application on the Android Platform.
+ *
+ * Copyright (C) 2017-2018 by Frederic-Charles Barthelery.
+ *
+ * This file is part of Geekttrss.
+ *
+ * Geekttrss is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Geekttrss is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Geekttrss.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.geekorum.ttrss.logging
+
+import android.app.Application
+import com.crashlytics.android.Crashlytics
+import com.crashlytics.android.core.CrashlyticsCore
+import com.geekorum.geekdroid.dagger.AppInitializer
+import com.geekorum.ttrss.BuildConfig
+import io.fabric.sdk.android.Fabric
+
+/**
+ * [AppInitializer] to initialize crashlytics
+ */
+class CrashlyticsInitializer : AppInitializer {
+    override fun initialize(app: Application) {
+        val crashlytics = Crashlytics.Builder()
+            .core(CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
+            .build()
+        Fabric.with(app, crashlytics)
+    }
+
+}
--- a/app/src/google/java/com/geekorum/ttrss/logging/CrashlyticsLoggingModule.kt	Wed Feb 06 08:34:24 2019 -0800
+++ b/app/src/google/java/com/geekorum/ttrss/logging/CrashlyticsLoggingModule.kt	Wed Feb 06 08:46:59 2019 -0800
@@ -20,6 +20,7 @@
  */
 package com.geekorum.ttrss.logging
 
+import com.geekorum.geekdroid.dagger.AppInitializer
 import com.geekorum.geekdroid.firebase.logging.CrashlyticsLoggingTree
 import dagger.Module
 import dagger.Provides
@@ -34,4 +35,8 @@
     @Provides
     @IntoSet
     fun provideCrashlyticsLoggingTree(): Timber.Tree = CrashlyticsLoggingTree()
+
+    @Provides
+    @IntoSet
+    fun providesCrahslyticsInitializer(): AppInitializer = CrashlyticsInitializer()
 }
--- a/app/src/main/java/com/geekorum/ttrss/di/NetworkModule.java	Wed Feb 06 08:34:24 2019 -0800
+++ b/app/src/main/java/com/geekorum/ttrss/di/NetworkModule.java	Wed Feb 06 08:46:59 2019 -0800
@@ -21,21 +21,26 @@
 package com.geekorum.ttrss.di;
 
 import android.app.Application;
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import com.geekorum.geekdroid.dagger.AppInitializer;
+import com.geekorum.geekdroid.dagger.AppInitializersModule;
 import com.geekorum.geekdroid.network.PicassoOkHttp3Downloader;
 import com.geekorum.ttrss.logging.RetrofitInvocationLogger;
 import com.squareup.picasso.Picasso;
 import dagger.Module;
 import dagger.Provides;
+import dagger.multibindings.IntoSet;
 import okhttp3.Cache;
 import okhttp3.OkHttpClient;
 import okhttp3.logging.HttpLoggingInterceptor;
 
 import java.io.File;
 
+import javax.inject.Inject;
 import javax.inject.Singleton;
 
-@Module
+@Module(includes = {AppInitializersModule.class})
 public class NetworkModule {
     private static final boolean DEBUG_REQUEST = false;
     private static final boolean DEBUG_RETROFIT_CALL = true;
@@ -95,4 +100,25 @@
         return picasso;
     }
 
+    @Provides
+    @IntoSet
+    static AppInitializer providesPicassoInitializer(Picasso picasso) {
+        return new PicassoInitializer(picasso);
+    }
+
 }
+
+class PicassoInitializer implements AppInitializer {
+    private final Picasso picasso;
+
+    @Inject
+    PicassoInitializer(Picasso picasso) {
+        this.picasso = picasso;
+    }
+
+    @Override
+    public void initialize(@NonNull Application application) {
+        Picasso.setSingletonInstance(picasso);
+
+    }
+}