Skip to content

Commit

Permalink
Go directly to language settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Dec 5, 2024
1 parent 46fdf18 commit 9d029c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ private boolean handleAppLocalePickerClick() {
// if per-app language preferences are enabled and the device is on API 33+, take the user to the
// system app settings to change the language
if (mIsPerAppLanguagePrefsEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
mLocaleHelper.openAppSettings(getContext());
mLocaleHelper.openAppLanguageSettings(getContext());
return true;
} else if (getActivity() instanceof AppCompatActivity) {
LocalePickerBottomSheet bottomSheet = LocalePickerBottomSheet.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.wordpress.android.ui.prefs.language
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
Expand Down Expand Up @@ -85,18 +86,25 @@ class LocaleHelper @Inject constructor(
}

/**
* Open the app settings screen so the user can change the app locale - note that
* the locale is only available in API 33+
* Open the app settings screen so the user can change the app language.
* Note that the per-app language setting is only available in API 33+
* and it's up to the caller to check the version
*/
fun openAppSettings(context: Context) {
Intent().also { intent ->
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.setData(Uri.parse("package:" + context.packageName))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
context.startActivity(intent)
fun openAppLanguageSettings(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Intent().also { intent ->
intent.setAction(Settings.ACTION_APP_LOCALE_SETTINGS)
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.setData(Uri.parse("package:" + context.packageName))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
context.startActivity(intent)
}
} else {
throw UnsupportedOperationException(
"Per-app language settings are not available in this version of Android"
)
}
}

Expand Down

0 comments on commit 9d029c1

Please sign in to comment.