增加匿名统计开关
This commit is contained in:
@@ -550,6 +550,12 @@
|
|||||||
tools:node="remove" />
|
tools:node="remove" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="com.google.firebase.provider.FirebaseInitProvider"
|
||||||
|
android:authorities="${applicationId}.firebaseinitprovider"
|
||||||
|
android:exported="false"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="channel"
|
android:name="channel"
|
||||||
android:value="${APP_CHANNEL_VALUE}" />
|
android:value="${APP_CHANNEL_VALUE}" />
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import android.app.Notification
|
|||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.content.pm.ActivityInfo
|
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -17,7 +15,6 @@ import com.jeremyliao.liveeventbus.logger.DefaultLogger
|
|||||||
import com.script.rhino.ReadOnlyJavaObject
|
import com.script.rhino.ReadOnlyJavaObject
|
||||||
import com.script.rhino.RhinoScriptEngine
|
import com.script.rhino.RhinoScriptEngine
|
||||||
import com.script.rhino.RhinoWrapFactory
|
import com.script.rhino.RhinoWrapFactory
|
||||||
import io.legato.kazusa.base.AppContextWrapper
|
|
||||||
import io.legato.kazusa.constant.AppConst.channelIdDownload
|
import io.legato.kazusa.constant.AppConst.channelIdDownload
|
||||||
import io.legato.kazusa.constant.AppConst.channelIdReadAloud
|
import io.legato.kazusa.constant.AppConst.channelIdReadAloud
|
||||||
import io.legato.kazusa.constant.AppConst.channelIdWeb
|
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.RuleBigDataHelp
|
||||||
import io.legato.kazusa.help.book.BookHelp
|
import io.legato.kazusa.help.book.BookHelp
|
||||||
import io.legato.kazusa.help.config.AppConfig
|
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.config.ThemeConfig.applyDayNightInit
|
||||||
import io.legato.kazusa.help.coroutine.Coroutine
|
import io.legato.kazusa.help.coroutine.Coroutine
|
||||||
import io.legato.kazusa.help.http.Cronet
|
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.help.storage.Backup
|
||||||
import io.legato.kazusa.model.BookCover
|
import io.legato.kazusa.model.BookCover
|
||||||
import io.legato.kazusa.utils.ChineseUtils
|
import io.legato.kazusa.utils.ChineseUtils
|
||||||
|
import io.legato.kazusa.utils.FirebaseManager
|
||||||
import io.legato.kazusa.utils.LogUtils
|
import io.legato.kazusa.utils.LogUtils
|
||||||
import io.legato.kazusa.utils.defaultSharedPreferences
|
import io.legato.kazusa.utils.defaultSharedPreferences
|
||||||
import io.legato.kazusa.utils.getPrefBoolean
|
import io.legato.kazusa.utils.getPrefBoolean
|
||||||
@@ -70,6 +67,7 @@ class App : Application() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||||
|
FirebaseManager.initFromPreferences(this)
|
||||||
CrashHandler(this)
|
CrashHandler(this)
|
||||||
if (isDebuggable) {
|
if (isDebuggable) {
|
||||||
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
ThreadUtils.setThreadAssertsDisabledForTesting(true)
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ object PreferKey {
|
|||||||
const val readAloudByMediaButton = "readAloudByMediaButton"
|
const val readAloudByMediaButton = "readAloudByMediaButton"
|
||||||
const val showMangaUi = "showMangaUi"
|
const val showMangaUi = "showMangaUi"
|
||||||
const val disableMangaScale = "disableMangaScale"
|
const val disableMangaScale = "disableMangaScale"
|
||||||
|
const val firebaseEnabled = "firebaseEnabled"
|
||||||
|
|
||||||
const val cPrimary = "colorPrimary"
|
const val cPrimary = "colorPrimary"
|
||||||
const val cAccent = "colorAccent"
|
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
|
val showMangaUi: Boolean
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import io.legato.kazusa.receiver.SharedReceiverActivity
|
|||||||
import io.legato.kazusa.service.WebService
|
import io.legato.kazusa.service.WebService
|
||||||
import io.legato.kazusa.ui.file.HandleFileContract
|
import io.legato.kazusa.ui.file.HandleFileContract
|
||||||
import io.legato.kazusa.ui.widget.number.NumberPickerDialog
|
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.LogUtils
|
||||||
import io.legato.kazusa.utils.getPrefBoolean
|
import io.legato.kazusa.utils.getPrefBoolean
|
||||||
import io.legato.kazusa.utils.postEvent
|
import io.legato.kazusa.utils.postEvent
|
||||||
@@ -218,6 +219,13 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
PreferKey.sourceEditMaxLine -> {
|
PreferKey.sourceEditMaxLine -> {
|
||||||
upPreferenceSummary(key, AppConfig.sourceEditMaxLine.toString())
|
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
|
||||||
|
}
|
||||||
@@ -1236,5 +1236,6 @@
|
|||||||
<string name="descending_order">降序</string>
|
<string name="descending_order">降序</string>
|
||||||
<string name="checking_update">检查更新中...</string>
|
<string name="checking_update">检查更新中...</string>
|
||||||
<string name="search_empty">没有内容哦</string>
|
<string name="search_empty">没有内容哦</string>
|
||||||
|
<string name="firebase_enable_title">匿名统计</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1239,5 +1239,7 @@
|
|||||||
<string name="descending_order">降序</string>
|
<string name="descending_order">降序</string>
|
||||||
<string name="checking_update">检查更新中...</string>
|
<string name="checking_update">检查更新中...</string>
|
||||||
<string name="search_empty">没有内容哦</string>
|
<string name="search_empty">没有内容哦</string>
|
||||||
|
<string name="firebase_enable_title">匿名统计</string>
|
||||||
|
<string name="firebase_enable_summary">允许应用使用Google Firebase进行崩溃和性能统计</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -66,6 +66,12 @@
|
|||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:layout="@layout/view_preference_category">
|
app:layout="@layout/view_preference_category">
|
||||||
|
|
||||||
|
<io.legato.kazusa.lib.prefs.SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="firebaseEnable"
|
||||||
|
android:summary="@string/firebase_enable_summary"
|
||||||
|
android:title="@string/firebase_enable_title" />
|
||||||
|
|
||||||
<io.legato.kazusa.lib.prefs.Preference
|
<io.legato.kazusa.lib.prefs.Preference
|
||||||
android:key="localPassword"
|
android:key="localPassword"
|
||||||
android:summary="@string/set_local_password_summary"
|
android:summary="@string/set_local_password_summary"
|
||||||
|
|||||||
Reference in New Issue
Block a user