Skip to content

Commit 6de9b48

Browse files
committed
fix: git conflicts
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 1000c82 commit 6de9b48

4 files changed

Lines changed: 24 additions & 118 deletions

File tree

app/src/main/java/com/nextcloud/client/database/dao/UploadDao.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,24 @@ interface UploadDao {
4545
"AND ${ProviderTableMeta.UPLOADS_REMOTE_PATH} = :remotePath"
4646
)
4747
fun deleteByAccountAndRemotePath(accountName: String, remotePath: String)
48+
49+
@Query(
50+
"SELECT * FROM " + ProviderTableMeta.UPLOADS_TABLE_NAME +
51+
" WHERE " + ProviderTableMeta._ID + " = :id AND " +
52+
ProviderTableMeta.UPLOADS_ACCOUNT_NAME + " = :accountName " +
53+
"LIMIT 1"
54+
)
55+
fun getUploadById(id: Long, accountName: String): UploadEntity?
56+
57+
@Insert(onConflict = OnConflictStrategy.Companion.REPLACE)
58+
fun insertOrReplace(entity: UploadEntity): Long
59+
60+
@Query(
61+
"SELECT * FROM " + ProviderTableMeta.UPLOADS_TABLE_NAME +
62+
" WHERE " + ProviderTableMeta.UPLOADS_ACCOUNT_NAME + " = :accountName AND " +
63+
ProviderTableMeta.UPLOADS_LOCAL_PATH + " = :localPath AND " +
64+
ProviderTableMeta.UPLOADS_REMOTE_PATH + " = :remotePath " +
65+
"LIMIT 1"
66+
)
67+
fun getUploadByAccountAndPaths(accountName: String, localPath: String, remotePath: String): UploadEntity?
4868
}

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ class FileUploadHelper {
232232
ioScope.launch {
233233
uploadsStorageManager.run {
234234
uploadDao.getByRemotePath(remotePath)?.let { entity ->
235-
entity.status = UploadStatus.UPLOAD_CANCELLED.value
236-
uploadDao.update(entity)
235+
uploadDao.update(entity.copy(status = UploadStatus.UPLOAD_CANCELLED.value))
237236
}
238237
}
239238
}

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.nextcloud.model.WorkerState
2525
import com.nextcloud.model.WorkerStateLiveData
2626
import com.nextcloud.utils.ForegroundServiceHelper
2727
import com.nextcloud.utils.extensions.getPercent
28+
import com.nextcloud.utils.extensions.updateStatus
2829
import com.owncloud.android.R
2930
import com.owncloud.android.datamodel.FileDataStorageManager
3031
import com.owncloud.android.datamodel.ForegroundServiceType
@@ -258,6 +259,8 @@ class FileUploadWorker(
258259
val result = withContext(Dispatchers.IO) {
259260
upload(operation, user, client)
260261
}
262+
val entity = uploadsStorageManager.uploadDao.getUploadById(upload.uploadId, accountName)
263+
uploadsStorageManager.updateStatus(entity, result.isSuccess)
261264
currentUploadFileOperation = null
262265
sendUploadFinishEvent(totalUploadSize, currentUploadIndex, operation, result)
263266
}

app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
*/
1515
package com.owncloud.android.datamodel;
1616

17-
import android.content.ContentProviderOperation;
18-
import android.content.ContentProviderResult;
1917
import android.content.ContentResolver;
2018
import android.content.ContentValues;
21-
import android.content.OperationApplicationException;
2219
import android.database.Cursor;
23-
import android.net.Uri;
24-
import android.os.RemoteException;
2520

2621
import com.nextcloud.client.account.CurrentAccountProvider;
2722
import com.nextcloud.client.account.User;
@@ -94,97 +89,6 @@ private void initOCCapability() {
9489
}
9590
}
9691

97-
/**
98-
* Stores an upload object in DB.
99-
*
100-
* @param ocUpload Upload object to store
101-
* @return upload id, -1 if the insert process fails.
102-
*/
103-
public long storeUpload(OCUpload ocUpload) {
104-
OCUpload existingUpload = getPendingCurrentOrFailedUpload(ocUpload);
105-
if (existingUpload != null) {
106-
Log_OC.v(TAG, "Will update upload in db since " + ocUpload.getLocalPath() + " already exists as " +
107-
"pending, current or failed upload");
108-
long existingId = existingUpload.getUploadId();
109-
ocUpload.setUploadId(existingId);
110-
updateUpload(ocUpload);
111-
return existingId;
112-
}
113-
114-
115-
Log_OC.v(TAG, "Inserting " + ocUpload.getLocalPath() + " with status=" + ocUpload.getUploadStatus());
116-
117-
ContentValues cv = getContentValues(ocUpload);
118-
Uri result = getDB().insert(ProviderTableMeta.CONTENT_URI_UPLOADS, cv);
119-
120-
Log_OC.d(TAG, "storeUpload returns with: " + result + " for file: " + ocUpload.getLocalPath());
121-
if (result == null) {
122-
Log_OC.e(TAG, "Failed to insert item " + ocUpload.getLocalPath() + " into upload db.");
123-
return -1;
124-
} else {
125-
long new_id = Long.parseLong(result.getPathSegments().get(1));
126-
ocUpload.setUploadId(new_id);
127-
notifyObserversNow();
128-
129-
return new_id;
130-
}
131-
132-
}
133-
134-
public void storeUploads(final List<OCUpload> ocUploads) {
135-
Log_OC.v(TAG, "Inserting " + ocUploads.size() + " uploads");
136-
ArrayList<ContentProviderOperation> operations = new ArrayList<>(ocUploads.size());
137-
for (OCUpload ocUpload : ocUploads) {
138-
139-
OCUpload existingUpload = getPendingCurrentOrFailedUpload(ocUpload);
140-
if (existingUpload != null) {
141-
Log_OC.v(TAG, "Will update upload in db since " + ocUpload.getLocalPath() + " already exists as" +
142-
" pending, current or failed upload");
143-
ocUpload.setUploadId(existingUpload.getUploadId());
144-
updateUpload(ocUpload);
145-
continue;
146-
}
147-
148-
final ContentProviderOperation operation = ContentProviderOperation
149-
.newInsert(ProviderTableMeta.CONTENT_URI_UPLOADS)
150-
.withValues(getContentValues(ocUpload))
151-
.build();
152-
operations.add(operation);
153-
}
154-
155-
try {
156-
final ContentProviderResult[] contentProviderResults = getDB().applyBatch(MainApp.getAuthority(), operations);
157-
for (int i = 0; i < contentProviderResults.length; i++) {
158-
final ContentProviderResult result = contentProviderResults[i];
159-
final long new_id = Long.parseLong(result.uri.getPathSegments().get(1));
160-
ocUploads.get(i).setUploadId(new_id);
161-
}
162-
notifyObserversNow();
163-
} catch (OperationApplicationException | RemoteException e) {
164-
Log_OC.e(TAG, "Error inserting uploads", e);
165-
}
166-
}
167-
168-
@NonNull
169-
private ContentValues getContentValues(OCUpload ocUpload) {
170-
ContentValues cv = new ContentValues();
171-
cv.put(ProviderTableMeta.UPLOADS_LOCAL_PATH, ocUpload.getLocalPath());
172-
cv.put(ProviderTableMeta.UPLOADS_REMOTE_PATH, ocUpload.getRemotePath());
173-
cv.put(ProviderTableMeta.UPLOADS_ACCOUNT_NAME, ocUpload.getAccountName());
174-
cv.put(ProviderTableMeta.UPLOADS_FILE_SIZE, ocUpload.getFileSize());
175-
cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value);
176-
cv.put(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR, ocUpload.getLocalAction());
177-
cv.put(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY, ocUpload.getNameCollisionPolicy().serialize());
178-
cv.put(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER, ocUpload.isCreateRemoteFolder() ? 1 : 0);
179-
cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue());
180-
cv.put(ProviderTableMeta.UPLOADS_CREATED_BY, ocUpload.getCreatedBy());
181-
cv.put(ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY, ocUpload.isWhileChargingOnly() ? 1 : 0);
182-
cv.put(ProviderTableMeta.UPLOADS_IS_WIFI_ONLY, ocUpload.isUseWifiOnly() ? 1 : 0);
183-
cv.put(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN, ocUpload.getFolderUnlockToken());
184-
return cv;
185-
}
186-
187-
18892
/**
18993
* Update an upload object in DB.
19094
*
@@ -414,26 +318,6 @@ public OCUpload getPendingCurrentOrFailedUpload(OCUpload upload) {
414318
return null;
415319
}
416320

417-
@Nullable
418-
public OCUpload getUploadByRemotePath(String remotePath) {
419-
OCUpload result = null;
420-
try (Cursor cursor = getDB().query(
421-
ProviderTableMeta.CONTENT_URI_UPLOADS,
422-
null,
423-
ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?",
424-
new String[]{remotePath},
425-
ProviderTableMeta.UPLOADS_REMOTE_PATH + " ASC")) {
426-
427-
if (cursor != null) {
428-
if (cursor.moveToFirst()) {
429-
result = createOCUploadFromCursor(cursor);
430-
}
431-
}
432-
}
433-
Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath);
434-
return result;
435-
}
436-
437321
public @Nullable
438322
OCUpload getUploadById(long id) {
439323
OCUpload result = null;

0 commit comments

Comments
 (0)