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

Commit

Permalink
Fix for the what's configuration change issue (#3536)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored Jun 24, 2020
1 parent 71aabd0 commit 64db2d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public NavigationURLBar(Context context, AttributeSet attrs) {

@SuppressLint("ClickableViewAccessibility")
private void initialize(Context aContext) {
mSettingsViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(SettingsViewModel.class);

mAudio = AudioEngine.fromContext(aContext);

mUIThreadExecutor = ((VRBrowserApplication)getContext().getApplicationContext()).getExecutors().mainThread();
Expand All @@ -120,6 +125,7 @@ private void initialize(Context aContext) {
// Layout setup
mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.navigation_url, this, true);
mBinding.setLifecycleOwner((VRBrowserActivity)getContext());
mBinding.setSettingsViewmodel(mSettingsViewModel);

// Use Domain autocomplete provider from components
mAutocompleteProvider = new ShippedDomainsProvider();
Expand Down Expand Up @@ -239,25 +245,15 @@ public void detachFromWindow() {
mViewModel.getIsBookmarked().removeObserver(mIsBookmarkedObserver);
mViewModel = null;
}
if (mSettingsViewModel != null) {
mSettingsViewModel = null;
}
}

public void attachToWindow(@NonNull WindowWidget aWindow) {
mViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(String.valueOf(aWindow.hashCode()), WindowViewModel.class);
mSettingsViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(SettingsViewModel.class);

mBinding.setViewmodel(mViewModel);
mBinding.setSettingsViewmodel(mSettingsViewModel);

mSettingsViewModel.refresh();

mViewModel.getIsLoading().observe((VRBrowserActivity)getContext(), mIsLoadingObserver);
mViewModel.getIsBookmarked().observe((VRBrowserActivity)getContext(), mIsBookmarkedObserver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ private void initialize(@NonNull Context aContext) {
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(TrayViewModel.class);
mSettingsViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(SettingsViewModel.class);

updateUI();

Expand Down Expand Up @@ -189,6 +193,7 @@ private void updateUI() {
mBinding = DataBindingUtil.inflate(inflater, R.layout.navigation_bar, this, true);
mBinding.setLifecycleOwner((VRBrowserActivity)getContext());
mBinding.setViewmodel(mViewModel);
mBinding.setSettingsmodel(mSettingsViewModel);

mBinding.navigationBarNavigation.backButton.setOnClickListener(v -> {
v.requestFocusFromTouch();
Expand Down Expand Up @@ -424,6 +429,8 @@ public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

updateUI();

mSettingsViewModel.refresh();
}

@Override
Expand Down Expand Up @@ -521,10 +528,6 @@ public void detachFromWindow() {
mViewModel.getIsPopUpBlocked().removeObserver(mIsPopUpBlockedListener);
mViewModel = null;
}

if (mSettingsViewModel != null) {
mSettingsViewModel = null;
}
}

@Override
Expand All @@ -541,15 +544,8 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(String.valueOf(mAttachedWindow.hashCode()), WindowViewModel.class);
mSettingsViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(SettingsViewModel.class);

mBinding.setViewmodel(mViewModel);
mBinding.setSettingsmodel(mSettingsViewModel);

mSettingsViewModel.refresh();

mViewModel.getIsActiveWindow().observeForever(mIsActiveWindowObserver);
mViewModel.getIsPopUpBlocked().observeForever(mIsPopUpBlockedListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public SettingsWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {

@SuppressLint("ClickableViewAccessibility")
private void initialize() {
mSettingsViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(SettingsViewModel.class);

updateUI();

mOpenDialog = SettingsView.SettingViewType.MAIN;
Expand All @@ -129,12 +134,6 @@ public void updateUI() {

// Inflate this data binding layout
mBinding = DataBindingUtil.inflate(inflater, R.layout.settings, this, true);

mSettingsViewModel = new ViewModelProvider(
(VRBrowserActivity)getContext(),
ViewModelProvider.AndroidViewModelFactory.getInstance(((VRBrowserActivity) getContext()).getApplication()))
.get(SettingsViewModel.class);

mBinding.setSettingsmodel(mSettingsViewModel);

mBinding.backButton.setOnClickListener(v -> {
Expand Down

0 comments on commit 64db2d4

Please sign in to comment.