mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 17:12:44 +01:00
Fix follow system language setting (#1113)
This commit is contained in:
parent
4984cb9b26
commit
82b207b03a
@ -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"
|
||||
|
@ -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()
|
||||
|
@ -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<Preference>(serviceEnablesKey)?.run {
|
||||
summary = if (isHolidays) getString(R.string.pref_services_suspended) else ""
|
||||
|
@ -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}")
|
||||
|
@ -14,6 +14,8 @@ interface SettingsView : BaseView {
|
||||
|
||||
fun updateLanguage(langCode: String)
|
||||
|
||||
fun updateLanguageToFollowSystem()
|
||||
|
||||
fun setServicesSuspended(serviceEnablesKey: String, isHolidays: Boolean)
|
||||
|
||||
fun setSyncInProgress(inProgress: Boolean)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user