Search in sources :

Example 1 with SimpleDragCallback

use of com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback 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 SimpleDragCallback

use of com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback 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)

Aggregations

DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 SearchView (android.support.v7.widget.SearchView)2 Toolbar (android.support.v7.widget.Toolbar)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 View (android.view.View)2 FastAdapter (com.mikepenz.fastadapter.FastAdapter)2 IItemAdapter (com.mikepenz.fastadapter.IItemAdapter)2 SimpleItem (com.mikepenz.fastadapter.app.items.SimpleItem)2 SimpleDragCallback (com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback)2 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)2 ArrayList (java.util.ArrayList)2 Handler (android.os.Handler)1 FastScrollIndicatorAdapter (com.mikepenz.fastadapter.app.adapters.FastScrollIndicatorAdapter)1 ProgressItem (com.mikepenz.fastadapter_extensions.items.ProgressItem)1 EndlessRecyclerOnScrollListener (com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener)1 Random (java.util.Random)1