Fix z-order and remove V.dp from more custom views

This commit is contained in:
Grishka 2023-03-22 16:55:09 +03:00
parent e5d60050a2
commit 477a691c9e
6 changed files with 63 additions and 15 deletions

View File

@ -69,6 +69,7 @@ import org.joinmastodon.android.ui.text.CustomEmojiSpan;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.ui.views.CoverImageView;
import org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout;
import org.joinmastodon.android.ui.views.NestedRecyclerScrollView;
import org.joinmastodon.android.ui.views.ProgressBarButton;
import org.joinmastodon.android.utils.ElevationOnScrollListener;
@ -125,6 +126,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private View nameEditWrap, bioEditWrap;
private View tabsDivider;
private View actionButtonWrap;
private CustomDrawingOrderLinearLayout scrollableContent;
private Account account;
private String accountID;
@ -204,6 +206,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
countersLayout=content.findViewById(R.id.profile_counters);
tabsDivider=content.findViewById(R.id.tabs_divider);
actionButtonWrap=content.findViewById(R.id.profile_action_btn_wrap);
scrollableContent=content.findViewById(R.id.scrollable_content);
avatar.setOutlineProvider(OutlineProviders.roundedRect(24));
avatar.setClipToOutline(true);
@ -288,6 +291,14 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
return true;
});
scrollableContent.setDrawingOrderCallback((count, pos)->{
// The header is the first child, draw it last to overlap everything for the photo viewer transition to look nice
if(pos==count-1)
return 0;
// Offset the order of other child views to compensate
return pos+1;
});
return sizeWrapper;
}

View File

@ -79,6 +79,7 @@ import androidx.recyclerview.widget.util.Pools;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import me.grishka.appkit.utils.CubicBezierInterpolator;
import me.grishka.appkit.utils.CustomViewHelper;
import me.grishka.appkit.utils.V;
import java.lang.annotation.Retention;
@ -157,7 +158,7 @@ import java.util.Iterator;
* @attr ref com.google.android.material.R.styleable#TabLayout_tabTextAppearance
*/
@ViewPager.DecorView
public class TabLayout extends HorizontalScrollView {
public class TabLayout extends HorizontalScrollView implements CustomViewHelper{
private static final CubicBezierInterpolator FAST_OUT_SLOW_IN_INTERPOLATOR=new CubicBezierInterpolator(.4f, 0f, .2f, 1f);
private static final int DEF_STYLE_RES = R.style.Widget_Design_TabLayout;
@ -1657,7 +1658,7 @@ public class TabLayout extends HorizontalScrollView {
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// If we have a MeasureSpec which allows us to decide our height, try and use the default
// height
final int idealHeight = Math.round(V.dp(getDefaultHeight()));
final int idealHeight = Math.round(dp(getDefaultHeight()));
switch (MeasureSpec.getMode(heightMeasureSpec)) {
case MeasureSpec.AT_MOST:
if (getChildCount() == 1 && MeasureSpec.getSize(heightMeasureSpec) >= idealHeight) {
@ -1680,7 +1681,7 @@ public class TabLayout extends HorizontalScrollView {
tabMaxWidth =
requestedTabMaxWidth > 0
? requestedTabMaxWidth
: (int) (specWidth - V.dp(TAB_MIN_WIDTH_MARGIN));
: (int) (specWidth - dp(TAB_MIN_WIDTH_MARGIN));
}
// Now super measure itself using the (possibly) modified height spec
@ -2842,7 +2843,7 @@ public class TabLayout extends HorizontalScrollView {
int iconMargin = 0;
if (hasText && iconView.getVisibility() == VISIBLE) {
// If we're showing both text and icon, add some margin bottom to the icon
iconMargin = (int) V.dp(DEFAULT_GAP_TEXT_ICON);
iconMargin = (int) dp(DEFAULT_GAP_TEXT_ICON);
}
if (inlineLabel) {
if (iconMargin != lp.getMarginEnd()) {
@ -3043,7 +3044,7 @@ public class TabLayout extends HorizontalScrollView {
return;
}
final int gutter = (int) V.dp(FIXED_WRAP_GUTTER_MIN);
final int gutter = (int) dp(FIXED_WRAP_GUTTER_MIN);
boolean remeasure = false;
if (largestTabWidth * count <= getMeasuredWidth() - gutter * 2) {

View File

@ -0,0 +1,5 @@
package org.joinmastodon.android.ui.views;
public interface ChildDrawingOrderCallback{
int getChildDrawingOrder(int childCount, int drawingPosition);
}

View File

@ -0,0 +1,33 @@
package org.joinmastodon.android.ui.views;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class CustomDrawingOrderLinearLayout extends LinearLayout{
private ChildDrawingOrderCallback drawingOrderCallback;
public CustomDrawingOrderLinearLayout(Context context){
this(context, null);
}
public CustomDrawingOrderLinearLayout(Context context, AttributeSet attrs){
this(context, attrs, 0);
}
public CustomDrawingOrderLinearLayout(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
setChildrenDrawingOrderEnabled(true);
}
@Override
protected int getChildDrawingOrder(int childCount, int drawingPosition){
if(drawingOrderCallback!=null)
return drawingOrderCallback.getChildDrawingOrder(childCount, drawingPosition);
return super.getChildDrawingOrder(childCount, drawingPosition);
}
public void setDrawingOrderCallback(ChildDrawingOrderCallback drawingOrderCallback){
this.drawingOrderCallback=drawingOrderCallback;
}
}

View File

@ -35,9 +35,9 @@ import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import me.grishka.appkit.utils.CubicBezierInterpolator;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.utils.CustomViewHelper;
public class FloatingHintEditTextLayout extends FrameLayout{
public class FloatingHintEditTextLayout extends FrameLayout implements CustomViewHelper{
private EditText edit;
private TextView label;
private int labelTextSize;
@ -60,10 +60,8 @@ public class FloatingHintEditTextLayout extends FrameLayout{
public FloatingHintEditTextLayout(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
if(isInEditMode())
V.setApplicationContext(context);
TypedArray ta=context.obtainStyledAttributes(attrs, R.styleable.FloatingHintEditTextLayout);
labelTextSize=ta.getDimensionPixelSize(R.styleable.FloatingHintEditTextLayout_android_labelTextSize, V.dp(12));
labelTextSize=ta.getDimensionPixelSize(R.styleable.FloatingHintEditTextLayout_android_labelTextSize, dp(12));
offsetY=ta.getDimensionPixelOffset(R.styleable.FloatingHintEditTextLayout_editTextOffsetY, 0);
labelColors=ta.getColorStateList(R.styleable.FloatingHintEditTextLayout_labelTextColor);
ta.recycle();
@ -103,7 +101,7 @@ public class FloatingHintEditTextLayout extends FrameLayout{
errorView.setTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3OnSurfaceVariant));
errorView.setLinkTextColor(UiUtils.getThemeColor(getContext(), R.attr.colorM3Primary));
errorView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
errorView.setPadding(V.dp(16), V.dp(4), V.dp(16), 0);
errorView.setPadding(dp(16), dp(4), dp(16), 0);
errorView.setVisibility(View.GONE);
addView(errorView);
}
@ -187,7 +185,7 @@ public class FloatingHintEditTextLayout extends FrameLayout{
public void onDrawForeground(Canvas canvas){
if(getForeground()!=null && animProgress>0){
canvas.save();
float width=(label.getWidth()+V.dp(8))*animProgress;
float width=(label.getWidth()+dp(8))*animProgress;
float centerX=label.getLeft()+label.getWidth()/2f;
tmpRect.set(centerX-width/2f, label.getTop(), centerX+width/2f, label.getBottom());
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
@ -347,7 +345,7 @@ public class FloatingHintEditTextLayout extends FrameLayout{
@Override
protected void onBoundsChange(@NonNull Rect bounds){
super.onBoundsChange(bounds);
int offset=V.dp(12);
int offset=dp(12);
wrapped.setBounds(edit.getLeft()-offset, edit.getTop()-offset, edit.getRight()+offset, edit.getBottom()+offset);
}
}

View File

@ -16,7 +16,7 @@
android:layout_height="match_parent"
android:nestedScrollingEnabled="true">
<LinearLayout
<org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout
android:id="@+id/scrollable_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -316,7 +316,7 @@
android:background="?colorM3SurfaceVariant"/>
</FrameLayout>
</LinearLayout>
</org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout>
</org.joinmastodon.android.ui.views.NestedRecyclerScrollView>
<ImageButton