Made wrapping behaviour of long names and long content warnings better on timelines.

This commit is contained in:
Vavassor 2017-02-01 17:01:34 -05:00
parent cad060282b
commit 887e68700a
3 changed files with 106 additions and 11 deletions

View file

@ -0,0 +1,90 @@
package com.keylesspalace.tusky;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
public class FlowLayout extends ViewGroup {
private int paddingHorizontal; // internal padding between child views
private int paddingVertical; //
private int totalHeight;
public FlowLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.FlowLayout, 0, 0);
try {
paddingHorizontal = a.getDimensionPixelSize(
R.styleable.FlowLayout_paddingHorizontal, 0);
paddingVertical = a.getDimensionPixelSize(R.styleable.FlowLayout_paddingVertical, 0);
} finally {
a.recycle();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
assert (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED);
int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight();
int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom();
int count = getChildCount();
int x = getPaddingLeft();
int y = getPaddingTop();
int childHeightMeasureSpec;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
} else {
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
totalHeight = 0;
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
childHeightMeasureSpec);
int childwidth = child.getMeasuredWidth();
totalHeight = Math.max(totalHeight, child.getMeasuredHeight() + paddingVertical);
if (x + childwidth > width) {
x = getPaddingLeft();
y += totalHeight;
}
x += childwidth + paddingHorizontal;
}
}
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) {
height = y + totalHeight;
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
if (y + totalHeight < height) {
height = y + totalHeight;
}
}
height += 5; // Fudge to avoid clipping bottom of last row.
setMeasuredDimension(width, height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int width = r - l;
int x = getPaddingLeft();
int y = getPaddingTop();
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
int childWidth = child.getMeasuredWidth();
int childHeight = child.getMeasuredHeight();
if (x + childWidth > width) {
x = getPaddingLeft();
y += totalHeight;
}
child.layout(x, y, x + childWidth, y + childHeight);
x += childWidth + paddingHorizontal;
}
}
}
}

View file

@ -39,8 +39,7 @@
android:layout_below="@+id/status_boosted"
android:padding="@dimen/status_avatar_padding" />
<LinearLayout
android:orientation="horizontal"
<com.keylesspalace.tusky.FlowLayout
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/status_avatar"
android:layout_toEndOf="@+id/status_avatar"
@ -59,20 +58,19 @@
android:id="@+id/status_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/status_username_left_margin" />
android:paddingLeft="@dimen/status_username_left_margin" />
<TextView
android:id="@+id/status_since_created"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/status_since_created_left_margin" />
android:paddingLeft="@dimen/status_since_created_left_margin" />
</LinearLayout>
</com.keylesspalace.tusky.FlowLayout>
<LinearLayout
<com.keylesspalace.tusky.FlowLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/status_content_warning_bar"
android:visibility="gone"
android:layout_toRightOf="@+id/status_avatar"
@ -83,7 +81,8 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/status_content_warning_description" />
android:id="@+id/status_content_warning_description"
android:paddingRight="8dp"/>
<ToggleButton
android:layout_width="wrap_content"
@ -94,10 +93,9 @@
android:textOn="@string/status_content_warning_show_less"
android:textOff="@string/status_content_warning_show_more"
android:background="@drawable/toggle_small"
android:padding="4dp"
android:layout_marginLeft="8dp"/>
android:padding="4dp" />
</LinearLayout>
</com.keylesspalace.tusky.FlowLayout>
<TextView
android:id="@+id/status_content"

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="FlowLayout">
<attr name="paddingHorizontal" format="dimension" />
<attr name="paddingVertical" format="dimension" />
</declare-styleable>
</resources>