use of com.honeyneutrons.undoswipe.helper.SimpleItemTouchHelperCallback in project RecyclerViewUndoSwipe by HoneyNeutrons.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayShowTitleEnabled(false);
setTabs();
TextView tvDate = (TextView) findViewById(R.id.tvDate);
TextView tvDay = (TextView) findViewById(R.id.tvDay);
tvNumber = (TextView) findViewById(R.id.tvNumber);
Calendar c = Calendar.getInstance();
SimpleDateFormat dateformat = new SimpleDateFormat("MM.dd.yyyy", Locale.getDefault());
assert tvDate != null;
assert tvDay != null;
tvDate.setTypeface(Typefaces.getRobotoBlack(this));
tvDay.setTypeface(Typefaces.getRobotoBlack(this));
tvDate.setText(dateformat.format(c.getTime()).toUpperCase());
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.cardList);
assert recyclerView != null;
recyclerView.setHasFixedSize(true);
final LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(llm);
final ItemAdapter itemAdapter = new ItemAdapter(getApplicationContext(), this, tvNumber);
recyclerView.setAdapter(itemAdapter);
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(itemAdapter, this);
mItemTouchHelper = new ItemTouchHelper(callback);
mItemTouchHelper.attachToRecyclerView(recyclerView);
loadItems();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
assert fab != null;
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Item item = new Item();
nu = ItemAdapter.itemList.size();
nu++;
item.setItemName("item" + nu);
llm.scrollToPositionWithOffset(0, dpToPx(56));
itemAdapter.addItem(0, item);
}
});
}
Aggregations