Android Open Source - silent-meeting Event Dao






From Project

Back to project page silent-meeting.

License

The source code is released under:

GNU General Public License

If you think the Android project silent-meeting listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package uk.co.bensproule.silentmeeting.dao;
/*w  w w  .ja  v  a  2 s.c om*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.provider.CalendarContract;
import android.util.Log;
import uk.co.bensproule.silentmeeting.domain.Event;

import java.util.ArrayList;
import java.util.List;

import static android.provider.CalendarContract.Events.*;
import static uk.co.bensproule.silentmeeting.dao.SQLiteHelper.EVENTS_TABLE_NAME;

public class EventDao {

    private SQLiteDatabase db;

    public EventDao(Context context) {
        SQLiteHelper sqLiteHelper = SQLiteHelper.instance(context);
        db = sqLiteHelper.getWritableDatabase();
        assert db != null;
    }

    public List<Event> getAll() {
        Log.d("EventDao", "Getting all Events");

        Cursor cursor = db.query(EVENTS_TABLE_NAME, null, null, null, null, null, null);

        List<Event> events = new ArrayList<>();
        while (cursor.moveToNext()) {
            Event event = new Event(cursor.getInt(cursor.getColumnIndex(CalendarContract.Events._ID)),
                    cursor.getInt(cursor.getColumnIndex(CalendarContract.Events.CALENDAR_ID)),
                    cursor.getString(cursor.getColumnIndex(CalendarContract.Events.TITLE)),
                    cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTSTART)),
                    cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTEND)),
                    cursor.getInt(cursor.getColumnIndex(CalendarContract.Events.AVAILABILITY)),
                    cursor.getString(cursor.getColumnIndex(CalendarContract.Events.ORGANIZER)));
            events.add(event);
        }

        return events;
    }

    public void save(Event event) {
        Log.d("EventDao", "Saving " + event.toString());

        ContentValues values = new ContentValues();
        values.put(_ID, event.getId());
        values.put(CALENDAR_ID, event.getCalendarID());
        values.put(TITLE, event.getTitle());
        values.put(DTSTART, event.getStartDate());
        values.put(DTEND, event.getEndDate());
        values.put(AVAILABILITY, event.getAvailability());
        values.put(ORGANIZER, event.getOrganiser());

        db.insert(EVENTS_TABLE_NAME, null, values);
    }

    public void delete(int id) {
        Log.d("EventDao", "Deleting " + id);

        String selection = _ID + " = ?";
        String[] selectionArgs = {String.valueOf(id)};
        db.delete(EVENTS_TABLE_NAME, selection, selectionArgs);
    }
}




Java Source Code List

uk.co.bensproule.silentmeeting.ApplicationTest.java
uk.co.bensproule.silentmeeting.activity.PreferencesActivity.java
uk.co.bensproule.silentmeeting.constants.Actions.java
uk.co.bensproule.silentmeeting.constants.Extra.java
uk.co.bensproule.silentmeeting.constants.Setting.java
uk.co.bensproule.silentmeeting.dao.EventDao.java
uk.co.bensproule.silentmeeting.dao.InstanceDao.java
uk.co.bensproule.silentmeeting.dao.SQLiteHelper.java
uk.co.bensproule.silentmeeting.domain.Attendee.java
uk.co.bensproule.silentmeeting.domain.Calendar.java
uk.co.bensproule.silentmeeting.domain.DialogCloseListener.java
uk.co.bensproule.silentmeeting.domain.Event.java
uk.co.bensproule.silentmeeting.domain.Instance.java
uk.co.bensproule.silentmeeting.fragment.TimePickerFragment.java
uk.co.bensproule.silentmeeting.receiver.CalendarEventsReceiver.java
uk.co.bensproule.silentmeeting.receiver.MutePhoneBroadcastReceiver.java
uk.co.bensproule.silentmeeting.receiver.UnmutePhoneBroadcastReceiver.java
uk.co.bensproule.silentmeeting.util.StringUtils.java