Search in sources :

Example 11 with DBNote

use of it.niedermann.owncloud.notes.model.DBNote in project nextcloud-notes by stefan-niedermann.

the class LoadNotesListTask method fillListByCategory.

@NonNull
@WorkerThread
private List<Item> fillListByCategory(@NonNull List<DBNote> noteList) {
    List<Item> itemList = new ArrayList<>();
    String currentCategory = category.category;
    for (DBNote note : noteList) {
        if (currentCategory != null && !currentCategory.equals(note.getCategory())) {
            itemList.add(new SectionItem(NoteUtil.extendCategory(note.getCategory())));
        }
        itemList.add(note);
        currentCategory = note.getCategory();
    }
    return itemList;
}
Also used : DBNote(it.niedermann.owncloud.notes.model.DBNote) SectionItem(it.niedermann.owncloud.notes.model.SectionItem) SectionItem(it.niedermann.owncloud.notes.model.SectionItem) Item(it.niedermann.owncloud.notes.model.Item) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 12 with DBNote

use of it.niedermann.owncloud.notes.model.DBNote in project nextcloud-notes by stefan-niedermann.

the class NoteSQLiteOpenHelper method addNote.

/**
 * Inserts a note directly into the Database.
 * No Synchronisation will be triggered! Use addNoteAndSync()!
 *
 * @param note Note to be added. Remotely created Notes must be of type CloudNote and locally created Notes must be of Type DBNote (with DBStatus.LOCAL_EDITED)!
 */
long addNote(CloudNote note) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    if (note instanceof DBNote) {
        DBNote dbNote = (DBNote) note;
        if (dbNote.getId() > 0) {
            values.put(key_id, dbNote.getId());
        }
        values.put(key_status, dbNote.getStatus().getTitle());
    } else {
        values.put(key_status, DBStatus.VOID.getTitle());
    }
    if (note.getRemoteId() > 0) {
        values.put(key_remote_id, note.getRemoteId());
    }
    values.put(key_title, note.getTitle());
    values.put(key_modified, note.getModified(NoteSQLiteOpenHelper.DATE_FORMAT));
    values.put(key_content, note.getContent());
    values.put(key_favorite, note.isFavorite());
    values.put(key_category, note.getCategory());
    values.put(key_etag, note.getEtag());
    return db.insert(table_notes, null, values);
}
Also used : ContentValues(android.content.ContentValues) DBNote(it.niedermann.owncloud.notes.model.DBNote) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 13 with DBNote

use of it.niedermann.owncloud.notes.model.DBNote in project nextcloud-notes by stefan-niedermann.

the class NoteSQLiteOpenHelper method addNoteAndSync.

/**
 * Creates a new Note in the Database and adds a Synchronization Flag.
 *
 * @param note Note
 */
@SuppressWarnings("UnusedReturnValue")
public long addNoteAndSync(CloudNote note) {
    DBNote dbNote = new DBNote(0, 0, note.getModified(), note.getTitle(), note.getContent(), note.isFavorite(), note.getCategory(), note.getEtag(), DBStatus.LOCAL_EDITED);
    long id = addNote(dbNote);
    notifyNotesChanged();
    getNoteServerSyncHelper().scheduleSync(true);
    return id;
}
Also used : DBNote(it.niedermann.owncloud.notes.model.DBNote)

Aggregations

DBNote (it.niedermann.owncloud.notes.model.DBNote)13 Intent (android.content.Intent)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 NonNull (android.support.annotation.NonNull)3 WorkerThread (android.support.annotation.WorkerThread)3 Item (it.niedermann.owncloud.notes.model.Item)3 ArrayList (java.util.ArrayList)3 ContentValues (android.content.ContentValues)2 Bundle (android.os.Bundle)2 ItemAdapter (it.niedermann.owncloud.notes.model.ItemAdapter)2 SectionItem (it.niedermann.owncloud.notes.model.SectionItem)2 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Canvas (android.graphics.Canvas)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 SimpleCallback (android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback)1