Prevent showing notification megaphone if not translated.

This commit is contained in:
Alan Evans
2021-02-25 14:16:50 -04:00
parent 8f6ff215aa
commit 3f6c8cb622
6 changed files with 60 additions and 15 deletions

View File

@@ -12,16 +12,20 @@ import java.util.Locale;
/**
* Gives access to English strings.
*/
public final class EnglishResourceUtil {
public final class ResourceUtil {
private EnglishResourceUtil() {
private ResourceUtil() {
}
public static Resources getEnglishResources(@NonNull Context context) {
return getResources(context, Locale.ENGLISH);
}
public static Resources getResources(@NonNull Context context, @NonNull Locale locale) {
Configuration configurationLocal = context.getResources().getConfiguration();
Configuration configurationEn = new Configuration(configurationLocal);
configurationEn.setLocale(Locale.ENGLISH);
configurationEn.setLocale(locale);
return context.createConfigurationContext(configurationEn)
.getResources();

View File

@@ -24,7 +24,17 @@ public final class TranslationDetection {
public TranslationDetection(@NonNull Context context) {
this.resourcesLocal = context.getResources();
this.configurationLocal = resourcesLocal.getConfiguration();
this.resourcesEn = EnglishResourceUtil.getEnglishResources(context);
this.resourcesEn = ResourceUtil.getEnglishResources(context);
}
/**
* @param context Can be Application context.
* @param usersLocale Locale of user.
*/
public TranslationDetection(@NonNull Context context, @NonNull Locale usersLocale) {
this.resourcesLocal = ResourceUtil.getResources(context.getApplicationContext(), usersLocale);
this.configurationLocal = resourcesLocal.getConfiguration();
this.resourcesEn = ResourceUtil.getEnglishResources(context);
}
/**
@@ -44,6 +54,15 @@ public final class TranslationDetection {
return !stringEn.equals(stringLocal);
}
public boolean textExistsInUsersLanguage(@StringRes int... resIds) {
for (int resId : resIds) {
if (!textExistsInUsersLanguage(resId)) {
return false;
}
}
return true;
}
protected boolean configSupportsEnglish() {
if (configurationLocal.locale.getLanguage().equals("en")) {
return true;