mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-28 10:42:31 -04:00
refactor: migrate to Firebase KTX in the main modules (#836)
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package com.geeksville.mesh.analytics
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
public interface AnalyticsProvider {
|
||||
|
||||
// Turn analytics logging on/off
|
||||
fun setEnabled(on: Boolean)
|
||||
|
||||
/**
|
||||
* Store an event
|
||||
*/
|
||||
fun track(event: String, vararg properties: DataPair)
|
||||
|
||||
/**
|
||||
* Only track this event if using a cheap provider (like google)
|
||||
*/
|
||||
fun trackLowValue(event: String, vararg properties: DataPair)
|
||||
|
||||
fun endSession()
|
||||
fun startSession()
|
||||
|
||||
/**
|
||||
* 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,11 +3,19 @@ package com.geeksville.mesh.analytics
|
||||
import android.content.Context
|
||||
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
|
||||
*/
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
class GoogleAnalytics(context: Context) : AnalyticsProvider, Logging {
|
||||
class NopAnalytics(context: Context) : AnalyticsProvider, Logging {
|
||||
|
||||
init {
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.geeksville.mesh.android
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.edit
|
||||
@@ -17,35 +15,6 @@ open class GeeksvilleApplication : Application(), Logging {
|
||||
|
||||
companion object {
|
||||
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?
|
||||
@@ -81,12 +50,8 @@ open class GeeksvilleApplication : Application(), Logging {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
val googleAnalytics = com.geeksville.mesh.analytics.GoogleAnalytics(this)
|
||||
analytics = googleAnalytics
|
||||
|
||||
// Set analytics per prefs
|
||||
isAnalyticsAllowed = isAnalyticsAllowed
|
||||
|
||||
registerActivityLifecycleCallbacks(lifecycleCallbacks)
|
||||
val nopAnalytics = com.geeksville.mesh.analytics.NopAnalytics(this)
|
||||
analytics = nopAnalytics
|
||||
isAnalyticsAllowed = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user