mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
move methods out of analyticsmanager
This commit is contained in:
parent
64d95a563e
commit
bb301aa399
14 changed files with 30 additions and 73 deletions
|
|
@ -40,7 +40,7 @@ dependencies {
|
|||
compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
|
||||
//App Compatibility and Material Design
|
||||
implementation "androidx.appcompat:appcompat:$appcompat_version"
|
||||
implementation 'com.google.android.material:material:1.8.0'
|
||||
implementation 'com.google.android.material:material:1.9.0'
|
||||
implementation "androidx.recyclerview:recyclerview:$recyclerview_version"
|
||||
implementation "androidx.preference:preference-ktx:$preferences_version"
|
||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||
|
|
@ -73,7 +73,7 @@ dependencies {
|
|||
|
||||
androidTestImplementation 'androidx.test:runner:1.5.2'
|
||||
androidTestImplementation 'androidx.test:rules:1.5.0'
|
||||
debugImplementation 'androidx.fragment:fragment-testing:1.5.7'
|
||||
debugImplementation 'androidx.fragment:fragment-testing:1.6.1'
|
||||
androidTestImplementation 'androidx.test:core-ktx:1.5.0'
|
||||
debugImplementation "androidx.test:monitor:1.6.1"
|
||||
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5'
|
||||
|
|
@ -112,10 +112,10 @@ dependencies {
|
|||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
|
||||
implementation "com.google.accompanist:accompanist-themeadapter-material:$accompanist_version"
|
||||
implementation "androidx.compose.material3:material3:1.0.1"
|
||||
implementation "androidx.compose.material3:material3:1.1.1"
|
||||
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version"
|
||||
|
||||
implementation 'androidx.activity:activity-compose:1.7.1'
|
||||
implementation 'androidx.activity:activity-compose:1.7.2'
|
||||
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
|
||||
implementation "androidx.compose.material:material:$compose_version"
|
||||
implementation "androidx.compose.animation:animation:$compose_version"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import androidx.appcompat.app.AppCompatDelegate
|
|||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.gms.wearable.Wearable
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
import com.google.firebase.installations.FirebaseInstallations
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
|
||||
|
|
@ -88,9 +87,11 @@ abstract class HabiticaBaseApplication : Application(), Application.ActivityLife
|
|||
|
||||
setupCoil()
|
||||
|
||||
ExceptionHandler.init(analyticsManager)
|
||||
ExceptionHandler.init {
|
||||
Analytics.logException(it)
|
||||
}
|
||||
|
||||
FirebaseAnalytics.getInstance(this).setUserProperty("app_testing_level", BuildConfig.TESTING_LEVEL)
|
||||
Analytics.setUserProperty("app_testing_level", BuildConfig.TESTING_LEVEL)
|
||||
|
||||
checkIfNewVersion()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class ApiClientImpl(
|
|||
private var hadError = false
|
||||
|
||||
init {
|
||||
analyticsManager.setUserIdentifier(this.hostConfig.userID)
|
||||
Analytics.setUserID(this.hostConfig.userID)
|
||||
buildRetrofit()
|
||||
}
|
||||
|
||||
|
|
@ -256,9 +256,9 @@ class ApiClientImpl(
|
|||
showConnectionProblemDialog(R.string.internal_error_api)
|
||||
}
|
||||
} else if (JsonSyntaxException::class.java.isAssignableFrom(throwableClass)) {
|
||||
analyticsManager.logError("Json Error: " + lastAPICallURL + ", " + throwable.message)
|
||||
Analytics.logError("Json Error: " + lastAPICallURL + ", " + throwable.message)
|
||||
} else {
|
||||
analyticsManager.logException(throwable)
|
||||
Analytics.logException(throwable)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +273,7 @@ class ApiClientImpl(
|
|||
return try {
|
||||
errorConverter?.convert(errorResponse) as ErrorResponse
|
||||
} catch (e: IOException) {
|
||||
analyticsManager.logError("Json Error: " + lastAPICallURL + ", " + e.message)
|
||||
Analytics.logError("Json Error: " + lastAPICallURL + ", " + e.message)
|
||||
ErrorResponse()
|
||||
}
|
||||
}
|
||||
|
|
@ -332,7 +332,6 @@ class ApiClientImpl(
|
|||
override fun updateAuthenticationCredentials(userID: String?, apiToken: String?) {
|
||||
this.hostConfig.userID = userID ?: ""
|
||||
this.hostConfig.apiKey = apiToken ?: ""
|
||||
analyticsManager.setUserIdentifier(this.hostConfig.userID)
|
||||
Analytics.setUserID(hostConfig.userID)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import androidx.core.os.bundleOf
|
|||
import com.habitrpg.android.habitica.data.ApiClient
|
||||
import com.habitrpg.android.habitica.data.TaskRepository
|
||||
import com.habitrpg.android.habitica.data.local.TaskLocalRepository
|
||||
import com.habitrpg.android.habitica.helpers.Analytics
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.interactors.ScoreTaskLocallyInteractor
|
||||
import com.habitrpg.android.habitica.models.BaseMainObject
|
||||
|
|
@ -101,7 +102,7 @@ class TaskRepositoryImpl(
|
|||
val thisUser = user ?: localRepository.getUser(authenticationHandler.currentUserID ?: "").firstOrNull() ?: return null
|
||||
// save local task changes
|
||||
|
||||
analyticsManager.logEvent(
|
||||
Analytics.logEvent(
|
||||
"task_scored",
|
||||
bundleOf(
|
||||
Pair("type", task.type),
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import com.amplitude.android.Configuration
|
|||
import com.amplitude.android.events.Identify
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.habitrpg.android.habitica.BuildConfig
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.shared.habitica.BuildConfig
|
||||
|
||||
enum class AnalyticsTarget {
|
||||
AMPLITUDE,
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ class PurchaseHandler(
|
|||
try {
|
||||
apiClient.validateSubscription(validationRequest)
|
||||
processedPurchase(purchase)
|
||||
analyticsManager.logEvent("user_subscribed", bundleOf(Pair("sku", sku)))
|
||||
Analytics.sendEvent("user_subscribed", bundleOf(Pair("sku", sku)))
|
||||
CoroutineScope(Dispatchers.IO).launch(ExceptionHandler.coroutine()) {
|
||||
acknowledgePurchase(purchase)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,23 +5,4 @@ import com.habitrpg.common.habitica.helpers.AnalyticsManager
|
|||
|
||||
class EmptyAnalyticsManager : AnalyticsManager {
|
||||
|
||||
override fun logException(t: Throwable) {
|
||||
// pass
|
||||
}
|
||||
|
||||
override fun setUserIdentifier(identifier: String) {
|
||||
// pass
|
||||
}
|
||||
|
||||
override fun setUserProperty(identifier: String, value: String) {
|
||||
// pass
|
||||
}
|
||||
|
||||
override fun logError(msg: String) {
|
||||
// pass
|
||||
}
|
||||
|
||||
override fun logEvent(eventName: String, data: Bundle) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.data.ApiClient
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.extensions.addCloseButton
|
||||
import com.habitrpg.android.habitica.helpers.Analytics
|
||||
import com.habitrpg.android.habitica.modules.AuthenticationHandler
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.common.habitica.api.HostConfig
|
||||
|
|
@ -145,7 +146,7 @@ class AuthenticationViewModel @Inject constructor(
|
|||
try {
|
||||
saveTokens(userAuthResponse.apiToken, userAuthResponse.id)
|
||||
} catch (e: Exception) {
|
||||
analyticsManager.logException(e)
|
||||
Analytics.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class MainActivityViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
analyticsManager.logException(e)
|
||||
Analytics.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,19 +96,19 @@ class MainActivityViewModel @Inject constructor(
|
|||
viewModelScope.launch(ExceptionHandler.coroutine()) {
|
||||
contentRepository.retrieveWorldState()
|
||||
userRepository.retrieveUser(true, forced)?.let { user ->
|
||||
analyticsManager.setUserProperty(
|
||||
Analytics.setUserProperty(
|
||||
"has_party",
|
||||
if (user.party?.id?.isNotEmpty() == true) "true" else "false"
|
||||
)
|
||||
analyticsManager.setUserProperty(
|
||||
Analytics.setUserProperty(
|
||||
"is_subscribed",
|
||||
if (user.isSubscribed) "true" else "false"
|
||||
)
|
||||
analyticsManager.setUserProperty(
|
||||
Analytics.setUserProperty(
|
||||
"checkin_count",
|
||||
user.loginIncentives.toString()
|
||||
)
|
||||
analyticsManager.setUserProperty("level", user.stats?.lvl?.toString() ?: "")
|
||||
Analytics.setUserProperty("level", user.stats?.lvl?.toString() ?: "")
|
||||
pushNotificationManager.setUser(user)
|
||||
if (!pushNotificationManager.notificationPermissionEnabled()) {
|
||||
if (sharedPreferences.getBoolean("usePushNotifications", true)) {
|
||||
|
|
|
|||
|
|
@ -10,23 +10,4 @@ class AnalyticsManagerImpl(context: Context) : AnalyticsManager {
|
|||
|
||||
private val firebaseAnalytics = FirebaseAnalytics.getInstance(context)
|
||||
|
||||
override fun logException(t: Throwable) {
|
||||
FirebaseCrashlytics.getInstance().recordException(t)
|
||||
}
|
||||
|
||||
override fun setUserIdentifier(identifier: String) {
|
||||
FirebaseCrashlytics.getInstance().setUserId(identifier)
|
||||
}
|
||||
|
||||
override fun setUserProperty(identifier: String, value: String) {
|
||||
firebaseAnalytics.setUserProperty(identifier, value)
|
||||
}
|
||||
|
||||
override fun logError(msg: String) {
|
||||
FirebaseCrashlytics.getInstance().log(msg)
|
||||
}
|
||||
|
||||
override fun logEvent(eventName: String, data: Bundle) {
|
||||
firebaseAnalytics.logEvent(eventName, data)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:8.0.1'
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
||||
classpath 'com.google.gms:google-services:4.3.15'
|
||||
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
|
||||
|
|
|
|||
|
|
@ -1,11 +1,4 @@
|
|||
package com.habitrpg.common.habitica.helpers
|
||||
|
||||
import android.os.Bundle
|
||||
|
||||
interface AnalyticsManager {
|
||||
fun logException(t: Throwable)
|
||||
fun setUserIdentifier(identifier: String)
|
||||
fun setUserProperty(identifier: String, value: String)
|
||||
fun logError(msg: String)
|
||||
fun logEvent(eventName: String, data: Bundle)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ import kotlinx.coroutines.launch
|
|||
import java.io.IOException
|
||||
|
||||
class ExceptionHandler {
|
||||
private var analyticsManager: AnalyticsManager? = null
|
||||
private var exceptionLogger: ((Throwable) -> Unit)? = null
|
||||
|
||||
companion object {
|
||||
|
||||
private var instance = ExceptionHandler()
|
||||
|
||||
fun init(analyticsManager: AnalyticsManager? = null) {
|
||||
instance.analyticsManager = analyticsManager
|
||||
fun init(exceptionLogger: ((Throwable) -> Unit)? = null) {
|
||||
instance.exceptionLogger = exceptionLogger
|
||||
}
|
||||
|
||||
fun coroutine(handler: ((Throwable) -> Unit)? = null): CoroutineExceptionHandler {
|
||||
|
|
@ -38,7 +38,7 @@ class ExceptionHandler {
|
|||
throwable !is HttpException &&
|
||||
throwable !is CancellationException
|
||||
) {
|
||||
instance.analyticsManager?.logException(throwable)
|
||||
instance.exceptionLogger?.invoke(throwable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ object NumberAbbreviator {
|
|||
if (number < 0) {
|
||||
result = "-$result"
|
||||
}
|
||||
return result + abbreviationForCounter(context, counter)
|
||||
return result + abbreviationForCounter(counter)
|
||||
}
|
||||
|
||||
private fun abbreviationForCounter(context: Context?, counter: Int): String = when (counter) {
|
||||
private fun abbreviationForCounter(counter: Int): String = when (counter) {
|
||||
0 -> ""
|
||||
1 -> "k"
|
||||
2 -> "m"
|
||||
|
|
|
|||
Loading…
Reference in a new issue