Here are the examples of the java api android.content.ContentProviderResult taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
40 Examples
19
Source : AbsStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
static int extractId(ContentProviderResult result) {
return Integer.parseInt(result.uri.getPathSegments().get(1));
}
19
Source : ActivityItemsProvider.java
with Apache License 2.0
from OlgaKuklina
with Apache License 2.0
from OlgaKuklina
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
19
Source : ItemsProvider.java
with Apache License 2.0
from Madonahs
with Apache License 2.0
from Madonahs
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@NonNull
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
19
Source : ReminderCalendarProviderObserver.java
with GNU General Public License v3.0
from Kunzisoft
with GNU General Public License v3.0
from Kunzisoft
/**
* Apply operations
*/
private void applyBatch() {
try {
ContentProviderResult[] contentProviderResults = contentResolver.applyBatch(CalendarContract.AUTHORITY, ops);
for (ContentProviderResult result : contentProviderResults) if (result.uri != null)
Log.d(this.getClreplaced().getSimpleName(), result.uri.toString());
} catch (RemoteException | OperationApplicationException e) {
Log.e(this.getClreplaced().getSimpleName(), e.getMessage());
} finally {
ops.clear();
}
}
19
Source : RviewProvider.java
with Apache License 2.0
from jruesga
with Apache License 2.0
from jruesga
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> ops) throws OperationApplicationException {
ContentProviderResult[] results;
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
results = super.applyBatch(ops);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return results;
}
19
Source : VCardEntryCommitter.java
with Apache License 2.0
from alperali
with Apache License 2.0
from alperali
private Uri pushIntoContentResolver(ArrayList<ContentProviderOperation> operationList) {
try {
final ContentProviderResult[] results = mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);
// the first result is always the raw_contact. return it's uri so
// that it can be found later. do null checking for badly behaving
// ContentResolvers
return ((results == null || results.length == 0 || results[0] == null) ? null : results[0].uri);
} catch (RemoteException e) {
Log.e(LOG_TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
} catch (OperationApplicationException e) {
Log.e(LOG_TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
}
}
18
Source : SQLiteContentProvider.java
with Apache License 2.0
from yuchuangu85
with Apache License 2.0
from yuchuangu85
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
int ypCount = 0;
int opCount = 0;
boolean callerIsSyncAdapter = false;
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
mApplyingBatch.set(true);
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
throw new OperationApplicationException("Too many content provider operations between yield points. " + "The maximum number of operations per yield point is " + MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
}
final ContentProviderOperation operation = operations.get(i);
if (!callerIsSyncAdapter && isCallerSyncAdapter(operation.getUri())) {
callerIsSyncAdapter = true;
}
if (i > 0 && operation.isYieldAllowed()) {
opCount = 0;
if (db.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
ypCount++;
}
}
results[i] = operation.apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
mApplyingBatch.set(false);
db.endTransaction();
onEndTransaction(callerIsSyncAdapter);
}
}
18
Source : CoinProvider.java
with MIT License
from xionger
with MIT License
from xionger
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = dbHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
18
Source : AddContactActivity.java
with Apache License 2.0
from UriahShaulMandel
with Apache License 2.0
from UriahShaulMandel
public boolean insert() {
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
final String name = String.valueOf(et_name.getText());
operations.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null).withValue(ContactsContract.RawContacts.DIRTY, false).build());
operations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, name).withValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, null).withValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME, null).build());
try {
ContentProviderResult[] results = getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
try (Cursor contactsCursor = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, null, ContactsContract.RawContacts._ID + "=?", new String[] { String.valueOf(ContentUris.parseId(results[0].uri)) }, null)) {
if (!contactsCursor.moveToFirst())
throw new replacedertionError("cursor is empty");
final String contactId = contactsCursor.getString(contactsCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID));
currentContact = Contact.fromId(contactId, getContentResolver());
}
return update();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
}
}
18
Source : LauncherProvider.java
with Apache License 2.0
from Launcher3-dev
with Apache License 2.0
from Launcher3-dev
@Override
@NonNull
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
// XLog.e(XLog.getTag(), XLog.TAG_GU + operations);
createDbIfNotExists();
try (SQLiteTransaction t = new SQLiteTransaction(mOpenHelper.getWritableDatabase())) {
ContentProviderResult[] result = super.applyBatch(operations);
t.commit();
reloadLauncherIfExternal();
return result;
}
}
18
Source : SQLiteContentProvider.java
with Apache License 2.0
from alperali
with Apache License 2.0
from alperali
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
int ypCount = 0;
int opCount = 0;
mDb = mOpenHelper.getWritableDatabase();
mDb.beginTransactionWithListener(this);
try {
mApplyingBatch.set(true);
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
if (++opCount > getMaxOperationsPerYield()) {
throw new OperationApplicationException("Too many content provider operations between yield points. " + "The maximum number of operations per yield point is " + MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
}
final ContentProviderOperation operation = operations.get(i);
if (i > 0 && operation.isYieldAllowed()) {
opCount = 0;
boolean savedNotifyChange = mNotifyChange;
if (mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
mDb = mOpenHelper.getWritableDatabase();
mNotifyChange = savedNotifyChange;
ypCount++;
}
}
results[i] = operation.apply(this, results, i);
}
mDb.setTransactionSuccessful();
return results;
} finally {
mApplyingBatch.set(false);
mDb.endTransaction();
onEndTransaction();
}
}
17
Source : FaveStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> storeArticles(int accountId, List<ArticleEnreplacedy> articles, boolean clearBeforeStore) {
return Single.create(e -> {
Uri uri = MessengerContentProvider.getFaveArticlesContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBeforeStore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[articles.size()];
for (int i = 0; i < articles.size(); i++) {
ArticleEnreplacedy dbo = articles.get(i);
ContentValues cv = new ContentValues();
cv.put(FaveArticlesColumns.ARTICLE, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[results.length];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
e.onSuccess(ids);
});
}
17
Source : FaveStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> storeVideos(int accountId, List<VideoEnreplacedy> videos, boolean clearBeforeStore) {
return Single.create(e -> {
Uri uri = MessengerContentProvider.getFaveVideosContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBeforeStore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[videos.size()];
for (int i = 0; i < videos.size(); i++) {
VideoEnreplacedy dbo = videos.get(i);
ContentValues cv = new ContentValues();
cv.put(FaveVideosColumns.VIDEO, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[results.length];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
e.onSuccess(ids);
});
}
17
Source : UtilAddContact.java
with Apache License 2.0
from srasthofer
with Apache License 2.0
from srasthofer
public static void writePhoneContact(String displayName, String number) {
// Application's context or Activity's context
Context contetx = Hooker.applicationContext;
// Name of the Person to add
String strDisplayName = displayName;
// number of the person to add with the Contact
String strNumber = number;
ArrayList<ContentProviderOperation> cntProOper = new ArrayList<ContentProviderOperation>();
// ContactSize
int contactIndex = cntProOper.size();
// Newly Inserted contact
// A raw contact will be inserted ContactsContract.RawContacts table in contacts database.
cntProOper.add(// Step1
ContentProviderOperation.newInsert(RawContacts.CONTENT_URI).withValue(RawContacts.ACCOUNT_TYPE, null).withValue(RawContacts.ACCOUNT_NAME, null).build());
// Display name will be inserted in ContactsContract.Data table
cntProOper.add(// Step2
ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, contactIndex).withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE).withValue(StructuredName.DISPLAY_NAME, // Name of the contact
strDisplayName).build());
// Mobile number will be inserted in ContactsContract.Data table
cntProOper.add(// Step 3
ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, contactIndex).withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE).withValue(Phone.NUMBER, // Number to be added
strNumber).withValue(Phone.TYPE, Phone.TYPE_MOBILE).build());
try {
// We will do batch operation to insert all above data
// Contains the output of the app of a ContentProviderOperation.
// It is sure to have exactly one of uri or count set
ContentProviderResult[] contentProresult = null;
// apply above data insertion into contacts list
contentProresult = contetx.getContentResolver().applyBatch(ContactsContract.AUTHORITY, cntProOper);
} catch (RemoteException exp) {
// logs;
} catch (OperationApplicationException exp) {
// logs
}
}
17
Source : LauncherProvider.java
with GNU General Public License v3.0
from LawnchairLauncher
with GNU General Public License v3.0
from LawnchairLauncher
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
createDbIfNotExists();
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
ContentProviderResult[] result = super.applyBatch(operations);
db.setTransactionSuccessful();
reloadLauncherIfExternal();
return result;
} finally {
db.endTransaction();
}
}
16
Source : MessagesStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> insert(int accountId, @NonNull List<MessageEnreplacedy> dbos) {
return Single.create(emitter -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
MessageEnreplacedy dbo = dbos.get(i);
int index = appendDboOperation(accountId, dbo, operations, null, null);
indexes[i] = index;
}
ContentProviderResult[] results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
16
Source : FaveStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> storeVideos(int accountId, List<VideoEnreplacedy> videos, boolean clearBeforeStore) {
return Single.create(e -> {
Uri uri = MessengerContentProvider.getFaveVideosContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBeforeStore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[videos.size()];
for (int i = 0; i < videos.size(); i++) {
VideoEnreplacedy dbo = videos.get(i);
ContentValues cv = new ContentValues();
cv.put(FaveVideosColumns.VIDEO, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
final int[] ids = new int[results.length];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
e.onSuccess(ids);
});
}
15
Source : ContactsProvider.java
with MIT License
from wix
with MIT License
from wix
public void saveContact(ReadableMap contact, Promise promise) {
try {
ArrayList<ContentProviderOperation> ops = (new Contact(contact)).createOps();
ContentResolver cr = this.context.getContentResolver();
ContentProviderResult[] result = cr.applyBatch(ContactsContract.AUTHORITY, ops);
promise.resolve(null);
} catch (Exception e) {
promise.reject(e);
}
}
15
Source : FeedStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> store(int accountId, @NonNull List<NewsEnreplacedy> dbos, @Nullable OwnerEnreplacedies owners, boolean clearBeforeStore) {
return Single.create(emitter -> {
Uri uri = MessengerContentProvider.getNewsContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBeforeStore) {
// for performance test (before - 500-600ms, after - 200-300ms)
// operations.add(ContentProviderOperation.newDelete(MessengerContentProvider.getNewsAttachmentsContentUriFor(accountId))
// .build());
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
NewsEnreplacedy dbo = dbos.get(i);
ContentValues cv = getCV(dbo);
ContentProviderOperation mainPostHeaderOperation = ContentProviderOperation.newInsert(uri).withValues(cv).build();
int mainPostHeaderIndex = addToListAndReturnIndex(operations, mainPostHeaderOperation);
indexes[i] = mainPostHeaderIndex;
}
if (nonNull(owners)) {
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
}
ContentProviderResult[] results;
synchronized (storeLock) {
results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
}
int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
15
Source : FaveStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> storeProducts(int accountId, List<MarketEnreplacedy> products, boolean clearBeforeStore) {
return Single.create(e -> {
Uri uri = MessengerContentProvider.getFaveProductsContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBeforeStore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[products.size()];
for (int i = 0; i < products.size(); i++) {
MarketEnreplacedy dbo = products.get(i);
ContentValues cv = new ContentValues();
cv.put(FaveProductColumns.PRODUCT, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[results.length];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
e.onSuccess(ids);
});
}
15
Source : FaveStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> storePhotos(int accountId, List<PhotoEnreplacedy> photos, boolean clearBeforeStore) {
return Single.create(e -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
Uri uri = MessengerContentProvider.getFavePhotosContentUriFor(accountId);
if (clearBeforeStore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
// массив для хранения индексов операций вставки для каждого фото
int[] indexes = new int[photos.size()];
for (int i = 0; i < photos.size(); i++) {
PhotoEnreplacedy dbo = photos.get(i);
ContentValues cv = new ContentValues();
cv.put(FavePhotosColumns.PHOTO_ID, dbo.getId());
cv.put(FavePhotosColumns.OWNER_ID, dbo.getOwnerId());
cv.put(FavePhotosColumns.POST_ID, dbo.getPostId());
cv.put(FavePhotosColumns.PHOTO, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[results.length];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
e.onSuccess(ids);
});
}
15
Source : AttachmentsStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> attachDbos(int accountId, int attachToType, int attachToDbid, @NonNull List<Enreplacedy> enreplacedies) {
return Single.create(emitter -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>(enreplacedies.size());
int[] indexes = new int[enreplacedies.size()];
for (int i = 0; i < enreplacedies.size(); i++) {
Enreplacedy enreplacedy = enreplacedies.get(i);
indexes[i] = appendAttachOperationWithStableAttachToId(operations, accountId, attachToType, attachToDbid, enreplacedy);
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[enreplacedies.size()];
for (int i = 0; i < indexes.length; i++) {
ContentProviderResult result = results[indexes[i]];
int dbid = Integer.parseInt(result.uri.getPathSegments().get(1));
ids[i] = dbid;
}
emitter.onSuccess(ids);
});
}
15
Source : SpatiAtlasProvider.java
with Apache License 2.0
from sevar83
with Apache License 2.0
from sevar83
/**
* Apply the given set of {@link ContentProviderOperation}, executing inside
* a {@link SQLiteDatabase} transaction. All changes will be rolled back if
* any single one fails.
*/
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
final SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.beginTransaction();
try {
final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) {
results[i] = operations.get(i).apply(this, results, i);
}
db.setTransactionSuccessful();
return results;
} finally {
db.endTransaction();
}
}
15
Source : MessagesStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> insert(int accountId, @NonNull List<MessageEnreplacedy> dbos) {
return Single.create(emitter -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
final int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
MessageEnreplacedy dbo = dbos.get(i);
int index = appendDboOperation(accountId, dbo, operations, null, null);
indexes[i] = index;
}
ContentProviderResult[] results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
final int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
15
Source : CommentsStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> insert(int accountId, int sourceId, int sourceOwnerId, int sourceType, List<CommentEnreplacedy> dbos, OwnerEnreplacedies owners, boolean clearBefore) {
return Single.create(emitter -> {
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBefore) {
ContentProviderOperation delete = ContentProviderOperation.newDelete(MessengerContentProvider.getCommentsContentUriFor(accountId)).withSelection(CommentsColumns.SOURCE_ID + " = ? " + " AND " + CommentsColumns.SOURCE_OWNER_ID + " = ? " + " AND " + CommentsColumns.COMMENT_ID + " != ? " + " AND " + CommentsColumns.SOURCE_TYPE + " = ?", new String[] { String.valueOf(sourceId), String.valueOf(sourceOwnerId), String.valueOf(CommentsColumns.PROCESSING_COMMENT_ID), String.valueOf(sourceType) }).build();
operations.add(delete);
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
CommentEnreplacedy dbo = dbos.get(i);
ContentProviderOperation mainPostHeaderOperation = ContentProviderOperation.newInsert(MessengerContentProvider.getCommentsContentUriFor(accountId)).withValues(getCV(sourceId, sourceOwnerId, sourceType, dbo)).build();
int mainPostHeaderIndex = addToListAndReturnIndex(operations, mainPostHeaderOperation);
indexes[i] = mainPostHeaderIndex;
for (Enreplacedy attachmentEnreplacedy : dbo.getAttachments()) {
appendAttachOperationWithBackReference(operations, accountId, AttachToType.COMMENT, mainPostHeaderIndex, attachmentEnreplacedy);
}
}
if (nonNull(owners)) {
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
}
ContentProviderResult[] results;
synchronized (mStoreLock) {
results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
}
final int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
14
Source : WallStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> storeWallEnreplacedies(int accountId, @NonNull List<PostEnreplacedy> dbos, @Nullable OwnerEnreplacedies owners, @Nullable IClearWallTask clearWall) {
return Single.create(emitter -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (nonNull(clearWall)) {
operations.add(operationForClearWall(accountId, clearWall.getOwnerId()));
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
PostEnreplacedy dbo = dbos.get(i);
ContentValues cv = createCv(dbo);
ContentProviderOperation mainPostHeaderOperation = ContentProviderOperation.newInsert(getPostsContentUriFor(accountId)).withValues(cv).build();
int mainPostHeaderIndex = addToListAndReturnIndex(operations, mainPostHeaderOperation);
indexes[i] = mainPostHeaderIndex;
appendDboAttachmentsAndCopies(dbo, operations, accountId, mainPostHeaderIndex);
}
if (nonNull(owners)) {
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
}
ContentProviderResult[] results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
14
Source : FeedStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> store(int accountId, @NonNull List<NewsEnreplacedy> dbos, @Nullable OwnerEnreplacedies owners, boolean clearBeforeStore) {
return Single.create(emitter -> {
Uri uri = MessengerContentProvider.getNewsContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBeforeStore) {
// for performance test (before - 500-600ms, after - 200-300ms)
// operations.add(ContentProviderOperation.newDelete(MessengerContentProvider.getNewsAttachmentsContentUriFor(accountId))
// .build());
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
NewsEnreplacedy dbo = dbos.get(i);
ContentValues cv = getCV(dbo);
ContentProviderOperation mainPostHeaderOperation = ContentProviderOperation.newInsert(uri).withValues(cv).build();
int mainPostHeaderIndex = addToListAndReturnIndex(operations, mainPostHeaderOperation);
indexes[i] = mainPostHeaderIndex;
}
if (nonNull(owners)) {
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
}
ContentProviderResult[] results;
synchronized (storeLock) {
results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
}
final int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
14
Source : FaveStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> storePhotos(int accountId, List<PhotoEnreplacedy> photos, boolean clearBeforeStore) {
return Single.create(e -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
Uri uri = MessengerContentProvider.getFavePhotosContentUriFor(accountId);
if (clearBeforeStore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
// массив для хранения индексов операций вставки для каждого фото
int[] indexes = new int[photos.size()];
for (int i = 0; i < photos.size(); i++) {
PhotoEnreplacedy dbo = photos.get(i);
ContentValues cv = new ContentValues();
cv.put(FavePhotosColumns.PHOTO_ID, dbo.getId());
cv.put(FavePhotosColumns.OWNER_ID, dbo.getOwnerId());
cv.put(FavePhotosColumns.POST_ID, dbo.getPostId());
cv.put(FavePhotosColumns.PHOTO, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
final int[] ids = new int[results.length];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
e.onSuccess(ids);
});
}
13
Source : CommentsStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> insert(int accountId, int sourceId, int sourceOwnerId, int sourceType, List<CommentEnreplacedy> dbos, OwnerEnreplacedies owners, boolean clearBefore) {
return Single.create(emitter -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBefore) {
ContentProviderOperation delete = ContentProviderOperation.newDelete(MessengerContentProvider.getCommentsContentUriFor(accountId)).withSelection(CommentsColumns.SOURCE_ID + " = ? " + " AND " + CommentsColumns.SOURCE_OWNER_ID + " = ? " + " AND " + CommentsColumns.COMMENT_ID + " != ? " + " AND " + CommentsColumns.SOURCE_TYPE + " = ?", new String[] { String.valueOf(sourceId), String.valueOf(sourceOwnerId), String.valueOf(CommentsColumns.PROCESSING_COMMENT_ID), String.valueOf(sourceType) }).build();
operations.add(delete);
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
CommentEnreplacedy dbo = dbos.get(i);
ContentProviderOperation mainPostHeaderOperation = ContentProviderOperation.newInsert(MessengerContentProvider.getCommentsContentUriFor(accountId)).withValues(getCV(sourceId, sourceOwnerId, sourceType, dbo)).build();
int mainPostHeaderIndex = addToListAndReturnIndex(operations, mainPostHeaderOperation);
indexes[i] = mainPostHeaderIndex;
for (Enreplacedy attachmentEnreplacedy : dbo.getAttachments()) {
appendAttachOperationWithBackReference(operations, accountId, AttachToType.COMMENT, mainPostHeaderIndex, attachmentEnreplacedy);
}
}
if (nonNull(owners)) {
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
}
ContentProviderResult[] results;
synchronized (mStoreLock) {
results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
}
int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
13
Source : EventLoader.java
with GNU General Public License v3.0
from Kunzisoft
with GNU General Public License v3.0
from Kunzisoft
public synchronized static void deleteEventsFromContact(Context context, Contact contact) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
try {
for (CalendarEvent event : getEventsSavedForEachYear(context, contact)) {
operations.add(ReminderProvider.deleteAll(context, event.getId()));
operations.add(EventProvider.delete(event));
}
ContentProviderResult[] contentProviderResults = context.getContentResolver().applyBatch(CalendarContract.AUTHORITY, operations);
for (ContentProviderResult contentProviderResult : contentProviderResults) {
Log.d(TAG, contentProviderResult.toString());
if (contentProviderResult.uri != null)
Log.d(TAG, contentProviderResult.uri.toString());
}
} catch (RemoteException | OperationApplicationException | EventException e) {
Log.e(TAG, "Unable to deleteById events : " + e.getMessage());
}
}
12
Source : WallStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> storeWallEnreplacedies(int accountId, @NonNull List<PostEnreplacedy> dbos, @Nullable OwnerEnreplacedies owners, @Nullable IClearWallTask clearWall) {
return Single.create(emitter -> {
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (nonNull(clearWall)) {
operations.add(operationForClearWall(accountId, clearWall.getOwnerId()));
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
PostEnreplacedy dbo = dbos.get(i);
ContentValues cv = createCv(dbo);
ContentProviderOperation mainPostHeaderOperation = ContentProviderOperation.newInsert(getPostsContentUriFor(accountId)).withValues(cv).build();
int mainPostHeaderIndex = addToListAndReturnIndex(operations, mainPostHeaderOperation);
indexes[i] = mainPostHeaderIndex;
appendDboAttachmentsAndCopies(dbo, operations, accountId, mainPostHeaderIndex);
}
if (nonNull(owners)) {
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
}
ContentProviderResult[] results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
final int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
11
Source : BaseContentProvider.java
with Apache License 2.0
from mengdd
with Apache License 2.0
from mengdd
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
HashSet<Uri> urisToNotify = new HashSet<Uri>(operations.size());
for (ContentProviderOperation operation : operations) {
urisToNotify.add(operation.getUri());
}
SQLiteDatabase db = mSqLiteOpenHelper.getWritableDatabase();
db.beginTransaction();
try {
int numOperations = operations.size();
ContentProviderResult[] results = new ContentProviderResult[numOperations];
int i = 0;
for (ContentProviderOperation operation : operations) {
results[i] = operation.apply(this, results, i);
if (operation.isYieldAllowed()) {
db.yieldIfContendedSafely();
}
i++;
}
db.setTransactionSuccessful();
for (Uri uri : urisToNotify) {
getContext().getContentResolver().notifyChange(uri, null);
}
return results;
} finally {
db.endTransaction();
}
}
10
Source : WallStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<Integer> replacePost(int accountId, @NonNull PostEnreplacedy dbo) {
return Single.create(e -> {
Uri uri = getPostsContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
ContentValues cv = createCv(dbo);
if (dbo.getDbid() > 0) {
cv.put(BaseColumns._ID, dbo.getDbid());
// если пост был сохранен ранее - удаляем старые данные
// и сохраняем заново с тем же _ID
operations.add(ContentProviderOperation.newDelete(uri).withSelection(BaseColumns._ID + " = ?", new String[] { String.valueOf(dbo.getDbid()) }).build());
}
ContentProviderOperation main = ContentProviderOperation.newInsert(uri).withValues(cv).build();
int mainPostIndex = addToListAndReturnIndex(operations, main);
appendDboAttachmentsAndCopies(dbo, operations, accountId, mainPostIndex);
ContentProviderResult[] results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int dbid = extractId(results[mainPostIndex]);
e.onSuccess(dbid);
});
}
10
Source : WallStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<Integer> replacePost(int accountId, @NonNull PostEnreplacedy dbo) {
return Single.create(e -> {
Uri uri = getPostsContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
ContentValues cv = createCv(dbo);
if (dbo.getDbid() > 0) {
cv.put(PostsColumns._ID, dbo.getDbid());
// если пост был сохранен ранее - удаляем старые данные
// и сохраняем заново с тем же _ID
operations.add(ContentProviderOperation.newDelete(uri).withSelection(PostsColumns._ID + " = ?", new String[] { String.valueOf(dbo.getDbid()) }).build());
}
ContentProviderOperation main = ContentProviderOperation.newInsert(uri).withValues(cv).build();
int mainPostIndex = addToListAndReturnIndex(operations, main);
appendDboAttachmentsAndCopies(dbo, operations, accountId, mainPostIndex);
ContentProviderResult[] results = getContext().getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int dbid = extractId(results[mainPostIndex]);
e.onSuccess(dbid);
});
}
9
Source : EventLoader.java
with GNU General Public License v3.0
from Kunzisoft
with GNU General Public License v3.0
from Kunzisoft
public synchronized static void updateEvent(Context context, Contact contact, DateUnknownYear newBirthday) throws EventException {
// TODO UNIFORMISE
for (CalendarEvent event : getEventsSavedOrCreateNewsForEachYear(context, contact)) {
// Construct each anniversary of new birthday
int year = new DateTime(event.getDate()).getYear();
Date newBirthdayDate = DateUnknownYear.getDateWithYear(newBirthday.getDate(), year);
event.setDateStart(newBirthdayDate);
event.setAllDay(true);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
ContentProviderOperation contentProviderOperation = EventProvider.update(event);
operations.add(contentProviderOperation);
try {
ContentProviderResult[] contentProviderResults = context.getContentResolver().applyBatch(CalendarContract.AUTHORITY, operations);
for (ContentProviderResult contentProviderResult : contentProviderResults) {
if (contentProviderResult.count != 0)
Log.d(TAG, "Update event : " + event.toString());
}
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, "Unable to update event : " + e.getMessage());
}
}
}
9
Source : EventLoader.java
with GNU General Public License v3.0
from Kunzisoft
with GNU General Public License v3.0
from Kunzisoft
/**
* Save all events and default reminders from contacts with birthday
* @param context Context to call
*/
public synchronized static void saveEventsIfNotExistsFromAllContactWithBirthday(Context context) {
ContentResolver contentResolver = context.getContentResolver();
if (contentResolver == null) {
Log.e(TAG, "Unable to getAutoSmsById content resolver!");
return;
}
long calendarId = CalendarLoader.getCalendar(context);
if (calendarId == -1) {
Log.e(TAG, "Unable to create calendar");
return;
}
// Sync flow:
// 1. Clear events table for this account completely
// CalendarLoader.cleanTables(context, calendarId);
// 2. Get birthdays from contacts
// 3. Create events and reminders for each birthday
// List<ContactEventOperation> contactEventOperationList = new ArrayList<>();
ArrayList<ContentProviderOperation> allOperationList = new ArrayList<>();
// iterate through all Contact
List<Contact> contactList = ContactLoader.getAllContacts(context);
int backRef = 0;
for (Contact contact : contactList) {
// TODO Ids
Log.d(TAG, "BackRef is " + backRef);
// If next event in calendar is empty, add new event
CalendarEvent eventToAdd = CalendarEvent.buildDefaultEventFromContactToSave(context, contact);
// TODO ENCAPSULATE
EventWithoutYear eventWithoutYear = new EventWithoutYear(eventToAdd);
List<CalendarEvent> eventsAroundNeeded = eventWithoutYear.getEventsAroundAndForThisYear();
List<CalendarEvent> eventsAroundSaved = getEventsFromContactWithYears(context, contact, eventWithoutYear.getListOfYearsForEachEvent());
for (CalendarEvent event : eventsAroundNeeded) {
if (!eventsAroundSaved.contains(event)) {
// Add event operation in list of contact manager
allOperationList.add(EventProvider.insert(context, calendarId, event, contact));
int noOfReminderOperations = 0;
for (Reminder reminder : eventToAdd.getReminders()) {
allOperationList.add(ReminderProvider.insert(context, reminder, backRef));
noOfReminderOperations += 1;
}
// back references for the next reminders, 1 is for the event
backRef += 1 + noOfReminderOperations;
}
}
}
/* Create events with reminders and linkEventContract
* intermediate commit - otherwise the binder transaction fails on large
* operationList
* TODO for large list > 200, make multiple apply
*/
try {
Log.d(TAG, "Start applying the batch...");
/*
* Apply all Reminder Operations
*/
ContentProviderResult[] contentProviderResults = contentResolver.applyBatch(CalendarContract.AUTHORITY, allOperationList);
for (ContentProviderResult contentProviderResult : contentProviderResults) {
Log.d(TAG, "ReminderOperation apply : " + contentProviderResult.toString());
}
Log.d(TAG, "Applying the batch was successful!");
} catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, "Applying batch error!", e);
}
}
8
Source : FeedbackStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<int[]> insert(int accountId, List<FeedbackEnreplacedy> dbos, OwnerEnreplacedies owners, boolean clearBefore) {
return Single.create(emitter -> {
Uri uri = MessengerContentProvider.getNotificationsContentUriFor(accountId);
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBefore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
FeedbackEnreplacedy dbo = dbos.get(i);
ContentValues cv = new ContentValues();
cv.put(NotificationColumns.DATE, dbo.getDate());
cv.put(NotificationColumns.TYPE, typeForClreplaced(dbo.getClreplaced()));
cv.put(NotificationColumns.DATA, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
8
Source : FeedbackStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<int[]> insert(int accountId, List<FeedbackEnreplacedy> dbos, OwnerEnreplacedies owners, boolean clearBefore) {
return Single.create(emitter -> {
final Uri uri = MessengerContentProvider.getNotificationsContentUriFor(accountId);
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
if (clearBefore) {
operations.add(ContentProviderOperation.newDelete(uri).build());
}
int[] indexes = new int[dbos.size()];
for (int i = 0; i < dbos.size(); i++) {
FeedbackEnreplacedy dbo = dbos.get(i);
ContentValues cv = new ContentValues();
cv.put(NotificationColumns.DATE, dbo.getDate());
cv.put(NotificationColumns.TYPE, typeForClreplaced(dbo.getClreplaced()));
cv.put(NotificationColumns.DATA, GSON.toJson(dbo));
int index = addToListAndReturnIndex(operations, ContentProviderOperation.newInsert(uri).withValues(cv).build());
indexes[i] = index;
}
OwnersStorage.appendOwnersInsertOperations(operations, accountId, owners);
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
final int[] ids = new int[dbos.size()];
for (int i = 0; i < indexes.length; i++) {
int index = indexes[i];
ContentProviderResult result = results[index];
ids[i] = extractId(result);
}
emitter.onSuccess(ids);
});
}
1
Source : MessagesStorage.java
with GNU General Public License v3.0
from PhoenixDevTeam
with GNU General Public License v3.0
from PhoenixDevTeam
@Override
public Single<Integer> insert(int accountId, int peerId, @NonNull MessageEditEnreplacedy patch) {
return Single.create(emitter -> {
final ArrayList<ContentProviderOperation> operations = new ArrayList<>();
ContentValues cv = new ContentValues();
cv.put(MessageColumns.PEER_ID, peerId);
cv.put(MessageColumns.FROM_ID, patch.getSenderId());
cv.put(MessageColumns.DATE, patch.getDate());
// cv.put(MessageColumns.READ_STATE, patch.isRead());
cv.put(MessageColumns.OUT, patch.isOut());
// cv.put(MessageColumns.replacedLE, patch.getreplacedle());
cv.put(MessageColumns.BODY, patch.getBody());
cv.put(MessageColumns.ENCRYPTED, patch.isEncrypted());
cv.put(MessageColumns.IMPORTANT, patch.isImportant());
cv.put(MessageColumns.DELETED, patch.isDeleted());
cv.put(MessageColumns.FORWARD_COUNT, safeCountOf(patch.getForward()));
cv.put(MessageColumns.HAS_ATTACHMENTS, nonEmpty(patch.getAttachments()));
cv.put(MessageColumns.STATUS, patch.getStatus());
cv.put(MessageColumns.ATTACH_TO, MessageColumns.DONT_ATTACH);
cv.put(MessageColumns.EXTRAS, isNull(patch.getExtras()) ? null : GSON.toJson(patch.getExtras()));
// Other fileds is NULL
Uri uri = MessengerContentProvider.getMessageContentUriFor(accountId);
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri).withValues(cv);
int index = addToListAndReturnIndex(operations, builder.build());
if (nonEmpty(patch.getAttachments())) {
List<Enreplacedy> enreplacedies = patch.getAttachments();
for (Enreplacedy attachmentEnreplacedy : enreplacedies) {
AttachmentsStorage.appendAttachOperationWithBackReference(operations, accountId, AttachToType.MESSAGE, index, attachmentEnreplacedy);
}
}
if (nonEmpty(patch.getForward())) {
for (MessageEnreplacedy fwdDbo : patch.getForward()) {
appendDboOperation(accountId, fwdDbo, operations, null, index);
}
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int resultMessageId = extractId(results[index]);
emitter.onSuccess(resultMessageId);
});
}
0
Source : MessagesStorage.java
with GNU General Public License v3.0
from umerov1999
with GNU General Public License v3.0
from umerov1999
@Override
public Single<Integer> insert(int accountId, int peerId, @NonNull MessageEditEnreplacedy patch) {
return Single.create(emitter -> {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
ContentValues cv = new ContentValues();
cv.put(MessageColumns.PEER_ID, peerId);
cv.put(MessageColumns.FROM_ID, patch.getSenderId());
cv.put(MessageColumns.DATE, patch.getDate());
// cv.put(MessageColumns.READ_STATE, patch.isRead());
cv.put(MessageColumns.OUT, patch.isOut());
// cv.put(MessageColumns.replacedLE, patch.getreplacedle());
cv.put(MessageColumns.BODY, patch.getBody());
cv.put(MessageColumns.ENCRYPTED, patch.isEncrypted());
cv.put(MessageColumns.IMPORTANT, patch.isImportant());
cv.put(MessageColumns.DELETED, patch.isDeleted());
cv.put(MessageColumns.FORWARD_COUNT, safeCountOf(patch.getForward()));
cv.put(MessageColumns.HAS_ATTACHMENTS, nonEmpty(patch.getAttachments()));
cv.put(MessageColumns.STATUS, patch.getStatus());
cv.put(MessageColumns.ATTACH_TO, MessageColumns.DONT_ATTACH);
cv.put(MessageColumns.EXTRAS, isNull(patch.getExtras()) ? null : GSON.toJson(patch.getExtras()));
cv.put(MessageColumns.PAYLOAD, patch.getPayload());
cv.put(MessageColumns.KEYBOARD, isNull(patch.getKeyboard()) ? null : GSON.toJson(patch.getKeyboard()));
// Other fileds is NULL
Uri uri = MessengerContentProvider.getMessageContentUriFor(accountId);
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri).withValues(cv);
int index = addToListAndReturnIndex(operations, builder.build());
if (nonEmpty(patch.getAttachments())) {
List<Enreplacedy> enreplacedies = patch.getAttachments();
for (Enreplacedy attachmentEnreplacedy : enreplacedies) {
AttachmentsStorage.appendAttachOperationWithBackReference(operations, accountId, AttachToType.MESSAGE, index, attachmentEnreplacedy);
}
}
if (nonEmpty(patch.getForward())) {
for (MessageEnreplacedy fwdDbo : patch.getForward()) {
appendDboOperation(accountId, fwdDbo, operations, null, index);
}
}
ContentProviderResult[] results = getContentResolver().applyBatch(MessengerContentProvider.AUTHORITY, operations);
int resultMessageId = extractId(results[index]);
emitter.onSuccess(resultMessageId);
});
}