Search in sources :

Example 1 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem in project FastAdapter by mikepenz.

the class EndlessScrollListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withSelectable(true);
    //create our FooterAdapter which will manage the progress items
    footerAdapter = new FooterAdapter<>();
    //configure our fastAdapter
    fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<SimpleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
            return false;
        }
    });
    //configure the itemAdapter
    fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate<SimpleItem>() {

        @Override
        public boolean filter(SimpleItem item, CharSequence constraint) {
            //return false to keep it
            return !item.name.getText().toLowerCase().contains(constraint.toString().toLowerCase());
        }
    });
    fastItemAdapter.getItemAdapter().withItemFilterListener(this);
    //get our recyclerView and do basic setup
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(footerAdapter.wrap(fastItemAdapter));
    recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(footerAdapter) {

        @Override
        public void onLoadMore(final int currentPage) {
            footerAdapter.clear();
            footerAdapter.add(new ProgressItem().withEnabled(false));
            //simulate networking (2 seconds)
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    footerAdapter.clear();
                    for (int i = 1; i < 16; i++) {
                        fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new SimpleItem().withName("Item " + i + " Page " + currentPage));
                    }
                }
            }, 2000);
        }
    });
    //fill with some sample data (load the first page here)
    List<SimpleItem> items = new ArrayList<>();
    for (int i = 1; i < 16; i++) {
        items.add(new SimpleItem().withName("Item " + i + " Page " + 1));
    }
    fastItemAdapter.add(items);
    //add drag and drop for item
    touchCallback = new SimpleDragCallback(this);
    // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
    touchHelper = new ItemTouchHelper(touchCallback);
    // Attach ItemTouchHelper to RecyclerView
    touchHelper.attachToRecyclerView(recyclerView);
    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : EndlessRecyclerOnScrollListener(com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener) SimpleDragCallback(com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ProgressItem(com.mikepenz.fastadapter_extensions.items.ProgressItem) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) IItemAdapter(com.mikepenz.fastadapter.IItemAdapter) Toolbar(android.support.v7.widget.Toolbar) Handler(android.os.Handler) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) SearchView(android.support.v7.widget.SearchView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem)

Example 2 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem in project FastAdapter by mikepenz.

the class MultiselectSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_multi_select);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    mFastAdapter = new FastAdapter<>();
    //
    mUndoHelper = new UndoHelper(mFastAdapter, new UndoHelper.UndoListener<SimpleItem>() {

        @Override
        public void commitRemove(Set<Integer> positions, ArrayList<FastAdapter.RelativeInfo<SimpleItem>> removed) {
            Log.e("UndoHelper", "Positions: " + positions.toString() + " Removed: " + removed.size());
        }
    });
    //we init our ActionModeHelper
    mActionModeHelper = new ActionModeHelper(mFastAdapter, R.menu.cab, new ActionBarCallBack());
    //create our adapters
    ItemAdapter<SimpleItem> itemAdapter = new ItemAdapter<>();
    final HeaderAdapter<SimpleItem> headerAdapter = new HeaderAdapter<>();
    //configure our mFastAdapter
    //as we provide id's for the items we want the hasStableIds enabled to speed up things
    mFastAdapter.setHasStableIds(true);
    mFastAdapter.withSelectable(true);
    mFastAdapter.withMultiSelect(true);
    mFastAdapter.withSelectOnLongClick(true);
    mFastAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<SimpleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            //we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
            Boolean res = mActionModeHelper.onClick(item);
            return res != null ? res : false;
        }
    });
    mFastAdapter.withOnClickListener(new FastAdapter.OnClickListener<SimpleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            Toast.makeText(v.getContext(), "SelectedCount: " + mFastAdapter.getSelections().size() + " ItemsCount: " + mFastAdapter.getSelectedItems().size(), Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    mFastAdapter.withOnPreLongClickListener(new FastAdapter.OnLongClickListener<SimpleItem>() {

        @Override
        public boolean onLongClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            ActionMode actionMode = mActionModeHelper.onLongClick(MultiselectSampleActivity.this, position);
            if (actionMode != null) {
                //we want color our CAB
                findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(MultiselectSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
            }
            //if we have no actionMode we do not consume the event
            return actionMode != null;
        }
    });
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(itemAdapter.wrap(headerAdapter.wrap(mFastAdapter)));
    //fill with some sample data
    SimpleItem SimpleItem = new SimpleItem();
    SimpleItem.withName("Header").withIdentifier(1).withSelectable(false);
    headerAdapter.add(SimpleItem);
    List<SimpleItem> items = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        SimpleItem item = new SimpleItem();
        item.withName("Test " + i).withIdentifier(100 + i);
        items.add(item);
    }
    itemAdapter.add(items);
    //restore selections (this has to be done after the items were added
    mFastAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
    //inform that longClick is required
    Toast.makeText(this, "LongClick to enable Multi-Selection", Toast.LENGTH_LONG).show();
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) HeaderAdapter(com.mikepenz.fastadapter.adapters.HeaderAdapter) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) Toolbar(android.support.v7.widget.Toolbar) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter) UndoHelper(com.mikepenz.fastadapter_extensions.UndoHelper) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ActionMode(android.support.v7.view.ActionMode) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem) ActionModeHelper(com.mikepenz.fastadapter_extensions.ActionModeHelper)

Example 3 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem in project FastAdapter by mikepenz.

the class SimpleItemListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withSelectable(true);
    fastItemAdapter.withPositionBasedStateManagement(false);
    final FastScrollIndicatorAdapter<SimpleItem> fastScrollIndicatorAdapter = new FastScrollIndicatorAdapter<>();
    //configure our fastAdapter
    fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<SimpleItem>() {

        @Override
        public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
            Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
            return false;
        }
    });
    //configure the itemAdapter
    fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate<SimpleItem>() {

        @Override
        public boolean filter(SimpleItem item, CharSequence constraint) {
            //return false to keep it
            return !item.name.getText().toLowerCase().contains(constraint.toString().toLowerCase());
        }
    });
    fastItemAdapter.getItemAdapter().withItemFilterListener(this);
    //get our recyclerView and do basic setup
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(fastScrollIndicatorAdapter.wrap(fastItemAdapter));
    //add a FastScrollBar (Showcase compatibility)
    //DragScrollBar materialScrollBar = new DragScrollBar(this, recyclerView, true);
    //materialScrollBar.setHandleColour(ContextCompat.getColor(this, R.color.accent));
    //materialScrollBar.addIndicator(new AlphabetIndicator(this), true);
    //fill with some sample data
    int x = 0;
    List<SimpleItem> items = new ArrayList<>();
    for (String s : ALPHABET) {
        int count = new Random().nextInt(20);
        for (int i = 1; i <= count; i++) {
            SimpleItem item = new SimpleItem().withName(s + " Test " + x).withIdentifier(100 + x);
            items.add(item);
            x++;
        }
    }
    fastItemAdapter.add(items);
    //add drag and drop for item
    touchCallback = new SimpleDragCallback(this);
    // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
    touchHelper = new ItemTouchHelper(touchCallback);
    // Attach ItemTouchHelper to RecyclerView
    touchHelper.attachToRecyclerView(recyclerView);
    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : FastScrollIndicatorAdapter(com.mikepenz.fastadapter.app.adapters.FastScrollIndicatorAdapter) SimpleDragCallback(com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) SearchView(android.support.v7.widget.SearchView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Random(java.util.Random) IItemAdapter(com.mikepenz.fastadapter.IItemAdapter) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem in project FastAdapter by mikepenz.

the class SortActivity method makeItem.

/**
     * Build a simple item with one letter of the alphabet.
     *
     * @param position The position of the letter in the alphabet.
     * @return The new item.
     */
private SimpleItem makeItem(@IntRange(from = 0, to = 25) int position) {
    SimpleItem result = new SimpleItem();
    result.withName(ALPHABET[position]);
    position++;
    String description = "The " + (position);
    if (position == 1 || position == 21) {
        description += "st";
    } else if (position == 2 || position == 22) {
        description += "nd";
    } else if (position == 3 || position == 23) {
        description += "rd";
    } else {
        description += "th";
    }
    return result.withDescription(description + " letter in the alphabet");
}
Also used : SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem)

Example 5 with SimpleItem

use of com.mikepenz.fastadapter.app.items.SimpleItem in project FastAdapter by mikepenz.

the class StickyHeaderSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_sticky_header);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    fastAdapter = new FastAdapter();
    fastAdapter.withSelectable(true);
    //create our adapters
    final StickyHeaderAdapter stickyHeaderAdapter = new StickyHeaderAdapter();
    final HeaderAdapter headerAdapter = new HeaderAdapter();
    final ItemAdapter itemAdapter = new ItemAdapter();
    //configure our fastAdapter
    //as we provide id's for the items we want the hasStableIds enabled to speed up things
    fastAdapter.setHasStableIds(true);
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new DefaultItemAnimator());
    rv.setAdapter(stickyHeaderAdapter.wrap(itemAdapter.wrap(headerAdapter.wrap(fastAdapter))));
    //this adds the Sticky Headers within our list
    final StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(stickyHeaderAdapter);
    rv.addItemDecoration(decoration);
    //fill with some sample data
    headerAdapter.add(new SimpleItem().withName("Header").withIdentifier(1));
    List<IItem> items = new ArrayList<>();
    for (int i = 1; i <= 100; i++) {
        items.add(new SimpleItem().withName("Test " + i).withHeader(headers[i / 5]).withIdentifier(100 + i));
    }
    itemAdapter.add(items);
    //so the headers are aware of changes
    stickyHeaderAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            decoration.invalidateHeaders();
        }
    });
    //restore selections (this has to be done after the items were added
    fastAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) StickyHeaderAdapter(com.mikepenz.fastadapter.app.adapters.StickyHeaderAdapter) StickyHeaderAdapter(com.mikepenz.fastadapter.app.adapters.StickyHeaderAdapter) HeaderAdapter(com.mikepenz.fastadapter.adapters.HeaderAdapter) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) IItem(com.mikepenz.fastadapter.IItem) SimpleItem(com.mikepenz.fastadapter.app.items.SimpleItem) Toolbar(android.support.v7.widget.Toolbar) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter)

Aggregations

SimpleItem (com.mikepenz.fastadapter.app.items.SimpleItem)8 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)5 RecyclerView (android.support.v7.widget.RecyclerView)5 FastAdapter (com.mikepenz.fastadapter.FastAdapter)5 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)5 ArrayList (java.util.ArrayList)5 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)4 Toolbar (android.support.v7.widget.Toolbar)4 View (android.view.View)4 IItem (com.mikepenz.fastadapter.IItem)3 SearchView (android.support.v7.widget.SearchView)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)2 HeaderAdapter (com.mikepenz.fastadapter.adapters.HeaderAdapter)2 ItemAdapter (com.mikepenz.fastadapter.adapters.ItemAdapter)2 SimpleSubExpandableItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem)2 SimpleSubItem (com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem)2 SimpleDragCallback (com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback)2 Random (java.util.Random)2 Handler (android.os.Handler)1