blkIds, FileTransferEntity t
Request request = new Request.Builder().url(link).post(body).build();
//
- if (newCall != null && !newCall.isCanceled()) {
- newCall.cancel();
+ if (newCall != null && newCall.isExecuted()) {
+ SLogs.d("Folder upload block: newCall has executed()");
}
+ try {
+ newCall = IO.getInstanceWithLoggedIn().getClient().newCall(request);
+ Response response = newCall.execute();
- newCall = IO.getInstanceWithLoggedIn().getClient().newCall(request);
- Response response = newCall.execute();
+ if (!response.isSuccessful()) {
+ String b = response.body() != null ? response.body().string() : null;
+ SLogs.d("上传结果,失败:" + b);
- if (!response.isSuccessful()) {
- String b = response.body() != null ? response.body().string() : null;
- SLogs.d("上传结果,失败:" + b);
+ //[text={"error": "Out of quota.\n"}]
+ if (b != null && b.toLowerCase().contains("out of quota")) {
+ throw SeafException.OUT_OF_QUOTA;
+ }
- //[text={"error": "Out of quota.\n"}]
- if (b != null && b.toLowerCase().contains("out of quota")) {
- throw SeafException.OUT_OF_QUOTA;
+ throw SeafException.networkException;
}
- throw SeafException.networkException;
- }
-
- String fileId = response.body().string();
+ String fileId = response.body().string();
- updateSuccess(transferEntity, fileId, file);
+ updateSuccess(transferEntity, fileId, file);
+ } catch (Exception e) {
+ throw e;
+ }
}
private void updateSuccess(FileTransferEntity transferEntity, String fileId, File file) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/FolderBackupScannerWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/FolderBackupScannerWorker.java
new file mode 100644
index 000000000..e1870ad23
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/FolderBackupScannerWorker.java
@@ -0,0 +1,339 @@
+package com.seafile.seadroid2.framework.worker.upload;
+
+import static com.seafile.seadroid2.config.Constants.PERIODIC_SCAN_INTERVALS;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import androidx.annotation.NonNull;
+import androidx.work.Data;
+import androidx.work.ForegroundInfo;
+import androidx.work.WorkerParameters;
+
+import com.blankj.utilcode.util.CollectionUtils;
+import com.seafile.seadroid2.R;
+import com.seafile.seadroid2.account.Account;
+import com.seafile.seadroid2.account.SupportAccountManager;
+import com.seafile.seadroid2.config.Constants;
+import com.seafile.seadroid2.framework.data.db.AppDatabase;
+import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity;
+import com.seafile.seadroid2.framework.data.db.entities.RepoModel;
+import com.seafile.seadroid2.framework.data.model.enums.TransferAction;
+import com.seafile.seadroid2.framework.data.model.enums.TransferDataSource;
+import com.seafile.seadroid2.framework.data.model.enums.TransferResult;
+import com.seafile.seadroid2.framework.data.model.enums.TransferStatus;
+import com.seafile.seadroid2.framework.datastore.StorageManager;
+import com.seafile.seadroid2.framework.datastore.sp.FolderBackupManager;
+import com.seafile.seadroid2.framework.notification.FolderBackupScanNotificationHelper;
+import com.seafile.seadroid2.framework.util.SLogs;
+import com.seafile.seadroid2.framework.util.Utils;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
+import com.seafile.seadroid2.framework.worker.ExistingFileStrategy;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
+import com.seafile.seadroid2.ui.folder_backup.RepoConfig;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+
+/**
+ *
+ * FileMonitor is {@link com.seafile.seadroid2.framework.file_monitor.SupportFileAlterationMonitor}
+ *
+ *
+ * Worker Tag:
+ *
+ * @see BackgroundJobManagerImpl#TAG_ALL
+ * @see BackgroundJobManagerImpl#TAG_TRANSFER
+ */
+public class FolderBackupScannerWorker extends TransferWorker {
+ public static final UUID UID = UUID.nameUUIDFromBytes(FolderBackupScannerWorker.class.getSimpleName().getBytes());
+
+ private final FolderBackupScanNotificationHelper notificationHelper;
+
+ public FolderBackupScannerWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
+ super(context, workerParams);
+
+ notificationHelper = new FolderBackupScanNotificationHelper(context);
+ }
+
+ @NonNull
+ @Override
+ public Result doWork() {
+ Account account = SupportAccountManager.getInstance().getCurrentAccount();
+ if (account == null) {
+ return Result.success();
+ }
+
+ String[] ids = getInputData().getStringArray(TransferWorker.DATA_CANCEL_IDS);
+ if (ids != null && ids.length > 0) {
+ List idList = Arrays.asList(ids);
+ //
+ removeFromDB(idList);
+
+ BackgroundJobManagerImpl.getInstance().startFolderUploadWorker();
+
+ return Result.success();
+ }
+
+ boolean canScan = checkCanScan();
+ if (!canScan) {
+ SLogs.i("The folder scan task was not started");
+
+ BackgroundJobManagerImpl.getInstance().startFolderUploadWorker();
+
+ return Result.success(getScanEndData());
+ }
+
+ List backupPaths = FolderBackupManager.readBackupPaths();
+ RepoConfig repoConfig = FolderBackupManager.readRepoConfig();
+ if (CollectionUtils.isEmpty(backupPaths) || repoConfig == null) {
+
+ return Result.success(getScanEndData());
+ }
+
+ //
+ String title = getApplicationContext().getString(R.string.settings_folder_backup_info_title);
+ String subTitle = getApplicationContext().getString(R.string.is_scanning);
+
+ ForegroundInfo foregroundInfo = notificationHelper.getForegroundNotification(title, subTitle);
+ showForegroundAsync(foregroundInfo);
+// notificationHelper.showNotification(nTitle);
+
+ try {
+ //send a scan event
+ sendEvent(TransferEvent.EVENT_SCANNING, TransferDataSource.FOLDER_BACKUP);
+
+ //do
+ traverseBackupPath(account, repoConfig, backupPaths);
+
+ } finally {
+ //
+// notificationHelper.cancel();
+
+ FolderBackupManager.writeLastScanTime(System.currentTimeMillis());
+
+ //start upload worker
+ BackgroundJobManagerImpl.getInstance().startFolderUploadWorker();
+ }
+
+ return Result.success(getScanEndData());
+ }
+
+ private Data getScanEndData() {
+ return new Data.Builder()
+ .putString(TransferWorker.KEY_DATA_EVENT, TransferEvent.EVENT_SCAN_END)
+ .putString(TransferWorker.KEY_DATA_TYPE, String.valueOf(TransferDataSource.FOLDER_BACKUP))
+ .build();
+ }
+
+ private boolean checkCanScan() {
+ boolean isOpenBackup = FolderBackupManager.readBackupSwitch();
+ if (!isOpenBackup) {
+ return false;
+ }
+
+ boolean isForce = getInputData().getBoolean(TransferWorker.DATA_FORCE_TRANSFER_KEY, false);
+ if (isForce) {
+ return true;
+ }
+
+ long lastScanTime = FolderBackupManager.readLastScanTime();
+ if (lastScanTime != 0) {
+ long now = System.currentTimeMillis();
+ if (now - lastScanTime < PERIODIC_SCAN_INTERVALS) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private void removeFromDB(List ids) {
+ List dbList = AppDatabase.getInstance().fileTransferDAO().getListByUidsSync(ids);
+ if (CollectionUtils.isEmpty(dbList)) {
+ return;
+ }
+
+ for (FileTransferEntity fileTransferEntity : dbList) {
+ AppDatabase.getInstance().fileTransferDAO().deleteOne(fileTransferEntity);
+ }
+ }
+
+ private void traverseBackupPath(Account account, RepoConfig repoConfig, List backupPathsList) {
+
+ List repoModels = AppDatabase.getInstance().repoDao().getByIdSync(repoConfig.getRepoID());
+
+ if (CollectionUtils.isEmpty(repoModels)) {
+ return;
+ }
+
+ RepoModel repoModel = repoModels.get(0);
+
+ for (String backupPath : backupPathsList) {
+ long lastTime = FolderBackupManager.readBackupPathLastScanTime(backupPath);
+
+ //iterate over local files
+ List localFiles = traverseFiles(backupPath, lastTime);
+
+ //write last scan time
+ FolderBackupManager.writeBackupPathLastScanTime(backupPath);
+
+ if (CollectionUtils.isEmpty(localFiles)) {
+ SLogs.e("没有新增、更新的文件: " + backupPath);
+ continue;
+ }
+ SLogs.e("新文件: " + localFiles.size());
+
+ int pageSize = 99;
+ if (localFiles.size() < pageSize) {
+ pageSize = localFiles.size();
+ }
+
+ for (int pageNumber = 1; pageNumber <= (localFiles.size() + pageSize - 1) / pageSize; pageNumber++) {
+ int fromIndex = (pageNumber - 1) * pageSize;
+ int toIndex = Math.min(pageNumber * pageSize, localFiles.size());
+ List subFiles = localFiles.subList(fromIndex, toIndex);
+
+ compareToLocalAndInsert(account, repoModel, backupPath, subFiles);
+ }
+ }
+ }
+
+ private void compareToLocalAndInsert(Account account, RepoModel repoModel, String backupPath, List subFiles) {
+ if (CollectionUtils.isEmpty(subFiles)) {
+ return;
+ }
+
+ List fullPaths = subFiles.stream().map(File::getAbsolutePath).collect(Collectors.toList());
+
+ List tempExistsList = AppDatabase
+ .getInstance()
+ .fileTransferDAO()
+ .getListByFullPathsSync(repoModel.repo_id, fullPaths, TransferAction.UPLOAD);
+
+ List tList = CollectionUtils.newArrayList();
+ for (File file : subFiles) {
+ FileTransferEntity fEntity = FileTransferEntity.convert2ThisForUploadFileSyncWorker(account, repoModel, file, backupPath);
+ if (fEntity != null) {
+ tList.add(fEntity);
+ }
+ }
+
+ if (CollectionUtils.isEmpty(tempExistsList)) {
+ AppDatabase.getInstance().fileTransferDAO().insertAll(tList);
+ return;
+ }
+
+ List newList = CollectionUtils.newArrayList();
+
+ int i = 0;
+
+ for (FileTransferEntity transferEntity : tList) {
+ i++;
+
+ Optional optional = tempExistsList.stream().filter(f -> TextUtils.equals(f.full_path, transferEntity.full_path)).findFirst();
+ if (!optional.isPresent()) {
+ newList.add(transferEntity);
+ SLogs.d(i + " :folder backup scan: new file(local empty): " + transferEntity.target_path);
+ continue;
+ }
+
+ FileTransferEntity dbEntity = optional.get();
+ if (dbEntity.data_status == Constants.DataStatus.DELETED) {
+ // has been deleted in db.
+ SLogs.d(i + " :folder backup scan: skip file(deleted): " + transferEntity.target_path);
+
+ } else if (TextUtils.equals(dbEntity.file_md5, transferEntity.file_md5)) {
+ //it's the same file,do not insert into db.
+ SLogs.d(i + " :folder backup scan: skip file(same file): " + transferEntity.target_path);
+
+ } else {
+ SLogs.d(i + " :folder backup scan: new file: " + transferEntity.target_path);
+
+ transferEntity.transfer_action = TransferAction.UPLOAD;
+ transferEntity.transfer_result = TransferResult.NO_RESULT;
+ transferEntity.transfer_status = TransferStatus.WAITING;
+ transferEntity.file_strategy = ExistingFileStrategy.REPLACE;
+ newList.add(transferEntity);
+ }
+ }
+
+ if (CollectionUtils.isEmpty(newList)) {
+ AppDatabase.getInstance().fileTransferDAO().insertAll(newList);
+ }
+
+ }
+
+
+ private List traverseFiles(String path, long lastScanTime) {
+ Deque stack = new ArrayDeque<>();
+ stack.push(new File(path));
+
+ //skip folder: /storage/emulated/0/Android/media/com.seafile.seadroid2.debug/
+ String lPath = StorageManager.getInstance().getMediaDir().getAbsolutePath();
+ lPath = Utils.getParentPath(lPath);
+
+ List filePathList = new ArrayList<>();
+
+ boolean isSkipHiddenFile = FolderBackupManager.isFolderBackupSkipHiddenFiles();
+
+ while (!stack.isEmpty()) {
+ File currentDir = stack.pop();
+ File[] files = currentDir.listFiles();
+
+ if (files == null) {
+ continue;
+ }
+
+ for (File file : files) {
+ if (isSkipHiddenFile && file.isHidden()) {
+ continue;
+ }
+
+ if (file.isDirectory()) {
+ stack.push(file);
+ } else {
+ processFile(file, filePathList, lPath, lastScanTime);
+ }
+ }
+ }
+
+ return filePathList;
+ }
+
+ private void processFile(File file, List filePathList, String lPath, long lastScanTime) {
+ String fPath = file.getAbsolutePath();
+
+ if (fPath.startsWith(lPath)) {
+ return;
+ }
+
+ if (lastScanTime > 0) {
+ try {
+ BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
+ long created = attr.creationTime().toMillis();
+ long modified = attr.lastModifiedTime().toMillis();
+
+ if (created > lastScanTime || modified > lastScanTime) {
+ filePathList.add(file);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ filePathList.add(file);
+ }
+ }
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/MediaBackupScannerWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java
similarity index 89%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/MediaBackupScannerWorker.java
rename to app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java
index 3b4b8ef03..985479ba2 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/MediaBackupScannerWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java
@@ -1,4 +1,4 @@
-package com.seafile.seadroid2.framework.worker;
+package com.seafile.seadroid2.framework.worker.upload;
import static com.seafile.seadroid2.config.Constants.PERIODIC_SCAN_INTERVALS;
@@ -10,9 +10,12 @@
import android.text.TextUtils;
import androidx.annotation.NonNull;
+import androidx.work.Data;
+import androidx.work.ForegroundInfo;
import androidx.work.WorkerParameters;
import com.blankj.utilcode.util.CollectionUtils;
+import com.blankj.utilcode.util.FileUtils;
import com.google.common.base.Joiner;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeadroidApplication;
@@ -20,6 +23,7 @@
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.SupportAccountManager;
import com.seafile.seadroid2.framework.data.model.enums.TransferDataSource;
+import com.seafile.seadroid2.framework.datastore.DataManager;
import com.seafile.seadroid2.framework.datastore.StorageManager;
import com.seafile.seadroid2.framework.data.db.AppDatabase;
import com.seafile.seadroid2.framework.data.db.entities.DirentModel;
@@ -28,8 +32,12 @@
import com.seafile.seadroid2.framework.data.model.repo.DirentWrapperModel;
import com.seafile.seadroid2.framework.datastore.sp.AlbumBackupManager;
import com.seafile.seadroid2.framework.http.IO;
+import com.seafile.seadroid2.framework.notification.AlbumBackupScanNotificationHelper;
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.notification.AlbumBackupNotificationHelper;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
import com.seafile.seadroid2.ui.file.FileService;
import com.seafile.seadroid2.ui.folder_backup.RepoConfig;
import com.seafile.seadroid2.ui.repo.RepoService;
@@ -61,7 +69,7 @@
public class MediaBackupScannerWorker extends TransferWorker {
public static final UUID UID = UUID.nameUUIDFromBytes(MediaBackupScannerWorker.class.getSimpleName().getBytes());
- private AlbumBackupNotificationHelper albumNotificationHelper;
+ private final AlbumBackupScanNotificationHelper albumNotificationHelper;
private final String BASE_DIR = "My Photos";
@@ -73,7 +81,7 @@ public class MediaBackupScannerWorker extends TransferWorker {
public MediaBackupScannerWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
- albumNotificationHelper = new AlbumBackupNotificationHelper(context);
+ albumNotificationHelper = new AlbumBackupScanNotificationHelper(context);
account = SupportAccountManager.getInstance().getCurrentAccount();
}
@@ -86,43 +94,41 @@ public Result doWork() {
return Result.success();
}
-
boolean canScan = checkCanScan();
if (!canScan) {
SLogs.d("UploadMediaScanWorker: do not start the media scan task this time");
- //start media backup worker
BackgroundJobManagerImpl.getInstance().startMediaBackupWorker();
- return Result.success();
- }
- //
+ //start media backup worker
+ return Result.success(getScanEndData());
+ }
- String nTitle = getApplicationContext().getString(R.string.settings_camera_upload_info_title);
- nTitle += " - " + getApplicationContext().getString(R.string.is_scanning);
+ //todo
+ String title = getApplicationContext().getString(R.string.settings_camera_upload_info_title);
+ String subTitle = getApplicationContext().getString(R.string.is_scanning);
- albumNotificationHelper.showNotification(nTitle);
- albumNotificationHelper.cancel(3000);
+ ForegroundInfo foregroundInfo = albumNotificationHelper.getForegroundNotification(title, subTitle);
+ showForegroundAsync(foregroundInfo);
SLogs.d("MediaSyncWorker start");
try {
- sendProgressEvent(TransferEvent.EVENT_SCANNING);
+ sendEvent(TransferEvent.EVENT_SCANNING, TransferDataSource.ALBUM_BACKUP);
loadMedia();
+
} catch (SeafException | IOException e) {
SLogs.e("MediaBackupScannerWorker has occurred error", e);
} finally {
//
AlbumBackupManager.writeLastScanTime(System.currentTimeMillis());
- sendProgressEvent(TransferEvent.EVENT_SCAN_END);
-
//start upload worker
BackgroundJobManagerImpl.getInstance().startMediaBackupWorker();
}
- return Result.success();
+ return Result.success(getScanEndData());
}
private boolean checkCanScan() {
@@ -132,7 +138,7 @@ private boolean checkCanScan() {
}
boolean isForce = getInputData().getBoolean(TransferWorker.DATA_FORCE_TRANSFER_KEY, false);
- if (isForce){
+ if (isForce) {
return true;
}
@@ -147,6 +153,13 @@ private boolean checkCanScan() {
return true;
}
+ private Data getScanEndData() {
+ return new Data.Builder()
+ .putString(TransferWorker.KEY_DATA_EVENT, TransferEvent.EVENT_SCAN_END)
+ .putString(TransferWorker.KEY_DATA_TYPE, String.valueOf(TransferDataSource.ALBUM_BACKUP))
+ .build();
+ }
+
private void loadMedia() throws SeafException, IOException {
repoConfig = AlbumBackupManager.readRepoConfig();
@@ -154,7 +167,8 @@ private void loadMedia() throws SeafException, IOException {
if (repoConfig == null) {
SLogs.d("MediaSyncWorker: repoConfig is null");
- sendProgressEvent(TransferEvent.EVENT_TRANSFERRED_WITH_DATA);
+
+ sendEvent(TransferEvent.EVENT_FINISH, TransferDataSource.ALBUM_BACKUP);
return;
}
@@ -307,6 +321,13 @@ private String varArgs(int count) {
*/
private void iterateCursor(Cursor cursor, String media) {
+// String repoId = repoConfig.getRepoID();
+// String repoName = repoConfig.getRepoName();
+// File localRepoFilePath = DataManager.getLocalRepoPath(account, repoId, repoName);
+// String localRepoPhotoPath = Utils.pathJoin(localRepoFilePath.getAbsolutePath(), BASE_DIR);
+
+ String localCacheAbsPath = StorageManager.getInstance().getMediaDir().getAbsolutePath();
+
// upload them one by one
while (!isStopped() && cursor.moveToNext()) {
@@ -348,7 +369,6 @@ private void iterateCursor(Cursor cursor, String media) {
int dateAddIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATE_ADDED);
dateAdded = cursor.getLong(dateAddIndex);
-
file = new File(cursor.getString(dataColumn));
}
@@ -361,8 +381,10 @@ private void iterateCursor(Cursor cursor, String media) {
continue;
}
+
+// boolean isCached = FileUtils.isFileExists(Utils.pathJoin(localRepoPhotoPath,file.getName()));
// Ignore all media by Seafile. We don't want to upload our own cached files.
- if (file.getAbsolutePath().startsWith(StorageManager.getInstance().getMediaDir().getAbsolutePath())) {
+ if (file.getAbsolutePath().startsWith(localCacheAbsPath)) {
SLogs.d("skip file -> " + file.getAbsolutePath() + ", because it's part of the Seadroid cache");
continue;
}
@@ -419,6 +441,7 @@ private void forceCreateDirectory(String parent, String dirIsBucketName, List /
+ //todo 使用获取 path 详情接口
//get parent dirent list
Call direntWrapperModelCall = IO.getInstanceWithLoggedIn().execute(RepoService.class).getDirentsSync(repoConfig.getRepoID(), parent);
retrofit2.Response res = direntWrapperModelCall.execute();
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java
similarity index 57%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java
rename to app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java
index 54f6eec0f..6766df87e 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java
@@ -1,10 +1,12 @@
-package com.seafile.seadroid2.framework.worker;
+package com.seafile.seadroid2.framework.worker.upload;
import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.work.Data;
+import androidx.work.ForegroundInfo;
+import androidx.work.ListenableWorker;
import androidx.work.WorkerParameters;
import com.blankj.utilcode.util.CollectionUtils;
@@ -21,7 +23,11 @@
import com.seafile.seadroid2.framework.data.model.enums.TransferResult;
import com.seafile.seadroid2.framework.notification.FileBackupNotificationHelper;
import com.seafile.seadroid2.framework.notification.base.BaseNotification;
+import com.seafile.seadroid2.framework.notification.base.BaseTransferNotificationHelper;
import com.seafile.seadroid2.framework.util.SLogs;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
import java.util.List;
import java.util.UUID;
@@ -33,7 +39,7 @@
* @see BackgroundJobManagerImpl#TAG_ALL
* @see BackgroundJobManagerImpl#TAG_TRANSFER
*/
-public class UploadFileManuallyWorker extends BaseUploadFileWorker {
+public class UploadFileManuallyWorker extends BaseUploadWorker {
public static final UUID UID = UUID.nameUUIDFromBytes(UploadFileManuallyWorker.class.getSimpleName().getBytes());
private final FileBackupNotificationHelper notificationManager;
@@ -45,50 +51,55 @@ public UploadFileManuallyWorker(@NonNull Context context, @NonNull WorkerParamet
}
@Override
- public BaseNotification getNotification() {
+ public BaseTransferNotificationHelper getNotification() {
return notificationManager;
}
@NonNull
@Override
- public Result doWork() {
+ public ListenableWorker.Result doWork() {
return start();
}
/**
* The task here may not be from the current account
*/
- private Result start() {
+ private ListenableWorker.Result start() {
- notificationManager.cancel();
- notificationManager.showNotification();
+ ForegroundInfo foregroundInfo = notificationManager.getForegroundNotification();
+ showForegroundAsync(foregroundInfo);
+
+// notificationManager.cancel();
+// notificationManager.showNotification();
boolean isUploaded = false;
- String outEvent = null;
+ String finishFlagEvent = null;
while (true) {
SLogs.d("start upload file worker");
if (isStopped()) {
- return Result.success();
+ return ListenableWorker.Result.success();
}
- List transferList = AppDatabase.getInstance().fileTransferDAO()
+ List transferList = AppDatabase
+ .getInstance().fileTransferDAO()
.getOnePendingTransferAllAccountSync(
TransferAction.UPLOAD,
- TransferDataSource.FILE_BACKUP);
+ TransferDataSource.FILE_BACKUP
+ );
if (CollectionUtils.isEmpty(transferList)) {
break;
}
- FileTransferEntity transfer = transferList.get(0);
+ FileTransferEntity transferEntity = transferList.get(0);
try {
- boolean isAmple = calcQuota(CollectionUtils.newArrayList(transfer));
+ boolean isAmple = calcQuota(CollectionUtils.newArrayList(transferEntity));
if (!isAmple) {
getGeneralNotificationHelper().showErrorNotification(R.string.above_quota, R.string.settings_folder_backup_info_title);
AppDatabase.getInstance().fileTransferDAO().cancelWithFileBackup(TransferResult.OUT_OF_QUOTA);
- outEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
+ finishFlagEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
break;
}
} catch (Exception e) {
@@ -97,9 +108,10 @@ private Result start() {
}
isUploaded = true;
+
try {
- String relatedAccount = transfer.related_account;
+ String relatedAccount = transferEntity.related_account;
Account account = SupportAccountManager.getInstance().getSpecialAccount(relatedAccount);
if (account == null) {
SLogs.d("account is null : " + relatedAccount);
@@ -109,39 +121,57 @@ private Result start() {
throw SeafException.notLoggedInException;
}
- transferFile(account, transfer);
+ transferFile(account, transferEntity);
+ sendTransferEvent(transferEntity, true);
} catch (Exception e) {
- SLogs.e(e);
- catchExceptionAndUpdateDB(transfer, e);
+ SLogs.e("upload file file failed: ", e);
+ isUploaded = false;
+
+ TransferResult transferResult = onException(transferEntity, e);
+
+ notifyError(transferResult);
+
+ sendTransferEvent(transferEntity, false);
+
+ String finishFlag = isInterrupt(transferResult);
+ if (!TextUtils.isEmpty(finishFlag)) {
+ finishFlagEvent = finishFlag;
+ break;
+ }
+
} finally {
// After the user selects the file and completes the upload,
// the APP will no longer cache the file in ".../android/Media/Seafile/..."
- FileUtils.delete(transfer.full_path);
+ FileUtils.delete(transferEntity.full_path);
}
}
-
if (isUploaded) {
ToastUtils.showLong(R.string.upload_finished);
- SLogs.d("UploadFileManuallyWorker all task run");
- if (outEvent == null) {
- outEvent = TransferEvent.EVENT_TRANSFERRED_WITH_DATA;
- }
- } else {
- SLogs.d("UploadFileManuallyWorker nothing to run");
- if (outEvent == null) {
- outEvent = TransferEvent.EVENT_TRANSFERRED_WITHOUT_DATA;
- }
}
- notificationManager.cancel();
+ SLogs.e("UploadFileManuallyWorker all task run");
+
+ if (finishFlagEvent == null) {
+ finishFlagEvent = TransferEvent.EVENT_FINISH;
+ }
+
+// Account account = SupportAccountManager.getInstance().getCurrentAccount();
+// int pendingCount = AppDatabase
+// .getInstance()
+// .fileTransferDAO()
+// .countPendingTransferSync(account.getSignature(),
+// TransferAction.UPLOAD,
+// TransferDataSource.FILE_BACKUP
+// );
- //Send a completion event
Data data = new Data.Builder()
- .putString(TransferWorker.KEY_DATA_EVENT, outEvent)
+ .putString(TransferWorker.KEY_DATA_EVENT, finishFlagEvent)
+// .putInt(TransferWorker.KEY_DATA_PARAM, pendingCount)
.putString(TransferWorker.KEY_DATA_TYPE, String.valueOf(TransferDataSource.FILE_BACKUP))
.build();
- return Result.success(data);
+ return ListenableWorker.Result.success(data);
}
+
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java
similarity index 54%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java
rename to app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java
index dd735469f..ff8693d33 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java
@@ -1,10 +1,12 @@
-package com.seafile.seadroid2.framework.worker;
+package com.seafile.seadroid2.framework.worker.upload;
import android.content.Context;
import android.os.Build;
+import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.work.Data;
+import androidx.work.ForegroundInfo;
import androidx.work.WorkInfo;
import androidx.work.WorkerParameters;
@@ -20,8 +22,12 @@
import com.seafile.seadroid2.framework.data.model.enums.TransferResult;
import com.seafile.seadroid2.framework.datastore.sp.FolderBackupManager;
import com.seafile.seadroid2.framework.notification.base.BaseNotification;
+import com.seafile.seadroid2.framework.notification.base.BaseTransferNotificationHelper;
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.notification.FolderBackupNotificationHelper;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
import java.util.List;
import java.util.UUID;
@@ -33,7 +39,7 @@
* @see BackgroundJobManagerImpl#TAG_ALL
* @see BackgroundJobManagerImpl#TAG_TRANSFER
*/
-public class UploadFolderFileAutomaticallyWorker extends BaseUploadFileWorker {
+public class UploadFolderFileAutomaticallyWorker extends BaseUploadWorker {
public static final UUID UID = UUID.nameUUIDFromBytes(UploadFolderFileAutomaticallyWorker.class.getSimpleName().getBytes());
private final FolderBackupNotificationHelper notificationManager;
@@ -45,7 +51,7 @@ public UploadFolderFileAutomaticallyWorker(@NonNull Context context, @NonNull Wo
}
@Override
- public BaseNotification getNotification() {
+ public BaseTransferNotificationHelper getNotification() {
return notificationManager;
}
@@ -55,8 +61,17 @@ public Result doWork() {
return start();
}
+ @Override
+ public void onStopped() {
+ super.onStopped();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
+ SLogs.e("文件夹备份已停止:" + getStopReason());
+ }
+ }
+
private Result start() {
- notificationManager.cancel();
+// notificationManager.cancel();
Account account = SupportAccountManager.getInstance().getCurrentAccount();
if (account == null) {
@@ -70,87 +85,90 @@ private Result start() {
boolean isUploaded = false;
- notificationManager.showNotification();
- String outEvent = null;
+ ForegroundInfo foregroundInfo = notificationManager.getForegroundNotification();
+ showForegroundAsync(foregroundInfo);
+
+// notificationManager.showNotification();
+
+ String finishFlagEvent = null;
+
+ SLogs.d("start upload file worker");
+ sendEvent(TransferEvent.EVENT_TRANSFERRING, TransferDataSource.FILE_BACKUP);
while (true) {
if (isStopped()) {
- return Result.success();
+ break;
}
- SLogs.d("start upload file worker");
-
//check
- List transferList = AppDatabase.getInstance().fileTransferDAO()
- .getOnePendingTransferSync(account.getSignature(),
- TransferAction.UPLOAD, TransferDataSource.FOLDER_BACKUP);
+ List transferList = AppDatabase.getInstance()
+ .fileTransferDAO()
+ .getOnePendingTransferSync(
+ account.getSignature(),
+ TransferAction.UPLOAD,
+ TransferDataSource.FOLDER_BACKUP
+ );
if (CollectionUtils.isEmpty(transferList)) {
break;
}
- FileTransferEntity transfer = transferList.get(0);
+ FileTransferEntity transferEntity = transferList.get(0);
+ isUploaded = true;
try {
- boolean isAmple = calcQuota(CollectionUtils.newArrayList(transfer));
- if (!isAmple) {
- getGeneralNotificationHelper().showErrorNotification(R.string.above_quota, R.string.settings_folder_backup_info_title);
- //
- AppDatabase.getInstance().fileTransferDAO().cancel(account.getSignature(), TransferDataSource.FOLDER_BACKUP, TransferResult.OUT_OF_QUOTA);
+ transferFile(account, transferEntity);
- outEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
-
- break;
- }
+ sendTransferEvent(transferEntity, true);
} catch (Exception e) {
- e.printStackTrace();
- break;
- }
-
- isUploaded = true;
+ isUploaded = false;
+ SLogs.e("upload folder file failed: ", e);
- try {
+ TransferResult transferResult = onException(transferEntity, e);
- transferFile(account, transfer);
+ notifyError(transferResult);
- } catch (Exception e) {
- SLogs.e(e);
- catchExceptionAndUpdateDB(transfer, e);
+ sendTransferEvent(transferEntity, false);
- ToastUtils.showLong(R.string.upload_failed);
- isUploaded = false;
+ String finishFlag = isInterrupt(transferResult);
+ if (!TextUtils.isEmpty(finishFlag)) {
+ finishFlagEvent = finishFlag;
+ break;
+ }
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- if (getStopReason() == WorkInfo.STOP_REASON_CANCELLED_BY_APP) {
+ if (getStopReason() >= WorkInfo.STOP_REASON_CANCELLED_BY_APP) {
isUploaded = false;
}
}
if (isUploaded) {
ToastUtils.showLong(R.string.upload_finished);
- SLogs.d("UploadFolderFileAutomaticallyWorker all task run");
- if (outEvent == null) {
- outEvent = TransferEvent.EVENT_TRANSFERRED_WITH_DATA;
- }
- } else {
- SLogs.d("UploadFolderFileAutomaticallyWorker nothing to run");
- if (outEvent == null) {
- outEvent = TransferEvent.EVENT_TRANSFERRED_WITHOUT_DATA;
- }
}
- notificationManager.cancel();
+ SLogs.e("UploadFolderFileAutomaticallyWorker all task run");
+
+ if (finishFlagEvent == null) {
+ finishFlagEvent = TransferEvent.EVENT_FINISH;
+ }
+
+// int pendingCount = AppDatabase
+// .getInstance()
+// .fileTransferDAO()
+// .countPendingTransferSync(account.getSignature(),
+// TransferAction.UPLOAD,
+// TransferDataSource.FOLDER_BACKUP
+// );
- //Send a completion event
Data data = new Data.Builder()
- .putString(TransferWorker.KEY_DATA_EVENT, outEvent)
+ .putString(TransferWorker.KEY_DATA_EVENT, finishFlagEvent)
+// .putInt(TransferWorker.KEY_DATA_PARAM, pendingCount)
.putString(TransferWorker.KEY_DATA_TYPE, String.valueOf(TransferDataSource.FOLDER_BACKUP))
.build();
return Result.success(data);
}
-
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java
similarity index 55%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java
rename to app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java
index ebc28efcf..831585a0e 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java
@@ -1,10 +1,13 @@
-package com.seafile.seadroid2.framework.worker;
+package com.seafile.seadroid2.framework.worker.upload;
import android.content.Context;
import android.os.Build;
+import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.work.Data;
+import androidx.work.ForegroundInfo;
+import androidx.work.ListenableWorker;
import androidx.work.WorkInfo;
import androidx.work.WorkerParameters;
@@ -20,8 +23,12 @@
import com.seafile.seadroid2.framework.data.model.enums.TransferResult;
import com.seafile.seadroid2.framework.datastore.sp.AlbumBackupManager;
import com.seafile.seadroid2.framework.notification.base.BaseNotification;
+import com.seafile.seadroid2.framework.notification.base.BaseTransferNotificationHelper;
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.notification.AlbumBackupNotificationHelper;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
import java.util.List;
import java.util.UUID;
@@ -32,7 +39,7 @@
* @see BackgroundJobManagerImpl#TAG_ALL
* @see BackgroundJobManagerImpl#TAG_TRANSFER
*/
-public class UploadMediaFileAutomaticallyWorker extends BaseUploadFileWorker {
+public class UploadMediaFileAutomaticallyWorker extends BaseUploadWorker {
public static final UUID UID = UUID.nameUUIDFromBytes(UploadMediaFileAutomaticallyWorker.class.getSimpleName().getBytes());
private final AlbumBackupNotificationHelper albumNotificationHelper;
@@ -44,28 +51,36 @@ public UploadMediaFileAutomaticallyWorker(@NonNull Context context, @NonNull Wor
}
@Override
- public BaseNotification getNotification() {
+ public BaseTransferNotificationHelper getNotification() {
return albumNotificationHelper;
}
@NonNull
@Override
- public Result doWork() {
-
- albumNotificationHelper.cancel();
+ public ListenableWorker.Result doWork() {
Account account = SupportAccountManager.getInstance().getCurrentAccount();
if (account == null) {
- return Result.failure();
+
+ notifyError(TransferResult.ACCOUNT_NOT_FOUND);
+
+ return ListenableWorker.Result.success();
}
boolean isEnable = AlbumBackupManager.readBackupSwitch();
if (!isEnable) {
- return Result.success();
+ return ListenableWorker.Result.success();
}
- String outEvent = null;
+ //send start transfer event
+ sendEvent(TransferEvent.EVENT_TRANSFERRING, TransferDataSource.ALBUM_BACKUP);
+ // show foreground notification
+ ForegroundInfo foregroundInfo = albumNotificationHelper.getForegroundNotification();
+ showForegroundAsync(foregroundInfo);
+
+ //
+ String finishFlagEvent = null;
boolean isUploaded = false;
while (true) {
if (isStopped()) {
@@ -74,46 +89,45 @@ public Result doWork() {
SLogs.d("start upload media worker");
- List transferList = AppDatabase.getInstance().fileTransferDAO()
+ List transferList = AppDatabase
+ .getInstance()
+ .fileTransferDAO()
.getOnePendingTransferSync(account.getSignature(),
TransferAction.UPLOAD,
- TransferDataSource.ALBUM_BACKUP);
+ TransferDataSource.ALBUM_BACKUP
+ );
if (CollectionUtils.isEmpty(transferList)) {
break;
}
- FileTransferEntity transfer = transferList.get(0);
-
- try {
- boolean isAmple = calcQuota(CollectionUtils.newArrayList(transfer));
- if (!isAmple) {
- getGeneralNotificationHelper().showErrorNotification(R.string.above_quota, R.string.settings_camera_upload_info_title);
- AppDatabase.getInstance().fileTransferDAO().cancel(account.getSignature(), TransferDataSource.ALBUM_BACKUP, TransferResult.OUT_OF_QUOTA);
-
- outEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
- break;
- }
- } catch (Exception e) {
- e.printStackTrace();
- break;
- }
+ FileTransferEntity transferEntity = transferList.get(0);
isUploaded = true;
try {
- transferFile(account, transfer);
+ transferFile(account, transferEntity);
+ sendTransferEvent(transferEntity, true);
} catch (Exception e) {
SLogs.e("upload media file failed: ", e);
- catchExceptionAndUpdateDB(transfer, e);
-
- ToastUtils.showLong(R.string.upload_failed);
isUploaded = false;
+
+ TransferResult transferResult = onException(transferEntity, e);
+
+ notifyError(transferResult);
+
+ sendTransferEvent(transferEntity, false);
+
+ String finishFlag = isInterrupt(transferResult);
+ if (!TextUtils.isEmpty(finishFlag)) {
+ finishFlagEvent = finishFlag;
+ break;
+ }
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- if (getStopReason() == WorkInfo.STOP_REASON_CANCELLED_BY_APP) {
+ if (getStopReason() >= WorkInfo.STOP_REASON_CANCELLED_BY_APP) {
isUploaded = false;
}
}
@@ -121,22 +135,24 @@ public Result doWork() {
//
if (isUploaded) {
ToastUtils.showLong(R.string.upload_finished);
- SLogs.d("UploadMediaFileAutomaticallyWorker all task run");
- if (outEvent == null) {
- outEvent = TransferEvent.EVENT_TRANSFERRED_WITH_DATA;
- }
- } else {
- if (outEvent == null) {
- outEvent = TransferEvent.EVENT_TRANSFERRED_WITHOUT_DATA;
- }
- SLogs.d("UploadMediaFileAutomaticallyWorker nothing to run");
}
- albumNotificationHelper.cancel();
+ SLogs.e("UploadMediaFileAutomaticallyWorker all task run");
+ if (finishFlagEvent == null) {
+ finishFlagEvent = TransferEvent.EVENT_FINISH;
+ }
+
+// int pendingCount = AppDatabase
+// .getInstance()
+// .fileTransferDAO()
+// .countPendingTransferSync(account.getSignature(),
+// TransferAction.UPLOAD,
+// TransferDataSource.ALBUM_BACKUP
+// );
- //Send a completion event
Data data = new Data.Builder()
- .putString(TransferWorker.KEY_DATA_EVENT, outEvent)
+ .putString(TransferWorker.KEY_DATA_EVENT, finishFlagEvent)
+// .putInt(TransferWorker.KEY_DATA_PARAM, pendingCount)
.putString(TransferWorker.KEY_DATA_TYPE, String.valueOf(TransferDataSource.ALBUM_BACKUP))
.build();
return Result.success(data);
diff --git a/app/src/main/java/com/seafile/seadroid2/ssl/SSLSeafileSocketFactory.java b/app/src/main/java/com/seafile/seadroid2/ssl/SSLSeafileSocketFactory.java
index 8f940e03c..ef88d9e12 100644
--- a/app/src/main/java/com/seafile/seadroid2/ssl/SSLSeafileSocketFactory.java
+++ b/app/src/main/java/com/seafile/seadroid2/ssl/SSLSeafileSocketFactory.java
@@ -26,6 +26,7 @@
* based on:
* https://stackoverflow.com/questions/1037590/which-cipher-suites-to-enable-for-ssl-socket
*/
+@Deprecated
public class SSLSeafileSocketFactory extends SSLSocketFactory {
private SSLContext context;
diff --git a/app/src/main/java/com/seafile/seadroid2/ssl/SSLTrustManager.java b/app/src/main/java/com/seafile/seadroid2/ssl/SSLTrustManager.java
index 69e7d164e..29ea2dbf5 100644
--- a/app/src/main/java/com/seafile/seadroid2/ssl/SSLTrustManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/ssl/SSLTrustManager.java
@@ -29,7 +29,7 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
-
+@Deprecated
public final class SSLTrustManager {
public enum SslFailureReason {
CERT_NOT_TRUSTED,
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activities/AllActivitiesFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/activities/AllActivitiesFragment.java
index 71c351f31..9c6d314f3 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/activities/AllActivitiesFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/activities/AllActivitiesFragment.java
@@ -88,19 +88,13 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
}
- private boolean isFirstLoadData = true;
-
@Override
- public void onResume() {
- super.onResume();
- d("load data:onResume");
- if (isFirstLoadData) {
- isFirstLoadData = false;
- d("load data:isFirstLoadData");
- loadNext();
- }
+ public void onFirstResume() {
+ super.onFirstResume();
+ loadNext();
}
+
private void initAdapter() {
adapter = new ActivityAdapter();
TextView tipView = TipsViews.getTipTextView(requireContext());
@@ -115,6 +109,16 @@ private void initAdapter() {
checkOpen(activityModel);
});
+ LogicLoadMoreAdapter loadMoreAdapter = getLogicLoadMoreAdapter();
+
+ helper = new QuickAdapterHelper.Builder(adapter)
+ .setTrailingLoadStateAdapter(loadMoreAdapter)
+ .build();
+ binding.rv.setAdapter(helper.getAdapter());
+ }
+
+ @NonNull
+ private LogicLoadMoreAdapter getLogicLoadMoreAdapter() {
LogicLoadMoreAdapter loadMoreAdapter = new LogicLoadMoreAdapter();
loadMoreAdapter.setOnLoadMoreListener(new TrailingLoadStateAdapter.OnTrailingListener() {
@Override
@@ -133,11 +137,7 @@ public boolean isAllowLoading() {
return !binding.swipeRefreshLayout.isRefreshing();
}
});
-
- helper = new QuickAdapterHelper.Builder(adapter)
- .setTrailingLoadStateAdapter(loadMoreAdapter)
- .build();
- binding.rv.setAdapter(helper.getAdapter());
+ return loadMoreAdapter;
}
private void showErrorTip() {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java
index 2c1e12097..fc1de61a4 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/base/fragment/BaseFragment.java
@@ -8,4 +8,25 @@ public class BaseFragment extends Fragment {
public void d(String e) {
SLogs.d(this.getClass().getSimpleName() + " => " + e);
}
+
+ private boolean isFirstLoadData = true;
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (isFirstLoadData) {
+ isFirstLoadData = false;
+ onFirstResume();
+ } else {
+ onNonFirstResume();
+ }
+ }
+
+ public void onFirstResume() {
+
+ }
+
+ public void onNonFirstResume() {
+
+ }
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/viewmodel/BaseViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/base/viewmodel/BaseViewModel.java
index f628842f6..ce5dee2b2 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/base/viewmodel/BaseViewModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/base/viewmodel/BaseViewModel.java
@@ -260,15 +260,18 @@ public SeafException getExceptionByThrowable(Throwable throwable) throws IOExcep
try {
ResponseBody body = resp.errorBody();
if (body == null) {
- return SeafException.unknownException;
+ return SeafException.networkException;
}
String result = body.string();
if (TextUtils.isEmpty(result)) {
- return SeafException.unknownException;
+ return SeafException.networkException;
}
JSONObject json = Utils.parseJsonObject(result);
+ if (json == null) {
+ return SeafException.networkException;
+ }
if (json.has("error_msg")) {
String errorMsg = json.optString("error_msg");
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java
index be8a14aa7..08274687c 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/AlbumBackupAdapter.java
@@ -10,6 +10,7 @@
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.SupportAccountManager;
+import com.seafile.seadroid2.framework.datastore.sp.AlbumBackupManager;
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
@@ -83,6 +84,11 @@ public void onPerformSync(android.accounts.Account account,
return;
}
+ boolean isEnable = AlbumBackupManager.readBackupSwitch();
+ if (!isEnable) {
+ return;
+ }
+
//start
boolean isForce = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL);
BackgroundJobManagerImpl.getInstance().scheduleMediaScanWorker(isForce);
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/folder_backup/FolderBackupSelectedPathActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/folder_backup/FolderBackupSelectedPathActivity.java
index 28d9c8c3a..9779b6a3c 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/folder_backup/FolderBackupSelectedPathActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/folder_backup/FolderBackupSelectedPathActivity.java
@@ -1,8 +1,12 @@
package com.seafile.seadroid2.ui.folder_backup;
import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
+import android.content.ServiceConnection;
import android.os.Bundle;
+import android.os.IBinder;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
@@ -14,12 +18,16 @@
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
+import androidx.work.NetworkType;
import com.blankj.utilcode.util.CollectionUtils;
import com.chad.library.adapter4.QuickAdapterHelper;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.bottomsheetmenu.BottomSheetHelper;
import com.seafile.seadroid2.bottomsheetmenu.BottomSheetMenuFragment;
+import com.seafile.seadroid2.framework.file_monitor.FileSyncService;
+import com.seafile.seadroid2.framework.util.SLogs;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
import com.seafile.seadroid2.ui.base.BaseActivity;
import com.seafile.seadroid2.framework.datastore.sp.FolderBackupManager;
@@ -31,6 +39,7 @@ public class FolderBackupSelectedPathActivity extends BaseActivity {
private FolderBackupSelectedPathAdapter mAdapter;
private QuickAdapterHelper helper;
private String initialPathStr;
+ private FileSyncService fileSyncService;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -82,14 +91,31 @@ private void initAdapter() {
private void showRepoBottomSheet(int position) {
BottomSheetHelper.showSheet(this, R.menu.folder_backup_bottom_sheet_delete, menuItem -> {
if (menuItem.getItemId() == R.id.delete) {
- mAdapter.removeAt(position);
-
- List list = mAdapter.getItems();
- FolderBackupManager.writeBackupPaths(list);
+ deletePath(position);
}
});
}
+ private void deletePath(int position) {
+ //clear last scan time
+ String path = mAdapter.getItems().get(position);
+ FolderBackupManager.clearBackupPathLastScanTime(path);
+
+ mAdapter.removeAt(position);
+
+ List list = mAdapter.getItems();
+ FolderBackupManager.writeBackupPaths(list);
+
+ if (fileSyncService != null) {
+ fileSyncService.stopFolderMonitor();
+
+ fileSyncService.startFolderMonitor();
+ }
+
+ //restart
+ BackgroundJobManagerImpl.getInstance().restartFolderUploadWorker();
+ }
+
private void showBottomDialog(String text) {
new BottomSheetMenuFragment.Builder(this)
.setTitle(text)
@@ -135,4 +161,45 @@ public void onActivityResult(ActivityResult o) {
initData();
}
});
+
+
+ private boolean isBound = false;
+
+ private final ServiceConnection syncConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ FileSyncService.FileSyncBinder binder = (FileSyncService.FileSyncBinder) service;
+ fileSyncService = binder.getService();
+ isBound = true;
+ SLogs.d("SettingsFragment: bond FileSyncService");
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ fileSyncService = null;
+ isBound = false;
+ SLogs.d("SettingsFragment: FileSyncService disconnected");
+ }
+ };
+
+ private void bindService() {
+ if (!isBound) {
+ Intent syncIntent = new Intent(this, FileSyncService.class);
+ bindService(syncIntent, syncConnection, Context.BIND_AUTO_CREATE);
+ }
+ }
+
+ private void unbindService() {
+ if (isBound) {
+ unbindService(syncConnection);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+
+ unbindService();
+
+ super.onDestroy();
+ }
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java
index 14fb2469a..8d755d834 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/main/MainActivity.java
@@ -28,6 +28,8 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager2.widget.ViewPager2;
+import androidx.work.Data;
+import androidx.work.WorkInfo;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.CollectionUtils;
@@ -53,6 +55,10 @@
import com.seafile.seadroid2.framework.util.Utils;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
import com.seafile.seadroid2.framework.file_monitor.FileSyncService;
+import com.seafile.seadroid2.framework.worker.upload.FolderBackupScannerWorker;
+import com.seafile.seadroid2.framework.worker.SupportWorkManager;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
import com.seafile.seadroid2.ui.account.AccountsActivity;
import com.seafile.seadroid2.ui.adapter.ViewPager2Adapter;
import com.seafile.seadroid2.ui.base.BaseActivity;
@@ -129,7 +135,9 @@ protected void onCreate(Bundle savedInstanceState) {
initOnBackPressedDispatcher();
initBottomNavigation();
initViewPager();
+
initViewModel();
+ initWorkerListener();
//service
bindService();
@@ -367,6 +375,32 @@ public void onPageSelected(int position) {
});
}
+ private void initWorkerListener() {
+ SupportWorkManager.getWorkManager()
+ .getWorkInfoByIdLiveData(FolderBackupScannerWorker.UID)
+ .observe(this, new Observer() {
+ @Override
+ public void onChanged(WorkInfo workInfo) {
+ if (null == workInfo) {
+ return;
+ }
+
+ Data data = workInfo.getOutputData();
+ String event = data.getString(TransferWorker.KEY_DATA_EVENT);
+
+ if (TextUtils.isEmpty(event)) {
+ return;
+ }
+
+ if (TransferEvent.EVENT_SCAN_END.equals(event)) {
+ if (syncService != null) {
+ syncService.startFolderMonitor();
+ }
+ }
+ }
+ });
+ }
+
private void initViewModel() {
mainViewModel.getOnForceRefreshRepoListLiveData().observe(this, new Observer() {
@Override
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java
index 596d4fc34..f8fec260f 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoQuickFragment.java
@@ -27,6 +27,7 @@
import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.util.UnstableApi;
import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.work.Data;
import androidx.work.WorkInfo;
import com.blankj.utilcode.util.CollectionUtils;
@@ -54,13 +55,13 @@
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.util.Utils;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
-import com.seafile.seadroid2.framework.worker.DownloadWorker;
+import com.seafile.seadroid2.framework.worker.download.DownloadWorker;
import com.seafile.seadroid2.framework.worker.SupportWorkManager;
import com.seafile.seadroid2.framework.worker.TransferEvent;
import com.seafile.seadroid2.framework.worker.TransferWorker;
-import com.seafile.seadroid2.framework.worker.UploadFileManuallyWorker;
-import com.seafile.seadroid2.framework.worker.UploadFolderFileAutomaticallyWorker;
-import com.seafile.seadroid2.framework.worker.UploadMediaFileAutomaticallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadFileManuallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadFolderFileAutomaticallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadMediaFileAutomaticallyWorker;
import com.seafile.seadroid2.ui.WidgetUtils;
import com.seafile.seadroid2.ui.base.fragment.BaseFragmentWithVM;
import com.seafile.seadroid2.ui.dialog_fragment.CopyMoveDialogFragment;
@@ -90,8 +91,10 @@ public class RepoQuickFragment extends BaseFragmentWithVM {
private static final String KEY_REPO_SCROLL_POSITION = "repo_scroll_position";
private static final String KEY_REPO_LIST = "key_in_repo_list";
+ private final int forceRefreshInterval = 1000 * 60 * 5;//5m
+
private final HashMap mRefreshStatusExpireTimeMap = new HashMap<>();
- private boolean isFirstLoadData = true;
+
private LayoutFrameSwipeRvBinding binding;
private RepoQuickAdapter adapter;
private LinearLayoutManager rvManager;
@@ -146,17 +149,16 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}
@Override
- public void onResume() {
- super.onResume();
- d("load data:onResume");
- if (isFirstLoadData) {
- isFirstLoadData = false;
- d("load data:isFirstLoadData");
+ public void onFirstResume() {
+ super.onFirstResume();
+ loadData(true);
+ }
+
+ @Override
+ public void onNonFirstResume() {
+ super.onNonFirstResume();
+ if (isForce()) {
loadData(true);
- } else {
- if (isForce()) {
- loadData(true);
- }
}
}
@@ -322,9 +324,13 @@ public void onChanged(WorkInfo workInfo) {
private void checkWorkInfo(WorkInfo workInfo) {
if (workInfo != null && workInfo.getState().isFinished()) {
- String transferState = workInfo.getOutputData().getString(TransferWorker.KEY_DATA_EVENT);
- if (TransferEvent.EVENT_TRANSFERRED_WITH_DATA.equals(transferState)) {
- loadData(true);
+ Data data = workInfo.getOutputData();
+ String transferState = data.getString(TransferWorker.KEY_DATA_EVENT);
+// int pendingTransferCount = data.getInt(TransferWorker.KEY_DATA_PARAM, -1);
+ String dataType = data.getString(TransferWorker.KEY_DATA_TYPE);
+ SLogs.e(dataType + " -> " + transferState);
+ if (TransferEvent.EVENT_FINISH.equals(transferState)) {
+ loadData(isForce());
}
}
}
@@ -352,14 +358,13 @@ public void loadData() {
public void loadData(boolean forceRefresh) {
if (forceRefresh) {
long now = TimeUtils.getNowMills();
- now += 1000 * 60 * 10;//10min
+ now += forceRefreshInterval;
if (getNavContext().isInRepoList()) {
mRefreshStatusExpireTimeMap.put(KEY_REPO_LIST, now);
} else {
String k = getNavContext().getRepoModel().repo_id + getNavContext().getNavPath();
mRefreshStatusExpireTimeMap.put(k, now);
}
-
}
//
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoService.java b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoService.java
index 1f61c4a8a..2ffebabca 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoService.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoService.java
@@ -33,6 +33,11 @@ public interface RepoService {
@GET("api/v2.1/repos/{repo_id}/dir/?with_thumbnail=true")
Single getDirents(@Path("repo_id") String repoId, @Query("p") String path);
+
+ @GET("api/v2.1/repos/{repo_id}/dir/?with_thumbnail=true")
+ Call getDirentsCall(@Path("repo_id") String repoId, @Query("p") String path);
+
+
@GET("api/v2.1/repos/{repo_id}/dir/?with_thumbnail=true")
Call getDirentsSync(@Path("repo_id") String repoId, @Query("p") String path);
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoViewModel.java
index fed85fe50..3da56d2d9 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoViewModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/repo/RepoViewModel.java
@@ -106,7 +106,9 @@ public void loadData(NavContext context, boolean forceRefresh) {
}
private void loadReposFromDB(Account account, boolean isForce) {
- getRefreshLiveData().setValue(true);
+ if (isForce) {
+ getRefreshLiveData().setValue(true);
+ }
Single> singleDB = AppDatabase.getInstance().repoDao().getListByAccount(account.getSignature());
addSingleDisposable(singleDB, new Consumer>() {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java
index fdc1bc725..30102db51 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragment.java
@@ -30,7 +30,6 @@
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreferenceCompat;
import androidx.work.Data;
-import androidx.work.NetworkType;
import androidx.work.WorkInfo;
import com.blankj.utilcode.util.AppUtils;
@@ -60,10 +59,10 @@
import com.seafile.seadroid2.framework.worker.SupportWorkManager;
import com.seafile.seadroid2.framework.worker.TransferEvent;
import com.seafile.seadroid2.framework.worker.TransferWorker;
-import com.seafile.seadroid2.framework.worker.FolderBackupScannerWorker;
-import com.seafile.seadroid2.framework.worker.UploadFolderFileAutomaticallyWorker;
-import com.seafile.seadroid2.framework.worker.MediaBackupScannerWorker;
-import com.seafile.seadroid2.framework.worker.UploadMediaFileAutomaticallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.FolderBackupScannerWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadFolderFileAutomaticallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.MediaBackupScannerWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadMediaFileAutomaticallyWorker;
import com.seafile.seadroid2.gesturelock.LockPatternUtils;
import com.seafile.seadroid2.ui.camera_upload.CameraUploadConfigActivity;
import com.seafile.seadroid2.ui.camera_upload.CameraUploadManager;
@@ -242,27 +241,34 @@ private void checkScanWorkInfo(TransferDataSource dataSource, WorkInfo workInfo)
return;
}
- Data progressData = workInfo.getProgress();
Data outData = workInfo.getOutputData();
+ String outDataEvent = outData.getString(TransferWorker.KEY_DATA_EVENT);
+ String outDataType = outData.getString(TransferWorker.KEY_DATA_TYPE);
+ if (String.valueOf(TransferDataSource.ALBUM_BACKUP).equals(outDataType)) {
+ if (TransferEvent.EVENT_SCAN_END.equals(outDataEvent)) {
+ mCameraBackupState.setSummary(R.string.waiting);
+ return;
+ }
+ } else if (String.valueOf(TransferDataSource.FOLDER_BACKUP).equals(outDataType)) {
+ if (TransferEvent.EVENT_SCAN_END.equals(outDataEvent)) {
+ mFolderBackupState.setSummary(R.string.waiting);
+ return;
+ }
+ }
+ Data progressData = workInfo.getProgress();
String pDataEvent = progressData.getString(TransferWorker.KEY_DATA_EVENT);
- String oDataEvent = outData.getString(TransferWorker.KEY_DATA_EVENT);
-
- if (TextUtils.isEmpty(oDataEvent) && TextUtils.isEmpty(pDataEvent)) {
+ if (TextUtils.isEmpty(pDataEvent)) {
return;
}
if (TransferDataSource.ALBUM_BACKUP == dataSource) {
if (TransferEvent.EVENT_SCANNING.equals(pDataEvent)) {
mCameraBackupState.setSummary(R.string.is_scanning);
- } else if (TransferEvent.EVENT_SCAN_END.equals(oDataEvent)) {
- mCameraBackupState.setSummary(R.string.waiting);
}
} else if (TransferDataSource.FOLDER_BACKUP == dataSource) {
if (TransferEvent.EVENT_SCANNING.equals(pDataEvent)) {
mFolderBackupState.setSummary(R.string.is_scanning);
- } else if (TransferEvent.EVENT_SCAN_END.equals(oDataEvent)) {
- mFolderBackupState.setSummary(R.string.waiting);
}
}
}
@@ -273,34 +279,24 @@ private void doWorkInfoLiveData(WorkInfo workInfo) {
}
Data outData = workInfo.getOutputData();
- Data progressData = workInfo.getProgress();
-
String outDataEvent = outData.getString(TransferWorker.KEY_DATA_EVENT);
String outDataType = outData.getString(TransferWorker.KEY_DATA_TYPE);
- if (!TextUtils.isEmpty(outDataEvent)) {
- if (String.valueOf(TransferDataSource.ALBUM_BACKUP).equals(outDataType)) {
- if (TransferEvent.EVENT_TRANSFERRED_WITHOUT_DATA.equals(outDataEvent)) {
- mCameraBackupState.setSummary(R.string.settings_cuc_finish_title);
- } else if (TransferEvent.EVENT_TRANSFERRED_WITH_DATA.equals(outDataEvent)) {
- mCameraBackupState.setSummary(R.string.settings_cuc_finish_title);
- } else if (TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA.equals(outDataEvent)) {
- mCameraBackupState.setSummary(R.string.above_quota);
- }
- } else if (String.valueOf(TransferDataSource.FOLDER_BACKUP).equals(outDataType)) {
- if (TransferEvent.EVENT_TRANSFERRED_WITHOUT_DATA.equals(outDataEvent)) {
- mFolderBackupState.setSummary(R.string.folder_backup_waiting_state);
- } else if (TransferEvent.EVENT_TRANSFERRED_WITH_DATA.equals(outDataEvent)) {
- mFolderBackupState.setSummary(R.string.folder_backup_waiting_state);
- } else if (TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA.equals(outDataEvent)) {
- mFolderBackupState.setSummary(R.string.above_quota);
- }
+ if (String.valueOf(TransferDataSource.ALBUM_BACKUP).equals(outDataType)) {
+ if (TransferEvent.EVENT_FINISH.equals(outDataEvent)) {
+ mCameraBackupState.setSummary(R.string.settings_cuc_finish_title);
+ return;
+ }
+ } else if (String.valueOf(TransferDataSource.FOLDER_BACKUP).equals(outDataType)) {
+ if (TransferEvent.EVENT_FINISH.equals(outDataEvent)) {
+ mFolderBackupState.setSummary(R.string.folder_backup_waiting_state);
+ return;
}
-
- return;
}
+
+ Data progressData = workInfo.getProgress();
String dataType = progressData.getString(TransferWorker.KEY_DATA_TYPE);
- String progressDataEvent = progressData.getString(TransferWorker.KEY_DATA_EVENT);
+ String progressEvent = progressData.getString(TransferWorker.KEY_DATA_EVENT);
String progressFileName = progressData.getString(TransferWorker.DATA_TRANSFER_NAME_KEY);
if (TextUtils.isEmpty(dataType)) {
@@ -308,16 +304,18 @@ private void doWorkInfoLiveData(WorkInfo workInfo) {
}
if (String.valueOf(TransferDataSource.ALBUM_BACKUP).equals(dataType)) {
- if (TransferEvent.EVENT_TRANSFERRING.equals(progressDataEvent)) {
+ if (TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA.equals(progressEvent)) {
+ mCameraBackupState.setSummary(R.string.above_quota);
+ } else if (TransferEvent.EVENT_TRANSFERRING.equals(progressEvent)) {
viewModel.countAlbumBackupState(requireContext());
}
} else if (String.valueOf(TransferDataSource.FOLDER_BACKUP).equals(dataType)) {
- if (TransferEvent.EVENT_TRANSFERRING.equals(progressDataEvent)) {
+ if (TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA.equals(progressEvent)) {
+ mFolderBackupState.setSummary(R.string.above_quota);
+ } else if (TransferEvent.EVENT_TRANSFERRING.equals(progressEvent)) {
viewModel.countFolderBackupState(requireContext());
}
}
-
-
}
private void loadData() {
@@ -634,12 +632,7 @@ public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result)
refreshFolderBackNetworkMode(which);
//restart
- NetworkType networkType = NetworkType.UNMETERED;
- if (FolderBackupManager.readDataPlanAllowed()) {
- networkType = NetworkType.CONNECTED;
- }
-
- BackgroundJobManagerImpl.getInstance().restartFolderUploadWorker(networkType);
+ BackgroundJobManagerImpl.getInstance().restartFolderUploadWorker();
}
});
@@ -728,7 +721,7 @@ private void switchCameraWorker(boolean isChecked) {
CameraUploadManager.getInstance().setCameraAccount(currentAccount);
BackgroundJobManagerImpl.getInstance().restartMediaBackupWorker(true);
- //firebase - event -login
+ //firebase - event - switch camera worker
Bundle eventBundle = new Bundle();
eventBundle.putString(FirebaseAnalytics.Param.METHOD, "switchCameraWorker");
FirebaseAnalytics.getInstance(requireContext()).logEvent(AnalyticsEvent.ALBUM_BACKUP, eventBundle);
@@ -749,7 +742,7 @@ private void refreshFolderBackupView(boolean isSync) {
setFolderPreferencesVisible(isFolderAutomaticBackup);
if (!isFolderAutomaticBackup) {
- BackgroundJobManagerImpl.getInstance().cancelFolderWorker();
+ BackgroundJobManagerImpl.getInstance().cancelFilesUploadWorker();
if (fileSyncService != null) {
fileSyncService.stopFolderMonitor();
}
@@ -772,7 +765,7 @@ private void refreshFolderBackupView(boolean isSync) {
if (isSync && !CollectionUtils.isEmpty(pathList) && repoConfig != null) {
if (fileSyncService != null) {
- fileSyncService.startFolderMonitor(pathList);
+ fileSyncService.startFolderMonitor();
}
BackgroundJobManagerImpl.getInstance().scheduleFolderBackupScannerWorker(true);
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragmentViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragmentViewModel.java
index ad0e4b6f4..7ab1a5f4a 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragmentViewModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/settings/SettingsFragmentViewModel.java
@@ -20,8 +20,8 @@
import com.seafile.seadroid2.framework.datastore.StorageManager;
import com.seafile.seadroid2.framework.http.IO;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
-import com.seafile.seadroid2.framework.worker.UploadFolderFileAutomaticallyWorker;
-import com.seafile.seadroid2.framework.worker.UploadMediaFileAutomaticallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadFolderFileAutomaticallyWorker;
+import com.seafile.seadroid2.framework.worker.upload.UploadMediaFileAutomaticallyWorker;
import com.seafile.seadroid2.ui.account.AccountService;
import com.seafile.seadroid2.ui.base.viewmodel.BaseViewModel;
import com.seafile.seadroid2.ui.main.MainService;
@@ -93,10 +93,6 @@ public void accept(AccountInfo accountInfo) throws Exception {
}
public void countFolderBackupState(Context context) {
- countFolderBackupState(context, null);
- }
-
- public void countFolderBackupState(Context context, String fileName) {
Account account = SupportAccountManager.getInstance().getCurrentAccount();
@@ -118,11 +114,7 @@ public void accept(Integer s) throws Exception {
if (workInfo != null && WorkInfo.State.ENQUEUED == workInfo.getState()) {
folderBackupStateLiveData.setValue(context.getString(R.string.waiting));
} else {
- if (TextUtils.isEmpty(fileName)) {
- folderBackupStateLiveData.setValue(String.valueOf(s));
- } else {
- folderBackupStateLiveData.setValue("(" + s + ") " + fileName);
- }
+ folderBackupStateLiveData.setValue(String.valueOf(s));
}
}
}
@@ -130,10 +122,6 @@ public void accept(Integer s) throws Exception {
}
public void countAlbumBackupState(Context context) {
- countAlbumBackupState(context, null);
- }
-
- public void countAlbumBackupState(Context context, String fileName) {
Account account = SupportAccountManager.getInstance().getCurrentAccount();
Single folderBackupInProgressCountSingle = AppDatabase
@@ -146,7 +134,7 @@ public void countAlbumBackupState(Context context, String fileName) {
addSingleDisposable(folderBackupInProgressCountSingle, new Consumer() {
@Override
- public void accept(Integer s) throws Exception {
+ public void accept(Integer s) {
if (s == 0) {
albumBackupStateLiveData.setValue(context.getString(R.string.settings_cuc_finish_title));
} else {
@@ -154,11 +142,7 @@ public void accept(Integer s) throws Exception {
if (workInfo != null && WorkInfo.State.ENQUEUED == workInfo.getState()) {
albumBackupStateLiveData.setValue(context.getString(R.string.waiting));
} else {
- if (TextUtils.isEmpty(fileName)) {
- albumBackupStateLiveData.setValue(String.valueOf(s));
- } else {
- albumBackupStateLiveData.setValue("(" + s + ") " + fileName);
- }
+ albumBackupStateLiveData.setValue(String.valueOf(s));
}
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/star/StarredQuickFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/star/StarredQuickFragment.java
index 5e19cac2f..d514d3f03 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/star/StarredQuickFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/star/StarredQuickFragment.java
@@ -94,19 +94,19 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
initViewModel();
}
- private boolean isFirstLoadData = true;
private boolean isForce = false;
+ @Override
+ public void onFirstResume() {
+ super.onFirstResume();
+ reload();
+ }
+
@Override
public void onResume() {
super.onResume();
- d("load data:onResume");
if (isForce) {
reload();
- } else if (isFirstLoadData) {
- isFirstLoadData = false;
- d("load data:isFirstLoadData");
- reload();
}
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java
index 7ca4ca69f..985d9e8d5 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/DownloadListFragment.java
@@ -19,11 +19,10 @@
import com.seafile.seadroid2.framework.data.model.enums.TransferDataSource;
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
-import com.seafile.seadroid2.framework.worker.DownloadWorker;
+import com.seafile.seadroid2.framework.worker.download.DownloadWorker;
import com.seafile.seadroid2.framework.worker.SupportWorkManager;
import com.seafile.seadroid2.framework.worker.TransferEvent;
import com.seafile.seadroid2.framework.worker.TransferWorker;
-import com.seafile.seadroid2.framework.worker.UploadMediaFileAutomaticallyWorker;
import java.util.List;
@@ -70,19 +69,19 @@ private void doWorkInfoLiveData(TransferDataSource dataSource, WorkInfo workInfo
}
Data outData = workInfo.getOutputData();
- Data progressData = workInfo.getProgress();
-
String outEvent = outData.getString(TransferWorker.KEY_DATA_EVENT);
- String progressEvent = progressData.getString(TransferWorker.KEY_DATA_EVENT);
+ if (TransferEvent.EVENT_FINISH.equals(outEvent)) {
+ refreshData();
+ return;
+ }
- if (TransferEvent.EVENT_TRANSFERRED_WITH_DATA.equals(outEvent)) {
- loadData();
- } else if (TransferEvent.EVENT_TRANSFERRED_WITHOUT_DATA.equals(outEvent)) {
+ Data progressData = workInfo.getProgress();
+ String progressEvent = progressData.getString(TransferWorker.KEY_DATA_EVENT);
- } else if (TransferEvent.EVENT_TRANSFERRING.equals(progressEvent)) {
+ if (TransferEvent.EVENT_TRANSFERRING.equals(progressEvent)) {
- String transferId = progressData.getString(TransferWorker.DATA_TRANSFER_KEY);
+ String transferId = progressData.getString(TransferWorker.DATA_TRANSFER_ID_KEY);
String fileName = progressData.getString(TransferWorker.DATA_TRANSFER_NAME_KEY);
int percent = progressData.getInt(TransferWorker.KEY_DATA_PROGRESS, 0);
long transferredSize = progressData.getLong(TransferWorker.KEY_DATA_TRANSFERRED_SIZE, 0);
@@ -91,11 +90,30 @@ private void doWorkInfoLiveData(TransferDataSource dataSource, WorkInfo workInfo
SLogs.d("download: " + fileName + ", percent:" + percent + ", total_size:" + totalSize + ", dataSource: " + dataSource);
if (TextUtils.equals(transferId, lastTransferId)) {
- adapter.notifyProgressById(transferId, transferredSize, percent);
+ notifyProgressById(transferId, transferredSize, percent, progressEvent);
} else {
lastTransferId = transferId;
- loadData(false);
+
}
+ } else if (TransferEvent.EVENT_TRANSFER_SUCCESS.equals(progressEvent)) {
+ String transferId = progressData.getString(TransferWorker.DATA_TRANSFER_ID_KEY);
+ String fileName = progressData.getString(TransferWorker.DATA_TRANSFER_NAME_KEY);
+ long transferredSize = progressData.getLong(TransferWorker.KEY_DATA_TRANSFERRED_SIZE, 0);
+ long totalSize = progressData.getLong(TransferWorker.KEY_DATA_TOTAL_SIZE, 0);
+
+ SLogs.d("download finish: " + fileName + ", total_size:" + totalSize + ", dataSource: " + dataSource);
+
+ notifyProgressById(transferId, transferredSize, 100, progressEvent);
+
+ } else if (TransferEvent.EVENT_TRANSFER_FAILED.equals(progressEvent)) {
+ String transferId = progressData.getString(TransferWorker.DATA_TRANSFER_ID_KEY);
+ String fileName = progressData.getString(TransferWorker.DATA_TRANSFER_NAME_KEY);
+ long transferredSize = progressData.getLong(TransferWorker.KEY_DATA_TRANSFERRED_SIZE, 0);
+ long totalSize = progressData.getLong(TransferWorker.KEY_DATA_TOTAL_SIZE, 0);
+
+ SLogs.d("download failed: " + fileName + ", dataSource: " + dataSource);
+
+ notifyProgressById(transferId, transferredSize, 0, progressEvent);
}
}
@@ -122,7 +140,7 @@ public void accept(Boolean aBoolean) throws Exception {
dialog.dismiss();
- loadData();
+ refreshData();
}
});
}
@@ -170,7 +188,7 @@ public void cancelAllTasks() {
public void accept(Boolean aBoolean) throws Exception {
ToastUtils.showLong(R.string.cancel_download);
- loadData();
+ refreshData();
}
});
}
@@ -191,7 +209,7 @@ public void onClick(DialogInterface dialog, int which) {
public void accept(Boolean aBoolean) throws Exception {
ToastUtils.showLong(R.string.deleted);
- loadData();
+ refreshData();
}
});
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListAdapter.java
index f818c4f29..5bee44a5e 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListAdapter.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListAdapter.java
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
public class TransferListAdapter extends BaseAdapter {
private boolean actionModeOn;
@@ -177,7 +178,7 @@ private void onBindHolder(TransferItemViewHolder holder, FileTransferEntity enti
if (TransferResult.NO_RESULT == entity.transfer_result) {
holder.binding.transferFileErrorState.setVisibility(View.GONE);
holder.binding.transferFileErrorState.setText(null);
- }else if (TransferResult.TRANSMITTED == entity.transfer_result) {
+ } else if (TransferResult.TRANSMITTED == entity.transfer_result) {
holder.binding.transferFileErrorState.setVisibility(View.GONE);
holder.binding.transferFileErrorState.setText(null);
} else {
@@ -206,20 +207,6 @@ private void onBindPayloadHolder(TransferItemViewHolder holder, FileTransferEnti
holder.binding.transferFileProgressBar.setProgress(percent);
}
- public void notifyProgressById(String transferId, long transferredSize, int percent) {
- int position = getPositionById(transferId);
- if (position == -1) {
- return;
- }
-
- getItems().get(position).transferred_size = transferredSize;
-
- Bundle bundle = new Bundle();
- bundle.putInt(TransferWorker.KEY_DATA_PROGRESS, percent);
- bundle.putLong(TransferWorker.KEY_DATA_TRANSFERRED_SIZE, transferredSize);
- notifyItemChanged(position, bundle);
- }
-
public void notifyDataChanged(List list) {
if (CollectionUtils.isEmpty(list)) {
submitList(list);
@@ -370,19 +357,6 @@ public boolean selectItemByMode(int position) {
}
- private int getPositionById(String id) {
- if (CollectionUtils.isEmpty(getItems())) {
- return -1;
- }
-
- for (int i = 0; i < getItems().size(); i++) {
- if (TextUtils.equals(id, getItems().get(i).uid)) {
- return i;
- }
- }
- return -1;
- }
-
private int getSelectedPositionByMode() {
for (int i = 0; i < getItems().size(); i++) {
if (getItems().get(i).is_selected) {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java
index e3dbdeb63..5c7318781 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/transfer_list/TransferListFragment.java
@@ -3,6 +3,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
+import android.util.Pair;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -14,12 +15,15 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.view.ActionMode;
+import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.LinearLayoutManager;
import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter4.BaseQuickAdapter;
import com.chad.library.adapter4.QuickAdapterHelper;
+import com.chad.library.adapter4.loadState.trailing.TrailingLoadStateAdapter;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.bottomsheetmenu.BottomSheetHelper;
@@ -27,11 +31,17 @@
import com.seafile.seadroid2.databinding.LayoutFrameSwipeRvBinding;
import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity;
import com.seafile.seadroid2.framework.data.model.enums.TransferAction;
+import com.seafile.seadroid2.framework.data.model.enums.TransferResult;
+import com.seafile.seadroid2.framework.data.model.enums.TransferStatus;
import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
+import com.seafile.seadroid2.framework.worker.TransferEvent;
+import com.seafile.seadroid2.framework.worker.TransferWorker;
+import com.seafile.seadroid2.ui.base.adapter.LogicLoadMoreAdapter;
import com.seafile.seadroid2.ui.base.fragment.BaseFragment;
import com.seafile.seadroid2.view.TipsViews;
import java.util.List;
+import java.util.Map;
import io.reactivex.functions.Consumer;
@@ -40,8 +50,9 @@ public abstract class TransferListFragment extends BaseFragment {
protected TransferListAdapter adapter;
private ActionMode actionMode;
protected TransferActivity activity = null;
-
+ private LinearLayoutManager layoutManager;
private TransferListViewModel viewModel;
+ private Map positionMap;
@Override
public void onAttach(@NonNull Context context) {
@@ -64,7 +75,8 @@ public TransferListViewModel getViewModel() {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = LayoutFrameSwipeRvBinding.inflate(inflater, container, false);
- binding.swipeRefreshLayout.setOnRefreshListener(this::loadData);
+ binding.swipeRefreshLayout.setOnRefreshListener(this::refreshData);
+ layoutManager = (LinearLayoutManager) binding.rv.getLayoutManager();
return binding.getRoot();
}
@@ -75,8 +87,12 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
initAdapter();
initViewModel();
+ }
- loadData();
+ @Override
+ public void onFirstResume() {
+ super.onFirstResume();
+ refreshData();
}
private void initAdapter() {
@@ -122,14 +138,23 @@ public boolean onLongClick(@NonNull BaseQuickAdapter base
});
- QuickAdapterHelper helper = new QuickAdapterHelper.Builder(adapter).build();
+// LogicLoadMoreAdapter loadMoreAdapter = getLogicLoadMoreAdapter();
+
+ QuickAdapterHelper helper = new QuickAdapterHelper.Builder(adapter)
+ .build();
binding.rv.setAdapter(helper.getAdapter());
}
private void initViewModel() {
getViewModel().getRefreshLiveData().observe(getViewLifecycleOwner(), aBoolean -> binding.swipeRefreshLayout.setRefreshing(aBoolean));
- getViewModel().getFileTransferEntitiesLiveData().observe(getViewLifecycleOwner(), this::notifyDataChanged);
+ getViewModel().getFileTransferEntitiesLiveData().observe(getViewLifecycleOwner(), new Observer, List>>() {
+ @Override
+ public void onChanged(Pair