use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class BooksClient method fromCursor.
public static Book fromCursor(Cursor cursor) {
Book book = new Book(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.NAME)), cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.PREFACE)), cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.MTIME)), cursor.getInt(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.IS_DUMMY)) == 1);
book.getOrgFileSettings().setTitle(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.TITLE)));
book.getOrgFileSettings().setIndented(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.IS_INDENTED)) == 1);
book.setId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param._ID)));
book.setSyncStatus(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNC_STATUS)));
book.setDetectedEncoding(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.DETECTED_ENCODING)));
book.setSelectedEncoding(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SELECTED_ENCODING)));
book.setUsedEncoding(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.USED_ENCODING)));
/* Set link. */
int linkRepoUriColumn = cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LINK_REPO_URL);
if (!cursor.isNull(linkRepoUriColumn)) {
Uri uri = Uri.parse(cursor.getString(linkRepoUriColumn));
book.setLinkRepo(uri);
}
/* Set versioned rook. */
if (!cursor.isNull(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_URL))) {
Uri syncRookUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_URL)));
Uri syncRepoUri = Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_REPO_URL)));
String rev = cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_REVISION));
long mtime = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.SYNCED_ROOK_MTIME));
VersionedRook vrook = new VersionedRook(syncRepoUri, syncRookUri, rev, mtime);
book.setLastSyncedToRook(vrook);
}
/* Set last action. */
String lastActionMessage = cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LAST_ACTION));
if (!TextUtils.isEmpty(lastActionMessage)) {
BookAction.Type lastActionType = BookAction.Type.valueOf(cursor.getString(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LAST_ACTION_TYPE)));
long lastActionTimestamp = cursor.getLong(cursor.getColumnIndexOrThrow(ProviderContract.Books.Param.LAST_ACTION_TIMESTAMP));
BookAction lastAction = new BookAction(lastActionType, lastActionMessage, lastActionTimestamp);
book.setLastAction(lastAction);
}
return book;
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class CurrentRooksClient method getAll.
public static Map<String, VersionedRook> getAll(Context context) {
Map<String, VersionedRook> result = new HashMap<>();
Cursor cursor = context.getContentResolver().query(ProviderContract.CurrentRooks.ContentUri.currentRooks(), null, null, null, null);
try {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
VersionedRook vrook = CurrentRooksClient.fromCursor(cursor);
result.put(vrook.getUri().toString(), vrook);
}
} finally {
cursor.close();
}
return result;
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class CurrentRooksClient method set.
public static void set(Context context, List<VersionedRook> books) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
/* Delete all previous. */
ops.add(ContentProviderOperation.newDelete(ProviderContract.CurrentRooks.ContentUri.currentRooks()).build());
/* Insert each one. */
for (VersionedRook book : books) {
ContentValues values = new ContentValues();
CurrentRooksClient.toContentValues(values, book);
ops.add(ContentProviderOperation.newInsert(ProviderContract.CurrentRooks.ContentUri.currentRooks()).withValues(values).build());
}
try {
context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
}
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class LocalDbRepoClient method retrieveBook.
public static VersionedRook retrieveBook(Context context, Uri repoUri, Uri uri, File file) throws IOException {
Cursor cursor = context.getContentResolver().query(ProviderContract.LocalDbRepo.ContentUri.dbRepos(), null, ProviderContract.LocalDbRepo.Param.URL + "=?", new String[] { uri.toString() }, null);
try {
if (!cursor.moveToFirst()) {
throw new IOException("Book " + uri + " not found in repo");
}
if (cursor.getCount() != 1) {
throw new IOException("Found " + cursor.getCount() + " books matching name " + uri);
}
/* Get data from Cursor. */
String content = cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.CONTENT));
String revision = cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.REVISION));
long mtime = cursor.getLong(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.MTIME));
/* Write content to file. */
MiscUtils.writeStringToFile(content, file);
/* Return book. */
return new VersionedRook(repoUri, uri, revision, mtime);
} finally {
cursor.close();
}
}
use of com.orgzly.android.repos.VersionedRook in project orgzly-android by orgzly.
the class LocalDbRepoClient method fromCursor.
public static VersionedRook fromCursor(Cursor cursor) {
Uri repoUri = Uri.parse(cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.REPO_URL)));
Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.URL)));
String revision = cursor.getString(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.REVISION));
long mtime = cursor.getLong(cursor.getColumnIndex(ProviderContract.LocalDbRepo.Param.MTIME));
return new VersionedRook(repoUri, uri, revision, mtime);
}
Aggregations