Skip to content

Commit

Permalink
If the user doesn't have Portuguese installed, use English as the spe…
Browse files Browse the repository at this point in the history
…ll parsing locale.
  • Loading branch information
Carifio24 committed Sep 27, 2023
1 parent 56ce372 commit e95cde5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/dnd/jon/spellbook/LocalizationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ private static <E extends Enum<E>> int[] supportedIDs(E[] items, Map<E,Integer>
static int[] supportedTableLayoutIDs() { return supportedIDs(supportedClasses(), tableLayoutIDs); }
static int[] supportedSpellcastingInfoIDs() { return supportedIDs(supportedClasses(), spellcastingInfoIDs); }

// TODO: Think of a way to make this more generic for other languages
static boolean hasPortugueseInstalled() {
final LocaleList localeList = LocaleList.getDefault();
final Locale ptLocale = localeList.getFirstMatch(new String[]{"pt-BR", "pt-PT"});
return ptLocale.getLanguage().equals("pt");
}

}
5 changes: 2 additions & 3 deletions app/src/main/java/dnd/jon/spellbook/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}

// Enable the ability to change the spell language, if applicable
final LocaleList localeList = LocaleList.getDefault();
final Locale ptLocale = localeList.getFirstMatch(new String[]{"pt-BR", "pt-PT"});
final boolean hasPortuguese = LocalizationUtils.hasPortugueseInstalled();
final PreferenceScreen preferenceScreen = getPreferenceScreen();
final Preference languagePreference = preferenceScreen.findPreference(getString(R.string.spell_language_key));
if (languagePreference != null) {
if (ptLocale.getLanguage().equals("pt")) {
if (hasPortuguese) {
languagePreference.setVisible(true);
languagePreference.setEnabled(true);
} else {
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/dnd/jon/spellbook/SpellbookViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ public SpellbookViewModel(Application application) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(application);
final String spellLanguageKey = application.getString(R.string.spell_language_key);
final String spellsLocaleString = sharedPreferences.getString(spellLanguageKey, null);
this.spellsLocale = spellsLocaleString == null ? LocalizationUtils.defaultSpellLocale() : new Locale(spellsLocaleString);
if (LocalizationUtils.hasPortugueseInstalled()) {
this.spellsLocale = spellsLocaleString == null ? LocalizationUtils.defaultSpellLocale() : new Locale(spellsLocaleString);
} else {
this.spellsLocale = Locale.US;
}

// If we don't have an existing value for the spell language setting
// we set the default.
Expand Down

0 comments on commit e95cde5

Please sign in to comment.