Skip to content

Commit adff331

Browse files
committed
Post merge WIP
1 parent 306db1e commit adff331

24 files changed

Lines changed: 969 additions & 81 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/DeleteTask.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,6 @@ private boolean doDeleteFile(@NonNull HybridFileParcelable file) throws Exceptio
195195
});
196196
}
197197
return true;
198-
// CloudStorage cloudStorage = dataUtils.getAccount(file.getMode());
199-
// try {
200-
// cloudStorage.delete(CloudUtil.stripPath(file.getMode(), file.getPath()));
201-
// return true;
202-
// } catch (Exception e) {
203-
// LOG.warn("failed to delete cloud files", e);
204-
// return false;
205-
// }
206198
default:
207199
try {
208200
/* SMB and SFTP (or any remote files that may support in the future) should not be

app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/movecopy/MoveFiles.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,38 @@
2121
package com.amaze.filemanager.asynchronous.asynctasks.movecopy;
2222

2323
import java.io.File;
24+
import java.io.FileOutputStream;
25+
import java.io.IOException;
2426
import java.util.ArrayList;
2527
import java.util.HashSet;
2628
import java.util.concurrent.Callable;
2729

2830
import org.slf4j.Logger;
2931
import org.slf4j.LoggerFactory;
3032

33+
import com.amaze.filemanager.application.AppConfig;
3134
import com.amaze.filemanager.fileoperations.exceptions.ShellNotRunningException;
3235
import com.amaze.filemanager.fileoperations.filesystem.OpenMode;
3336
import com.amaze.filemanager.filesystem.HybridFile;
3437
import com.amaze.filemanager.filesystem.HybridFileParcelable;
3538
import com.amaze.filemanager.filesystem.Operations;
39+
import com.amaze.filemanager.filesystem.cloud.CloudUtil;
3640
import com.amaze.filemanager.filesystem.files.FileUtils;
3741
import com.amaze.filemanager.filesystem.root.RenameFileCommand;
42+
import com.amaze.filemanager.utils.omh.OMHClientHelper;
43+
import com.amaze.filemanager.utils.omh.OmhAuthClientExtKt;
44+
import com.amaze.filemanager.utils.omh.OmhStorageClientExtKt;
45+
import com.openmobilehub.android.storage.core.OmhStorageClient;
46+
import com.openmobilehub.android.storage.core.model.OmhStorageEntity;
3847

3948
import android.content.Context;
4049

4150
import androidx.annotation.Nullable;
4251
import androidx.annotation.WorkerThread;
4352

53+
import kotlin.Unit;
54+
import kotlin.text.StringsKt;
55+
4456
/**
4557
* AsyncTask that moves files from source to destination by trying to rename files first, if they're
4658
* in the same filesystem, else starting the copy service. Be advised - do not start this AsyncTask
@@ -130,7 +142,56 @@ private MoveFilesReturn processFile(
130142
case BOX:
131143
case ONEDRIVE:
132144
case GDRIVE:
133-
// FIXME: OmhStorageClient should support move operation
145+
OmhStorageClient storageClient = OMHClientHelper.getStorageClient(mode);
146+
if (storageClient == null) {
147+
LOG.warn("No storage client available for mode: {}", mode);
148+
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
149+
}
150+
try {
151+
OmhAuthClientExtKt.retryOnUnauthorizedBlocking(
152+
mode,
153+
AppConfig.getInstance().getCloudAuthTrigger(),
154+
() -> {
155+
// 1. Download source file into a local temp file
156+
String name = baseFile.getName(context);
157+
String baseName = StringsKt.substringBeforeLast(name, ".", name);
158+
String ext = StringsKt.substringAfterLast(name, ".", "");
159+
File tmpFile;
160+
try {
161+
tmpFile =
162+
File.createTempFile(
163+
baseName, "." + ext, AppConfig.getInstance().getCacheDir());
164+
} catch (IOException e) {
165+
throw new RuntimeException(e);
166+
}
167+
tmpFile.deleteOnExit();
168+
try {
169+
OmhStorageClientExtKt.downloadFileBlocking(
170+
storageClient, baseFile.getCloudFileId())
171+
.writeTo(new FileOutputStream(tmpFile));
172+
} catch (IOException e) {
173+
throw new RuntimeException(e);
174+
}
175+
// 2. Resolve destination parent folder
176+
OmhStorageEntity destFolder =
177+
OmhStorageClientExtKt.resolvePathBlocking(
178+
storageClient, CloudUtil.stripCloudPath(mode, path));
179+
String parentId =
180+
(destFolder != null && destFolder.getId() != null)
181+
? destFolder.getId()
182+
: storageClient.getRootFolder();
183+
// 3. Upload to destination
184+
OmhStorageClientExtKt.uploadFileBlocking(storageClient, tmpFile, parentId);
185+
tmpFile.delete();
186+
// 4. Delete original source
187+
OmhStorageClientExtKt.deleteFileBlocking(storageClient, baseFile.getCloudFileId());
188+
return Unit.INSTANCE;
189+
});
190+
} catch (Exception e) {
191+
LOG.warn("Cloud move failed for {}", baseFile.getPath(), e);
192+
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
193+
}
194+
break;
134195
default:
135196
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
136197
}

app/src/main/java/com/amaze/filemanager/database/CloudContract.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ object CloudContract {
5959
OpenMode.GDRIVE,
6060
OpenMode.DROPBOX,
6161
OpenMode.ONEDRIVE,
62+
OpenMode.BOX,
6263
)
6364

6465
val ENABLED_PROVIDER_IDS: Array<String> =

app/src/main/java/com/amaze/filemanager/database/ExplorerDatabase.kt

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,70 @@ abstract class ExplorerDatabase : RoomDatabase() {
327327
internal val MIGRATION_11_12: Migration =
328328
object : Migration(11, DATABASE_VERSION) {
329329
override fun migrate(database: SupportSQLiteDatabase) {
330-
database.execSQL("DROP TABLE IF EXISTS $TABLE_CLOUD_PERSIST")
330+
database.execSQL(
331+
"CREATE TABLE " +
332+
TEMP_TABLE_PREFIX +
333+
TABLE_TAB +
334+
"(" +
335+
COLUMN_TAB_NO +
336+
" INTEGER PRIMARY KEY NOT NULL, " +
337+
COLUMN_PATH +
338+
" TEXT NOT NULL, " +
339+
COLUMN_HOME +
340+
" TEXT NOT NULL)",
341+
)
342+
database.execSQL(
343+
"INSERT INTO " +
344+
TEMP_TABLE_PREFIX +
345+
TABLE_TAB +
346+
"(" +
347+
COLUMN_TAB_NO +
348+
"," +
349+
COLUMN_PATH +
350+
"," +
351+
COLUMN_HOME +
352+
")" +
353+
" SELECT " +
354+
COLUMN_TAB_NO +
355+
"," +
356+
COLUMN_PATH +
357+
"," +
358+
COLUMN_HOME +
359+
" FROM " +
360+
TABLE_TAB,
361+
)
362+
database.execSQL("DROP TABLE $TABLE_TAB")
363+
database.execSQL(
364+
"ALTER TABLE $TEMP_TABLE_PREFIX$TABLE_TAB RENAME TO $TABLE_TAB",
365+
)
366+
367+
database.execSQL(
368+
"CREATE TABLE " +
369+
TEMP_TABLE_PREFIX +
370+
TABLE_ENCRYPTED +
371+
"(" +
372+
COLUMN_ENCRYPTED_ID +
373+
" INTEGER PRIMARY KEY NOT NULL," +
374+
COLUMN_ENCRYPTED_PATH +
375+
" TEXT NOT NULL," +
376+
COLUMN_ENCRYPTED_PASSWORD +
377+
" TEXT NOT NULL)",
378+
)
379+
database.execSQL(
380+
"INSERT INTO " +
381+
TEMP_TABLE_PREFIX +
382+
TABLE_ENCRYPTED +
383+
" SELECT * FROM " +
384+
TABLE_ENCRYPTED,
385+
)
386+
database.execSQL("DROP TABLE $TABLE_ENCRYPTED")
387+
database.execSQL(
388+
"ALTER TABLE " +
389+
TEMP_TABLE_PREFIX +
390+
TABLE_ENCRYPTED +
391+
" RENAME TO " +
392+
TABLE_ENCRYPTED,
393+
)
331394
}
332395
}
333396

0 commit comments

Comments
 (0)