Search in sources :

Example 1 with AlphaInAnimator

use of com.mikepenz.itemanimators.AlphaInAnimator in project FastAdapter by mikepenz.

the class RealmActivity method onCreate.

@Override
protected void onCreate(final 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_main);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_realm_list);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    mFastItemAdapter = new FastItemAdapter<>();
    //configure our fastAdapter
    mFastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<RealmSampleUserItem>() {

        @Override
        public boolean onClick(View v, IAdapter<RealmSampleUserItem> adapter, RealmSampleUserItem item, int position) {
            Toast.makeText(v.getContext(), item.getName(), Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    //get our recyclerView and do basic setup
    RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new AlphaInAnimator());
    rv.setAdapter(mFastItemAdapter);
    //Get a realm instance for this activity
    mRealm = Realm.getDefaultInstance();
    //Add a realm on change listener (donĀ“t forget to close this realm instance before adding this listener again)
    mRealm.where(RealmSampleUserItem.class).findAllAsync().addChangeListener(new RealmChangeListener<RealmResults<RealmSampleUserItem>>() {

        @Override
        public void onChange(RealmResults<RealmSampleUserItem> userItems) {
            //This will call twice
            //1.) from findAllAsync()
            //2.) from createData()
            mFastItemAdapter.setNewList(userItems);
        }
    });
    //fill with some sample data
    createData();
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
    //restore selections (this has to be done after the items were added
    mFastItemAdapter.withSavedInstanceState(savedInstanceState);
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AlphaInAnimator(com.mikepenz.itemanimators.AlphaInAnimator) RealmSampleUserItem(com.mikepenz.fastadapter.app.items.RealmSampleUserItem) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar) RealmResults(io.realm.RealmResults)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 FastAdapter (com.mikepenz.fastadapter.FastAdapter)1 RealmSampleUserItem (com.mikepenz.fastadapter.app.items.RealmSampleUserItem)1 AlphaInAnimator (com.mikepenz.itemanimators.AlphaInAnimator)1 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)1 RealmResults (io.realm.RealmResults)1