use of com.fima.cardsui.StackAdapter in project Rashr by DsLNeXuS.
the class CardUI method refresh.
//suppress this error message to be able to use spaces in higher api levels
@SuppressLint("NewApi")
public void refresh() {
if (mAdapter == null) {
mAdapter = new StackAdapter(mContext, mStacks, mSwipeable);
if (mListView != null) {
mListView.setAdapter(mAdapter);
} else if (mTableLayout != null) {
TableRow tr = null;
for (int i = 0; i < mAdapter.getCount(); i += mColumnNumber) {
//add a new table row with the current context
tr = new TableRow(mTableLayout.getContext());
tr.setOrientation(TableRow.HORIZONTAL);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
//add as many cards as the number of columns indicates per row
for (int j = 0; j < mColumnNumber; j++) {
if (i + j < mAdapter.getCount()) {
View card = mAdapter.getView(i + j, null, tr);
if (card.getLayoutParams() != null) {
card.setLayoutParams(new TableRow.LayoutParams(card.getLayoutParams().width, card.getLayoutParams().height, 1f));
} else {
card.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
}
tr.addView(card);
}
}
mTableLayout.addView(tr);
}
if (tr != null) {
//fill the empty space with spacers
for (int j = mAdapter.getCount() % mColumnNumber; j > 0; j--) {
View space = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
space = new Space(tr.getContext());
} else {
space = new View(tr.getContext());
}
space.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 1f));
tr.addView(space);
}
}
}
} else {
// in case swipeable changed;
mAdapter.setSwipeable(mSwipeable);
mAdapter.setItems(mStacks);
}
}
Aggregations