Search in sources :

Example 1 with SimpleItemTouchHelperCallback

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);
        }
    });
}
Also used : SimpleItemTouchHelperCallback(com.honeyneutrons.undoswipe.helper.SimpleItemTouchHelperCallback) Calendar(java.util.Calendar) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuItem(android.view.MenuItem) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) SimpleDateFormat(java.text.SimpleDateFormat) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

FloatingActionButton (android.support.design.widget.FloatingActionButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 TextView (android.widget.TextView)1 SimpleItemTouchHelperCallback (com.honeyneutrons.undoswipe.helper.SimpleItemTouchHelperCallback)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1