use of com.orgzly.android.NotesBatch in project orgzly-android by orgzly.
the class NotesClient method getLatestNotesBatch.
/**
* Collect all notes with latest (newest, largest) batch id.
* @return Latest {@link NotesBatch}
*/
public static NotesBatch getLatestNotesBatch(Context context) {
/* Get latest batch ID. */
long batchId;
Cursor cursor = context.getContentResolver().query(ProviderContract.Notes.ContentUri.notes(), new String[] { "MAX(" + DbNoteView.IS_CUT + ")" }, null, null, null);
try {
if (!cursor.moveToFirst()) {
return null;
}
batchId = cursor.getLong(0);
} finally {
cursor.close();
}
if (batchId == 0) {
return null;
}
cursor = context.getContentResolver().query(ProviderContract.Notes.ContentUri.notes(), DatabaseUtils.PROJECTION_FOR_ID, DbNoteView.IS_CUT + " = " + batchId, null, null);
try {
int count = cursor.getCount();
if (count == 0) {
return null;
}
Set<Long> ids = new HashSet<>();
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
ids.add(cursor.getLong(0));
}
NotesBatch batch = new NotesBatch(batchId, ids);
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, "Latest cut batch: " + batch);
return batch;
} finally {
cursor.close();
}
}
use of com.orgzly.android.NotesBatch in project orgzly-android by orgzly.
the class NotesClient method paste.
public static NotesBatch paste(Context context, long bookId, long noteId, Place place) {
NotesBatch batch = getLatestNotesBatch(context);
if (batch != null) {
ContentValues values = new ContentValues();
values.put(ProviderContract.Paste.Param.SPOT, place.toString());
values.put(ProviderContract.Paste.Param.NOTE_ID, noteId);
values.put(ProviderContract.Paste.Param.BATCH_ID, batch.getId());
context.getContentResolver().update(ProviderContract.Paste.ContentUri.paste(), values, null, null);
}
return batch;
}
Aggregations