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);
}
Aggregations