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

Commit

Permalink
take switcher width into account for button
Browse files Browse the repository at this point in the history
  • Loading branch information
sk22 committed Oct 20, 2023
1 parent 11c7816 commit 303461d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,25 @@ public void onPageSelected(int position){

ViewTreeObserver vto = getToolbar().getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnGlobalLayoutListener(() -> {
Toolbar t = getToolbar();
if (t == null) return;
int toolbarWidth = t.getWidth();
if (toolbarWidth == 0) return;

int toolbarFrameWidth = toolbarFrame.getWidth();
int padding = toolbarWidth - toolbarFrameWidth;
FrameLayout parent = ((FrameLayout) toolbarShowNewPostsBtn.getParent());
if (padding == parent.getPaddingStart()) return;
vto.addOnGlobalLayoutListener(()->{
Toolbar t=getToolbar();
if(t==null) return;
int toolbarWidth=t.getWidth();
if(toolbarWidth==0) return;

int toolbarFrameWidth=toolbarFrame.getWidth();
int actionsWidth=toolbarWidth-toolbarFrameWidth;
// margin (4) + padding (12) + icon (24) + margin (8) + chevron (16) + padding (12)
int switcherWidth=V.dp(76);
FrameLayout parent=((FrameLayout) toolbarShowNewPostsBtn.getParent());
if(actionsWidth==parent.getPaddingStart()) return;
int paddingMax=Math.max(actionsWidth, switcherWidth);
int paddingEnd=(Math.max(0, switcherWidth-actionsWidth));

// toolbar frame goes from screen edge to beginning of right-aligned option buttons.
// centering button by applying the same space on the left
parent.setPaddingRelative(padding, 0, 0, 0);
toolbarShowNewPostsBtn.setMaxWidth(toolbarWidth - padding * 2);
parent.setPaddingRelative(paddingMax, 0, paddingEnd, 0);
toolbarShowNewPostsBtn.setMaxWidth(toolbarWidth-paddingMax*2);

switcher.setPivotX(V.dp(28)); // padding + half of icon
switcher.setPivotY(switcher.getHeight() / 2f);
Expand Down
3 changes: 1 addition & 2 deletions mastodon/src/main/res/layout/home_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/bg_button_m3_tonal_selector"
android:maxLines="2"
android:maxLines="1"
android:ellipsize="end"
android:lineSpacingMultiplier="0.8"
android:textAppearance="@style/m3_title_medium"
android:text="@string/see_new_posts"
android:drawableStart="@drawable/ic_fluent_arrow_up_16_filled"
Expand Down

0 comments on commit 303461d

Please sign in to comment.