Skip to content

Commit

Permalink
Keep currently open dialogs after a config change (#2741)
Browse files Browse the repository at this point in the history
* Restore view after a config change

* Keep bookmarks and history opened after a language change
  • Loading branch information
keianhzo committed Feb 5, 2020
1 parent 6c51e61 commit 78f5696
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ public void updateUI() {

updateBookmarks();

setVisibility(GONE);

setOnTouchListener((v, event) -> {
v.requestFocusFromTouch();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ public void updateUI() {

updateHistory();

setVisibility(GONE);

setOnTouchListener((v, event) -> {
v.requestFocusFromTouch();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.mozilla.vrbrowser.databinding.TrayBinding;
import org.mozilla.vrbrowser.ui.viewmodel.WindowViewModel;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsView;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;

import java.util.ArrayList;
Expand Down Expand Up @@ -429,10 +430,10 @@ private void handleSessionState(boolean refresh) {
}

public void toggleSettingsDialog() {
toggleSettingsDialog(SettingsWidget.SettingDialog.MAIN);
toggleSettingsDialog(SettingsView.SettingViewType.MAIN);
}

public void toggleSettingsDialog(@NonNull SettingsWidget.SettingDialog settingDialog) {
public void toggleSettingsDialog(@NonNull SettingsView.SettingViewType settingDialog) {
UIWidget widget = getChild(mSettingsDialogHandle);
if (widget == null) {
widget = createChild(SettingsWidget.class, false);
Expand All @@ -449,7 +450,7 @@ public void toggleSettingsDialog(@NonNull SettingsWidget.SettingDialog settingDi
}
}

public void showSettingsDialog(@NonNull SettingsWidget.SettingDialog settingDialog) {
public void showSettingsDialog(@NonNull SettingsView.SettingViewType settingDialog) {
UIWidget widget = getChild(mSettingsDialogHandle);
if (widget == null) {
widget = createChild(SettingsWidget.class, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.mozilla.vrbrowser.ui.widgets.dialogs.SelectionActionWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.ContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.menus.LibraryMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.Arrays;
Expand All @@ -75,6 +74,7 @@
import mozilla.components.concept.storage.VisitInfo;
import mozilla.components.concept.storage.VisitType;

import static org.mozilla.vrbrowser.ui.widgets.settings.SettingsView.SettingViewType.FXA;
import static org.mozilla.vrbrowser.utils.ServoUtils.isInstanceOfServoSession;

public class WindowWidget extends UIWidget implements SessionChangeListener,
Expand Down Expand Up @@ -315,12 +315,6 @@ public void onConfigurationChanged(Configuration newConfig) {
mHistoryView.updateUI();
mBookmarksView.updateUI();

if (mView != null) {
View temp = mView;
unsetView(mView, false);
setView(temp, false);
}

mViewModel.refresh();
}

Expand Down Expand Up @@ -1361,7 +1355,7 @@ public void onShowContextMenu(@NonNull View view, @NonNull Bookmark item, boolea

@Override
public void onFxASynSettings(@NonNull View view) {
mWidgetManager.getTray().showSettingsDialog(SettingsWidget.SettingDialog.FXA);
mWidgetManager.getTray().showSettingsDialog(FXA);
}

@Override
Expand Down Expand Up @@ -1400,7 +1394,7 @@ public void onShowContextMenu(@NonNull View view, @NonNull VisitInfo item, boole

@Override
public void onFxASynSettings(@NonNull View view) {
mWidgetManager.getTray().showSettingsDialog(SettingsWidget.SettingDialog.FXA);
mWidgetManager.getTray().showSettingsDialog(FXA);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.widgets.dialogs.PromptDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.UIDialog;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
import org.mozilla.vrbrowser.utils.BitmapCache;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
import org.mozilla.vrbrowser.utils.SystemUtils;
Expand All @@ -47,6 +46,8 @@
import mozilla.components.concept.sync.Profile;
import mozilla.components.concept.sync.TabData;

import static org.mozilla.vrbrowser.ui.widgets.settings.SettingsView.SettingViewType.FXA;

public class Windows implements TrayListener, TopBarWidget.Delegate, TitleBarWidget.Delegate,
WindowWidget.WindowListener, TabsWidget.TabDelegate, Services.TabReceivedDelegate {

Expand Down Expand Up @@ -880,7 +881,7 @@ public void onAuthenticated(@NonNull OAuthAccount oAuthAccount, @NonNull AuthTyp
break;

case SETTINGS:
mWidgetManager.getTray().showSettingsDialog(SettingsWidget.SettingDialog.FXA);
mWidgetManager.getTray().showSettingsDialog(FXA);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import org.mozilla.vrbrowser.browser.Accounts;
import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;

import java.util.Objects;
import java.util.concurrent.Executor;

import static org.mozilla.vrbrowser.ui.widgets.settings.SettingsView.SettingViewType.FXA;

public class SignOutDialogWidget extends PromptDialogWidget {

private Accounts mAccounts;
Expand Down Expand Up @@ -60,10 +61,10 @@ protected void initialize(Context aContext) {

} else if (index == PromptDialogWidget.POSITIVE) {
hide(UIWidget.REMOVE_WIDGET);
mWidgetManager.getTray().toggleSettingsDialog(SettingsWidget.SettingDialog.FXA);
mWidgetManager.getTray().toggleSettingsDialog(FXA);
}
});
setDelegate(() -> mWidgetManager.getTray().toggleSettingsDialog(SettingsWidget.SettingDialog.FXA));
setDelegate(() -> mWidgetManager.getTray().toggleSettingsDialog(FXA));

setDescriptionVisible(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void updateUI() {

// Header
mBinding.headerLayout.setBackClickListener(view -> {
mDelegate.showView(new LanguageOptionsView(getContext(), mWidgetManager));
mDelegate.showView(SettingViewType.LANGUAGE);
});
mBinding.headerLayout.setHelpClickListener(view -> {
SessionStore.get().getActiveSession().loadUri(getResources().getString(R.string.sumo_language_content_url));
Expand Down Expand Up @@ -158,4 +158,8 @@ public void onShown() {
refreshLanguages();
}

@Override
protected SettingViewType getType() {
return SettingViewType.LANGUAGE_CONTENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ private void setScrollDirection(int checkedId, boolean doApply) {
setScrollDirection(checkedId, doApply);
};

@Override
protected SettingViewType getType() {
return SettingViewType.CONTROLLER;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,9 @@ private void setServo(boolean value, boolean doApply) {
}
}

@Override
protected SettingViewType getType() {
return SettingViewType.LANGUAGE_VOICE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void updateUI() {

// Header
mBinding.headerLayout.setBackClickListener(view -> {
mDelegate.showView(new LanguageOptionsView(getContext(), mWidgetManager));
mDelegate.showView(SettingViewType.LANGUAGE);
});
mBinding.headerLayout.setHelpClickListener(view -> {
SessionStore.get().getActiveSession().loadUri(getResources().getString(R.string.sumo_language_display_url));
Expand Down Expand Up @@ -111,4 +111,9 @@ public Point getDimensions() {
WidgetPlacement.dpDimension(getContext(), R.dimen.settings_dialog_height));
}

@Override
protected SettingViewType getType() {
return SettingViewType.LANGUAGE_DISPLAY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,9 @@ public Point getDimensions() {
WidgetPlacement.dpDimension(getContext(), R.dimen.display_options_height));
}

@Override
protected SettingViewType getType() {
return SettingViewType.DISPLAY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,9 @@ private void setEnv(int checkedId, boolean doApply) {
}
}

@Override
protected SettingViewType getType() {
return SettingViewType.ENVIRONMENT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,9 @@ public void onAuthenticationProblems() {
}
};

@Override
protected SettingViewType getType() {
return SettingViewType.FXA;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ private SpannableStringBuilder getSpannedLanguageText(@NonNull String language)
return spanned;
}

private OnClickListener mContentListener = v -> mDelegate.showView(mContentLanguage);
private OnClickListener mContentListener = v -> mDelegate.showView(SettingViewType.LANGUAGE_CONTENT);

private OnClickListener mVoiceSearchListener = v -> mDelegate.showView(mVoiceLanguage);
private OnClickListener mVoiceSearchListener = v -> mDelegate.showView(SettingViewType.LANGUAGE_VOICE);

private OnClickListener mDisplayListener = v -> mDelegate.showView(mDisplayLanguage);
private OnClickListener mDisplayListener = v -> mDelegate.showView(SettingViewType.LANGUAGE_DISPLAY);

private SharedPreferences.OnSharedPreferenceChangeListener mPreferencesListener = (sharedPreferences, key) -> {
if (key.equals(getContext().getString(R.string.settings_key_content_languages))) {
Expand All @@ -159,4 +159,9 @@ public Point getDimensions() {
WidgetPlacement.dpDimension(getContext(), R.dimen.settings_dialog_height));
}

@Override
protected SettingViewType getType() {
return SettingViewType.LANGUAGE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void updateUI() {

// Header
mBinding.headerLayout.setBackClickListener(view -> {
mDelegate.showView(new PrivacyOptionsView(getContext(), mWidgetManager));
mDelegate.showView(SettingViewType.PRIVACY);
});

// Adapters
Expand Down Expand Up @@ -122,4 +122,9 @@ public void onDelete(@NonNull PopUpSite item) {

};

@Override
protected SettingViewType getType() {
return SettingViewType.POPUP_EXCEPTIONS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class PrivacyOptionsView extends SettingsView {

private OptionsPrivacyBinding mBinding;
private ArrayList<Pair<SwitchSetting, String>> mPermissionButtons;
private SettingsView mPopUpsBlockingExceptions;

public PrivacyOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
super(aContext, aWidgetManager);
Expand Down Expand Up @@ -85,8 +84,6 @@ protected void updateUI() {
TextView permissionsTitleText = findViewById(R.id.permissionsTitle);
permissionsTitleText.setText(getContext().getString(R.string.security_options_permissions_title, getContext().getString(R.string.app_name)));

mPopUpsBlockingExceptions = new PopUpExceptionsOptionsView(getContext(), mWidgetManager);

mPermissionButtons = new ArrayList<>();
mPermissionButtons.add(Pair.create(findViewById(R.id.cameraPermissionSwitch), Manifest.permission.CAMERA));
mPermissionButtons.add(Pair.create(findViewById(R.id.microphonePermissionSwitch), Manifest.permission.RECORD_AUDIO));
Expand Down Expand Up @@ -128,7 +125,7 @@ protected void updateUI() {
mBinding.popUpsBlockingSwitch.setOnCheckedChangeListener(mPopUpsBlockingListener);
setPopUpsBlocking(SettingsStore.getInstance(getContext()).isPopUpsBlockingEnabled(), false);

mBinding.popUpsBlockingExceptionsButton.setOnClickListener(v -> mDelegate.showView(mPopUpsBlockingExceptions));
mBinding.popUpsBlockingExceptionsButton.setOnClickListener(v -> mDelegate.showView(SettingViewType.POPUP_EXCEPTIONS));

mBinding.restoreTabsSwitch.setOnCheckedChangeListener(mRestoreTabsListener);
setRestoreTabs(SettingsStore.getInstance(getContext()).isRestoreTabsEnabled(), false);
Expand Down Expand Up @@ -354,4 +351,9 @@ public void onActivityDestroyed(Activity activity) {
}
};

@Override
protected SettingViewType getType() {
return SettingViewType.PRIVACY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;

abstract class SettingsView extends FrameLayout {
public abstract class SettingsView extends FrameLayout {

public enum SettingViewType {
MAIN,
LANGUAGE,
LANGUAGE_DISPLAY,
LANGUAGE_CONTENT,
LANGUAGE_VOICE,
DISPLAY,
PRIVACY,
POPUP_EXCEPTIONS,
DEVELOPER,
FXA,
ENVIRONMENT,
CONTROLLER
}

protected Delegate mDelegate;
protected WidgetManagerDelegate mWidgetManager;
protected CustomScrollView mScrollbar;
Expand All @@ -23,7 +39,7 @@ public interface Delegate {
void exitWholeSettings();
void showRestartDialog();
void showAlert(String aTitle, String aMessage);
void showView(SettingsView view);
void showView(SettingsView.SettingViewType type);
}

public SettingsView(@NonNull Context context, WidgetManagerDelegate aWidgetManager) {
Expand Down Expand Up @@ -96,4 +112,6 @@ protected void updateUI() {
removeAllViews();
}

protected abstract SettingViewType getType();

}

0 comments on commit 78f5696

Please sign in to comment.