From 295fd0fd902de2a9adc505833889ec95df6b25cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Sat, 26 Dec 2020 22:40:21 +0100 Subject: [PATCH] Add language event (#1052) * Add log event to language * Add log event to app --- .../java/io/github/wulkanowy/WulkanowyApp.kt | 19 +++++++++++++++++++ .../ui/modules/settings/SettingsFragment.kt | 5 ----- .../ui/modules/settings/SettingsPresenter.kt | 7 +++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt index 57d14725..3661ac0a 100644 --- a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt +++ b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt @@ -11,8 +11,10 @@ import androidx.work.Configuration import com.yariksoffice.lingver.Lingver import dagger.hilt.android.HiltAndroidApp import fr.bipi.tressence.file.FileLoggerTree +import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository import io.github.wulkanowy.ui.base.ThemeManager import io.github.wulkanowy.utils.ActivityLifecycleLogger +import io.github.wulkanowy.utils.AnalyticsHelper import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.CrashLogExceptionTree import io.github.wulkanowy.utils.CrashLogTree @@ -32,6 +34,12 @@ class WulkanowyApp : Application(), Configuration.Provider { @Inject lateinit var appInfo: AppInfo + @Inject + lateinit var preferencesRepository: PreferencesRepository + + @Inject + lateinit var analyticsHelper: AnalyticsHelper + override fun attachBaseContext(base: Context?) { super.attachBaseContext(base) MultiDex.install(this) @@ -43,6 +51,7 @@ class WulkanowyApp : Application(), Configuration.Provider { themeManager.applyDefaultTheme() initLogging() + logCurrentLanguage() } private fun initLogging() { @@ -62,6 +71,16 @@ class WulkanowyApp : Application(), Configuration.Provider { registerActivityLifecycleCallbacks(ActivityLifecycleLogger()) } + private fun logCurrentLanguage() { + val newLang = if (preferencesRepository.appLanguage == "system") { + appInfo.systemLanguage + } else { + preferencesRepository.appLanguage + } + + analyticsHelper.logEvent("language", "startup" to newLang) + } + override fun getWorkManagerConfiguration() = Configuration.Builder() .setWorkerFactory(workerFactory) .setMinimumLoggingLevel(if (appInfo.isDebug) VERBOSE else INFO) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt index 6f4a695d..bda07e34 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsFragment.kt @@ -1,6 +1,5 @@ package io.github.wulkanowy.ui.modules.settings -import android.content.Context import android.content.SharedPreferences import android.os.Bundle import androidx.appcompat.app.AlertDialog @@ -42,10 +41,6 @@ class SettingsFragment : PreferenceFragmentCompat(), override val syncFailedString get() = getString(R.string.pref_services_message_sync_failed) - override fun onAttach(context: Context) { - super.onAttach(context) - } - override fun initView() { findPreference(getString(R.string.pref_key_services_force_sync))?.run { onPreferenceClickListener = Preference.OnPreferenceClickListener { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt index e640dd60..758bedf0 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsPresenter.kt @@ -8,8 +8,8 @@ import io.github.wulkanowy.services.alarm.TimetableNotificationSchedulerHelper import io.github.wulkanowy.services.sync.SyncManager import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.ErrorHandler -import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.AnalyticsHelper +import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.isHolidays import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.onEach @@ -46,7 +46,10 @@ class SettingsPresenter @Inject constructor( appThemeKey -> view?.recreateView() isUpcomingLessonsNotificationsEnableKey -> if (!isUpcomingLessonsNotificationsEnable) timetableNotificationHelper.cancelNotification() appLanguageKey -> view?.run { - updateLanguage(if (appLanguage == "system") appInfo.systemLanguage else appLanguage) + val newLang = if (appLanguage == "system") appInfo.systemLanguage else appLanguage + analytics.logEvent("language", "setting_changed" to newLang) + + updateLanguage(newLang) recreateView() } }