Skip to content

Commit

Permalink
Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Animeboynz committed Sep 28, 2024
1 parent 8132c83 commit 7286ca7
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/src/dev/java/mihon/core/firebase/Firebase.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mihon.core.firebase

import android.content.Context
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.core.security.PrivacyPreferences
import kotlinx.coroutines.CoroutineScope

object Firebase {
fun setup(context: Context, preference: SecurityPreferences, scope: CoroutineScope) = Unit
fun setup(context: Context, preference: PrivacyPreferences, scope: CoroutineScope) = Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.LocalLifecycleOwner
import eu.kanade.presentation.util.rememberRequestPackageInstallsPermissionState
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.core.security.PrivacyPreferences
import eu.kanade.tachiyomi.util.system.launchRequestPackageInstallsPermission
import tachiyomi.i18n.MR
import tachiyomi.presentation.core.i18n.stringResource
import tachiyomi.presentation.core.util.collectAsState
import tachiyomi.presentation.core.util.secondaryItemAlpha
import uy.kohesive.injekt.injectLazy

internal class PermissionStep : OnboardingStep {

private val securityPreferences: SecurityPreferences by injectLazy()
private val privacyPreferences: PrivacyPreferences by injectLazy()

private var notificationGranted by mutableStateOf(false)
private var batteryGranted by mutableStateOf(false)
private var allowCrashLogs by mutableStateOf(true)
private var allowAnalytics by mutableStateOf(true)

override val isComplete: Boolean = true

Expand Down Expand Up @@ -123,24 +122,24 @@ internal class PermissionStep : OnboardingStep {
color = MaterialTheme.colorScheme.onPrimaryContainer,
)

val crashlyticsPref = privacyPreferences.crashlytics()
val crashlytics by crashlyticsPref.collectAsState()

PermissionSwitch(
title = stringResource(MR.strings.onboarding_permission_crashlytics),
subtitle = stringResource(MR.strings.onboarding_permission_crashlytics_description),
granted = allowCrashLogs,
onToggleChange = {
allowCrashLogs = it
securityPreferences.crashlytics().set(allowCrashLogs)
},
granted = crashlytics,
onToggleChange = crashlyticsPref::set,
)

val analyticsPref = privacyPreferences.analytics()
val analytics by analyticsPref.collectAsState()

PermissionSwitch(
title = stringResource(MR.strings.onboarding_permission_analytics),
subtitle = stringResource(MR.strings.onboarding_permission_analytics_description),
granted = allowAnalytics,
onToggleChange = {
allowAnalytics = it
securityPreferences.analytics().set(allowAnalytics)
},
granted = analytics,
onToggleChange = analyticsPref::set,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.fragment.app.FragmentActivity
import eu.kanade.presentation.more.settings.Preference
import eu.kanade.tachiyomi.core.security.PrivacyPreferences
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
Expand All @@ -29,9 +30,10 @@ object SettingsSecurityScreen : SearchableSettings {
@Composable
override fun getPreferences(): List<Preference> {
val securityPreferences = remember { Injekt.get<SecurityPreferences>() }
val privacyPreferences = remember { Injekt.get<PrivacyPreferences>() }
return listOf(
getSecurityGroup(securityPreferences),
getFirebaseGroup(securityPreferences),
getFirebaseGroup(privacyPreferences),
)
}
}
Expand Down Expand Up @@ -96,18 +98,18 @@ private fun getSecurityGroup(

@Composable
private fun getFirebaseGroup(
securityPreferences: SecurityPreferences,
privacyPreferences: PrivacyPreferences,
): Preference.PreferenceGroup {
return Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_firebase),
preferenceItems = persistentListOf(
Preference.PreferenceItem.SwitchPreference(
pref = securityPreferences.crashlytics(),
pref = privacyPreferences.crashlytics(),
title = stringResource(MR.strings.onboarding_permission_crashlytics),
subtitle = stringResource(MR.strings.onboarding_permission_crashlytics_description),
),
Preference.PreferenceItem.SwitchPreference(
pref = securityPreferences.analytics(),
pref = privacyPreferences.analytics(),
title = stringResource(MR.strings.onboarding_permission_analytics),
subtitle = stringResource(MR.strings.onboarding_permission_analytics_description),
),
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/eu/kanade/tachiyomi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import eu.kanade.domain.DomainModule
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.core.security.PrivacyPreferences
import eu.kanade.tachiyomi.crash.CrashActivity
import eu.kanade.tachiyomi.crash.GlobalExceptionHandler
import eu.kanade.tachiyomi.data.coil.BufferedSourceFetcher
Expand Down Expand Up @@ -69,7 +69,7 @@ import java.security.Security
class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factory {

private val basePreferences: BasePreferences by injectLazy()
private val securityPreferences: SecurityPreferences by injectLazy()
private val privacyPreferences: PrivacyPreferences by injectLazy()
private val networkPreferences: NetworkPreferences by injectLazy()

private val disableIncognitoReceiver = DisableIncognitoReceiver()
Expand All @@ -96,7 +96,7 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
Injekt.importModule(AppModule(this))
Injekt.importModule(DomainModule())

Firebase.setup(applicationContext, securityPreferences, ProcessLifecycleOwner.get().lifecycleScope)
Firebase.setup(applicationContext, privacyPreferences, ProcessLifecycleOwner.get().lifecycleScope)

setupNotificationChannels()

Expand Down
4 changes: 2 additions & 2 deletions app/src/standard/java/mihon/core/firebase/Firebase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ 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.SecurityPreferences
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: SecurityPreferences, scope: CoroutineScope) {
fun setup(context: Context, preference: PrivacyPreferences, scope: CoroutineScope) {
preference.analytics().changes().onEach { enabled ->
FirebaseAnalytics.getInstance(context).setAnalyticsCollectionEnabled(enabled)
}.launchIn(scope)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.kanade.tachiyomi.core.security

import tachiyomi.core.common.preference.PreferenceStore

class PrivacyPreferences(
private val preferenceStore: PreferenceStore,
) {
fun crashlytics() = preferenceStore.getBoolean("crashlytics", false)

fun analytics() = preferenceStore.getBoolean("analytics", false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class SecurityPreferences(

fun hideNotificationContent() = preferenceStore.getBoolean("hide_notification_content", false)

fun crashlytics() = preferenceStore.getBoolean("crashlytics", false)

fun analytics() = preferenceStore.getBoolean("analytics", false)

/**
* For app lock. Will be set when there is a pending timed lock.
* Otherwise this pref should be deleted.
Expand Down

0 comments on commit 7286ca7

Please sign in to comment.