diff --git a/app/src/dev/java/mihon/core/firebase/Firebase.kt b/app/src/dev/java/mihon/core/firebase/Firebase.kt deleted file mode 100644 index 6108a4c76..000000000 --- a/app/src/dev/java/mihon/core/firebase/Firebase.kt +++ /dev/null @@ -1,9 +0,0 @@ -package mihon.core.firebase - -import android.content.Context -import eu.kanade.tachiyomi.core.security.PrivacyPreferences -import kotlinx.coroutines.CoroutineScope - -object Firebase { - fun setup(context: Context, preference: PrivacyPreferences, scope: CoroutineScope) = Unit -} diff --git a/app/src/dev/java/mihon/core/firebase/FirebaseConfig.kt b/app/src/dev/java/mihon/core/firebase/FirebaseConfig.kt new file mode 100644 index 000000000..820543bd0 --- /dev/null +++ b/app/src/dev/java/mihon/core/firebase/FirebaseConfig.kt @@ -0,0 +1,11 @@ +package mihon.core.firebase + +import android.content.Context + +object FirebaseConfig { + fun init(context: Context) = Unit + + fun setAnalyticsEnabled(enabled: Boolean) = Unit + + fun setCrashlyticsEnabled(enabled: Boolean) = Unit +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 4b7b03c33..0f15cf095 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -51,7 +51,7 @@ import kotlinx.coroutines.flow.onEach import logcat.AndroidLogcatLogger import logcat.LogPriority import logcat.LogcatLogger -import mihon.core.firebase.Firebase +import mihon.core.firebase.FirebaseConfig import mihon.core.migration.Migrator import mihon.core.migration.migrations.migrations import org.conscrypt.Conscrypt @@ -78,6 +78,7 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor override fun onCreate() { super.onCreate() patchInjekt() + FirebaseConfig.init(applicationContext) GlobalExceptionHandler.initialize(applicationContext, CrashActivity::class.java) @@ -96,12 +97,12 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor Injekt.importModule(AppModule(this)) Injekt.importModule(DomainModule()) - Firebase.setup(applicationContext, privacyPreferences, ProcessLifecycleOwner.get().lifecycleScope) - setupNotificationChannels() ProcessLifecycleOwner.get().lifecycle.addObserver(this) + val scope = ProcessLifecycleOwner.get().lifecycleScope + // Show notification to disable Incognito Mode when it's enabled basePreferences.incognitoMode().changes() .onEach { enabled -> @@ -129,14 +130,22 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor cancelNotification(Notifications.ID_INCOGNITO_MODE) } } - .launchIn(ProcessLifecycleOwner.get().lifecycleScope) + .launchIn(scope) + + privacyPreferences.analytics() + .changes() + .onEach(FirebaseConfig::setAnalyticsEnabled) + .launchIn(scope) + + privacyPreferences.crashlytics() + .changes() + .onEach(FirebaseConfig::setCrashlyticsEnabled) + .launchIn(scope) setAppCompatDelegateThemeMode(Injekt.get().themeMode().get()) // Updates widget update - with(WidgetManager(Injekt.get(), Injekt.get())) { - init(ProcessLifecycleOwner.get().lifecycleScope) - } + WidgetManager(Injekt.get(), Injekt.get()).apply { init(scope) } if (!LogcatLogger.isInstalled && networkPreferences.verboseLogging().get()) { LogcatLogger.install(AndroidLogcatLogger(LogPriority.VERBOSE)) diff --git a/app/src/standard/java/mihon/core/firebase/Firebase.kt b/app/src/standard/java/mihon/core/firebase/Firebase.kt deleted file mode 100644 index 7ec88da27..000000000 --- a/app/src/standard/java/mihon/core/firebase/Firebase.kt +++ /dev/null @@ -1,20 +0,0 @@ -package mihon.core.firebase - -import android.content.Context -import com.google.firebase.analytics.FirebaseAnalytics -import com.google.firebase.crashlytics.FirebaseCrashlytics -import eu.kanade.tachiyomi.core.security.PrivacyPreferences -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach - -object Firebase { - fun setup(context: Context, preference: PrivacyPreferences, scope: CoroutineScope) { - preference.analytics().changes().onEach { enabled -> - FirebaseAnalytics.getInstance(context).setAnalyticsCollectionEnabled(enabled) - }.launchIn(scope) - preference.crashlytics().changes().onEach { enabled -> - FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(enabled) - }.launchIn(scope) - } -} diff --git a/app/src/standard/java/mihon/core/firebase/FirebaseConfig.kt b/app/src/standard/java/mihon/core/firebase/FirebaseConfig.kt new file mode 100644 index 000000000..c94436332 --- /dev/null +++ b/app/src/standard/java/mihon/core/firebase/FirebaseConfig.kt @@ -0,0 +1,25 @@ +package mihon.core.firebase + +import android.content.Context +import com.google.firebase.FirebaseApp +import com.google.firebase.analytics.FirebaseAnalytics +import com.google.firebase.crashlytics.FirebaseCrashlytics + +object FirebaseConfig { + private lateinit var analytics: FirebaseAnalytics + private lateinit var crashlytics: FirebaseCrashlytics + + fun init(context: Context) { + analytics = FirebaseAnalytics.getInstance(context) + FirebaseApp.initializeApp(context) + crashlytics = FirebaseCrashlytics.getInstance() + } + + fun setAnalyticsEnabled(enabled: Boolean) { + analytics.setAnalyticsCollectionEnabled(enabled) + } + + fun setCrashlyticsEnabled(enabled: Boolean) { + crashlytics.isCrashlyticsCollectionEnabled = enabled + } +}