Search in sources :

Example 1 with StickyRecyclerHeadersDecoration

use of com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration 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)

Example 2 with StickyRecyclerHeadersDecoration

use of com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration in project FastAdapter by mikepenz.

the class AdvancedSampleActivity 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);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_advanced);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    mFastAdapter = new FastAdapter<>();
    //we init our ActionModeHelper
    mActionModeHelper = new ActionModeHelper(mFastAdapter, R.menu.cab, new ActionBarCallBack());
    mActionModeHelper.withSupportSubItems(true);
    //create our adapters
    final StickyHeaderAdapter stickyHeaderAdapter = new StickyHeaderAdapter();
    mItemAdapter = new ItemAdapter<>();
    mHeaderAdapter = new HeaderAdapter<>();
    //configure our mFastAdapter
    //as we provide id's for the items we want the hasStableIds enabled to speed up things
    mFastAdapter.withSelectable(true);
    mFastAdapter.withMultiSelect(true);
    mFastAdapter.withSelectOnLongClick(true);
    mFastAdapter.withPositionBasedStateManagement(false);
    mFastAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<IItem>() {

        @Override
        public boolean onClick(View v, IAdapter adapter, IItem 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.withOnPreLongClickListener(new FastAdapter.OnLongClickListener<IItem>() {

        @Override
        public boolean onLongClick(View v, IAdapter adapter, IItem item, int position) {
            //we do not want expandable items to be selected
            if (item instanceof IExpandable) {
                if (((IExpandable) item).getSubItems() != null) {
                    return true;
                }
            }
            //handle the longclick actions
            ActionMode actionMode = mActionModeHelper.onLongClick(AdvancedSampleActivity.this, position);
            if (actionMode != null) {
                //we want color our CAB
                findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(AdvancedSampleActivity.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 DefaultItemAnimator());
    rv.setAdapter(stickyHeaderAdapter.wrap(mItemAdapter.wrap(mHeaderAdapter.wrap(mFastAdapter))));
    final StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(stickyHeaderAdapter);
    rv.addItemDecoration(decoration);
    //so the headers are aware of changes
    stickyHeaderAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            decoration.invalidateHeaders();
        }
    });
    //init cache with the added items, this is useful for shorter lists with many many different view types (at least 4 or more
    //new RecyclerViewCacheUtil().withCacheSize(2).apply(rv, items);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
    //we define the items
    setItems();
    //restore selections (this has to be done after the items were added
    mFastAdapter.withSavedInstanceState(savedInstanceState);
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) StickyHeaderAdapter(com.mikepenz.fastadapter.app.adapters.StickyHeaderAdapter) IItem(com.mikepenz.fastadapter.IItem) IAdapter(com.mikepenz.fastadapter.IAdapter) Toolbar(android.support.v7.widget.Toolbar) IExpandable(com.mikepenz.fastadapter.IExpandable) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) ActionMode(android.support.v7.view.ActionMode) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) ActionModeHelper(com.mikepenz.fastadapter_extensions.ActionModeHelper)

Example 3 with StickyRecyclerHeadersDecoration

use of com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration in project open-event-orga-app by fossasia.

the class AttendeesFragment method setupRecyclerView.

private void setupRecyclerView() {
    if (!initialized) {
        fastItemAdapter = new ItemAdapter<>();
        fastItemAdapter.getItemFilter().withFilterPredicate((attendee, query) -> {
            if (query == null)
                return true;
            if (query.equals(FILTER_SYNC)) {
                return attendee.checking.get();
            }
            return !SearchUtils.filter(query.toString(), attendee.getFirstname(), attendee.getLastname(), attendee.getEmail());
        });
        stickyHeaderAdapter = new StickyHeaderAdapter<>();
        stickyHeaderAdapter.setSortByName(false);
        fastAdapter = FastAdapter.with(Arrays.asList(fastItemAdapter, stickyHeaderAdapter));
        fastAdapter.setHasStableIds(true);
        fastAdapter.withEventHook(new AttendeeItemCheckInEvent(this));
        RecyclerView recyclerView = binding.rvAttendeeList;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(fastAdapter);
        final StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(stickyHeaderAdapter);
        recyclerView.addItemDecoration(decoration);
        observer = new RecyclerView.AdapterDataObserver() {

            @Override
            public void onChanged() {
                super.onChanged();
                decoration.invalidateHeaders();
            }
        };
        fastAdapter.registerAdapterDataObserver(observer);
        ViewUtils.setRecyclerViewScrollAwareFabBehaviour(recyclerView, binding.fabScanQr);
    }
}
Also used : AttendeeItemCheckInEvent(org.fossasia.openevent.app.core.attendee.list.listeners.AttendeeItemCheckInEvent) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 4 with StickyRecyclerHeadersDecoration

use of com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration in project sticky-headers-recyclerview by timehop.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    Button button = (Button) findViewById(R.id.button_update);
    final ToggleButton isReverseButton = (ToggleButton) findViewById(R.id.button_is_reverse);
    // Set adapter populated with example dummy data
    final AnimalsHeadersAdapter adapter = new AnimalsHeadersAdapter();
    adapter.add("Animals below!");
    adapter.addAll(getDummyDataSet());
    recyclerView.setAdapter(adapter);
    // Set button to update all views one after another (Test for the "Dance")
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Handler handler = new Handler(Looper.getMainLooper());
            for (int i = 0; i < adapter.getItemCount(); i++) {
                final int index = i;
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        adapter.notifyItemChanged(index);
                    }
                }, 50);
            }
        }
    });
    // Set layout manager
    int orientation = getLayoutManagerOrientation(getResources().getConfiguration().orientation);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this, orientation, isReverseButton.isChecked());
    recyclerView.setLayoutManager(layoutManager);
    // Add the sticky headers decoration
    final StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter);
    recyclerView.addItemDecoration(headersDecor);
    // Add decoration for dividers between list items
    recyclerView.addItemDecoration(new DividerDecoration(this));
    // Add touch listeners
    StickyRecyclerHeadersTouchListener touchListener = new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
    touchListener.setOnHeaderClickListener(new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() {

        @Override
        public void onHeaderClick(View header, int position, long headerId) {
            Toast.makeText(MainActivity.this, "Header position: " + position + ", id: " + headerId, Toast.LENGTH_SHORT).show();
        }
    });
    recyclerView.addOnItemTouchListener(touchListener);
    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            adapter.remove(adapter.getItem(position));
        }
    }));
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            headersDecor.invalidateHeaders();
        }
    });
    isReverseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isChecked = isReverseButton.isChecked();
            isReverseButton.setChecked(isChecked);
            layoutManager.setReverseLayout(isChecked);
            adapter.notifyDataSetChanged();
        }
    });
}
Also used : ToggleButton(android.widget.ToggleButton) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StickyRecyclerHeadersTouchListener(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersTouchListener) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) RecyclerView(android.support.v7.widget.RecyclerView)

Example 5 with StickyRecyclerHeadersDecoration

use of com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration in project open-event-orga-app by fossasia.

the class EventListFragment method setupRecyclerView.

private void setupRecyclerView() {
    if (!initialized) {
        eventListAdapter = new EventsListAdapter(getPresenter().getEvents(), bus);
        recyclerView = binding.eventRecyclerView;
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setAdapter(eventListAdapter);
        recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(eventListAdapter);
        recyclerView.addItemDecoration(decoration);
        adapterDataObserver = new RecyclerView.AdapterDataObserver() {

            @Override
            public void onChanged() {
                decoration.invalidateHeaders();
            }
        };
    }
    eventListAdapter.registerAdapterDataObserver(adapterDataObserver);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 RecyclerView (android.support.v7.widget.RecyclerView)6 StickyRecyclerHeadersDecoration (com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration)6 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)5 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)3 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 FastAdapter (com.mikepenz.fastadapter.FastAdapter)2 IItem (com.mikepenz.fastadapter.IItem)2 StickyHeaderAdapter (com.mikepenz.fastadapter.app.adapters.StickyHeaderAdapter)2 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)2 Handler (android.os.Handler)1 ActionMode (android.support.v7.view.ActionMode)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 ToggleButton (android.widget.ToggleButton)1 IAdapter (com.mikepenz.fastadapter.IAdapter)1 IExpandable (com.mikepenz.fastadapter.IExpandable)1 HeaderAdapter (com.mikepenz.fastadapter.adapters.HeaderAdapter)1 ItemAdapter (com.mikepenz.fastadapter.adapters.ItemAdapter)1