/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_events);

    getUIElements();
    setupActionBar();

    Calendar c = Calendar.getInstance(); // Current time
    listviewAdapter = new EventAdapter(this, listData, c.getTime());
    listview.setAdapter(listviewAdapter);

    events = Event.readAll(dbWriteable);
    if (events.isEmpty()) {
      new DownloadEvents().execute();
    } else {
      iterateThroughEvents();
    }

    listview.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            EventRow eventRow = listData.get(position);
            if (!eventRow.isHeader()) {
              localyticsSession.tagEvent(LocalyticsPreferences.EVENTS_ACTIVITY_CLICK_SINGLE_EVENT);
              Intent i = new Intent(EventsActivity.this, SingleEventActivity.class);
              i.putExtra("event_id", eventRow.getEvent().getId());
              startActivity(i);
            }
          }
        });
  }