Search in sources :

Example 1 with PlaidItem

use of io.plaidapp.data.PlaidItem in project plaid by nickbutcher.

the class FeedAdapter method removeDataSource.

public void removeDataSource(String dataSource) {
    for (int i = items.size() - 1; i >= 0; i--) {
        PlaidItem item = items.get(i);
        if (dataSource.equals(item.dataSource)) {
            items.remove(i);
        }
    }
    sort();
    expandPopularItems();
    notifyDataSetChanged();
}
Also used : PlaidItem(io.plaidapp.data.PlaidItem)

Example 2 with PlaidItem

use of io.plaidapp.data.PlaidItem in project plaid by nickbutcher.

the class FeedAdapter method expandPopularItems.

private void expandPopularItems() {
    // for now just expand the first dribbble image per page which should be
    // the most popular according to our weighing & sorting
    List<Integer> expandedPositions = new ArrayList<>();
    int page = -1;
    final int count = items.size();
    for (int i = 0; i < count; i++) {
        PlaidItem item = getItem(i);
        if (item instanceof Shot && item.page > page) {
            item.colspan = columns;
            page = item.page;
            expandedPositions.add(i);
        } else {
            item.colspan = 1;
        }
    }
    // so that we don't leave any gaps in the grid
    for (int expandedPos = 0; expandedPos < expandedPositions.size(); expandedPos++) {
        int pos = expandedPositions.get(expandedPos);
        int extraSpannedSpaces = expandedPos * (columns - 1);
        int rowPosition = (pos + extraSpannedSpaces) % columns;
        if (rowPosition != 0) {
            int swapWith = pos + (columns - rowPosition);
            if (swapWith < items.size()) {
                Collections.swap(items, pos, swapWith);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PlaidItem(io.plaidapp.data.PlaidItem) Shot(io.plaidapp.data.api.dribbble.model.Shot)

Aggregations

PlaidItem (io.plaidapp.data.PlaidItem)2 Shot (io.plaidapp.data.api.dribbble.model.Shot)1 ArrayList (java.util.ArrayList)1