diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/DirentDAO.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/DirentDAO.java
index 505f641bc..c2a883381 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/DirentDAO.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/DirentDAO.java
@@ -30,16 +30,7 @@ public interface DirentDAO {
Single> getAllByFullPath(String repo_id, String full_path);
@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id limit 1")
- DirentModel getByFullPathSync(String repo_id, String full_path);
-
- @Query("select * from dirents where full_path = :full_path and repo_id = :repo_id limit 1")
- DirentModel getByTargetPathSync(String repo_id, String full_path);
-
- @Query("select * from dirents where uid = :uid")
- Single getDirentById(String uid);
-
- @Query("select * from dirents where uid = :uid limit 1")
- DirentModel getOneByIdSync(String uid);
+ List getByFullPathSync(String repo_id, String full_path);
@Query("select * from dirents where uid in ( :uids )")
List getListByIdsSync(List uids);
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/EncKeyCacheDAO.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/EncKeyCacheDAO.java
index 1bdc61500..c515ba9fb 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/EncKeyCacheDAO.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/EncKeyCacheDAO.java
@@ -27,7 +27,7 @@ public interface EncKeyCacheDAO {
void insertAllSync(List entities);
@Query("select * from enc_key_cache where repo_id = :repoId limit 1")
- EncKeyCacheEntity getOneByRepoIdSync(String repoId);
+ List getOneByRepoIdSync(String repoId);
@Query("select * from enc_key_cache where repo_id = :repoId limit 1")
Single> getListByRepoIdAsync(String repoId);
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java
index 57954d9c1..1146e8ac4 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/FileTransferDAO.java
@@ -76,14 +76,14 @@ public interface FileTransferDAO {
Single> getListByFeatAsync(String related_account, List feats);
@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1")
- FileTransferEntity getOnePendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);
+ List getOnePendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);
@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc limit :limit")
List getListPendingTransferSync(String related_account, TransferAction transfer_action, int limit);
@Query("select * from file_transfer_list where transfer_action = :transfer_action and is_auto_transfer = 1 and transfer_status in ('IN_PROGRESS', 'WAITING') and data_source = :feature and data_status = 0 order by created_at asc limit 1")
- FileTransferEntity getOnePendingTransferAllAccountSync(TransferAction transfer_action, TransferDataSource feature);
+ List getOnePendingTransferAllAccountSync(TransferAction transfer_action, TransferDataSource feature);
@Query("select * from file_transfer_list where related_account = :related_account and is_auto_transfer = 1 and transfer_action = 'DOWNLOAD' and transfer_status in ('IN_PROGRESS', 'WAITING') and data_status = 0 order by created_at asc")
List getPendingDownloadListByActionSync(String related_account);
@@ -98,10 +98,8 @@ public interface FileTransferDAO {
List getDownloadListSync(String related_account);
@Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and target_path = :target_path and data_status = 0 order by created_at desc limit 1")
- FileTransferEntity getByTargetPathSync(String related_account, TransferAction transferAction, String target_path);
+ List getByTargetPathSync(String related_account, TransferAction transferAction, String target_path);
- @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at desc limit 1")
- FileTransferEntity getByFullPathSync(String related_account, TransferAction transferAction, String full_path);
@Query("select * from file_transfer_list where uid = :uid")
List getByUid(String uid);
@@ -109,20 +107,14 @@ public interface FileTransferDAO {
@Query("select * from file_transfer_list where uid in ( :uids )")
List getListByUidsSync(List uids);
- @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source = 'ALBUM_BACKUP' and mime_type like :mime_type_str and data_status = 0 order by file_original_modified_at desc limit 1")
- FileTransferEntity getLastOneForMedia(String related_account, String mime_type_str);
-
@Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc")
Single> getListByFullPathsAsync(String repoId, List fullPaths, TransferAction transfer_action);
@Query("select * from file_transfer_list where repo_id = :repoId and full_path IN(:fullPaths) and transfer_action = :transfer_action order by created_at asc")
List getListByFullPathsSync(String repoId, List fullPaths, TransferAction transfer_action);
- @Query("select * from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action order by created_at asc limit 1")
- FileTransferEntity getOneByFullPathSync(String repoId, String fullPath, TransferAction transfer_action);
-
- @Query("select * from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action order by created_at asc limit 1")
- Single getOneByFullPathAsync(String repoId, String fullPath, TransferAction transfer_action);
+ @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at")
+ List getListByFullPathsSync(String related_account, TransferAction transferAction, String full_path);
@Query("select COUNT(*) from file_transfer_list where repo_id = :repoId and full_path = :fullPath and transfer_action = :transfer_action and data_source = :feature and data_status = 0 ")
int checkOneByFullPath(String repoId, String fullPath, TransferAction transfer_action, TransferDataSource feature);
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataManager.java b/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataManager.java
index 50e45dfa6..97836cf74 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataManager.java
@@ -2,7 +2,9 @@
import android.text.TextUtils;
+import com.blankj.utilcode.util.GsonUtils;
import com.google.common.collect.Maps;
+import com.google.gson.reflect.TypeToken;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.account.Account;
@@ -13,7 +15,9 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -129,27 +133,36 @@ public static String getAccountDir(Account account) {
* repo-id::::new-repo-name
*
*/
- private static String getSpecialRepoDirMapping(String repo_id) {
+ private static String getSpecialRepoDirMapping(Account account, String repo_id) {
- Set sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);
-
- for (String set : sets) {
- String[] ss = StringUtils.split(set, DataStoreKeys.SEPARATOR);
- if (repo_id.equals(ss[0])) {
- return ss[1];
+ List list = getRepoNameMaps(account);
+ for (String set : list) {
+ String[] sp = StringUtils.split(set, DataStoreKeys.SEPARATOR);
+ if (repo_id.equals(sp[0])) {
+ return sp[1];
}
}
return null;
}
- private static boolean checkSpecialRepoDirMapping(String repo_name) {
+ public static List getRepoNameMaps(Account account) {
+ String names = DataStoreManager.getInstanceByUser(account.getSignature()).readString(DataStoreKeys.DS_REPO_DIR_MAPPING);
+ Type listType = new TypeToken>() {
+ }.getType();
- Set sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);
+ List list = GsonUtils.fromJson(names, listType);
+ if (null == list) {
+ list = new ArrayList<>();
+ }
+ return list;
+ }
- for (String set : sets) {
- String[] ss = StringUtils.split(set, DataStoreKeys.SEPARATOR);
- if (repo_name.equals(ss[1])) {
+ private static boolean checkSpecialRepoDirMapping(Account account, String repo_name) {
+ List list = getRepoNameMaps(account);
+ for (String set : list) {
+ String[] sp = StringUtils.split(set, DataStoreKeys.SEPARATOR);
+ if (repo_name.equals(sp[1])) {
return true;
}
}
@@ -161,7 +174,7 @@ public static File getRepoDirMappingDataStore(Account account, String repo_id, S
String accountDir = DataManager.getAccountDir(account);
- String repoDirName = getSpecialRepoDirMapping(repo_id);
+ String repoDirName = getSpecialRepoDirMapping(account, repo_id);
File repoDir;
if (!TextUtils.isEmpty(repoDirName)) {
@@ -181,7 +194,7 @@ public static File getRepoDirMappingDataStore(Account account, String repo_id, S
uniqueRepoName = repo_name + " (" + i + ")";
}
- boolean isDuplicate = checkSpecialRepoDirMapping(uniqueRepoName);
+ boolean isDuplicate = checkSpecialRepoDirMapping(account, uniqueRepoName);
repoDir = new File(accountDir, uniqueRepoName);
if (!repoDir.exists() && !isDuplicate) {
break;
@@ -196,9 +209,10 @@ public static File getRepoDirMappingDataStore(Account account, String repo_id, S
}
- Set sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);
- sets.add(repo_id + DataStoreKeys.SEPARATOR + uniqueRepoName);
- DataStoreManager.getCommonInstance().writeSetString(DataStoreKeys.DS_REPO_DIR_MAPPING, sets);
+ List list = getRepoNameMaps(account);
+ list.add(repo_id + DataStoreKeys.SEPARATOR + uniqueRepoName);
+ String v = GsonUtils.toJson(list);
+ DataStoreManager.getInstanceByUser(account.getSignature()).writeString(DataStoreKeys.DS_REPO_DIR_MAPPING, v);
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreManager.java b/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreManager.java
index 0114929f7..08dbdf8f1 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreManager.java
@@ -151,7 +151,6 @@ public static DataStoreManager getInstanceByUser(String accountSignature) {
// file1.delete();
// }
// }
-
public void writeInteger(String strKey, Integer value) {
writeValue(strKey, value);
}
@@ -179,12 +178,12 @@ public void writeLong(String strKey, @NonNull Long value) {
writeValue(strKey, value);
}
- public void writeSetString(String strKey, Set value) {
- if (null == value) {
- value = new HashSet<>();
- }
- writeValue(strKey, value);
- }
+// public void writeSetString(String strKey, Set value) {
+// if (null == value) {
+// value = new HashSet<>();
+// }
+// writeValue(strKey, value);
+// }
/**
* write value
@@ -192,7 +191,7 @@ public void writeSetString(String strKey, Set value) {
private void writeValue(String strKey, Object value) {
// Single single = null;
if (value instanceof Integer) {
- sharedPreferences.edit().putInt(strKey, (Integer) value).commit();
+ sharedPreferences.edit().putInt(strKey, (Integer) value).apply();
// Preferences.Key intKey = PreferencesKeys.intKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
@@ -201,7 +200,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof String) {
- sharedPreferences.edit().putString(strKey, (String) value).commit();
+ sharedPreferences.edit().putString(strKey, (String) value).apply();
// Preferences.Key stringKey = PreferencesKeys.stringKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
@@ -211,7 +210,7 @@ private void writeValue(String strKey, Object value) {
// }
// );
} else if (value instanceof Boolean) {
- sharedPreferences.edit().putBoolean(strKey, (Boolean) value).commit();
+ sharedPreferences.edit().putBoolean(strKey, (Boolean) value).apply();
// Preferences.Key booleanKey = PreferencesKeys.booleanKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
@@ -220,7 +219,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Double) {
- sharedPreferences.edit().putFloat(strKey, (Float) value).commit();
+ sharedPreferences.edit().putFloat(strKey, (Float) value).apply();
// Preferences.Key doubleKey = PreferencesKeys.doubleKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
@@ -229,7 +228,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Float) {
- sharedPreferences.edit().putFloat(strKey, (Float) value).commit();
+ sharedPreferences.edit().putFloat(strKey, (Float) value).apply();
// Preferences.Key floatKey = PreferencesKeys.floatKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
@@ -238,7 +237,7 @@ private void writeValue(String strKey, Object value) {
// return Single.just(mutablePreferences);
// });
} else if (value instanceof Long) {
- sharedPreferences.edit().putLong(strKey, (Long) value).commit();
+ sharedPreferences.edit().putLong(strKey, (Long) value).apply();
// Preferences.Key longKey = PreferencesKeys.longKey(strKey);
// single = dataStore.updateDataAsync(preferences -> {
@@ -246,16 +245,19 @@ private void writeValue(String strKey, Object value) {
// mutablePreferences.set(longKey, (Long) value);
// return Single.just(mutablePreferences);
// });
- } else if (value instanceof Set) {
- sharedPreferences.edit().putStringSet(strKey, (Set) value).commit();
-
-// Preferences.Key> setKey = PreferencesKeys.stringSetKey(strKey);
-// single = dataStore.updateDataAsync(preferences -> {
-// MutablePreferences mutablePreferences = preferences.toMutablePreferences();
-// mutablePreferences.set(setKey, (Set) value);
-// return Single.just(mutablePreferences);
-// });
- } else {
+ }
+// else if (value instanceof Set>) {
+// Set set = (Set) value;
+// sharedPreferences.edit().putStringSet(strKey, set).apply();
+//
+//// Preferences.Key> setKey = PreferencesKeys.stringSetKey(strKey);
+//// single = dataStore.updateDataAsync(preferences -> {
+//// MutablePreferences mutablePreferences = preferences.toMutablePreferences();
+//// mutablePreferences.set(setKey, (Set) value);
+//// return Single.just(mutablePreferences);
+//// });
+// }
+ else {
throw new IllegalStateException("Unexpected value: " + value);
}
@@ -372,20 +374,20 @@ public long readLong(String key) {
}
- public Set readSetString(String key) {
- return sharedPreferences.getStringSet(key, new HashSet<>());
-
-// Preferences.Key> setKey = PreferencesKeys.stringSetKey(key);
-// Flowable> flowable = dataStore.data().map(new Function>() {
-// @Override
-// public Set apply(Preferences preferences) throws Exception {
-// Set value = preferences.get(setKey);
-// return value != null ? new HashSet<>(value) : new HashSet<>();
-// }
-// });
+// public Set readSetString(String key) {
+// return sharedPreferences.getStringSet(key, new HashSet<>());
//
-// return flowable.first(new HashSet<>()).blockingGet();
- }
+//// Preferences.Key> setKey = PreferencesKeys.stringSetKey(key);
+//// Flowable> flowable = dataStore.data().map(new Function>() {
+//// @Override
+//// public Set apply(Preferences preferences) throws Exception {
+//// Set value = preferences.get(setKey);
+//// return value != null ? new HashSet<>(value) : new HashSet<>();
+//// }
+//// });
+////
+//// return flowable.first(new HashSet<>()).blockingGet();
+// }
// public void removeByStringKey(String strKey) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/BaseUploadFileWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/BaseUploadFileWorker.java
index 62728149c..790a8299f 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/BaseUploadFileWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/BaseUploadFileWorker.java
@@ -399,11 +399,12 @@ private void uploadBlockFile(Account account, FileTransferEntity transferEntity)
AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
//
- EncKeyCacheEntity encKeyCacheEntity = AppDatabase.getInstance().encKeyCacheDAO().getOneByRepoIdSync(transferEntity.repo_id);
- if (encKeyCacheEntity == null) {
+ List encKeyCacheEntityList = AppDatabase.getInstance().encKeyCacheDAO().getOneByRepoIdSync(transferEntity.repo_id);
+ if (CollectionUtils.isEmpty(encKeyCacheEntityList)) {
throw SeafException.encryptException;
}
+ EncKeyCacheEntity encKeyCacheEntity = encKeyCacheEntityList.get(0);
final String encKey = encKeyCacheEntity.enc_key;
final String encIv = encKeyCacheEntity.enc_iv;
if (TextUtils.isEmpty(encKey) || TextUtils.isEmpty(encIv)) {
@@ -560,8 +561,9 @@ private void updateSuccess(FileTransferEntity transferEntity, String fileId, Fil
AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
//update
- DirentModel direntModel = AppDatabase.getInstance().direntDao().getByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
- if (direntModel != null) {
+ List direntList = AppDatabase.getInstance().direntDao().getByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
+ if (!CollectionUtils.isEmpty(direntList)) {
+ DirentModel direntModel = direntList.get(0);
direntModel.last_modified_at = transferEntity.modified_at;
direntModel.id = fileId;
direntModel.size = transferEntity.file_size;
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadWorker.java
index c77fdb36f..6d07ee6eb 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadWorker.java
@@ -308,8 +308,9 @@ private void updateEntitySuccessState(FileTransferEntity fileTransferEntity, Fil
AppDatabase.getInstance().fileTransferDAO().update(fileTransferEntity);
//update
- DirentModel direntModel = AppDatabase.getInstance().direntDao().getByFullPathSync(fileTransferEntity.repo_id, fileTransferEntity.full_path);
- if (direntModel != null) {
+ List direntList = AppDatabase.getInstance().direntDao().getByFullPathSync(fileTransferEntity.repo_id, fileTransferEntity.full_path);
+ if (!CollectionUtils.isEmpty(direntList)) {
+ DirentModel direntModel = direntList.get(0);
direntModel.last_modified_at = fileTransferEntity.modified_at;
direntModel.id = fileTransferEntity.file_id;
direntModel.size = fileTransferEntity.file_size;
@@ -349,10 +350,12 @@ private void downloadFileByBlock(Account account, FileTransferEntity transferEnt
FileBlocks fileBlocks = getDownloadBlockList(transferEntity);
- EncKeyCacheEntity entity = AppDatabase.getInstance().encKeyCacheDAO().getOneByRepoIdSync(transferEntity.repo_id);
- if (entity == null) {
+ List encKeyCacheEntityList = AppDatabase.getInstance().encKeyCacheDAO().getOneByRepoIdSync(transferEntity.repo_id);
+
+ if (CollectionUtils.isEmpty(encKeyCacheEntityList)) {
throw SeafException.decryptException;
}
+ EncKeyCacheEntity entity = encKeyCacheEntityList.get(0);
final String encKey = entity.enc_key;
final String encIv = entity.enc_iv;
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorker.java
index 4f5e51d38..39138feba 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorker.java
@@ -8,6 +8,7 @@
import androidx.work.WorkerParameters;
import com.blankj.utilcode.util.CloneUtils;
+import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.FileUtils;
import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.account.Account;
@@ -26,6 +27,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.List;
import java.util.UUID;
/**
@@ -77,19 +79,19 @@ private Result start() {
String outEvent = TransferEvent.EVENT_TRANSFERRED_WITH_DATA;
//
- FileTransferEntity transferEntity = AppDatabase
+ List transferEntityList = AppDatabase
.getInstance()
.fileTransferDAO()
.getByTargetPathSync(account.getSignature(), TransferAction.DOWNLOAD, filePath);
- if (transferEntity == null) {
+ if (CollectionUtils.isEmpty(transferEntityList)) {
return Result.success();
}
notificationManager.showNotification();
try {
- checkFile(account, transferEntity);
+ checkFile(account, transferEntityList.get(0));
} catch (IOException | SeafException e) {
throw new RuntimeException(e);
}
@@ -115,8 +117,8 @@ private void checkFile(Account account, FileTransferEntity downloadTransferEntit
return;
}
- DirentModel direntModel = AppDatabase.getInstance().direntDao().getByFullPathSync(downloadTransferEntity.repo_id, downloadTransferEntity.full_path);
- if (direntModel == null) {
+ List direntList = AppDatabase.getInstance().direntDao().getByFullPathSync(downloadTransferEntity.repo_id, downloadTransferEntity.full_path);
+ if (CollectionUtils.isEmpty(direntList)) {
// db not exist
SLogs.d("db is not exists: " + downloadTransferEntity.target_path);
return;
@@ -132,12 +134,14 @@ private void checkFile(Account account, FileTransferEntity downloadTransferEntit
}
//target_path is Absolute Path
- FileTransferEntity transferEntity = AppDatabase
+ List transferEntityList = AppDatabase
.getInstance()
.fileTransferDAO()
- .getByFullPathSync(account.getSignature(), TransferAction.UPLOAD, downloadTransferEntity.target_path);
- if (transferEntity == null) {
- transferEntity = CloneUtils.deepClone(downloadTransferEntity,FileTransferEntity.class);
+ .getListByFullPathsSync(account.getSignature(), TransferAction.UPLOAD, downloadTransferEntity.target_path);
+
+ FileTransferEntity transferEntity = null;
+ if (CollectionUtils.isEmpty(transferEntityList)) {
+ transferEntity = CloneUtils.deepClone(downloadTransferEntity, FileTransferEntity.class);
transferEntity.full_path = downloadTransferEntity.target_path;
transferEntity.target_path = downloadTransferEntity.full_path;
transferEntity.setParent_path(Utils.getParentPath(transferEntity.target_path));
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorkerBak.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorkerBak.java
index a6dcc6160..421ce73f4 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorkerBak.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/DownloadedFileCheckerWorkerBak.java
@@ -103,12 +103,13 @@ private void checkFile(Account account, FileTransferEntity transferEntity) throw
return;
}
- DirentModel direntModel = AppDatabase.getInstance().direntDao().getByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
- if (direntModel == null) {
+ List direntList = AppDatabase.getInstance().direntDao().getByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
+ if (CollectionUtils.isEmpty(direntList)) {
// db not exist
SLogs.d("db is not exists: " + transferEntity.target_path);
return;
}
+ DirentModel direntModel = direntList.get(0);
//More judgment conditions may be required
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java
index f332e3123..2c498fde8 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFileManuallyWorker.java
@@ -22,6 +22,7 @@
import com.seafile.seadroid2.framework.notification.base.BaseNotification;
import com.seafile.seadroid2.framework.util.SLogs;
+import java.util.List;
import java.util.UUID;
@@ -72,14 +73,16 @@ private Result start() {
return Result.success();
}
- FileTransferEntity transfer = AppDatabase.getInstance().fileTransferDAO()
+ List transferList = AppDatabase.getInstance().fileTransferDAO()
.getOnePendingTransferAllAccountSync(
TransferAction.UPLOAD,
TransferDataSource.FILE_BACKUP);
- if (transfer == null) {
+ if (CollectionUtils.isEmpty(transferList)) {
break;
}
+ FileTransferEntity transfer = transferList.get(0);
+
try {
boolean isAmple = calculateQuota(CollectionUtils.newArrayList(transfer));
if (!isAmple) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java
index 56aa7c9a9..252bbb43e 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadFolderFileAutomaticallyWorker.java
@@ -23,6 +23,7 @@
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.notification.FolderBackupNotificationHelper;
+import java.util.List;
import java.util.UUID;
@@ -83,14 +84,16 @@ private Result start() {
SLogs.d("start upload file worker");
//check
- FileTransferEntity transfer = AppDatabase.getInstance().fileTransferDAO()
+ List transferList = AppDatabase.getInstance().fileTransferDAO()
.getOnePendingTransferSync(account.getSignature(),
TransferAction.UPLOAD, TransferDataSource.FOLDER_BACKUP);
- if (transfer == null) {
+ if (CollectionUtils.isEmpty(transferList)) {
break;
}
+ FileTransferEntity transfer = transferList.get(0);
+
try {
boolean isAmple = calculateQuota(CollectionUtils.newArrayList(transfer));
if (!isAmple) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java
index 2af6bf267..ce53f19e2 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/UploadMediaFileAutomaticallyWorker.java
@@ -23,6 +23,7 @@
import com.seafile.seadroid2.framework.util.SLogs;
import com.seafile.seadroid2.framework.notification.AlbumBackupNotificationHelper;
+import java.util.List;
import java.util.UUID;
/**
@@ -75,13 +76,14 @@ public Result doWork() {
SLogs.d("start upload media worker");
- FileTransferEntity transfer = AppDatabase.getInstance().fileTransferDAO()
+ List transferList = AppDatabase.getInstance().fileTransferDAO()
.getOnePendingTransferSync(account.getSignature(),
TransferAction.UPLOAD,
TransferDataSource.ALBUM_BACKUP);
- if (transfer == null) {
+ if (CollectionUtils.isEmpty(transferList)) {
break;
}
+ FileTransferEntity transfer = transferList.get(0);
try {
boolean isAmple = calculateQuota(CollectionUtils.newArrayList(transfer));
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/data_migrate/DataMigrationActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/data_migrate/DataMigrationActivity.java
index 0bfc550c9..b24e6485b 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/data_migrate/DataMigrationActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/data_migrate/DataMigrationActivity.java
@@ -17,6 +17,7 @@
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.FileUtils;
+import com.blankj.utilcode.util.GsonUtils;
import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.AccountInfo;
@@ -36,6 +37,7 @@
import com.seafile.seadroid2.framework.data.model.enums.TransferResult;
import com.seafile.seadroid2.framework.data.model.enums.TransferStatus;
import com.seafile.seadroid2.framework.data.model.repo.RepoWrapperModel;
+import com.seafile.seadroid2.framework.datastore.DataManager;
import com.seafile.seadroid2.framework.datastore.DataStoreKeys;
import com.seafile.seadroid2.framework.datastore.DataStoreManager;
import com.seafile.seadroid2.framework.datastore.StorageManager;
@@ -116,10 +118,11 @@ public void run() {
startMigration();
- finishMigration();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
+ finishMigration();
+
navTo();
}
}
@@ -834,9 +837,6 @@ private void queryRepoDirOfDataDB() {
null // The sort order
);
- Set sets = DataStoreManager.getCommonInstance().readSetString(DataStoreKeys.DS_REPO_DIR_MAPPING);
-
-
try {
c.moveToFirst();
while (!c.isAfterLast()) {
@@ -851,7 +851,19 @@ private void queryRepoDirOfDataDB() {
String repo_dir = c.getString(repoDirIndex);
// item.related_account = c.getString(accountIndex);
- sets.add(repo_id + DataStoreKeys.SEPARATOR + repo_dir);
+ Optional repoModelOp = accountRepoList.stream().filter(repo -> repo.repo_id.equals(repo_id)).findFirst();
+ if (repoModelOp.isPresent()) {
+ RepoModel repo = repoModelOp.get();
+ Account account = SupportAccountManager.getInstance().getSpecialAccount(repo.related_account);
+ if (account != null) {
+ List list = DataManager.getRepoNameMaps(account);
+ list.add(repo_id + DataStoreKeys.SEPARATOR + repo_dir);
+
+ String v = GsonUtils.toJson(list);
+ DataStoreManager.getInstanceByUser(account.getSignature()).writeString(DataStoreKeys.DS_REPO_DIR_MAPPING, v);
+ }
+ }
+
c.moveToNext();
}
@@ -859,13 +871,7 @@ private void queryRepoDirOfDataDB() {
c.close();
}
-// AppDatabase.getInstance().repoDirMappingDAO().insertAll(list);
SLogs.d("--------------------" + table + " -> 完成");
-
- if (!sets.isEmpty()) {
- DataStoreManager.getCommonInstance().writeSetString(DataStoreKeys.DS_REPO_DIR_MAPPING, sets);
- }
-
}
private void queryDirentsCacheOfDataDB() {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/file/FileActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/file/FileActivity.java
index 7f39a734e..dcc39e922 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/file/FileActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/file/FileActivity.java
@@ -251,7 +251,7 @@ public void onClick(DialogInterface dialog, int which) {
}
});
- builder.setPositiveButton(R.string.replace, new DialogInterface.OnClickListener() {
+ builder.setPositiveButton(R.string.replace_local_file, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/file/FileViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/file/FileViewModel.java
index 9a1ca65dc..c291fb865 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/file/FileViewModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/file/FileViewModel.java
@@ -63,19 +63,19 @@ public void loadFileDetail(String repoId, String path, Consumer> repoListSingle = AppDatabase.getInstance().repoDao().getByIdAsync(repoId);
- Single transferEntity = AppDatabase
+ Single> transferEntity = AppDatabase
.getInstance()
.fileTransferDAO()
- .getOneByFullPathAsync(repoId, path, TransferAction.DOWNLOAD);
+ .getListByFullPathsAsync(repoId, CollectionUtils.newArrayList(path), TransferAction.DOWNLOAD);
- Single> s = Single.zip(single, repoListSingle, transferEntity, new Function3, FileTransferEntity, Triple>() {
+ Single> s = Single.zip(single, repoListSingle, transferEntity, new Function3, List, Triple>() {
@Override
- public Triple apply(DirentFileModel direntFileModel, List repoModels, FileTransferEntity fileTransferEntity) throws Exception {
+ public Triple apply(DirentFileModel direntFileModel, List repoModels, List fileTransferEntity) throws Exception {
if (CollectionUtils.isEmpty(repoModels)) {
throw SeafException.notFoundException;
}
- return new Triple<>(repoModels.get(0), direntFileModel, fileTransferEntity);
+ return new Triple<>(repoModels.get(0), direntFileModel, CollectionUtils.isEmpty(fileTransferEntity) ? null : fileTransferEntity.get(0));
}
});
@@ -99,20 +99,26 @@ public void preDownload(RepoModel repoModel, DirentModel direntModel, File desti
public void subscribe(SingleEmitter emitter) throws Exception {
//this is in child thread.
- FileTransferEntity dbEntity = AppDatabase
+ List transferEntityList = AppDatabase
.getInstance()
.fileTransferDAO()
- .getOneByFullPathSync(repoModel.repo_id, direntModel.full_path, TransferAction.DOWNLOAD);
+ .getListByFullPathsSync(repoModel.repo_id, CollectionUtils.newArrayList(direntModel.full_path), TransferAction.DOWNLOAD);
- if (null == dbEntity) {
+ if (CollectionUtils.isEmpty(transferEntityList)) {
FileTransferEntity transferEntity = FileTransferEntity.convertDirentModel2This(repoModel.encrypted, direntModel);
+ //newest file id
+ transferEntity.file_id = direntModel.id;
+ transferEntity.file_size = direntModel.size;
+ transferEntity.target_path = destinationFile.getAbsolutePath();
+
AppDatabase.getInstance().fileTransferDAO().insert(transferEntity);
emitter.onSuccess(true);
return;
}
+ FileTransferEntity dbEntity = transferEntityList.get(0);
//re-download
if (dbEntity.transfer_result == TransferResult.TRANSMITTED) {
@@ -199,13 +205,14 @@ private void updateFileTransferEntity(Account account, String repo_id, String fu
public void subscribe(SingleEmitter emitter) throws Exception {
//this is in child thread.
- FileTransferEntity dbEntity = AppDatabase
+ List transferEntityList = AppDatabase
.getInstance()
.fileTransferDAO()
- .getOneByFullPathSync(repo_id, fullPathInRepo, TransferAction.DOWNLOAD);
+ .getListByFullPathsSync(repo_id, CollectionUtils.newArrayList(fullPathInRepo), TransferAction.DOWNLOAD);
- if (dbEntity != null) {
+ if (!CollectionUtils.isEmpty(transferEntityList)) {
+ FileTransferEntity dbEntity = transferEntityList.get(0);
if (seafException != null) {
dbEntity.transfer_result = TransferUtils.convertException2TransferResult(seafException);
dbEntity.transfer_status = TransferStatus.FAILED;
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 9971ac53f..43fc8b5ab 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
@@ -230,6 +230,7 @@ public static void navToThis(Context context, String repo_id, String repo_name,
intent.putExtra("repo_name", repo_name);
intent.putExtra("path", path);
intent.putExtra("is_dir", is_dir);
+ intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java
index 9d04ae45c..43a2b2c78 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/main/MainViewModel.java
@@ -62,6 +62,7 @@ public class MainViewModel extends BaseViewModel {
//force refresh repo/dirents
private final MutableLiveData OnForceRefreshRepoListLiveData = new MutableLiveData<>();
+ private final MutableLiveData OnForceRefreshStarredListLiveData = new MutableLiveData<>();
//show swipeRefresh in Repo Fragment
private final MutableLiveData OnShowRefreshLoadingInRepoLiveData = new MutableLiveData<>();
@@ -88,6 +89,9 @@ public MutableLiveData getOnNavContextChangeListenerLiveData() {
return OnNavChangeListenerLiveData;
}
+ public MutableLiveData getOnForceRefreshStarredListLiveData() {
+ return OnForceRefreshStarredListLiveData;
+ }
public MutableLiveData getServerInfoLiveData() {
return ServerInfoLiveData;
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 0b7f84394..373ead766 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
@@ -254,6 +254,8 @@ public void onChanged(Boolean aBoolean) {
if (aBoolean) {
loadData(true);
}
+
+ mainViewModel.getOnForceRefreshStarredListLiveData().setValue(true);
});
getViewModel().getObjsListLiveData().observe(getViewLifecycleOwner(), repoModels -> {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java b/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java
index aa5c4569e..e3b7c3705 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/search/Search2Activity.java
@@ -46,6 +46,7 @@
import com.seafile.seadroid2.ui.WidgetUtils;
import com.seafile.seadroid2.ui.base.BaseActivityWithVM;
import com.seafile.seadroid2.ui.base.adapter.LoadMoreAdapter;
+import com.seafile.seadroid2.ui.base.adapter.LogicLoadMoreAdapter;
import com.seafile.seadroid2.ui.file.FileActivity;
import com.seafile.seadroid2.ui.main.MainActivity;
import com.seafile.seadroid2.ui.media.image_preview.ImagePreviewActivity;
@@ -192,8 +193,19 @@ public void onClick(@NonNull BaseQuickAdapter baseQuickAdapter,
}
});
- LoadMoreAdapter customLoadMoreAdapter = new LoadMoreAdapter();
- customLoadMoreAdapter.setOnLoadMoreListener(new TrailingLoadStateAdapter.OnTrailingListener() {
+ LogicLoadMoreAdapter logicLoadMoreAdapter = getLogicLoadMoreAdapter();
+
+ helper = new QuickAdapterHelper.Builder(adapter)
+ .setTrailingLoadStateAdapter(logicLoadMoreAdapter)
+ .build();
+
+ binding.rv.setAdapter(helper.getAdapter());
+ }
+
+ @NonNull
+ private LogicLoadMoreAdapter getLogicLoadMoreAdapter() {
+ LogicLoadMoreAdapter logicLoadMoreAdapter = new LogicLoadMoreAdapter();
+ logicLoadMoreAdapter.setOnLoadMoreListener(new TrailingLoadStateAdapter.OnTrailingListener() {
@Override
public void onFailRetry() {
loadNext(lastQuery, false);
@@ -209,12 +221,7 @@ public boolean isAllowLoading() {
return !binding.swipeRefreshLayout.isRefreshing();
}
});
-
- helper = new QuickAdapterHelper.Builder(adapter)
- .setTrailingLoadStateAdapter(customLoadMoreAdapter)
- .build();
-
- binding.rv.setAdapter(helper.getAdapter());
+ return logicLoadMoreAdapter;
}
private Disposable disposable;
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 336cea0a8..2644ac5a2 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
@@ -96,12 +96,15 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}
private boolean isFirstLoadData = true;
+ private boolean isForce = false;
@Override
public void onResume() {
super.onResume();
d("load data:onResume");
- if (isFirstLoadData) {
+ if (isForce) {
+ reload();
+ } else if (isFirstLoadData) {
isFirstLoadData = false;
d("load data:isFirstLoadData");
reload();
@@ -143,6 +146,13 @@ private void showErrorTip(SeafException seafException) {
}
private void initViewModel() {
+ mainViewModel.getOnForceRefreshStarredListLiveData().observe(getViewLifecycleOwner(), new Observer() {
+ @Override
+ public void onChanged(Boolean aBoolean) {
+ isForce = aBoolean;
+ }
+ });
+
getViewModel().getRefreshLiveData().observe(getViewLifecycleOwner(), new Observer() {
@Override
public void onChanged(Boolean aBoolean) {
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 b09b6eca4..9759b02ff 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
@@ -13,6 +13,7 @@
import androidx.recyclerview.widget.DiffUtil;
import com.blankj.utilcode.util.CollectionUtils;
+import com.blankj.utilcode.util.TimeUtils;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.framework.data.db.entities.FileTransferEntity;
import com.seafile.seadroid2.framework.data.model.enums.TransferAction;
@@ -106,6 +107,8 @@ private void onBindHolder(TransferItemViewHolder holder, FileTransferEntity enti
int iconId = Icons.getFileIcon(entity.file_name);
holder.binding.transferFileIcon.setImageResource(iconId);
+ holder.binding.transferTime.setText(Utils.translateCommitTime(entity.created_at));
+
//
long totalSize = entity.file_size;
long transferredSize = entity.transferred_size;
diff --git a/app/src/main/res/layout/item_transfer_list.xml b/app/src/main/res/layout/item_transfer_list.xml
index 20c38f4dd..4a7e23c49 100644
--- a/app/src/main/res/layout/item_transfer_list.xml
+++ b/app/src/main/res/layout/item_transfer_list.xml
@@ -29,82 +29,111 @@
android:layout_height="wrap_content"
android:src="@drawable/file_image"
app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@+id/content_container"
app:layout_constraintStart_toEndOf="@+id/item_multi_select"
app:layout_constraintTop_toTopOf="parent" />
-
+ android:layout_weight="1"
+ android:orientation="vertical"
+ android:paddingVertical="8dp">
-
+
-
+
+
+
+
+
-
+
+
+
+
+ android:layout_height="match_parent"
+ android:layout_marginStart="8dp"
+ android:orientation="vertical">
+
+
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ tools:text="5 hours ago" />
+
+
+
+
+
+
-
-
-
-
Add
Modify
Update
- Update local file
- Update remote file
Clear
Close
Clear all
@@ -634,6 +632,8 @@
Downloading
Replace All
Replace
+ Replace local file
+ Replace remote file
Do not replace
Keep Both