diff --git a/app/build.gradle b/app/build.gradle index 39930a73d..af3f4aef0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -184,7 +184,7 @@ dependencies { implementation "com.aurelhubert:ahbottomnavigation:2.3.4" implementation "com.ncapdevi:frag-nav:3.3.0" - implementation "com.github.YarikSOffice:lingver:1.2.2" + implementation "com.github.YarikSOffice:lingver:1.3.0" implementation "com.squareup.moshi:moshi:$moshi" implementation "com.squareup.moshi:moshi-adapters:$moshi" diff --git a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt index f1c61e82f..0e6055aac 100644 --- a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt +++ b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt @@ -5,6 +5,7 @@ import android.content.Context import android.util.Log.DEBUG import android.util.Log.INFO import android.util.Log.VERBOSE +import android.webkit.WebView import androidx.hilt.work.HiltWorkerFactory import androidx.multidex.MultiDex import androidx.work.Configuration @@ -47,22 +48,23 @@ class WulkanowyApp : Application(), Configuration.Provider { override fun onCreate() { super.onCreate() - Lingver.init(this) - themeManager.applyDefaultTheme() + initializeAppLanguage() + themeManager.applyDefaultTheme() initLogging() - logCurrentLanguage() + fixWebViewLocale() } private fun initLogging() { if (appInfo.isDebug) { Timber.plant(DebugLogTree()) - Timber.plant(FileLoggerTree.Builder() - .withFileName("wulkanowy.%g.log") - .withDirName(applicationContext.filesDir.absolutePath) - .withFileLimit(10) - .withMinPriority(DEBUG) - .build() + Timber.plant( + FileLoggerTree.Builder() + .withFileName("wulkanowy.%g.log") + .withDirName(applicationContext.filesDir.absolutePath) + .withFileLimit(10) + .withMinPriority(DEBUG) + .build() ) } else { Timber.plant(CrashLogExceptionTree()) @@ -71,14 +73,20 @@ class WulkanowyApp : Application(), Configuration.Provider { registerActivityLifecycleCallbacks(ActivityLifecycleLogger()) } - private fun logCurrentLanguage() { - val newLang = if (preferencesRepository.appLanguage == "system") { - appInfo.systemLanguage - } else { - preferencesRepository.appLanguage - } + private fun initializeAppLanguage() { + Lingver.init(this) - analyticsHelper.logEvent("language", "startup" to newLang) + if (preferencesRepository.appLanguage == "system") { + Lingver.getInstance().setFollowSystemLocale(this) + analyticsHelper.logEvent("language", "startup" to appInfo.systemLanguage) + } else { + analyticsHelper.logEvent("language", "startup" to preferencesRepository.appLanguage) + } + } + + private fun fixWebViewLocale() { + //https://stackoverflow.com/questions/40398528/android-webview-language-changes-abruptly-on-android-7-0-and-above + WebView(this).destroy() } override fun getWorkManagerConfiguration() = Configuration.Builder() 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 bda07e347..ad4692b96 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 @@ -79,6 +79,10 @@ class SettingsFragment : PreferenceFragmentCompat(), lingver.setLocale(requireContext(), langCode) } + override fun updateLanguageToFollowSystem() { + lingver.setFollowSystemLocale(requireContext()) + } + override fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean) { findPreference(serviceEnablesKey)?.run { summary = if (isHolidays) getString(R.string.pref_services_suspended) else "" 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 f9ad74a10..e3b2e232f 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 @@ -42,14 +42,18 @@ class SettingsPresenter @Inject constructor( when (key) { serviceEnableKey -> with(syncManager) { if (isServiceEnabled) startPeriodicSyncWorker() else stopSyncWorker() } servicesIntervalKey, servicesOnlyWifiKey -> syncManager.startPeriodicSyncWorker(true) - isDebugNotificationEnableKey -> chuckerCollector.showNotification = isDebugNotificationEnable + isDebugNotificationEnableKey -> chuckerCollector.showNotification = + isDebugNotificationEnable appThemeKey -> view?.recreateView() isUpcomingLessonsNotificationsEnableKey -> if (!isUpcomingLessonsNotificationsEnable) timetableNotificationHelper.cancelNotification() appLanguageKey -> view?.run { - val newLang = if (appLanguage == "system") appInfo.systemLanguage else appLanguage - analytics.logEvent("language", "setting_changed" to newLang) - - updateLanguage(newLang) + if (appLanguage == "system") { + updateLanguageToFollowSystem() + analytics.logEvent("language", "setting_changed" to appInfo.systemLanguage) + } else { + updateLanguage(appLanguage) + analytics.logEvent("language", "setting_changed" to appLanguage) + } recreateView() } } @@ -71,7 +75,10 @@ class SettingsPresenter @Inject constructor( analytics.logEvent("sync_now", "status" to "success") } WorkInfo.State.FAILED -> { - showError(syncFailedString, Throwable(workInfo.outputData.getString("error"))) + showError( + syncFailedString, + Throwable(workInfo.outputData.getString("error")) + ) analytics.logEvent("sync_now", "status" to "failed") } else -> Timber.d("Sync now state: ${workInfo.state}") diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt index b647c0b76..802717412 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/settings/SettingsView.kt @@ -14,6 +14,8 @@ interface SettingsView : BaseView { fun updateLanguage(langCode: String) + fun updateLanguageToFollowSystem() + fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean) fun setSyncInProgress(inProgress: Boolean) diff --git a/app/src/play/java/io/github/wulkanowy/utils/AnalyticsHelper.kt b/app/src/play/java/io/github/wulkanowy/utils/AnalyticsHelper.kt index ba29e1cb6..b65325790 100644 --- a/app/src/play/java/io/github/wulkanowy/utils/AnalyticsHelper.kt +++ b/app/src/play/java/io/github/wulkanowy/utils/AnalyticsHelper.kt @@ -20,7 +20,7 @@ class AnalyticsHelper @Inject constructor( params.forEach { if (it.second == null) return@forEach when (it.second) { - is String, is String? -> putString(it.first, it.second as String) + is String, is String? -> putString(it.first, it.second.toString()) is Int, is Int? -> putInt(it.first, it.second as Int) is Boolean, is Boolean? -> putBoolean(it.first, it.second as Boolean) }