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

Commit

Permalink
Merge pull request #871 from MozillaReality/private-state-restore
Browse files Browse the repository at this point in the history
Fixes #671 Tray doesn't indicate private icon on when restoring
  • Loading branch information
cvan authored Nov 29, 2018
2 parents 1120148 + 3a38f64 commit d2f7e44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.geckoview.WebRequestError;
import org.mozilla.vrbrowser.*;
import org.mozilla.vrbrowser.audio.AudioEngine;
Expand Down Expand Up @@ -309,6 +308,8 @@ else if (SessionStore.get().canUnstackSession())
mPrefs = PreferenceManager.getDefaultSharedPreferences(mAppContext);
mPrefs.registerOnSharedPreferenceChangeListener(this);
updateServoButton();

handleSessionState();
}

@Override
Expand Down Expand Up @@ -557,6 +558,15 @@ private void closeFloatingMenus() {
}
}

private void handleSessionState() {
boolean isPrivateMode = SessionStore.get().isCurrentSessionPrivate();

mURLBar.setPrivateMode(isPrivateMode);
for (CustomUIButton button : mButtons) {
button.setPrivateMode(isPrivateMode);
}
}

@Override
public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @NonNull String aUri) {
return null;
Expand Down Expand Up @@ -759,12 +769,8 @@ public void onRemoveSession(GeckoSession aSession, int aId) {

@Override
public void onCurrentSessionChange(GeckoSession aSession, int aId) {
boolean isPrivateMode = aSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
mURLBar.setPrivateMode(isPrivateMode);
handleSessionState();

for (CustomUIButton button : mButtons) {
button.setPrivateMode(isPrivateMode);
}
boolean isFullScreen = SessionStore.get().isInFullScreen(aSession);
if (isFullScreen && !mIsInFullScreenMode) {
enterFullScreenMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.util.AttributeSet;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.SessionStore;
Expand Down Expand Up @@ -52,6 +51,8 @@ private void initialize(Context aContext) {

SessionStore.get().addSessionChangeListener(this);
mWidgetManager.addUpdateListener(this);

handleSessionState();
}

@Override
Expand Down Expand Up @@ -97,9 +98,7 @@ public void onRemoveSession(GeckoSession aSession, int aId) {

@Override
public void onCurrentSessionChange(GeckoSession aSession, int aId) {
boolean isPrivateMode = aSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
setVisible(isPrivateMode);
mCloseButton.setPrivateMode(isPrivateMode);
handleSessionState();
}

@Override
Expand All @@ -112,6 +111,12 @@ public void setVisible(boolean isVisible) {
mWidgetManager.removeWidget(this);
}

private void handleSessionState() {
boolean isPrivateMode = SessionStore.get().isCurrentSessionPrivate();
setVisible(isPrivateMode);
mCloseButton.setPrivateMode(isPrivateMode);
}

// WidgetManagerDelegate.UpdateListener
@Override
public void onWidgetUpdate(Widget aWidget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.view.animation.AccelerateDecelerateInterpolator;

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.SessionStore;
Expand Down Expand Up @@ -113,6 +112,8 @@ private void initialize(Context aContext) {
mIsLastSessionPrivate = false;

SessionStore.get().addSessionChangeListener(this);

handleSessionState();
}

private OnHoverListener mButtonScaleHoverListener = (view, motionEvent) -> {
Expand Down Expand Up @@ -218,16 +219,20 @@ public void onRemoveSession(GeckoSession aSession, int aId) {

@Override
public void onCurrentSessionChange(GeckoSession aSession, int aId) {
boolean isPrivateMode = aSession.getSettings().getBoolean(GeckoSessionSettings.USE_PRIVATE_MODE);
handleSessionState();
}

private void handleSessionState() {
boolean isPrivateMode = SessionStore.get().isCurrentSessionPrivate();

if (isPrivateMode != mIsLastSessionPrivate) {
mPrivateButton.setPrivateMode(isPrivateMode);
if (isPrivateMode) {
mWidgetManager.setWorldBrightness(null, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
mWidgetManager.pushWorldBrightness(this, WidgetManagerDelegate.DEFAULT_DIM_BRIGHTNESS);
mPrivateButton.setImageResource(R.drawable.ic_tray_private_on);

} else {
mWidgetManager.setWorldBrightness(null,1.0f);
mWidgetManager.popWorldBrightness(this);
mPrivateButton.setImageResource(R.drawable.ic_tray_private);
}
}
Expand Down

0 comments on commit d2f7e44

Please sign in to comment.