Fixes long content warnings in posts wasting space. Closes #173
This commit is contained in:
parent
85f7b16736
commit
94639eeb69
1 changed files with 20 additions and 15 deletions
|
@ -26,7 +26,6 @@ import com.keylesspalace.tusky.R;
|
||||||
public class FlowLayout extends ViewGroup {
|
public class FlowLayout extends ViewGroup {
|
||||||
private int paddingHorizontal; // internal padding between child views
|
private int paddingHorizontal; // internal padding between child views
|
||||||
private int paddingVertical; //
|
private int paddingVertical; //
|
||||||
private int totalHeight;
|
|
||||||
|
|
||||||
public FlowLayout(Context context, AttributeSet attrs) {
|
public FlowLayout(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
|
@ -34,11 +33,10 @@ public class FlowLayout extends ViewGroup {
|
||||||
|
|
||||||
public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
|
public FlowLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
TypedArray a = context.getTheme().obtainStyledAttributes(
|
TypedArray a = context.getTheme()
|
||||||
attrs, R.styleable.FlowLayout, 0, 0);
|
.obtainStyledAttributes(attrs, R.styleable.FlowLayout, 0, 0);
|
||||||
try {
|
try {
|
||||||
paddingHorizontal = a.getDimensionPixelSize(
|
paddingHorizontal = a.getDimensionPixelSize(R.styleable.FlowLayout_paddingHorizontal, 0);
|
||||||
R.styleable.FlowLayout_paddingHorizontal, 0);
|
|
||||||
paddingVertical = a.getDimensionPixelSize(R.styleable.FlowLayout_paddingVertical, 0);
|
paddingVertical = a.getDimensionPixelSize(R.styleable.FlowLayout_paddingVertical, 0);
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
@ -59,26 +57,29 @@ public class FlowLayout extends ViewGroup {
|
||||||
} else {
|
} else {
|
||||||
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||||
}
|
}
|
||||||
totalHeight = 0;
|
int rowHeight = 0;
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
View child = getChildAt(i);
|
View child = getChildAt(i);
|
||||||
if (child.getVisibility() != GONE) {
|
if (child.getVisibility() != GONE) {
|
||||||
child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
|
int widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
|
||||||
childHeightMeasureSpec);
|
child.measure(widthSpec, childHeightMeasureSpec);
|
||||||
int childwidth = child.getMeasuredWidth();
|
int childwidth = child.getMeasuredWidth();
|
||||||
totalHeight = Math.max(totalHeight, child.getMeasuredHeight() + paddingVertical);
|
int childHeight = child.getMeasuredHeight();
|
||||||
if (x + childwidth > width) {
|
if (x + childwidth > width) {
|
||||||
x = getPaddingLeft();
|
x = getPaddingLeft();
|
||||||
y += totalHeight;
|
y += rowHeight;
|
||||||
|
rowHeight = childHeight + paddingVertical;
|
||||||
|
} else {
|
||||||
|
rowHeight = Math.max(rowHeight, childHeight + paddingVertical);
|
||||||
}
|
}
|
||||||
x += childwidth + paddingHorizontal;
|
x += childwidth + paddingHorizontal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) {
|
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) {
|
||||||
height = y + totalHeight;
|
height = y + rowHeight;
|
||||||
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
|
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
|
||||||
if (y + totalHeight < height) {
|
if (y + rowHeight < height) {
|
||||||
height = y + totalHeight;
|
height = y + rowHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
height += 5; // Fudge to avoid clipping bottom of last row.
|
height += 5; // Fudge to avoid clipping bottom of last row.
|
||||||
|
@ -90,6 +91,7 @@ public class FlowLayout extends ViewGroup {
|
||||||
final int width = r - l;
|
final int width = r - l;
|
||||||
int x = getPaddingLeft();
|
int x = getPaddingLeft();
|
||||||
int y = getPaddingTop();
|
int y = getPaddingTop();
|
||||||
|
int rowHeight = 0;
|
||||||
for (int i = 0; i < getChildCount(); i++) {
|
for (int i = 0; i < getChildCount(); i++) {
|
||||||
View child = getChildAt(i);
|
View child = getChildAt(i);
|
||||||
if (child.getVisibility() != GONE) {
|
if (child.getVisibility() != GONE) {
|
||||||
|
@ -97,7 +99,10 @@ public class FlowLayout extends ViewGroup {
|
||||||
int childHeight = child.getMeasuredHeight();
|
int childHeight = child.getMeasuredHeight();
|
||||||
if (x + childWidth > width) {
|
if (x + childWidth > width) {
|
||||||
x = getPaddingLeft();
|
x = getPaddingLeft();
|
||||||
y += totalHeight;
|
y += rowHeight;
|
||||||
|
rowHeight = childHeight + paddingVertical;
|
||||||
|
} else {
|
||||||
|
rowHeight = Math.max(childHeight, rowHeight);
|
||||||
}
|
}
|
||||||
child.layout(x, y, x + childWidth, y + childHeight);
|
child.layout(x, y, x + childWidth, y + childHeight);
|
||||||
x += childWidth + paddingHorizontal;
|
x += childWidth + paddingHorizontal;
|
||||||
|
|
Loading…
Reference in a new issue