Skip to content

Commit

Permalink
System config changes fixes (#2797)
Browse files Browse the repository at this point in the history
* Fixes restoration of some strings after a system language change

* Correct restoration of dialogs after a system language change
  • Loading branch information
keianhzo committed Feb 18, 2020
1 parent 2f3f358 commit aa2edc9
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void onConfigurationChanged(Configuration newConfig) {
Context context = LocaleUtils.init(this);
Language language = LocaleUtils.getDisplayLanguage(context);
newConfig.setLocale(language.getLocale());
getApplicationContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
super.onConfigurationChanged(newConfig);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,13 @@ public void onChanged(Spannable aUrl) {
navigationBarUrl.postValue(url);
}

if (isBookmarksVisible.getValue().get()) {
hint.postValue(getApplication().getString(R.string.url_bookmarks_title));

} else if (isHistoryVisible.getValue().get()) {
hint.postValue(getApplication().getString(R.string.url_history_title));

} else {
hint.postValue(getApplication().getString(R.string.search_placeholder));
}
hint.postValue(getHintValue());
}
};

public void refresh() {
url.postValue(url.getValue());
hint.postValue(getHintValue());
isWindowVisible.postValue(isWindowVisible.getValue());
placement.postValue(placement.getValue());
isOnlyWindow.postValue(isOnlyWindow.getValue());
Expand All @@ -308,6 +301,7 @@ public void refresh() {
canGoBack.postValue(canGoBack.getValue());
isInVRVideo.postValue(isInVRVideo.getValue());
autoEnteredVRVideo.postValue(autoEnteredVRVideo.getValue());
titleBarUrl.setValue(titleBarUrl.getValue());
isMediaAvailable.postValue(isMediaAvailable.getValue());
isMediaPlaying.postValue(isMediaPlaying.getValue());
}
Expand Down Expand Up @@ -384,12 +378,21 @@ public void setUrl(@Nullable Spannable url) {

@NonNull
public MutableLiveData<String> getHint() {
if (hint == null) {
hint = new MutableLiveData<>("");
}
return hint;
}

private String getHintValue() {
if (isBookmarksVisible.getValue().get()) {
return getApplication().getString(R.string.url_bookmarks_title);

} else if (isHistoryVisible.getValue().get()) {
return getApplication().getString(R.string.url_history_title);

} else {
return getApplication().getString(R.string.search_placeholder);
}
}

@NonNull
public MutableLiveData<ObservableBoolean> getIsWindowVisible() {
return isWindowVisible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ private void initialize(Context aContext) {
mBinding.popup.setOnClickListener(mPopUpListener);

// Bookmarks
mBinding.bookmarkButton.setOnClickListener(v -> {
handleBookmarkClick();
});
mBinding.bookmarkButton.setOnClickListener(v -> handleBookmarkClick());

clearFocus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public CrashDialogWidget(@NonNull Context aContext, @NonNull ArrayList<String> f
}

@Override
protected void initialize(Context aContext) {
super.initialize(aContext);
public void updateUI() {
super.updateUI();

setButtons(new int[] {
R.string.do_not_sent_button,
Expand All @@ -51,7 +51,7 @@ protected void initialize(Context aContext) {
if (mFiles != null) {
SystemUtils.clearCrashFiles(getContext(), mFiles);
}
onDismiss();
onDismiss();

} else if (index == PromptDialogWidget.POSITIVE) {
if (mFiles != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
public class PermissionWidget extends PromptDialogWidget {

private GeckoSession.PermissionDelegate.Callback mPermissionCallback;
private String mUri;
private PermissionType mPermissionType;

public enum PermissionType {
Camera,
Expand All @@ -34,8 +36,8 @@ public PermissionWidget(Context aContext) {
}

@Override
protected void initialize(Context aContext) {
super.initialize(aContext);
public void updateUI() {
super.updateUI();

setButtons(new int[] {
R.string.permission_reject,
Expand All @@ -53,6 +55,10 @@ protected void initialize(Context aContext) {
});
setCheckboxVisible(false);
setDescriptionVisible(false);

if (isVisible()) {
showPrompt(mUri, mPermissionType, mPermissionCallback);
}
}

public void showPrompt(String aUri, PermissionType aType, GeckoSession.PermissionDelegate.Callback aCallback) {
Expand Down Expand Up @@ -97,6 +103,8 @@ public void showPrompt(String aUri, PermissionType aType, GeckoSession.Permissio
}

mPermissionCallback = aCallback;
mUri = aUri;
mPermissionType = aType;

String requesterName = getRequesterName(aUri);
String message = String.format(getContext().getString(messageId), requesterName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public PopUpBlockDialogWidget(Context aContext) {
@Override
protected void initialize(Context aContext) {
super.initialize(aContext);
}

@Override
public void updateUI() {
super.updateUI();

setDescriptionVisible(false);

Expand All @@ -34,7 +39,6 @@ protected void initialize(Context aContext) {
setCheckboxText(R.string.popup_block_checkbox);

mBinding.checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> mIsChecked = isChecked);

}

public boolean askAgain() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public RestartDialogWidget(Context aContext) {
}

@Override
protected void initialize(Context aContext) {
super.initialize(aContext);
public void updateUI() {
super.updateUI();

setButtons(new int[] {
R.string.restart_later_dialog_button,
Expand All @@ -41,5 +41,4 @@ protected void initialize(Context aContext) {
setTitle(R.string.restart_dialog_restart);
setBody(getContext().getString(R.string.restart_dialog_text, getContext().getString(R.string.app_name)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package org.mozilla.vrbrowser.ui.widgets.dialogs;

import android.content.Context;
import android.content.res.Configuration;
import android.view.LayoutInflater;
import android.view.View;

Expand Down Expand Up @@ -74,13 +73,10 @@ public void updateUI() {
mBinding.headerLayout.setDescription(R.string.send_tab_dialog_description);
mBinding.footerLayout.setFooterButtonText(R.string.send_tab_dialog_button);
mBinding.footerLayout.setFooterButtonClickListener(this::sendTabButtonClick);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

updateUI();
if (isVisible()) {
mAccounts.refreshDevicesAsync();
}
}

@Override
Expand Down Expand Up @@ -143,13 +139,12 @@ public void onDevicesUpdate(@NonNull ConstellationState constellationState) {

List<Device> list = constellationState.getOtherDevices().stream()
.filter(device -> device.getCapabilities().contains(DeviceCapability.SEND_TAB)).collect(Collectors.toList());
if (!mDevicesList.equals(list)) {
mDevicesList = list;
mDevicesList = list;

List<String> devicesNamesList = new ArrayList<>();
mDevicesList.forEach((device) -> devicesNamesList.add(device.getDisplayName()));
mSendTabsDialogBinding.devicesList.setOptions(devicesNamesList.toArray(new String[]{}));

List<String> devicesNamesList = new ArrayList<>();
mDevicesList.forEach((device) -> devicesNamesList.add(device.getDisplayName()));
mSendTabsDialogBinding.devicesList.setOptions(devicesNamesList.toArray(new String[]{}));
}

if (!mDevicesList.isEmpty()) {
mBinding.footerLayout.setFooterButtonVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ protected void initialize(Context aContext) {
mUIThreadExecutor = ((VRBrowserApplication)getContext().getApplicationContext()).getExecutors().mainThread();
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
mPlaces = ((VRBrowserApplication)getContext().getApplicationContext()).getPlaces();
}

@Override
public void updateUI() {
super.updateUI();

setButtons(new int[] {
R.string.fxa_signout_confirmation_signout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ protected void initialize(Context aContext) {

mUIThreadExecutor = ((VRBrowserApplication)getContext().getApplicationContext()).getExecutors().mainThread();
mAccounts = ((VRBrowserApplication)getContext().getApplicationContext()).getAccounts();
}

@Override
public void updateUI() {
super.updateUI();

setButtons(new int[] {
R.string.whats_new_button_start_browsing,
Expand Down

0 comments on commit aa2edc9

Please sign in to comment.