1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-05 11:07:36 +01:00

fixed tab measurement

This commit is contained in:
Mariotaku Lee 2016-02-26 00:03:02 +08:00
parent 8069111e51
commit a0d96a63e6
4 changed files with 22 additions and 15 deletions

View File

@ -61,7 +61,7 @@ public abstract class AbsParcelableStatusesAdapter extends AbsStatusesAdapter<Li
@Override
public long getItemId(int adapterPosition) {
int dataPosition = adapterPosition - getStatusStartIndex();
if (dataPosition < 0 || dataPosition >= getStatusCount()) return RecyclerView.NO_ID;
if (dataPosition < 0 || dataPosition >= getStatusCount()) return adapterPosition;
if (mData instanceof ObjectCursor) {
final Cursor cursor = ((ObjectCursor) mData).getCursor(dataPosition);
final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData).getIndices();

View File

@ -287,7 +287,7 @@ public abstract class AbsActivitiesFragment<Data> extends AbsContentListRecycler
// The last activity is activityEndExclusiveIndex - 1
final int activityEndExclusiveIndex = activityStartIndex + adapter.getActivityCount();
if (activityEndExclusiveIndex >= 0) {
if (activityEndExclusiveIndex >= 0 && rememberPosition && tag != null) {
final long lastItemId = adapter.getTimestamp(activityEndExclusiveIndex);
// Activity corresponds to last read timestamp was deleted, use last item timestamp
// instead

View File

@ -273,7 +273,7 @@ public abstract class AbsStatusesFragment<Data> extends AbsContentListRecyclerVi
final int statusStartIndex = adapter.getStatusStartIndex();
// The last status is statusEndExclusiveIndex - 1
final int statusEndExclusiveIndex = statusStartIndex + adapter.getStatusCount();
if (statusEndExclusiveIndex >= 0) {
if (statusEndExclusiveIndex >= 0 && rememberPosition && tag != null) {
final long lastItemId = adapter.getStatusId(statusEndExclusiveIndex - 1);
// Status corresponds to last read id was deleted, use last item id instead
if (lastItemId > 0 && lastReadId < lastItemId) {

View File

@ -51,7 +51,6 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
private OnPageChangeListener mPageChangeListener;
private int mOption;
private boolean mTabExpandEnabled;
private int mHorizontalPadding, mVerticalPadding;
private int mColumns;
@ -65,7 +64,7 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
ViewCompat.setOverScrollMode(this, ViewCompat.OVER_SCROLL_NEVER);
setHorizontalScrollBarEnabled(false);
setVerticalScrollBarEnabled(false);
setLayoutManager(mLayoutManager = new TabLayoutManager(this));
setLayoutManager(mLayoutManager = new TabLayoutManager(context));
setItemContext(context);
setAdapter(mIndicatorAdapter);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPagerIndicator);
@ -240,11 +239,11 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
}
private boolean isTabExpandEnabled() {
return mTabExpandEnabled;
return mLayoutManager.isTabExpandEnabled();
}
public void setTabExpandEnabled(boolean expandEnabled) {
mTabExpandEnabled = expandEnabled;
mLayoutManager.setTabExpandEnabled(expandEnabled);
}
private void setHorizontalPadding(int padding) {
@ -489,24 +488,24 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
private static class TabLayoutManager extends FixedLinearLayoutManager {
private final TabPagerIndicator mIndicator;
private boolean mTabExpandEnabled;
public TabLayoutManager(TabPagerIndicator indicator) {
super(indicator.getContext(), HORIZONTAL, false);
mIndicator = indicator;
public TabLayoutManager(Context context) {
super(context, HORIZONTAL, false);
setAutoMeasureEnabled(true);
}
@Override
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) {
// first get default measured size
super.measureChildWithMargins(child, widthUsed, heightUsed);
if (!mIndicator.isTabExpandEnabled()) return;
final int count = mIndicator.getCount();
if (!isTabExpandEnabled()) return;
final int count = getItemCount();
if (count == 0) return;
final int parentHeight = mIndicator.getHeight(), parentWidth = mIndicator.getWidth();
final int parentHeight = getHeight(), parentWidth = getWidth();
final int decoratedWidth = getDecoratedMeasuredWidth(child);
final int decoratorWidth = decoratedWidth - child.getMeasuredWidth();
final int width = Math.max(parentWidth / count - decoratorWidth, decoratedWidth);
final int width = parentWidth / count - decoratorWidth;
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(parentHeight, MeasureSpec.EXACTLY);
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
child.measure(widthMeasureSpec, heightMeasureSpec);
@ -516,6 +515,14 @@ public class TabPagerIndicator extends RecyclerView implements PagerIndicator, C
protected boolean isLayoutRTL() {
return false;
}
public boolean isTabExpandEnabled() {
return mTabExpandEnabled;
}
public void setTabExpandEnabled(boolean tabExpandEnabled) {
mTabExpandEnabled = tabExpandEnabled;
}
}
public void updateAppearance() {