Skip to content

Commit

Permalink
Enable back button that can go back to New Tab and some redundant cha…
Browse files Browse the repository at this point in the history
…nges that need to be fixed in next commit
  • Loading branch information
haanhvu committed Nov 22, 2024
1 parent bd3c647 commit a61e93d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -788,14 +788,22 @@ public boolean isInputActive() {
return mState.mIsInputActive;
}

public void setCanGoBackForNewTab() {
mState.mCanGoBack = true;
}

public boolean canGoBack() {
if (mState.mCanGoBack || isInFullScreen()) {
Log.e("New Tab PR", "Session canGoBack() - First case (mState.mCanGoBack): true");
return true;
}
if (mState.mParentId != null) {
Session parent = SessionStore.get().getSession(mState.mParentId);
Log.e("New Tab PR", "Session canGoBack() - Second case - parent != null: " + (parent != null));
Log.e("New Tab PR", "Session canGoBack() - Second case - parent.mState.mDisplay == null: " + (parent.mState.mDisplay == null));
return parent != null && parent.mState.mDisplay == null;
}
Log.e("New Tab PR", "Session canGoBack() - Third case: false");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.TypedValue;
import android.webkit.URLUtil;

Expand Down Expand Up @@ -697,6 +698,7 @@ public MutableLiveData<ObservableBoolean> getCanGoBack() {
}

public void setCanGoBack(boolean canGoBack) {
Log.e("New Tab PR", "canGoBack: " + canGoBack);
this.canGoBack.postValue(new ObservableBoolean(canGoBack));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public interface NavigationListener {
private WidgetPlacement mBeforeFullscreenPlacement;
private float mSavedCylinderDensity = 0.0f;
private Animation mAnimation;
public boolean setBackButtonForNewTab;

private class MoveTouchListener implements OnTouchListener {
@Override
Expand Down Expand Up @@ -240,9 +241,16 @@ private void updateUI() {

mBinding.navigationBarFullscreen.fullScreenModeContainer.setVisibility(View.GONE);

if (setBackButtonForNewTab) {
mBinding.navigationBarNavigation.backButton.setEnabled(true);
}
mBinding.navigationBarNavigation.backButton.setOnClickListener(v -> {
v.requestFocusFromTouch();

if (setBackButtonForNewTab) {
mAttachedWindow.showNewTab();
}

if (getSession().canGoBack()) {
getSession().goBack();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ public void showPanel(@Windows.PanelType int panelType) {
}

public void showNewTab() {
hidePanel();
if (mNewTab != null) {
hidePanel();
setView(mNewTab, true);
mViewModel.setIsFindInPage(false);
mViewModel.setIsNewTabVisible(true);
Expand All @@ -544,6 +544,9 @@ public void showNewTab() {
}
};
}
mViewModel.setCanGoBack(true);
mWidgetManager.getNavigationBar().setBackButtonForNewTab = true;
mSession.setCanGoBackForNewTab();
}
}

Expand Down Expand Up @@ -592,7 +595,7 @@ private void hidePanel(boolean switchSurface) {
public void hideNewTab() {
if (mViewModel.getIsNewTabVisible().getValue().get()) {
hideNewTab(true);
mViewModel.setIsNewTabVisible(false);
//mViewModel.setIsNewTabVisible(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/navigation_bar_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
android:src="@drawable/ic_icon_back"
android:tint="@color/midnight"
android:tooltipText="@string/back_tooltip"
android:enabled="@{viewmodel.canGoBack}"
android:enabled="@{viewmodel.canGoBack || viewmodel.isNewTabVisible}"
app:privateMode="@{viewmodel.isPrivateSession}" />

<com.igalia.wolvic.ui.views.UIButton
Expand Down

0 comments on commit a61e93d

Please sign in to comment.