Storing the widget item views in Widget holder, to avoid looks on every bind/recycle

Change-Id: Ifad34f419b1b4f2bf97cc4ff533277867598a719
This commit is contained in:
Sunny Goyal
2016-05-19 09:33:30 -07:00
parent c64cfdd8fa
commit 81259cd086
3 changed files with 27 additions and 52 deletions

View File

@@ -91,19 +91,14 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
@Override
public String scrollToPositionAtProgress(float touchFraction) {
// Skip early if widgets are not bound.
if (mWidgets == null) {
return "";
}
// Skip early if there are no widgets.
int rowCount = mWidgets.getPackageSize();
if (rowCount == 0) {
if (isModelNotReady()) {
return "";
}
// Stop the scroller if it is scrolling
stopScroll();
int rowCount = mWidgets.getPackageSize();
getCurScrollState(mScrollPosState, -1);
float pos = rowCount * touchFraction;
int availableScrollHeight = getAvailableScrollHeight(rowCount);
@@ -121,14 +116,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
@Override
public void onUpdateScrollbar(int dy) {
// Skip early if widgets are not bound.
if (mWidgets == null) {
return;
}
// Skip early if there are no widgets.
int rowCount = mWidgets.getPackageSize();
if (rowCount == 0) {
mScrollbar.setThumbOffset(-1, -1);
if (isModelNotReady()) {
return;
}
@@ -139,7 +127,7 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
return;
}
synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, rowCount);
synchronizeScrollBarThumbOffsetToViewScroll(mScrollPosState, mWidgets.getPackageSize());
}
/**
@@ -151,15 +139,10 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
stateOut.itemPos = -1;
// Skip early if widgets are not bound.
if (mWidgets == null) {
if (isModelNotReady()) {
return;
}
// Return early if there are no items
int rowCount = mWidgets.getPackageSize();
if (rowCount == 0) {
return;
}
View child = getChildAt(0);
int position = getChildPosition(child);
@@ -178,4 +161,8 @@ public class WidgetsRecyclerView extends BaseRecyclerView {
View child = getChildAt(0);
return child.getMeasuredHeight() * rowIndex;
}
private boolean isModelNotReady() {
return mWidgets == null || mWidgets.getPackageSize() == 0;
}
}