diff --git a/.travis.yml b/.travis.yml index 3e2690f51..9043c6a13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: android -dist: trusty sudo: false +dist: trusty jdk: oraclejdk8 diff --git a/twidere/src/debug/AndroidManifest.xml b/twidere/src/debug/AndroidManifest.xml index cccb17ee6..40a6563ee 100644 --- a/twidere/src/debug/AndroidManifest.xml +++ b/twidere/src/debug/AndroidManifest.xml @@ -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"> { + @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 } } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt index 12cd4d25e..7b24a18a5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt @@ -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, 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 { return actionHelper.executeAfterFragmentResumed(this, useHandler, action) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt index 5f8b3d4ee..463075b91 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt @@ -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 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ContextExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ContextExtensions.kt new file mode 100644 index 000000000..965b584e9 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ContextExtensions.kt @@ -0,0 +1,38 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +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 + } +} \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ResourcesExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ResourcesExtensions.kt new file mode 100644 index 000000000..02c115060 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/ResourcesExtensions.kt @@ -0,0 +1,33 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * 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 . + */ + +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) +} \ No newline at end of file diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ExtendedRecyclerView.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedRecyclerView.kt similarity index 100% rename from twidere/src/main/java/org/mariotaku/twidere/view/ExtendedRecyclerView.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/view/ExtendedRecyclerView.kt diff --git a/twidere/src/main/res/layout/gallery_item_image_preview.xml b/twidere/src/main/res/layout/gallery_item_image_preview.xml index 1241f8780..d0f9fc61f 100644 --- a/twidere/src/main/res/layout/gallery_item_image_preview.xml +++ b/twidere/src/main/res/layout/gallery_item_image_preview.xml @@ -17,9 +17,10 @@ ~ along with this program. If not, see . --> - +