Skip to content

Commit

Permalink
Merge pull request brave#24425 from brave/android_tablet_no_tabs_ui_fix
Browse files Browse the repository at this point in the history
[C127] [Android] Fix for tablet overview UI with no tabs
  • Loading branch information
samartnik authored Jun 28, 2024
2 parents 70203ed + c283ef8 commit 8b1ea86
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;

import org.chromium.chrome.browser.toolbar.NewTabButton;
import org.chromium.chrome.browser.toolbar.R;
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarConfiguration;
import org.chromium.chrome.browser.toolbar.bottom.BottomToolbarVariationManager;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.ui.base.DeviceFormFactor;

public class BraveTabSwitcherModeTopToolbar extends TabSwitcherModeTopToolbar {
// To delete in bytecode, members from parent class will be used instead.
Expand All @@ -23,9 +28,34 @@ public class BraveTabSwitcherModeTopToolbar extends TabSwitcherModeTopToolbar {

// Own members.
private boolean mShouldShowNewTabButton;
private boolean mIsTablet;
private int mToolbarHeight;

public BraveTabSwitcherModeTopToolbar(Context context, AttributeSet attrs) {
super(context, attrs);

mIsTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(context);
// Tablets don't have bottom toolbar and thus should always show new tab button.
mShouldShowNewTabButton = mIsTablet;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

if (mIsTablet && mToolbarHeight == 0) {
mToolbarHeight = getMeasuredHeight();
maybeUpdateEmptyStateView();
}
}

@Override
void setTabSwitcherMode(boolean inTabSwitcherMode) {
super.setTabSwitcherMode(inTabSwitcherMode);

if (mIsTablet && inTabSwitcherMode && mToolbarHeight != 0) {
maybeUpdateEmptyStateView();
}
}

protected void updateNewTabButtonVisibility() {
Expand All @@ -45,9 +75,12 @@ protected boolean shouldShowIncognitoToggle() {
}

void onBottomToolbarVisibilityChanged(boolean isVisible) {
mShouldShowNewTabButton = !isVisible
|| (BottomToolbarConfiguration.isBottomToolbarEnabled()
&& !BottomToolbarVariationManager.isNewTabButtonOnBottom());
if (mIsTablet) return;

mShouldShowNewTabButton =
!isVisible
|| (BottomToolbarConfiguration.isBottomToolbarEnabled()
&& !BottomToolbarVariationManager.isNewTabButtonOnBottom());
updateNewTabButtonVisibility();
}

Expand All @@ -56,4 +89,22 @@ public int getToolbarColorForCurrentState() {
// browsing mode is still visible in tab switching mode with stack layout.
return ChromeColors.getPrimaryBackgroundColor(getContext(), mIsIncognito);
}

private void maybeUpdateEmptyStateView() {
if (!mIsTablet) return;

// Adjust empty state view top margin to not cover the top toolbar and keep its buttons
// clickable.
ViewParent parentView = getParent();
assert parentView instanceof ViewGroup : "Something has changed in the upstream code!";
if (parentView instanceof ViewGroup) {
View emptyView = ((ViewGroup) parentView).findViewById(R.id.empty_state_container);
if (emptyView != null) {
FrameLayout.LayoutParams emptyViewParams =
(FrameLayout.LayoutParams) emptyView.getLayoutParams();
emptyViewParams.topMargin = mToolbarHeight;
emptyView.setLayoutParams(emptyViewParams);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@
android:paddingEnd="16dp"
android:contentDescription="@string/accessibility_toolbar_btn_new_tab" />

<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_gravity="center"
android:scaleType="centerInside"
app:srcCompat="@drawable/google_logo"
android:visibility="gone"
android:contentDescription="@null"/>

<ViewStub
android:id="@+id/incognito_tabs_stub"
android:inflatedId="@+id/incognito_toggle_tabs"
Expand Down

0 comments on commit 8b1ea86

Please sign in to comment.