fix centering button in rtl

This commit is contained in:
sk 2023-01-16 16:15:35 +01:00 committed by LucasGGamerM
parent e12c3e2d68
commit 4e17256cfa
1 changed files with 24 additions and 9 deletions

View File

@ -19,6 +19,7 @@ import android.view.SubMenu;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.widget.Button; import android.widget.Button;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
@ -207,6 +208,26 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
error.showToast(getContext()); error.showToast(getContext());
} }
}).exec(accountID); }).exec(accountID);
ViewTreeObserver vto = view.getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
HomeTabFragment.this.onGlobalLayout();
}
});
}
}
private void onGlobalLayout() {
switcher.setPivotX(V.dp(28)); // padding + half of icon
switcher.setPivotY(switcher.getHeight() / 2f);
// toolbar frame goes from screen edge to beginning of right-aligned option buttons.
// centering button by applying the same space on the left
int padding = getToolbar().getWidth() - toolbarFrame.getWidth();
((FrameLayout) toolbarShowNewPostsBtn.getParent()).setPaddingRelative(padding, 0, 0, 0);
} }
public void updateToolbarLogo(){ public void updateToolbarLogo(){
@ -231,15 +252,6 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N) UiUtils.fixCompoundDrawableTintOnAndroid6(toolbarShowNewPostsBtn); if(Build.VERSION.SDK_INT<Build.VERSION_CODES.N) UiUtils.fixCompoundDrawableTintOnAndroid6(toolbarShowNewPostsBtn);
toolbarShowNewPostsBtn.setOnClickListener(this::onNewPostsBtnClick); toolbarShowNewPostsBtn.setOnClickListener(this::onNewPostsBtnClick);
toolbar.post(() -> {
// toolbar frame goes from screen edge to beginning of right-aligned option buttons.
// centering button by applying the same space on the left
int padding = toolbar.getWidth() - toolbarFrame.getWidth();
((FrameLayout) toolbarShowNewPostsBtn.getParent()).setPadding(padding, 0, 0, 0);
switcher.setPivotX(V.dp(28)); // padding + half of icon
switcher.setPivotY(switcher.getHeight() / 2f);
});
if(newPostsBtnShown){ if(newPostsBtnShown){
toolbarShowNewPostsBtn.setVisibility(View.VISIBLE); toolbarShowNewPostsBtn.setVisibility(View.VISIBLE);
collapsedChevron.setVisibility(View.VISIBLE); collapsedChevron.setVisibility(View.VISIBLE);
@ -255,6 +267,8 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
toolbarShowNewPostsBtn.setScaleY(.8f); toolbarShowNewPostsBtn.setScaleY(.8f);
timelineTitle.setVisibility(View.VISIBLE); timelineTitle.setVisibility(View.VISIBLE);
} }
showNewPostsButton();
} }
@Override @Override
@ -376,6 +390,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
} }
public void hideNewPostsButton(){ public void hideNewPostsButton(){
if (true) return;
if(!newPostsBtnShown) if(!newPostsBtnShown)
return; return;
newPostsBtnShown=false; newPostsBtnShown=false;