use of org.havenapp.main.model.Event 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);
}
}
use of org.havenapp.main.model.Event in project haven by guardianproject.
the class WebServer method showEvents.
private void showEvents(StringBuffer page) {
page.append("<h1>Events</h1><hr/>\n");
List<Event> events = Event.listAll(Event.class);
for (Event event : events) {
String title = event.getStartTime().toLocaleString();
String desc = event.getEventTriggers().size() + " triggered events";
page.append("<b>").append("<a href=\"/event/").append(event.getId()).append("\">");
page.append(title).append("</a></b><br/>");
page.append(desc);
page.append("<hr/>");
}
}
Aggregations