增加匿名统计开关
This commit is contained in:
@@ -5,8 +5,6 @@ import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
@@ -17,7 +15,6 @@ import com.jeremyliao.liveeventbus.logger.DefaultLogger
|
||||
import com.script.rhino.ReadOnlyJavaObject
|
||||
import com.script.rhino.RhinoScriptEngine
|
||||
import com.script.rhino.RhinoWrapFactory
|
||||
import io.legato.kazusa.base.AppContextWrapper
|
||||
import io.legato.kazusa.constant.AppConst.channelIdDownload
|
||||
import io.legato.kazusa.constant.AppConst.channelIdReadAloud
|
||||
import io.legato.kazusa.constant.AppConst.channelIdWeb
|
||||
@@ -40,7 +37,6 @@ import io.legato.kazusa.help.LifecycleHelp
|
||||
import io.legato.kazusa.help.RuleBigDataHelp
|
||||
import io.legato.kazusa.help.book.BookHelp
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.help.config.ThemeConfig.applyDayNight
|
||||
import io.legato.kazusa.help.config.ThemeConfig.applyDayNightInit
|
||||
import io.legato.kazusa.help.coroutine.Coroutine
|
||||
import io.legato.kazusa.help.http.Cronet
|
||||
@@ -51,6 +47,7 @@ import io.legato.kazusa.help.source.SourceHelp
|
||||
import io.legato.kazusa.help.storage.Backup
|
||||
import io.legato.kazusa.model.BookCover
|
||||
import io.legato.kazusa.utils.ChineseUtils
|
||||
import io.legato.kazusa.utils.FirebaseManager
|
||||
import io.legato.kazusa.utils.LogUtils
|
||||
import io.legato.kazusa.utils.defaultSharedPreferences
|
||||
import io.legato.kazusa.utils.getPrefBoolean
|
||||
@@ -70,6 +67,7 @@ class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
FirebaseManager.initFromPreferences(this)
|
||||
CrashHandler(this)
|
||||
if (isDebuggable) {
|
||||
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
||||
|
||||
@@ -169,6 +169,7 @@ object PreferKey {
|
||||
const val readAloudByMediaButton = "readAloudByMediaButton"
|
||||
const val showMangaUi = "showMangaUi"
|
||||
const val disableMangaScale = "disableMangaScale"
|
||||
const val firebaseEnabled = "firebaseEnabled"
|
||||
|
||||
const val cPrimary = "colorPrimary"
|
||||
const val cAccent = "colorAccent"
|
||||
|
||||
@@ -668,6 +668,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
var firebaseEnabled: Boolean
|
||||
get() = appCtx.getPrefBoolean(PreferKey.firebaseEnabled, false)
|
||||
set(value) {
|
||||
appCtx.putPrefBoolean(PreferKey.firebaseEnabled, value)
|
||||
}
|
||||
|
||||
//跳转到漫画界面不使用富文本模式
|
||||
val showMangaUi: Boolean
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.legato.kazusa.receiver.SharedReceiverActivity
|
||||
import io.legato.kazusa.service.WebService
|
||||
import io.legato.kazusa.ui.file.HandleFileContract
|
||||
import io.legato.kazusa.ui.widget.number.NumberPickerDialog
|
||||
import io.legato.kazusa.utils.FirebaseManager
|
||||
import io.legato.kazusa.utils.LogUtils
|
||||
import io.legato.kazusa.utils.getPrefBoolean
|
||||
import io.legato.kazusa.utils.postEvent
|
||||
@@ -218,6 +219,13 @@ class OtherConfigFragment : PreferenceFragment(),
|
||||
PreferKey.sourceEditMaxLine -> {
|
||||
upPreferenceSummary(key, AppConfig.sourceEditMaxLine.toString())
|
||||
}
|
||||
|
||||
PreferKey.firebaseEnabled -> {
|
||||
sharedPreferences?.let {
|
||||
FirebaseManager.setEnabled(requireContext(), it.getBoolean(key, true))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.legato.kazusa.utils
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.firebase.FirebaseApp
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
|
||||
object FirebaseManager {
|
||||
|
||||
private const val PREF_KEY = "firebaseEnabled"
|
||||
private var isEnabled = false
|
||||
|
||||
fun initFromPreferences(context: Context) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val enabled = prefs.getBoolean(PREF_KEY, true)
|
||||
applyState(context, enabled)
|
||||
}
|
||||
|
||||
fun setEnabled(context: Context, enabled: Boolean) {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
prefs.edit { putBoolean(PREF_KEY, enabled) }
|
||||
applyState(context, enabled)
|
||||
}
|
||||
|
||||
private fun applyState(context: Context, enabled: Boolean) {
|
||||
if (enabled) {
|
||||
if (FirebaseApp.getApps(context).isEmpty()) {
|
||||
FirebaseApp.initializeApp(context)
|
||||
}
|
||||
FirebaseAnalytics.getInstance(context).setAnalyticsCollectionEnabled(true)
|
||||
} else {
|
||||
try {
|
||||
if (FirebaseApp.getApps(context).isNotEmpty()) {
|
||||
FirebaseAnalytics.getInstance(context).setAnalyticsCollectionEnabled(false)
|
||||
FirebaseApp.getInstance().delete()
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
}
|
||||
}
|
||||
isEnabled = enabled
|
||||
}
|
||||
|
||||
fun isFirebaseEnabled(): Boolean = isEnabled
|
||||
}
|
||||
Reference in New Issue
Block a user