Search in sources :

Example 1 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class FragmentAnimators method performFabAction.

@Override
public void performFabAction() {
    int size = 1 + DatabaseService.getInstance().getDatabaseList().size();
    AbstractFlexibleItem item = DatabaseService.newAnimatorItem(size);
    DatabaseService.getInstance().addItem(item);
    mAdapter.addItem(mAdapter.getItemCount(), item);
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem)

Example 2 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class HeadersSectionsTest method testIsHeader.

@Test
public void testIsHeader() throws Exception {
    mAdapter = new FlexibleAdapter<>(mItems);
    mAdapter.setDisplayHeadersAtStartUp(true);
    AbstractFlexibleItem item = mAdapter.getItem(0);
    assertNotNull(item);
    assertTrue(mAdapter.isHeader(item));
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) Test(org.junit.Test)

Example 3 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class HeadersSectionsTest method testHasSameHeader.

@Test
public void testHasSameHeader() throws Exception {
    mAdapter = new FlexibleAdapter<>(mItems);
    mAdapter.setDisplayHeadersAtStartUp(true);
    AbstractFlexibleItem item1 = mAdapter.getItem(1);
    IHeader header = mAdapter.getHeaderOf(item1);
    assertNotNull(header);
    AbstractFlexibleItem item2 = mAdapter.getItem(3);
    assertNotNull(item2);
    assertTrue(mAdapter.hasSameHeader(item2, header));
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) IHeader(eu.davidea.flexibleadapter.items.IHeader) Test(org.junit.Test)

Example 4 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class HeadersSectionsTest method testHasHeader.

@Test
public void testHasHeader() throws Exception {
    mAdapter = new FlexibleAdapter<>(mItems);
    mAdapter.setDisplayHeadersAtStartUp(true);
    AbstractFlexibleItem item = mAdapter.getItem(1);
    assertNotNull(item);
    assertTrue(mAdapter.hasHeader(item));
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) Test(org.junit.Test)

Example 5 with AbstractFlexibleItem

use of eu.davidea.flexibleadapter.items.AbstractFlexibleItem in project FlexibleAdapter by davideas.

the class MainActivity method onDeleteConfirmed.

@Override
public void onDeleteConfirmed(int action) {
    // Disable Refreshing
    mSwipeRefreshLayout.setRefreshing(false);
    // Removing items from Database. Example:
    for (AbstractFlexibleItem adapterItem : mAdapter.getDeletedItems()) {
        try {
            // NEW! You can take advantage of AutoMap and differentiate logic by viewType using "switch" statement
            switch(adapterItem.getLayoutRes()) {
                case R.layout.recycler_sub_item:
                    SubItem subItem = (SubItem) adapterItem;
                    DatabaseService.getInstance().removeSubItem(mAdapter.getExpandableOfDeletedChild(subItem), subItem);
                    Log.d(TAG, "Confirm removed " + subItem.getTitle());
                    break;
                case R.layout.recycler_expandable_item:
                    DatabaseService.getInstance().removeItem(adapterItem);
                    Log.d(TAG, "Confirm removed " + adapterItem);
                    break;
            }
        } catch (IllegalStateException e) {
            // AutoMap is disabled, fallback to if-else with "instanceof" statement
            if (adapterItem instanceof SubItem) {
                // SubItem
                SubItem subItem = (SubItem) adapterItem;
                IExpandable expandable = mAdapter.getExpandableOf(subItem);
                DatabaseService.getInstance().removeSubItem(expandable, subItem);
                Log.d(TAG, "Confirm removed " + subItem.getTitle());
            } else if (adapterItem instanceof SimpleItem || adapterItem instanceof ExpandableItem) {
                DatabaseService.getInstance().removeItem(adapterItem);
                Log.d(TAG, "Confirm removed " + adapterItem);
            }
        }
    }
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) IExpandable(eu.davidea.flexibleadapter.items.IExpandable) ExpandableItem(eu.davidea.samples.flexibleadapter.items.ExpandableItem) SimpleItem(eu.davidea.samples.flexibleadapter.items.SimpleItem)

Aggregations

AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)8 Test (org.junit.Test)3 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (eu.davidea.flexibleadapter.common.DividerItemDecoration)1 IExpandable (eu.davidea.flexibleadapter.items.IExpandable)1 IHeader (eu.davidea.flexibleadapter.items.IHeader)1 ExampleAdapter (eu.davidea.samples.flexibleadapter.ExampleAdapter)1 AbstractItem (eu.davidea.samples.flexibleadapter.items.AbstractItem)1 ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)1 HeaderItem (eu.davidea.samples.flexibleadapter.items.HeaderItem)1 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)1 SimpleItem (eu.davidea.samples.flexibleadapter.items.SimpleItem)1 StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)1 StaggeredItem (eu.davidea.samples.flexibleadapter.items.StaggeredItem)1 SubItem (eu.davidea.samples.flexibleadapter.items.SubItem)1 ArrayList (java.util.ArrayList)1