-
Notifications
You must be signed in to change notification settings - Fork 723
Support Per-app language preferences #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
99f1b5a
943a4dd
83771c1
96ec463
6d5cc0a
4758f5d
730dc4f
402dcca
dc91a1e
a411b65
c3f3466
8ce2941
feaa2c8
286c209
e6bd8aa
903780a
90b5684
82fdb5e
3736705
bd4a529
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
| */ | ||
| package com.vrem.wifianalyzer | ||
|
|
||
| import android.content.Context | ||
| import android.content.SharedPreferences | ||
| import android.content.SharedPreferences.OnSharedPreferenceChangeListener | ||
| import android.content.res.Configuration | ||
|
|
@@ -26,18 +25,17 @@ import android.view.Menu | |
| import android.view.MenuItem | ||
| import android.view.View | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.appcompat.app.AppCompatDelegate | ||
| import androidx.core.os.LocaleListCompat | ||
| import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
| import androidx.core.view.GravityCompat | ||
| import androidx.drawerlayout.widget.DrawerLayout | ||
| import com.google.android.material.navigation.NavigationView | ||
| import com.vrem.annotation.OpenClass | ||
| import com.vrem.util.createContext | ||
| import com.vrem.wifianalyzer.navigation.NavigationMenu | ||
| import com.vrem.wifianalyzer.navigation.NavigationMenuControl | ||
| import com.vrem.wifianalyzer.navigation.NavigationMenuController | ||
| import com.vrem.wifianalyzer.navigation.options.OptionMenu | ||
| import com.vrem.wifianalyzer.settings.Repository | ||
| import com.vrem.wifianalyzer.settings.Settings | ||
| import com.vrem.wifianalyzer.wifi.accesspoint.ConnectionView | ||
| import com.vrem.wifianalyzer.wifi.scanner.ScannerService | ||
|
|
||
|
|
@@ -52,15 +50,13 @@ class MainActivity : | |
| internal lateinit var optionMenu: OptionMenu | ||
| internal lateinit var connectionView: ConnectionView | ||
|
|
||
| override fun attachBaseContext(newBase: Context) = | ||
| super.attachBaseContext(newBase.createContext(Settings(Repository(newBase)).languageLocale())) | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| val mainContext = MainContext.INSTANCE | ||
| mainContext.initialize(this, largeScreen) | ||
|
|
||
| val settings = mainContext.settings | ||
| settings.initializeDefaultValues() | ||
| settings.syncLanguage() | ||
| settings.themeStyle().setTheme(this) | ||
|
|
||
| mainReload = MainReload(settings) | ||
|
|
@@ -120,6 +116,18 @@ class MainActivity : | |
| sharedPreferences: SharedPreferences, | ||
| key: String?, | ||
| ) { | ||
| val languageKey = getString(R.string.language_key) | ||
| if (key == languageKey) { | ||
| val languageTag = sharedPreferences.getString(languageKey, "") | ||
| val locales = | ||
| languageTag | ||
| ?.takeIf { it.isNotEmpty() } | ||
| ?.let(LocaleListCompat::forLanguageTags) | ||
| ?: LocaleListCompat.getEmptyLocaleList() | ||
|
|
||
314systems marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| AppCompatDelegate.setApplicationLocales(locales) | ||
| } | ||
|
Comment on lines
+119
to
+129
|
||
|
|
||
| val mainContext = MainContext.INSTANCE | ||
| if (mainReload.shouldReload(mainContext.settings)) { | ||
| MainContext.INSTANCE.scannerService.stop() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new titlecaseFirst() extension function in StringUtils.kt lacks test coverage. This function is used to capitalize language display names in the language preference list. Consider adding test cases to verify its behavior with various inputs, including edge cases like empty strings, strings with different Unicode characters, and strings in different locales to ensure proper title casing.