kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: migrate to Firebase KTX in the main modules (#836)
rodzic
fa48888c3a
commit
01360dc557
|
@ -241,8 +241,8 @@ dependencies {
|
||||||
|
|
||||||
// For Firebase Crashlytics & Analytics
|
// For Firebase Crashlytics & Analytics
|
||||||
googleImplementation platform('com.google.firebase:firebase-bom:32.7.1')
|
googleImplementation platform('com.google.firebase:firebase-bom:32.7.1')
|
||||||
googleImplementation 'com.google.firebase:firebase-crashlytics-ktx'
|
googleImplementation 'com.google.firebase:firebase-crashlytics'
|
||||||
googleImplementation 'com.google.firebase:firebase-analytics-ktx'
|
googleImplementation 'com.google.firebase:firebase-analytics'
|
||||||
|
|
||||||
// barcode support
|
// barcode support
|
||||||
// per https://github.com/journeyapps/zxing-android-embedded#older-sdk-versions for minSdkVersion 21
|
// per https://github.com/journeyapps/zxing-android-embedded#older-sdk-versions for minSdkVersion 21
|
||||||
|
|
|
@ -3,11 +3,19 @@ package com.geeksville.mesh.analytics
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.geeksville.mesh.android.Logging
|
import com.geeksville.mesh.android.Logging
|
||||||
|
|
||||||
|
class DataPair(val name: String, valueIn: Any?) {
|
||||||
|
val value = valueIn ?: "null"
|
||||||
|
|
||||||
|
/// An accumulating firebase event - only one allowed per event
|
||||||
|
constructor(d: Double) : this("BOGUS", d)
|
||||||
|
constructor(d: Int) : this("BOGUS", d)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement our analytics API using Firebase Analytics
|
* Implement our analytics API using Firebase Analytics
|
||||||
*/
|
*/
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
class GoogleAnalytics(context: Context) : AnalyticsProvider, Logging {
|
class NopAnalytics(context: Context) : AnalyticsProvider, Logging {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
}
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
package com.geeksville.mesh.android
|
package com.geeksville.mesh.android
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
@ -17,35 +15,6 @@ open class GeeksvilleApplication : Application(), Logging {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var analytics: AnalyticsProvider
|
lateinit var analytics: AnalyticsProvider
|
||||||
var currentActivity: Activity? = null
|
|
||||||
private val backstack = mutableListOf<Activity>()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val lifecycleCallbacks = object : ActivityLifecycleCallbacks {
|
|
||||||
override fun onActivityPaused(activity: Activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
|
||||||
if (backstack.contains(activity)) backstack.remove(activity)
|
|
||||||
currentActivity = backstack.lastOrNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
|
||||||
backstack.add(activity)
|
|
||||||
currentActivity = backstack.lastOrNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Are we running inside the testlab?
|
/// Are we running inside the testlab?
|
||||||
|
@ -81,12 +50,8 @@ open class GeeksvilleApplication : Application(), Logging {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
val googleAnalytics = com.geeksville.mesh.analytics.GoogleAnalytics(this)
|
val nopAnalytics = com.geeksville.mesh.analytics.NopAnalytics(this)
|
||||||
analytics = googleAnalytics
|
analytics = nopAnalytics
|
||||||
|
isAnalyticsAllowed = false
|
||||||
// Set analytics per prefs
|
|
||||||
isAnalyticsAllowed = isAnalyticsAllowed
|
|
||||||
|
|
||||||
registerActivityLifecycleCallbacks(lifecycleCallbacks)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import com.geeksville.mesh.android.BuildUtils.isEmulator
|
||||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||||
import com.geeksville.mesh.android.Logging
|
import com.geeksville.mesh.android.Logging
|
||||||
import com.geeksville.mesh.util.Exceptions
|
import com.geeksville.mesh.util.Exceptions
|
||||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
import com.google.firebase.crashlytics.crashlytics
|
||||||
|
import com.google.firebase.Firebase
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
|
@ -20,7 +21,7 @@ class MeshUtilApplication : GeeksvilleApplication() {
|
||||||
// We default to off in the manifest - we turn on here if the user approves
|
// We default to off in the manifest - we turn on here if the user approves
|
||||||
// leave off when running in the debugger
|
// leave off when running in the debugger
|
||||||
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
|
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
|
||||||
val crashlytics = FirebaseCrashlytics.getInstance()
|
val crashlytics = Firebase.crashlytics
|
||||||
crashlytics.setCrashlyticsCollectionEnabled(isAnalyticsAllowed)
|
crashlytics.setCrashlyticsCollectionEnabled(isAnalyticsAllowed)
|
||||||
crashlytics.setCustomKey("debug_build", BuildConfig.DEBUG)
|
crashlytics.setCustomKey("debug_build", BuildConfig.DEBUG)
|
||||||
|
|
||||||
|
@ -51,4 +52,4 @@ class MeshUtilApplication : GeeksvilleApplication() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.geeksville.mesh.analytics
|
|
||||||
|
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by kevinh on 12/24/14.
|
|
||||||
*/
|
|
||||||
class DataPair(val name: String, valueIn: Any?) {
|
|
||||||
val value = valueIn ?: "null"
|
|
||||||
|
|
||||||
/// An accumulating firebase event - only one allowed per event
|
|
||||||
constructor(d: Double) : this(FirebaseAnalytics.Param.VALUE, d)
|
|
||||||
constructor(d: Int) : this(FirebaseAnalytics.Param.VALUE, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface AnalyticsProvider {
|
|
||||||
|
|
||||||
// Turn analytics logging on/off
|
|
||||||
fun setEnabled(on: Boolean)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store an event
|
|
||||||
*/
|
|
||||||
fun track(event: String, vararg properties: DataPair): Unit
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only track this event if using a cheap provider (like google)
|
|
||||||
*/
|
|
||||||
fun trackLowValue(event: String, vararg properties: DataPair): Unit
|
|
||||||
|
|
||||||
fun endSession(): Unit
|
|
||||||
fun startSession(): Unit
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set persistent ID info about this user, as a key value pair
|
|
||||||
*/
|
|
||||||
fun setUserInfo(vararg p: DataPair)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increment some sort of anyalytics counter
|
|
||||||
*/
|
|
||||||
fun increment(name: String, amount: Double = 1.0)
|
|
||||||
|
|
||||||
fun sendScreenView(name: String)
|
|
||||||
fun endScreenView()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,26 @@ package com.geeksville.mesh.analytics
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.geeksville.mesh.android.AppPrefs
|
import com.geeksville.mesh.android.AppPrefs
|
||||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
|
||||||
import com.geeksville.mesh.android.Logging
|
import com.geeksville.mesh.android.Logging
|
||||||
|
import com.google.firebase.analytics.FirebaseAnalytics
|
||||||
|
import com.google.firebase.analytics.analytics
|
||||||
|
import com.google.firebase.analytics.logEvent
|
||||||
|
import com.google.firebase.Firebase
|
||||||
|
|
||||||
|
class DataPair(val name: String, valueIn: Any?) {
|
||||||
|
val value = valueIn ?: "null"
|
||||||
|
|
||||||
|
/// An accumulating firebase event - only one allowed per event
|
||||||
|
constructor(d: Double) : this(FirebaseAnalytics.Param.VALUE, d)
|
||||||
|
constructor(d: Int) : this(FirebaseAnalytics.Param.VALUE, d)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement our analytics API using Firebase Analytics
|
* Implement our analytics API using Firebase Analytics
|
||||||
*/
|
*/
|
||||||
class GoogleAnalytics(context: Context) : AnalyticsProvider, Logging {
|
class FirebaseAnalytics(context: Context) : AnalyticsProvider, Logging {
|
||||||
|
|
||||||
val t = com.google.firebase.analytics.FirebaseAnalytics.getInstance(context)
|
val t = Firebase.analytics
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val pref = AppPrefs(context)
|
val pref = AppPrefs(context)
|
||||||
|
@ -65,14 +76,13 @@ class GoogleAnalytics(context: Context) : AnalyticsProvider, Logging {
|
||||||
*/
|
*/
|
||||||
override fun sendScreenView(name: String) {
|
override fun sendScreenView(name: String) {
|
||||||
debug("Analytics: start screen $name")
|
debug("Analytics: start screen $name")
|
||||||
GeeksvilleApplication.currentActivity?.let {
|
t.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW) {
|
||||||
t.setCurrentScreen(
|
param(FirebaseAnalytics.Param.SCREEN_NAME, name)
|
||||||
it, name, null
|
param(FirebaseAnalytics.Param.SCREEN_CLASS, "MainActivity")
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun endScreenView() {
|
override fun endScreenView() {
|
||||||
// debug("Analytics: end screen")
|
// debug("Analytics: end screen")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package com.geeksville.mesh.android
|
package com.geeksville.mesh.android
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
@ -28,35 +26,6 @@ open class GeeksvilleApplication : Application(), Logging {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
lateinit var analytics: AnalyticsProvider
|
lateinit var analytics: AnalyticsProvider
|
||||||
var currentActivity: Activity? = null
|
|
||||||
private val backstack = mutableListOf<Activity>()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val lifecycleCallbacks = object : ActivityLifecycleCallbacks {
|
|
||||||
override fun onActivityPaused(activity: Activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
|
||||||
if (backstack.contains(activity)) backstack.remove(activity)
|
|
||||||
currentActivity = backstack.lastOrNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
|
||||||
backstack.add(activity)
|
|
||||||
currentActivity = backstack.lastOrNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Are we running inside the testlab?
|
/// Are we running inside the testlab?
|
||||||
|
@ -100,12 +69,10 @@ open class GeeksvilleApplication : Application(), Logging {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
val googleAnalytics = com.geeksville.mesh.analytics.GoogleAnalytics(this)
|
val firebaseAnalytics = com.geeksville.mesh.analytics.FirebaseAnalytics(this)
|
||||||
analytics = googleAnalytics
|
analytics = firebaseAnalytics
|
||||||
|
|
||||||
// Set analytics per prefs
|
// Set analytics per prefs
|
||||||
isAnalyticsAllowed = isAnalyticsAllowed
|
isAnalyticsAllowed = isAnalyticsAllowed
|
||||||
|
|
||||||
registerActivityLifecycleCallbacks(lifecycleCallbacks)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package com.geeksville.mesh.analytics
|
package com.geeksville.mesh.analytics
|
||||||
|
|
||||||
class DataPair(val name: String, valueIn: Any?) {
|
/**
|
||||||
val value = valueIn ?: "null"
|
* Created by kevinh on 12/24/14.
|
||||||
|
*/
|
||||||
/// An accumulating firebase event - only one allowed per event
|
interface AnalyticsProvider {
|
||||||
constructor(d: Double) : this("BOGUS", d)
|
|
||||||
constructor(d: Int) : this("BOGUS", d)
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface AnalyticsProvider {
|
|
||||||
|
|
||||||
// Turn analytics logging on/off
|
// Turn analytics logging on/off
|
||||||
fun setEnabled(on: Boolean)
|
fun setEnabled(on: Boolean)
|
||||||
|
@ -32,11 +27,10 @@ public interface AnalyticsProvider {
|
||||||
fun setUserInfo(vararg p: DataPair)
|
fun setUserInfo(vararg p: DataPair)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment some sort of anyalytics counter
|
* Increment some sort of analytics counter
|
||||||
*/
|
*/
|
||||||
fun increment(name: String, amount: Double = 1.0)
|
fun increment(name: String, amount: Double = 1.0)
|
||||||
|
|
||||||
fun sendScreenView(name: String)
|
fun sendScreenView(name: String)
|
||||||
fun endScreenView()
|
fun endScreenView()
|
||||||
|
|
||||||
}
|
}
|
Ładowanie…
Reference in New Issue