Search in sources :

Example 16 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class PhotoNoteDB method findByPhotoNoteId.

public synchronized PhotoNote findByPhotoNoteId(long photoNoteId) {
    SQLiteDatabase db = mNotesSQLite.getReadableDatabase();
    Cursor cursor = db.query(NotesSQLite.TABLE_PHOTONOTE, null, "_id = ?", new String[] { photoNoteId + "" }, null, null, null);
    PhotoNote photoNote = null;
    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex("_id"));
        String photoName = cursor.getString(cursor.getColumnIndex("photoName"));
        long createdPhotoTime = cursor.getLong(cursor.getColumnIndex("createdPhotoTime"));
        long editedPhotoTime = cursor.getLong(cursor.getColumnIndex("editedPhotoTime"));
        String title = cursor.getString(cursor.getColumnIndex("title"));
        String content = cursor.getString(cursor.getColumnIndex("content"));
        long createdNoteTime = cursor.getLong(cursor.getColumnIndex("createdNoteTime"));
        long editedNoteTime = cursor.getLong(cursor.getColumnIndex("editedNoteTime"));
        int color = cursor.getInt(cursor.getColumnIndex("palette"));
        int tag = cursor.getInt(cursor.getColumnIndex("tag"));
        int categoryId_ = cursor.getInt(cursor.getColumnIndex("categoryId"));
        photoNote = new PhotoNote(id, photoName, createdPhotoTime, editedPhotoTime, title, content, createdNoteTime, editedNoteTime, categoryId_);
        photoNote.setPaletteColor(color);
    }
    cursor.close();
    db.close();
    return photoNote;
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 17 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class PhotoNoteDB method isExistInDB.

public synchronized boolean isExistInDB(PhotoNote photoNote) {
    int categoryId = photoNote.getCategoryId();
    List<PhotoNote> photoNoteList = findByCategoryId(categoryId);
    for (PhotoNote item : photoNoteList) {
        if (item.getId() == photoNote.getId()) {
            return true;
        }
    }
    return false;
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote)

Example 18 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote in project PhotoNoter by yydcdut.

the class PhotoNoteDB method save.

public synchronized long save(PhotoNote... photoNotes) {
    SQLiteDatabase db = mNotesSQLite.getWritableDatabase();
    db.beginTransaction();
    long id = -1;
    try {
        for (PhotoNote photoNote : photoNotes) {
            ContentValues contentValues = new ContentValues();
            contentValues.put("photoName", photoNote.getPhotoName());
            contentValues.put("createdPhotoTime", photoNote.getCreatedPhotoTime());
            contentValues.put("editedPhotoTime", photoNote.getEditedPhotoTime());
            contentValues.put("title", photoNote.getTitle());
            contentValues.put("content", photoNote.getContent());
            contentValues.put("createdNoteTime", photoNote.getCreatedNoteTime());
            contentValues.put("editedNoteTime", photoNote.getEditedNoteTime());
            contentValues.put("palette", photoNote.getPaletteColor());
            //            contentValues.put("tag", );
            contentValues.put("categoryId", photoNote.getCategoryId());
            contentValues.put("categoryLabel", "");
            id = db.insert(NotesSQLite.TABLE_PHOTONOTE, null, contentValues);
            db.setTransactionSuccessful();
        }
    } catch (Exception e) {
        YLog.e(e);
        return -1;
    } finally {
        db.endTransaction();
        db.close();
    }
    return id;
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote) ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

PhotoNote (com.yydcdut.note.entity.PhotoNote)18 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)10 Context (android.content.Context)8 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)8 YLog (com.yydcdut.note.utils.YLog)8 IView (com.yydcdut.note.views.IView)8 ArrayList (java.util.ArrayList)8 Inject (javax.inject.Inject)8 Handler (android.os.Handler)7 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)7 Utils (com.yydcdut.note.utils.Utils)7 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 List (java.util.List)7 R (com.yydcdut.note.R)6 Category (com.yydcdut.note.entity.Category)6 ContextLife (com.yydcdut.note.injector.ContextLife)6 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)6 RxCategory (com.yydcdut.note.model.rx.RxCategory)6 Map (java.util.Map)6