fixed language preferences
This commit is contained in:
parent
750925c978
commit
f76397e76a
|
@ -1,7 +1,7 @@
|
|||
language: android
|
||||
|
||||
dist: trusty
|
||||
sudo: false
|
||||
dist: trusty
|
||||
|
||||
jdk: oraclejdk8
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
android:enabled="false"
|
||||
android:icon="@drawable/leak_canary_icon"
|
||||
android:label="@string/leak_canary_display_activity_label"
|
||||
android:taskAffinity="com.squareup.leakcanary.${applicationId}"
|
||||
android:theme="@style/leak_canary_LeakCanary.Base">
|
||||
<intent-filter>
|
||||
<action
|
||||
|
|
|
@ -22,21 +22,40 @@ package org.mariotaku.ktextension
|
|||
import android.annotation.TargetApi
|
||||
import android.content.res.Configuration
|
||||
import android.os.Build
|
||||
import android.os.LocaleList
|
||||
import android.support.v4.os.ConfigurationCompat
|
||||
import android.support.v4.os.LocaleListCompat
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/3/23.
|
||||
*/
|
||||
|
||||
fun Configuration.setLayoutDirectionCompat(locale: Locale?) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return
|
||||
ConfigurationExtensionsApi18.setLayoutDirectionCompat(this, locale)
|
||||
}
|
||||
var Configuration.localesCompat: LocaleListCompat
|
||||
get() = ConfigurationCompat.getLocales(this)
|
||||
set(value) {
|
||||
when {
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 -> {
|
||||
@Suppress("DEPRECATION")
|
||||
this.locale = value[0]
|
||||
}
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.N -> {
|
||||
ConfigurationExtensionsApi18.setLocaleCompat(this, value[0])
|
||||
}
|
||||
else -> {
|
||||
ConfigurationExtensionsApi24.setLocalesCompat(this, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
private object ConfigurationExtensionsApi18 {
|
||||
|
||||
fun setLayoutDirectionCompat(configuration: Configuration, locale: Locale?) {
|
||||
configuration.setLayoutDirection(locale)
|
||||
fun setLocaleCompat(configuration: Configuration, locale: Locale?) {
|
||||
configuration.setLocale(locale)
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
private object ConfigurationExtensionsApi24 {
|
||||
|
||||
fun setLocalesCompat(configuration: Configuration, locales: LocaleListCompat) {
|
||||
configuration.locales = locales.unwrap() as? LocaleList
|
||||
}
|
||||
}
|
|
@ -63,6 +63,8 @@ import org.mariotaku.twidere.activity.iface.IControlBarActivity
|
|||
import org.mariotaku.twidere.activity.iface.IThemedActivity
|
||||
import org.mariotaku.twidere.annotation.NavbarStyle
|
||||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.extension.defaultSharedPreferences
|
||||
import org.mariotaku.twidere.extension.overriding
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowInsetsCallback
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.preference.iface.IDialogPreference
|
||||
|
@ -346,6 +348,19 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
|
|||
actionHelper.dispatchOnResumeFragments(this)
|
||||
}
|
||||
|
||||
override fun attachBaseContext(newBase: Context?) {
|
||||
if (newBase == null) {
|
||||
super.attachBaseContext(null)
|
||||
return
|
||||
}
|
||||
val locale = newBase.defaultSharedPreferences[overrideLanguageKey]
|
||||
if (locale == null) {
|
||||
super.attachBaseContext(newBase)
|
||||
return
|
||||
}
|
||||
super.attachBaseContext(newBase.overriding(locale))
|
||||
}
|
||||
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseActivity) -> Unit): Promise<Unit, Exception> {
|
||||
return actionHelper.executeAfterFragmentResumed(this, useHandler, action)
|
||||
}
|
||||
|
|
|
@ -43,12 +43,10 @@ import org.mariotaku.kpreferences.get
|
|||
import org.mariotaku.kpreferences.set
|
||||
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
|
||||
import org.mariotaku.ktextension.isCurrentThreadCompat
|
||||
import org.mariotaku.ktextension.setLayoutDirectionCompat
|
||||
import org.mariotaku.mediaviewer.library.MediaDownloader
|
||||
import org.mariotaku.restfu.http.RestHttpClient
|
||||
import org.mariotaku.twidere.BuildConfig
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.Constants.KEY_USAGE_STATISTICS
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.activity.AssistLauncherActivity
|
||||
import org.mariotaku.twidere.activity.MainActivity
|
||||
|
@ -56,6 +54,7 @@ import org.mariotaku.twidere.activity.MainHondaJOJOActivity
|
|||
import org.mariotaku.twidere.constant.*
|
||||
import org.mariotaku.twidere.extension.model.loadRemoteSettings
|
||||
import org.mariotaku.twidere.extension.model.save
|
||||
import org.mariotaku.twidere.extension.setLocale
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.receiver.ConnectivityStateReceiver
|
||||
import org.mariotaku.twidere.service.StreamingService
|
||||
|
@ -82,7 +81,7 @@ import java.util.concurrent.Future
|
|||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeListener {
|
||||
class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
|
||||
|
||||
@Inject
|
||||
lateinit internal var activityTracker: ActivityTracker
|
||||
|
@ -141,17 +140,16 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
|||
StrictModeUtils.detectAllVmPolicy()
|
||||
}
|
||||
super.onCreate()
|
||||
EmojioneTranslator.init(this)
|
||||
NotificationChannelsManager.initialize(this)
|
||||
applyLanguageSettings()
|
||||
startKovenant()
|
||||
initializeAsyncTask()
|
||||
initDebugMode()
|
||||
initBugReport()
|
||||
EmojioneTranslator.init(this)
|
||||
NotificationChannelsManager.initialize(this)
|
||||
|
||||
updateEasterEggIcon()
|
||||
|
||||
migrateUsageStatisticsPreferences()
|
||||
GeneralComponent.get(this).inject(this)
|
||||
|
||||
autoRefreshController.appStarted()
|
||||
|
@ -235,14 +233,9 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
|||
stopKovenant()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun applyLanguageSettings() {
|
||||
val locale = sharedPreferences[overrideLanguageKey] ?: return
|
||||
Locale.setDefault(locale)
|
||||
val config = resources.configuration
|
||||
config.locale = locale
|
||||
config.setLayoutDirectionCompat(locale)
|
||||
resources.updateConfiguration(config, resources.displayMetrics)
|
||||
resources.setLocale(locale)
|
||||
}
|
||||
|
||||
private fun loadDefaultFeatures() {
|
||||
|
@ -312,20 +305,6 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
|||
Analyzer.init(this)
|
||||
}
|
||||
|
||||
private fun migrateUsageStatisticsPreferences() {
|
||||
val preferences = sharedPreferences
|
||||
val hasUsageStatistics = preferences.contains(KEY_USAGE_STATISTICS)
|
||||
if (hasUsageStatistics) return
|
||||
if (preferences.contains(KEY_UCD_DATA_PROFILING) || preferences.contains(KEY_SPICE_DATA_PROFILING)) {
|
||||
val prevUsageEnabled = preferences.getBoolean(KEY_UCD_DATA_PROFILING, false) || preferences.getBoolean(KEY_SPICE_DATA_PROFILING, false)
|
||||
val editor = preferences.edit()
|
||||
editor.putBoolean(KEY_USAGE_STATISTICS, prevUsageEnabled)
|
||||
editor.remove(KEY_UCD_DATA_PROFILING)
|
||||
editor.remove(KEY_SPICE_DATA_PROFILING)
|
||||
editor.apply()
|
||||
}
|
||||
}
|
||||
|
||||
private fun reloadDnsSettings() {
|
||||
(dns as? TwidereDns)?.reloadDnsSettings()
|
||||
}
|
||||
|
@ -351,8 +330,6 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
|||
|
||||
companion object {
|
||||
|
||||
private val KEY_UCD_DATA_PROFILING = "ucd_data_profiling"
|
||||
private val KEY_SPICE_DATA_PROFILING = "spice_data_profiling"
|
||||
private val KEY_KEYBOARD_SHORTCUT_INITIALIZED = "keyboard_shortcut_initialized"
|
||||
var instance: TwidereApplication? = null
|
||||
private set
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.extension
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import org.mariotaku.twidere.TwidereConstants
|
||||
import java.util.*
|
||||
|
||||
val Context.defaultSharedPreferences: SharedPreferences
|
||||
get() = getSharedPreferences(TwidereConstants.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
fun Context.overriding(withLocale: Locale): Context {
|
||||
resources.setLocale(withLocale)
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
createConfigurationContext(resources.configuration)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.extension
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.support.v4.os.LocaleListCompat
|
||||
import org.mariotaku.ktextension.localesCompat
|
||||
import java.util.*
|
||||
|
||||
fun Resources.setLocale(locale: Locale) {
|
||||
Locale.setDefault(locale)
|
||||
val config = configuration
|
||||
config.localesCompat = LocaleListCompat.create(locale)
|
||||
@Suppress("DEPRECATION")
|
||||
updateConfiguration(config, displayMetrics)
|
||||
}
|
|
@ -17,7 +17,8 @@
|
|||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<org.mariotaku.twidere.view.SquareRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<org.mariotaku.twidere.view.SquareRelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
android:key="override_language"
|
||||
android:title="@string/preference_title_override_language">
|
||||
<extra
|
||||
android:name="should_terminate"
|
||||
android:name="should_recreate"
|
||||
android:value="true"/>
|
||||
</org.mariotaku.twidere.preference.EntrySummaryListPreference>
|
||||
|
||||
|
|
Loading…
Reference in New Issue