Search in sources :

Example 6 with Event

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);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SQLiteException(android.database.sqlite.SQLiteException) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) EventActivity(org.havenapp.main.ui.EventActivity) SuppressLint(android.annotation.SuppressLint) EventAdapter(org.havenapp.main.ui.EventAdapter) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Event(org.havenapp.main.model.Event) RecyclerView(android.support.v7.widget.RecyclerView)

Example 7 with Event

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/>");
    }
}
Also used : Event(org.havenapp.main.model.Event)

Aggregations

Event (org.havenapp.main.model.Event)7 SuppressLint (android.annotation.SuppressLint)3 RecyclerView (android.support.v7.widget.RecyclerView)3 View (android.view.View)3 Intent (android.content.Intent)2 ArrayList (java.util.ArrayList)2 EventTrigger (org.havenapp.main.model.EventTrigger)2 EventActivity (org.havenapp.main.ui.EventActivity)2 EventAdapter (org.havenapp.main.ui.EventAdapter)2 SQLiteException (android.database.sqlite.SQLiteException)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 SmsManager (android.telephony.SmsManager)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1