Search in sources :

Example 1 with EventAdapter

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

Example 2 with EventAdapter

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);
    }
}
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)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 Event (org.havenapp.main.model.Event)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 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1