Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Do not keep a default language (#1772)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Sep 4, 2019
1 parent 63a16d9 commit b0f2195
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,19 @@ public ArrayList<String> getContentLocales() {

String json = mPrefs.getString(
mContext.getString(R.string.settings_key_content_languages),
new JSONArray().toString());
null);

try {
JSONArray jsonArray = new JSONArray(json);
for (int i=0; i<jsonArray.length(); i++) {
result.add(jsonArray.getString(i));
}

} catch (JSONException e) {
e.printStackTrace();
}
return result;

return result;
} catch (Exception e) {
return null;
}
}

public void setContentLocales(List<String> languages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ public Language(String id, String name) {
this.id = id;
this.name = name;
this.isPreferred = false;
this.isDefault = false;
}

private String name;
private String id;
private boolean isPreferred;
private boolean isDefault;

public String getId() {
return this.id;
Expand All @@ -30,14 +28,6 @@ public boolean isPreferred() {
return isPreferred;
}

public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}

public boolean isDefault() {
return isDefault;
}

@Override
public int hashCode() {
return id.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ public void onBindViewHolder(@NonNull LanguageViewHolder holder, int position) {

} else if (holder.binding.add.getVisibility() == View.VISIBLE &&
ViewUtils.isInsideView(holder.binding.add, (int)event.getRawX(), (int)event.getRawY())) {
if (!language.isDefault() && !language.isPreferred()) {
if (!language.isPreferred()) {
mLanguageItemCallback.onAdd(holder.binding.add, language);
}

} else if (holder.binding.delete.getVisibility() == View.VISIBLE &&
ViewUtils.isInsideView(holder.binding.delete, (int)event.getRawX(), (int)event.getRawY())) {
if (!language.isDefault() && language.isPreferred()) {
if (language.isPreferred()) {
mLanguageItemCallback.onRemove(holder.binding.delete, language);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ private void setVoiceLanguage() {

private void setContentLanguage() {
List<Language> preferredLanguages = LocaleUtils.getPreferredLanguages(getContext());
String text = getContext().getResources().getString(R.string.language_options_content_language, preferredLanguages.get(0).getName());
mBinding.contentLanguageButton.setDescription(ViewUtils.getSpannedText(text));
String text = "";
if (preferredLanguages.size() > 0) {
text = preferredLanguages.get(0).getName();
}
mBinding.contentLanguageButton.setDescription(ViewUtils.getSpannedText(getContext().getResources().getString(R.string.language_options_content_language, text)));
}

private void setDisplayLanguage() {
Expand Down
21 changes: 10 additions & 11 deletions app/src/common/shared/org/mozilla/vrbrowser/utils/LocaleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -60,9 +59,6 @@ private static HashMap<String, Language> getAllLanguages() {
String languageId = temp.toLanguageTag();
String displayName = temp.getDisplayName().substring(0, 1).toUpperCase() + temp.getDisplayName().substring(1);
Language locale = new Language(languageId, displayName + " [" + languageId + "]");
if (languageId.equals(currentLocale)) {
locale.setDefault(true);
}
mLanguagesCache.put(languageId, locale);
}

Expand Down Expand Up @@ -93,14 +89,17 @@ public static List<Language> getPreferredLanguages(@NonNull Context aContext) {
HashMap<String, Language> languages = getAllLanguages();
List<String> savedLanguages = SettingsStore.getInstance(aContext).getContentLocales();
List<Language> preferredLanguages = new ArrayList<>();
for (String language : savedLanguages) {
Language lang = languages.get(language);
lang.setPreferred(true);
preferredLanguages.add(lang);
}
if (savedLanguages != null) {
for (String language : savedLanguages) {
Language lang = languages.get(language);
lang.setPreferred(true);
preferredLanguages.add(lang);
}

if (!savedLanguages.stream().anyMatch(str -> str.trim().equals(getCurrentLocale()))) {
preferredLanguages.add(getCurrentLocaleLanguage());
} else {
Language currentLanguage = getCurrentLocaleLanguage();
currentLanguage.setPreferred(true);
preferredLanguages.add(currentLanguage);
}

return preferredLanguages;
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/language_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
android:contentDescription="Preferred language delete button"
android:duplicateParentState="true"
android:soundEffectsEnabled="false"
android:src="@{language.isDefault ? @drawable/ic_icon_empty : @drawable/ic_icon_language_delete}"
android:src="@{@drawable/ic_icon_language_delete}"
android:tint="@color/fog"
app:srcCompat="@drawable/ic_icon_language_delete"
app:visibleGone="@{isPreferred}" />
Expand Down Expand Up @@ -95,8 +95,7 @@
android:gravity="center_vertical"
android:paddingStart="5dp"
android:singleLine="true"
android:text="@{language.isDefault &amp;&amp; isPreferred ? `(` + @string/language_default + `) ` + language.name : language.name}"
app:typeface='@{language.isDefault ? "bold" : "normal"}'
android:text="@{language.name}"
tool:text="Language Item" />
</org.mozilla.vrbrowser.ui.views.FadingFrameLayout>

Expand Down

0 comments on commit b0f2195

Please sign in to comment.