use of android.content.OperationApplicationException in project orgzly-android by orgzly.
the class NotesClient method updateScheduledTime.
public static void updateScheduledTime(Context context, Set<Long> noteIds, OrgDateTime time) {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
String noteIdsCommaSeparated = TextUtils.join(",", noteIds);
/* Update notes. */
ContentValues values = new ContentValues();
if (time != null) {
values.put(ProviderContract.Notes.UpdateParam.SCHEDULED_STRING, new OrgRange(time).toString());
} else {
values.putNull(ProviderContract.Notes.UpdateParam.SCHEDULED_STRING);
}
ops.add(ContentProviderOperation.newUpdate(ProviderContract.Notes.ContentUri.notes()).withValues(values).withSelection(ProviderContract.Notes.UpdateParam._ID + " IN (" + noteIdsCommaSeparated + ")", null).build());
updateBooksMtimeForNotes(context, noteIdsCommaSeparated, ops);
/*
* Apply batch.
*/
try {
context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of android.content.OperationApplicationException in project orgzly-android by orgzly.
the class NotesClient method create.
/**
* Insert as last note if position is not specified.
*/
public static Note create(Context context, Note note, NotePlace target, long time) {
ContentValues values = new ContentValues();
toContentValues(values, note);
Uri insertUri;
if (target != null) {
/* Create note relative to an existing note. */
insertUri = ProviderContract.Notes.ContentUri.notesIdTarget(target);
} else {
/* Create as last note. */
insertUri = ProviderContract.Notes.ContentUri.notes();
}
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
/* Insert note. */
ops.add(ContentProviderOperation.newInsert(insertUri).withValues(values).build());
/* Add each of the note's property. */
int i = 0;
OrgProperties properties = note.getHead().getProperties();
for (String name : properties.keySet()) {
String value = properties.get(name);
values = new ContentValues();
values.put(ProviderContract.NoteProperties.Param.NAME, name);
values.put(ProviderContract.NoteProperties.Param.VALUE, value);
values.put(ProviderContract.NoteProperties.Param.POSITION, i++);
ops.add(ContentProviderOperation.newInsert(ProviderContract.NoteProperties.ContentUri.notesProperties()).withValues(values).withValueBackReference(ProviderContract.NoteProperties.Param.NOTE_ID, 0).build());
}
// Update book's modification time
ops.add(ContentProviderOperation.newUpdate(ProviderContract.Books.ContentUri.books()).withValue(DbBook.MTIME, time).withSelection(DbBook._ID + " = " + note.getPosition().getBookId(), null).build());
ContentProviderResult[] result;
try {
result = context.getContentResolver().applyBatch(ProviderContract.AUTHORITY, ops);
} catch (RemoteException | OperationApplicationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
long noteId = ContentUris.parseId(result[0].uri);
/* Update ID of newly inserted note. */
note.setId(noteId);
return note;
}
use of android.content.OperationApplicationException in project Signal-Android by WhisperSystems.
the class DirectoryHelper method updateContactsDatabase.
private static void updateContactsDatabase(@NonNull Context context, @NonNull Collection<RecipientId> activeIds, boolean removeMissing, @NonNull Map<String, String> rewrites) {
if (!Permissions.hasAll(context, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS)) {
Log.w(TAG, "[updateContactsDatabase] No contact permissions. Skipping.");
return;
}
AccountHolder account = getOrCreateSystemAccount(context);
if (account == null) {
Log.w(TAG, "Failed to create an account!");
return;
}
try {
ContactsDatabase contactsDatabase = SignalDatabase.contacts();
List<String> activeAddresses = Stream.of(activeIds).map(Recipient::resolved).filter(Recipient::hasE164).map(Recipient::requireE164).toList();
contactsDatabase.removeDeletedRawContacts(account.getAccount());
contactsDatabase.setRegisteredUsers(account.getAccount(), activeAddresses, removeMissing);
syncRecipientInfoWithSystemContacts(context, rewrites);
} catch (RemoteException | OperationApplicationException e) {
Log.w(TAG, "Failed to update contacts.", e);
}
}
use of android.content.OperationApplicationException in project android by nextcloud.
the class FileDataStorageManager method updateSharedFiles.
public void updateSharedFiles(Collection<OCFile> sharedFiles) {
resetShareFlagsInAllFiles();
if (sharedFiles != null) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>(sharedFiles.size());
// prepare operations to insert or update files to save in the given folder
for (OCFile file : sharedFiles) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimeType());
cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
if (!file.isFolder()) {
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
}
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, user.getAccountName());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
cv.put(ProviderTableMeta.FILE_ETAG_ON_SERVER, file.getEtagOnServer());
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
cv.put(ProviderTableMeta.FILE_FAVORITE, file.isFavorite());
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.isUpdateThumbnailNeeded() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_IS_DOWNLOADING, file.isDownloading() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_ETAG_IN_CONFLICT, file.getEtagInConflict());
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
// updating an existing file
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).withValues(cv).withSelection(ProviderTableMeta._ID + "=?", new String[] { String.valueOf(file.getFileId()) }).build());
} else {
// adding a new file
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build());
}
}
// apply operations in batch
if (operations.size() > 0) {
@SuppressWarnings("unused") ContentProviderResult[] results = null;
Log_OC.d(TAG, String.format(Locale.ENGLISH, SENDING_TO_FILECONTENTPROVIDER_MSG, operations.size()));
try {
if (getContentResolver() != null) {
results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
} else {
results = getContentProviderClient().applyBatch(operations);
}
} catch (OperationApplicationException | RemoteException e) {
Log_OC.e(TAG, EXCEPTION_MSG + e.getMessage(), e);
}
}
}
}
use of android.content.OperationApplicationException in project android by nextcloud.
the class FileDataStorageManager method saveSharesDB.
public void saveSharesDB(List<OCShare> shares) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
// Reset flags & Remove shares for this files
String filePath = "";
for (OCShare share : shares) {
if (!filePath.equals(share.getPath())) {
filePath = share.getPath();
resetShareFlagInAFile(filePath);
operations = prepareRemoveSharesInFile(filePath, operations);
}
}
// Add operations to insert shares
operations = prepareInsertShares(shares, operations);
// apply operations in batch
if (operations.size() > 0) {
Log_OC.d(TAG, String.format(Locale.ENGLISH, SENDING_TO_FILECONTENTPROVIDER_MSG, operations.size()));
try {
if (getContentResolver() != null) {
getContentResolver().applyBatch(MainApp.getAuthority(), operations);
} else {
getContentProviderClient().applyBatch(operations);
}
} catch (OperationApplicationException | RemoteException e) {
Log_OC.e(TAG, EXCEPTION_MSG + e.getMessage(), e);
}
}
}
Aggregations