Skip to content

Commit

Permalink
Rework Firebase setup
Browse files Browse the repository at this point in the history
Fixes #1332
Closes #1339
  • Loading branch information
AntsyLich committed Oct 19, 2024
1 parent 3bf70b2 commit 15e3f28
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
9 changes: 0 additions & 9 deletions app/src/dev/java/mihon/core/firebase/Firebase.kt

This file was deleted.

11 changes: 11 additions & 0 deletions app/src/dev/java/mihon/core/firebase/FirebaseConfig.kt
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 16 additions & 7 deletions app/src/main/java/eu/kanade/tachiyomi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,6 +78,7 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
override fun onCreate() {
super<Application>.onCreate()
patchInjekt()
FirebaseConfig.init(applicationContext)

GlobalExceptionHandler.initialize(applicationContext, CrashActivity::class.java)

Expand All @@ -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 ->
Expand Down Expand Up @@ -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<UiPreferences>().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))
Expand Down
20 changes: 0 additions & 20 deletions app/src/standard/java/mihon/core/firebase/Firebase.kt

This file was deleted.

25 changes: 25 additions & 0 deletions app/src/standard/java/mihon/core/firebase/FirebaseConfig.kt
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 15e3f28

Please sign in to comment.