From 303461d8038bf9badbbd6327a26573b25ed57d35 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 20 Oct 2023 12:17:12 +0200 Subject: [PATCH] take switcher width into account for button --- .../android/fragments/HomeTabFragment.java | 28 +++++++++++-------- mastodon/src/main/res/layout/home_toolbar.xml | 3 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index 2488e7452e..85a79b7edb 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -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); diff --git a/mastodon/src/main/res/layout/home_toolbar.xml b/mastodon/src/main/res/layout/home_toolbar.xml index 9587bec324..599077613e 100644 --- a/mastodon/src/main/res/layout/home_toolbar.xml +++ b/mastodon/src/main/res/layout/home_toolbar.xml @@ -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"