use of org.havenapp.main.ui.EventAdapter in project haven by guardianproject.
the class ListActivity method onResume.
@Override
protected void onResume() {
super.onResume();
final long newCount = Event.count(Event.class);
if (newCount > events.size()) {
events = Event.listAll(Event.class, "id DESC");
adapter = new EventAdapter(ListActivity.this, events);
recyclerView.setAdapter(adapter);
adapter.SetOnItemClickListener(new EventAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Intent i = new Intent(ListActivity.this, EventActivity.class);
i.putExtra("eventid", events.get(position).getId());
modifyPos = position;
startActivity(i);
}
});
/**
* // Just load the last added note (new)
* Event event = Event.last(Event.class);
*
* events.add(0,event);
* adapter.notifyItemInserted(0);
* adapter.notifyDataSetChanged();
*
* initialCount = newCount;
*/
recyclerView.setVisibility(View.VISIBLE);
findViewById(R.id.empty_view).setVisibility(View.GONE);
} else if (newCount == 0) {
recyclerView.setVisibility(View.GONE);
findViewById(R.id.empty_view).setVisibility(View.VISIBLE);
}
if (modifyPos != -1) {
// Event.set(modifyPos, Event.listAll(Event.class).get(modifyPos));
adapter.notifyItemChanged(modifyPos);
}
}
use of org.havenapp.main.ui.EventAdapter in project haven by guardianproject.
the class ListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Log.d("Main", "onCreate");
preferences = new PreferenceManager(this.getApplicationContext());
recyclerView = findViewById(R.id.main_list);
fab = findViewById(R.id.fab);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm);
if (savedInstanceState != null)
modifyPos = savedInstanceState.getInt("modify");
// Handling swipe to delete
ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
// Remove swiped item from list and notify the RecyclerView
final int position = viewHolder.getAdapterPosition();
final Event event = events.get(viewHolder.getAdapterPosition());
deleteEvent(event, position);
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_play_arrow);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, Color.WHITE);
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
fab.setImageDrawable(drawable);
}
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(ListActivity.this, MonitorActivity.class);
startActivity(i);
}
});
if (preferences.isFirstLaunch()) {
showOnboarding();
}
try {
events = Event.listAll(Event.class, "id DESC");
if (events.size() > 0) {
findViewById(R.id.empty_view).setVisibility(View.GONE);
}
adapter = new EventAdapter(ListActivity.this, events);
recyclerView.setVisibility(View.VISIBLE);
recyclerView.setAdapter(adapter);
adapter.SetOnItemClickListener(new EventAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Intent i = new Intent(ListActivity.this, EventActivity.class);
i.putExtra("eventid", events.get(position).getId());
modifyPos = position;
startActivity(i);
}
});
} catch (SQLiteException sqe) {
Log.d(getClass().getName(), "database not yet initiatied", sqe);
}
}
Aggregations