diff --git a/app/build.gradle b/app/build.gradle
index 7111c400d..0219ed133 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -14,8 +14,8 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
compileSdk rootProject.ext.compileSdkVersion
- versionCode 157
- versionName "3.0.6"
+ versionCode 160
+ versionName "3.0.7"
multiDexEnabled true
resValue "string", "authorities", defaultConfig.applicationId + '.debug.cameraupload.provider'
@@ -184,7 +184,6 @@ android {
// Firebase
implementation platform('com.google.firebase:firebase-bom:33.2.0')
implementation 'com.google.firebase:firebase-crashlytics'
- implementation 'com.google.firebase:firebase-analytics'
//media3
final def media3_version = '1.4.1'
@@ -204,6 +203,9 @@ android {
implementation "androidx.webkit:webkit:1.12.1"
implementation 'com.google.android.flexbox:flexbox:3.0.0'
+// implementation "androidx.paging:paging-runtime:3.3.5"
+// implementation "androidx.paging:paging-rxjava3:3.3.5"
+
//https://github.com/material-components/material-components-android
implementation "com.google.android.material:material:1.12.0"
@@ -237,6 +239,17 @@ android {
//https://github.com/KunMinX/UnPeek-LiveData
implementation 'com.kunminx.arch:unpeek-livedata:7.8.0'
+ implementation 'org.commonmark:commonmark:0.21.0'
+// implementation 'org.commonmark:commonmark-ext-gfm-tables:0.21.0' // 如果需要表格支持
+ implementation 'org.commonmark:commonmark-ext-autolink:0.21.0' // 如果需要自动链接支持
+
+ //https://github.com/lzyzsd/JsBridge
+ implementation 'com.github.lzyzsd:jsbridge:1.0.4'
+
+// https://github.com/rubensousa/GravitySnapHelper
+// implementation 'com.github.rubensousa:gravitysnaphelper:2.2.2'
+
+
//
implementation 'com.blankj:utilcode:1.30.7'
@@ -246,8 +259,8 @@ android {
//https://github.com/panpf/stickyitemdecoration
implementation "io.github.panpf.stickyitemdecoration:stickyitemdecoration:1.0.2"
- //preference
- implementation 'dev.rikka.rikkax.preference:simplemenu-preference:1.0.3'
+ //Thanks: https://github.com/RikkaApps
+ //implementation 'dev.rikka.rikkax.preference:simplemenu-preference:1.0.3'
//https://github.com/michaellee123/LiveEventBus
implementation 'com.github.michaellee123:LiveEventBus:1.8.14'
@@ -287,20 +300,20 @@ android {
implementation 'com.github.yydcdut.RxMarkdown:markdown-processor:v0.1.3'
-// //markdown
+ //https://noties.io/Markwon/
// final def markwon_version = '4.6.2'
// implementation "io.noties.markwon:core:$markwon_version"
// implementation "io.noties.markwon:editor:$markwon_version"
-// implementation "io.noties.markwon:ext-latex:$markwon_version"
// implementation "io.noties.markwon:ext-strikethrough:$markwon_version"
// implementation "io.noties.markwon:ext-tables:$markwon_version"
// implementation "io.noties.markwon:ext-tasklist:$markwon_version"
+// implementation "io.noties.markwon:ext-latex:$markwon_version"
// implementation "io.noties.markwon:html:$markwon_version"
// implementation "io.noties.markwon:image:$markwon_version"
// implementation "io.noties.markwon:image-glide:$markwon_version"
-// implementation "io.noties.markwon:inline-parser:$markwon_version"
// implementation "io.noties.markwon:linkify:$markwon_version"
-// implementation "io.noties.markwon:syntax-highlight:$markwon_version"
+// implementation "io.noties.markwon:inline-parser:$markwon_version"
+// implementation "io.noties.markwon:recycler:$markwon_version"
implementation 'com.madgag.spongycastle:core:1.54.0.0'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 2846f793c..7bb73c189 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -204,13 +204,14 @@
-
-
+
+
+
getAccountList() {
List list = new ArrayList<>();
diff --git a/app/src/main/java/com/seafile/seadroid2/annotation/NotSupport.java b/app/src/main/java/com/seafile/seadroid2/annotation/NotSupport.java
new file mode 100644
index 000000000..e36d44f7d
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/annotation/NotSupport.java
@@ -0,0 +1,15 @@
+package com.seafile.seadroid2.annotation;
+
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+
+import java.lang.annotation.Target;
+
+/**
+ * There are no plans to develop this feature.
+ */
+@Target({TYPE, METHOD, CONSTRUCTOR, FIELD})
+public @interface NotSupport {
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/config/GlideLoadConfig.java b/app/src/main/java/com/seafile/seadroid2/config/GlideLoadConfig.java
index 4056c3008..c8cf72948 100644
--- a/app/src/main/java/com/seafile/seadroid2/config/GlideLoadConfig.java
+++ b/app/src/main/java/com/seafile/seadroid2/config/GlideLoadConfig.java
@@ -1,25 +1,32 @@
package com.seafile.seadroid2.config;
+import androidx.annotation.DrawableRes;
+
+import com.bumptech.glide.load.engine.DiskCacheStrategy;
+import com.bumptech.glide.load.model.GlideUrl;
+import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.signature.ObjectKey;
import com.seafile.seadroid2.R;
+import com.seafile.seadroid2.account.Account;
+import com.seafile.seadroid2.account.SupportAccountManager;
import com.seafile.seadroid2.ui.WidgetUtils;
public class GlideLoadConfig {
-// public static GlideUrl getGlideUrl(String url) {
-//
-// Account account = SupportAccountManager.getInstance().getCurrentAccount();
-// if (account == null) {
-// return new GlideUrl(url, new LazyHeaders.Builder().build());
-// }
-//
-// String token = account.token;
-//
-// return new GlideUrl(url, new LazyHeaders.Builder()
-// .addHeader("Authorization", "Token " + token)
-// .build());
-// }
+ public static GlideUrl getGlideUrl(String url) {
+
+ Account account = SupportAccountManager.getInstance().getCurrentAccount();
+ if (account == null) {
+ return new GlideUrl(url, new LazyHeaders.Builder().build());
+ }
+
+ String token = account.token;
+
+ return new GlideUrl(url, new LazyHeaders.Builder()
+ .addHeader("Authorization", "Token " + token)
+ .build());
+ }
//
// public static GlideUrl getGlideUrl(String url, String token) {
// return new GlideUrl(url, new LazyHeaders.Builder()
@@ -34,12 +41,33 @@ public static RequestOptions getAvatarOptions() {
.override(WidgetUtils.getThumbnailWidth(), WidgetUtils.getThumbnailWidth());
}
+ private final static RequestOptions _cacheableThumbnailOptions = new RequestOptions()
+ .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
+ .error(R.drawable.icon_image_error_filled)
+ .override(128);
+
+ /**
+ * Get cacheable thumbnail options, width and height are both 128
+ */
+ public static RequestOptions getCacheableThumbnailOptions() {
+ return _cacheableThumbnailOptions;
+ }
+
public static RequestOptions getOptions() {
return new RequestOptions()
+ .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.fallback(R.drawable.file_image)
.placeholder(R.drawable.file_image);
}
+
+ public static RequestOptions getCustomDrawableOptions(@DrawableRes int resId) {
+ return new RequestOptions()
+ .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
+ .fallback(resId)
+ .placeholder(resId);
+ }
+
public static RequestOptions getOptions(String key) {
return new RequestOptions()
.fallback(R.drawable.file_image)
diff --git a/app/src/main/java/com/seafile/seadroid2/config/OriGlideUrl.java b/app/src/main/java/com/seafile/seadroid2/config/OriGlideUrl.java
new file mode 100644
index 000000000..15b003beb
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/config/OriGlideUrl.java
@@ -0,0 +1,38 @@
+package com.seafile.seadroid2.config;
+
+import com.bumptech.glide.load.model.GlideUrl;
+import com.bumptech.glide.load.model.Headers;
+import com.seafile.seadroid2.framework.util.SLogs;
+
+import java.net.URL;
+
+public class OriGlideUrl extends GlideUrl {
+ private String oriCacheKey;
+
+ public OriGlideUrl(URL url) {
+ super(url);
+ }
+
+ public OriGlideUrl(String url) {
+ super(url);
+ }
+
+ public OriGlideUrl(String url, String oriCacheKey) {
+ super(url);
+ this.oriCacheKey = oriCacheKey;
+ }
+
+
+ public OriGlideUrl(URL url, Headers headers) {
+ super(url, headers);
+ }
+
+ public OriGlideUrl(String url, Headers headers) {
+ super(url, headers);
+ }
+
+ @Override
+ public String getCacheKey() {
+ return oriCacheKey;
+ }
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/config/WebViewActionConstant.java b/app/src/main/java/com/seafile/seadroid2/config/WebViewActionConstant.java
new file mode 100644
index 000000000..5cdb5fda2
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/config/WebViewActionConstant.java
@@ -0,0 +1,19 @@
+package com.seafile.seadroid2.config;
+
+public class WebViewActionConstant {
+ public final static String APP_VERSION_GET = "app.version.get";
+ public final static String APP_TOAST_SHOW = "app.toast.show";
+ public final static String PAGE_FINISH = "page.finish";
+ public final static String PAGE_STATUS_COLOR_SET = "page.status.color.set";
+ public final static String PAGE_STATUS_HEIGHT_GET = "page.status.height.get";
+
+ public static class CallJsFunction {
+ public final static String SDOC_OUTLINES_DATA_GET = "sdoc.outline.data.get";
+ public final static String SDOC_OUTLINES_DATA_SELECT = "sdoc.outline.data.select";
+
+ public static class CallJsFunctionRequestCode {
+ public final static int REQ = 1001;
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/context/NavContext.java b/app/src/main/java/com/seafile/seadroid2/context/NavContext.java
index 590b8d29e..d2b622ae8 100644
--- a/app/src/main/java/com/seafile/seadroid2/context/NavContext.java
+++ b/app/src/main/java/com/seafile/seadroid2/context/NavContext.java
@@ -5,7 +5,9 @@
import com.seafile.seadroid2.framework.data.model.BaseModel;
import com.seafile.seadroid2.framework.data.db.entities.DirentModel;
import com.seafile.seadroid2.framework.data.db.entities.RepoModel;
+import com.seafile.seadroid2.framework.data.model.ContextModel;
import com.seafile.seadroid2.framework.util.Utils;
+import com.seafile.seadroid2.preferences.ContextStackPreferenceHelper;
import java.util.Stack;
@@ -32,6 +34,9 @@ public void clear() {
}
}
+ /**
+ * Push a model to the stack
+ */
public void push(BaseModel model) {
if (model instanceof RepoModel) {
//clear
@@ -39,14 +44,74 @@ public void push(BaseModel model) {
//push
navStack.push(model);
+
+ saveToSp();
+
} else if (model instanceof DirentModel) {
//stack
navStack.push(model);
+ saveToSp();
+
} else {
throw new IllegalArgumentException("model must be RepoMode or DirentsModel.");
}
}
+ public void restoreNavContextFromSp() {
+
+ navStack.clear();
+
+ Stack stack = ContextStackPreferenceHelper.getStack();
+ if (stack != null && !stack.isEmpty()) {
+ for (ContextModel contextModel : stack) {
+ if (contextModel.type.equals("repo")) {
+ RepoModel repoModel = new RepoModel();
+ repoModel.repo_id = contextModel.repo_id;
+ repoModel.repo_name = contextModel.repo_name;
+ repoModel.permission = contextModel.permission;
+ navStack.push(repoModel);
+ } else if (contextModel.type.equals("dirent")) {
+ DirentModel direntModel = new DirentModel();
+ direntModel.repo_id = contextModel.repo_id;
+ direntModel.repo_name = contextModel.repo_name;
+ direntModel.full_path = contextModel.full_path;
+ direntModel.parent_dir = Utils.getParentPath(direntModel.full_path);
+ direntModel.name = Utils.getFileNameFromPath(contextModel.full_path);
+ direntModel.uid = direntModel.getUID();
+ direntModel.permission = contextModel.permission;
+ navStack.push(direntModel);
+ }
+ }
+ }
+
+ }
+
+ private void saveToSp() {
+ Stack stack = new Stack<>();
+ if (!navStack.isEmpty()) {
+ for (BaseModel baseModel : navStack) {
+ ContextModel contextModel = new ContextModel();
+
+ if (baseModel instanceof RepoModel e) {
+ contextModel.repo_id = e.repo_id;
+ contextModel.repo_name = e.repo_name;
+ contextModel.type = "repo";
+ contextModel.full_path = "/";
+ contextModel.permission = e.permission;
+ } else if (baseModel instanceof DirentModel e) {
+ contextModel.repo_id = e.repo_id;
+ contextModel.repo_name = e.repo_name;
+ contextModel.type = "dirent";
+ contextModel.full_path = e.full_path;
+ contextModel.permission = e.permission;
+ }
+ stack.add(contextModel);
+ }
+ }
+
+ ContextStackPreferenceHelper.saveStack(stack);
+ }
+
public void pop() {
if (navStack.empty()) {
return;
@@ -54,6 +119,9 @@ public void pop() {
//stack
navStack.pop();
+
+ saveToSp();
+
}
public void switchToPath(RepoModel repoModel, String full_path) {
@@ -87,6 +155,8 @@ public void switchToPath(RepoModel repoModel, String full_path) {
for (DirentModel model : stack) {
navStack.push(model);
}
+
+ saveToSp();
}
/**
diff --git a/app/src/main/java/com/seafile/seadroid2/enums/ActionModeCallbackType.java b/app/src/main/java/com/seafile/seadroid2/enums/ActionModeCallbackType.java
index 91d496292..3a506655b 100644
--- a/app/src/main/java/com/seafile/seadroid2/enums/ActionModeCallbackType.java
+++ b/app/src/main/java/com/seafile/seadroid2/enums/ActionModeCallbackType.java
@@ -1,5 +1,5 @@
package com.seafile.seadroid2.enums;
public enum ActionModeCallbackType {
- CREATE, DESTORY, SELECT_ALL, SELECT_NONE
+ CREATE, DESTROY, SELECT_ALL, SELECT_NONE
}
diff --git a/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java b/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java
index f8e4ee4df..a0b35e122 100644
--- a/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java
+++ b/app/src/main/java/com/seafile/seadroid2/enums/TransferDataSource.java
@@ -4,11 +4,13 @@ public enum TransferDataSource {
ALBUM_BACKUP,
/**
- *
+ * (automatically)
+ * folder backup
*/
FOLDER_BACKUP,
/**
+ * (manually)
* share_to_seafile/upload_from_local
*/
FILE_BACKUP,
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 faf9800dc..80705ca43 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
@@ -20,17 +20,19 @@ public interface DirentDAO {
Single> getListByAccount(String related_account);
@Query("select * from dirents where parent_dir = :parent_dir and repo_id = :repo_id")
- Single> getListByParentPath(String repo_id, String parent_dir);
-
- @Query("select * from dirents where parent_dir = :parent_dir and repo_id = :repo_id")
- Single> getImageListByParentPath(String repo_id, String parent_dir);
-
+ Single> getListByParentPathAsync(String repo_id, String parent_dir);
@Query("select * from dirents where parent_dir = :parent_dir and repo_id = :repo_id")
List getListByParentPathSync(String repo_id, String parent_dir);
+ @Query("select * from dirents where type='file' and parent_dir = :parent_dir and repo_id = :repo_id")
+ Single> getFileListByParentPath(String repo_id, String parent_dir);
+
+ /**
+ * get special one by full_path
+ */
@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id")
- Single> getListByFullPath(String repo_id, String full_path);
+ Single> getListByFullPathAsync(String repo_id, String full_path);
@Query("select * from dirents where full_path = :full_path and repo_id = :repo_id limit 1")
List getListByFullPathSync(String repo_id, String full_path);
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 86585bf64..797747e97 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
@@ -50,6 +50,9 @@ public interface FileTransferDAO {
@Delete
void deleteOne(FileTransferEntity entity);
+ @Delete
+ void deleteMultiple(List entity);
+
@Delete
Single deleteOneAsync(FileTransferEntity entity);
@@ -66,20 +69,20 @@ public interface FileTransferDAO {
/**
* Modify the task that is being in IN_PROGRESS to CANCELLED
*/
- @Query("update file_transfer_list set transfer_result = 'USER_CANCELLED', transfer_status = 'CANCELLED' where related_account = :related_account and data_source in ( :feats ) and transfer_status in ('IN_PROGRESS','WAITING')")
- Completable cancelByDataSource(String related_account, List feats);
+ @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'USER_CANCELLED' where related_account = :related_account and data_source in ( :feats ) and transfer_status in ('IN_PROGRESS','WAITING')")
+ Completable cancelAllByDataSource(String related_account, List feats);
- @Query("update file_transfer_list set transfer_result = 'CANCELLED', transfer_status = 'CANCELLED', transfer_result = :result where related_account = :related_account and data_source = :dataSource and transfer_status in ('IN_PROGRESS','WAITING')")
- void cancel(String related_account, TransferDataSource dataSource, TransferResult result);
+ @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = :result where related_account = :related_account and data_source = 'FILE_BACKUP' and transfer_status in ('IN_PROGRESS','WAITING')")
+ void cancelWithFileBackup(String related_account, TransferResult result);
- @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = :result where data_source = 'FILE_BACKUP' and transfer_status in ('IN_PROGRESS','WAITING')")
- void cancelWithFileBackup(TransferResult result);
-
- @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'CANCELLED', data_status = -1, transferred_size = 0 where data_source in ('FILE_BACKUP','FOLDER_BACKUP')")
- void cancelAllWithFileBackup();
+ /**
+ * remove all tasks for ['FILE_BACKUP','FOLDER_BACKUP','ALBUM_BACKUP']
+ */
+ @Query("update file_transfer_list set transfer_status = 'CANCELLED', transfer_result = 'USER_CANCELLED', data_status = -1, transferred_size = 0 where related_account = :related_account and data_source in ('FILE_BACKUP','FOLDER_BACKUP','ALBUM_BACKUP')")
+ Completable removeAllUploadByAccount(String related_account);
- @Query("select * from file_transfer_list where related_account = :related_account and data_source in ( :feats ) and data_status = 0 order by created_at asc")
- Single> getListByFeatAsync(String related_account, List feats);
+ @Query("select * from file_transfer_list where related_account = :related_account and data_source in ( :feats ) order by created_at asc")
+ Single> getListByDataSourceAsync(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")
List getOnePendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);
@@ -87,27 +90,26 @@ public interface FileTransferDAO {
@Query("select COUNT(*) 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")
int countPendingTransferSync(String related_account, TransferAction transfer_action, TransferDataSource feature);
+ @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = :transferAction and transfer_status = :transferStatus and data_status = 0 order by created_at")
+ Single> getByActionAndStatusAsync(String related_account, TransferAction transferAction, TransferStatus transferStatus);
- @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 offset :offset")
- List getPagePendingListTransferSync(String related_account, TransferAction transfer_action, int limit, int offset);
@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")
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 limit 1")
- List getOnePendingDownloadByActionSync(String related_account);
+ List getOnePendingDownloadByAccountSync(String related_account);
@Query("select COUNT(*) 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")
int countPendingDownloadListSync(String related_account);
+ @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by created_at desc limit :limit offset :offset")
+ Single> getPageUploadListAsync(String related_account, int limit, int offset);
- @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'UPLOAD' and data_source in ('FOLDER_BACKUP','FILE_BACKUP','ALBUM_BACKUP') and data_status = 0 order by modified_at desc limit :limit offset :offset")
- List getPageUploadListSync(String related_account, int limit, int offset);
-
- @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by modified_at desc limit :limit offset :offset")
- List getPageDownloadListSync(String related_account, int limit, int offset);
+ @Query("select * from file_transfer_list where related_account = :related_account and transfer_action = 'DOWNLOAD' and data_status = 0 order by created_at desc limit :limit offset :offset")
+ Single> getPageDownloadListAsync(String related_account, int limit, int offset);
- @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")
+ @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")
List getByTargetPathSync(String related_account, TransferAction transferAction, String target_path);
@@ -127,16 +129,12 @@ public interface FileTransferDAO {
@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 transfer_action = :transfer_action order by created_at asc limit :limit offset :offset")
- List getPageListSync(String repoId, TransferAction transfer_action, int limit, int offset);
-
- @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 getListByFullPathSync(String related_account, TransferAction transferAction, String full_path);
+ @Query("select * from file_transfer_list where repo_id = :repoId and transfer_action = :transferAction and full_path = :full_path and data_status = 0 order by created_at")
+ Single> getListByFullPathAsync(String repoId, 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);
-
@RawQuery
int updateEntityStatus(SupportSQLiteQuery query);
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/PermissionDAO.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/PermissionDAO.java
index 66fe2de1a..6018ed59b 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/PermissionDAO.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/dao/PermissionDAO.java
@@ -21,12 +21,11 @@ public interface PermissionDAO {
@Query("select * from permissions where id IN (:ids)")
Single> getByIdsAsync(List ids);
- @Query("select * from permissions where repo_id = :repoId and id = :id limit 1")
- Single> getWithAsync(String repoId, int id);
-
@Query("select * from permissions where repo_id = :repoId")
Single> getByRepoIdAsync(String repoId);
+ @Query("select * from permissions where repo_id = :repoId and id = :pid limit 1")
+ Single> getByRepoAndIdAsync(String repoId, int pid);
@Query("DELETE FROM permissions")
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/DirentModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/DirentModel.java
index fdcddfdf2..23fe3b00c 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/DirentModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/DirentModel.java
@@ -94,6 +94,10 @@ public boolean isDir() {
return TextUtils.equals(type, "dir");
}
+ public String getName() {
+ return name;
+ }
+
public String getSubtitle() {
if (TextUtils.isEmpty(timestamp)) {
timestamp = Utils.translateCommitTime(mtime * 1000);
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/FileTransferEntity.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/FileTransferEntity.java
index 0ca8f6f12..1c1d9d97b 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/FileTransferEntity.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/FileTransferEntity.java
@@ -106,8 +106,12 @@ public class FileTransferEntity extends BaseModel {
*
* eg. /storage/emulated/0/DCIM/xxx.jpg or /storage/emulated/0/Downloads/xxx.txt (locally)
*
+ * UPLOAD (FILE_BACKUP Manually)
+ *
+ * full_path is the absolute path to the file stored locally
*
- *
+ * eg. /storage/emulated/0/Android/media/(package_name)/Seafile/(repo_name)/
+ *
* DOWNLOAD
* full_path is the relative path to the file in the repository.
* eg. /a/b/c/d.txt (in remote repo)
@@ -361,44 +365,6 @@ public static FileTransferEntity convertDirentModel2This(boolean is_block, boole
return entity;
}
- public static FileTransferEntity convertDirentFileModel2This(RepoModel repoModel, String full_path, boolean is_auto_transfer, DirentFileModel direntModel) {
- FileTransferEntity entity = new FileTransferEntity();
- entity.full_path = full_path;
-// entity.target_path = direntModel.full_path;
- entity.data_source = TransferDataSource.DOWNLOAD;
- entity.repo_id = repoModel.repo_id;
- entity.repo_name = repoModel.repo_name;
- entity.related_account = repoModel.related_account;
-
-
- entity.file_id = direntModel.id;
- entity.setParent_path(Utils.getParentPath(full_path));
- entity.file_name = direntModel.name;
- entity.file_format = FileTools.getFileExtension(entity.full_path);
- entity.mime_type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(entity.file_format);
- entity.file_size = direntModel.size;
- entity.file_md5 = null;
-
- entity.is_auto_transfer = is_auto_transfer;
-
-// entity.is_block = repoModel.canLocalDecrypt();
- entity.file_strategy = ExistingFileStrategy.AUTO;
-
- entity.is_copy_to_local = true;
-
- long now = System.currentTimeMillis();
- entity.created_at = now;
- entity.modified_at = direntModel.mtime * 1000;
- entity.action_end_at = 0L;
-
- entity.transfer_action = TransferAction.DOWNLOAD;
- entity.transfer_status = TransferStatus.WAITING;
- entity.transfer_result = TransferResult.NO_RESULT;
-
- entity.uid = entity.getUID();
-
- return entity;
- }
public static FileTransferEntity convertDirentRecursiveModel2This(RepoModel repoModel, DirentRecursiveFileModel model) {
@@ -444,7 +410,7 @@ public static FileTransferEntity convertDirentRecursiveModel2This(RepoModel repo
return entity;
}
- public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account account, RepoModel repoModel, File file, String backupPath) {
+ public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account account, File file, String backupPath) {
if (!file.isFile()) {
return null;
}
@@ -466,8 +432,8 @@ public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account acc
entity.mime_type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(entity.file_format);
// entity.is_block = repoModel.encrypted;
- entity.repo_id = repoModel.repo_id;
- entity.repo_name = repoModel.repo_name;
+// entity.repo_id = repoModel.repo_id;
+// entity.repo_name = repoModel.repo_name;
entity.related_account = account.getSignature();
entity.data_source = TransferDataSource.FOLDER_BACKUP;
entity.created_at = System.currentTimeMillis();
@@ -489,7 +455,7 @@ public static FileTransferEntity convert2ThisForUploadFileSyncWorker(Account acc
}
- public static FileTransferEntity convert2ThisForUploadMediaSyncWorker(Account account, String repo_id, String repo_name, File file, String parenPath, long dateAdd, boolean isRemoteExists) {
+ public static FileTransferEntity convert2ThisForUploadMediaSyncWorker(Account account, File file, String parenPath, long dateAdd, boolean isRemoteExists) {
long now = System.currentTimeMillis();
FileTransferEntity entity = new FileTransferEntity();
@@ -502,8 +468,8 @@ public static FileTransferEntity convert2ThisForUploadMediaSyncWorker(Account ac
entity.file_md5 = FileUtils.getFileMD5ToString(entity.full_path).toLowerCase();
entity.mime_type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(entity.file_format);
// entity.is_block = false; //album backup is not store in encrypted repo.
- entity.repo_id = repo_id;
- entity.repo_name = repo_name;
+// entity.repo_id = repo_id;
+// entity.repo_name = repo_name;
entity.related_account = account.getSignature();
entity.created_at = now;
entity.modified_at = now;
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/PermissionEntity.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/PermissionEntity.java
index 81f830563..c08d90f35 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/PermissionEntity.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/PermissionEntity.java
@@ -7,10 +7,10 @@
import androidx.room.Ignore;
import com.seafile.seadroid2.framework.data.model.BaseModel;
+import com.seafile.seadroid2.framework.data.model.permission.PermissionParentModel;
import com.seafile.seadroid2.framework.data.model.permission.PermissionWrapperModel;
import java.util.HashMap;
-import java.util.Set;
@Entity(tableName = "permissions", primaryKeys = {"repo_id", "id"})
public class PermissionEntity extends BaseModel {
@@ -32,74 +32,29 @@ public class PermissionEntity extends BaseModel {
public boolean modify;
public boolean download_external_link;
+ public PermissionEntity() {
+ }
/**
- * key -> repo_id or dirent_id(uid)
+ * @return false if the permission is empty
*/
- @Ignore
- public HashMap cachedMap;
-
- public boolean hasId(String id) {
- if (cachedMap == null) {
- return false;
- }
-
- return cachedMap.containsKey(id);
- }
-
- public void cacheBaseModel(BaseModel model) {
- if (cachedMap == null) {
- cachedMap = new HashMap<>();
- return;
- }
-
- if (model instanceof RepoModel m) {
- cachedMap.put(m.repo_id, m);
- } else if (model instanceof DirentModel m) {
- cachedMap.put(m.uid, m);
- }
- }
-
- public void removeById(String id) {
- if (cachedMap == null) {
- return;
- }
-
- cachedMap.remove(id);
- }
-
- public void removeByModel(BaseModel model) {
- if (cachedMap == null) {
- return;
- }
-
- if (model instanceof RepoModel m) {
- cachedMap.remove(m.repo_id);
- } else if (model instanceof DirentModel m) {
- cachedMap.remove(m.uid);
- }
- }
-
- public boolean isEmptyIds() {
- return cachedMap == null || cachedMap.isEmpty();
- }
-
- public PermissionEntity() {
+ public boolean isValid() {
+ return !TextUtils.isEmpty(repo_id);
}
- public PermissionEntity(@NonNull String repoId, @NonNull PermissionWrapperModel model) {
- this.id = model.id;
- this.name = model.name;
- this.description = model.description;
-
- this.create = model.permission.create;
- this.upload = model.permission.upload;
- this.download = model.permission.download;
- this.copy = model.permission.copy;
- this.delete = model.permission.delete;
- this.modify = model.permission.modify;
- this.download_external_link = model.permission.download_external_link;
- this.preview = model.permission.preview;
+ public PermissionEntity(@NonNull String repoId, @NonNull PermissionParentModel p) {
+ this.id = p.id;
+ this.name = p.name;
+ this.description = p.description;
+
+ this.create = p.permission.create;
+ this.upload = p.permission.upload;
+ this.download = p.permission.download;
+ this.copy = p.permission.copy;
+ this.delete = p.permission.delete;
+ this.modify = p.permission.modify;
+ this.download_external_link = p.permission.download_external_link;
+ this.preview = p.permission.preview;
this.repo_id = repoId;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/StarredModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/StarredModel.java
index 360cb8d70..61496e97e 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/StarredModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/db/entities/StarredModel.java
@@ -60,7 +60,7 @@ public boolean isRepo() {
return TextUtils.equals("/", path) && is_dir;
}
- public static DirentModel converterThis2DirentModel(StarredModel model) {
+ public static DirentModel convert2DirentModel(StarredModel model) {
DirentModel d = new DirentModel();
d.full_path = model.path;
d.type = model.is_dir ? "dir" : "file";
@@ -68,6 +68,7 @@ public static DirentModel converterThis2DirentModel(StarredModel model) {
d.name = model.obj_name;
d.repo_id = model.repo_id;
d.repo_name = model.repo_name;
+ d.parent_dir = Utils.getParentPath(model.path);
return d;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java
new file mode 100644
index 000000000..70ac51ebf
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/ContextModel.java
@@ -0,0 +1,14 @@
+package com.seafile.seadroid2.framework.data.model;
+
+public class ContextModel {
+ public String repo_id;
+ public String repo_name; //repo_name
+
+ public String type; //repo/dirent
+
+ /**
+ * parent_dir + name
+ */
+ public String full_path;
+ public String permission;
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/WebRouteModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/WebRouteModel.java
new file mode 100644
index 000000000..8fae7b728
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/WebRouteModel.java
@@ -0,0 +1,11 @@
+package com.seafile.seadroid2.framework.data.model;
+
+public class WebRouteModel {
+ public int v = 1;
+ public String action;
+
+ /**
+ * params data
+ */
+ public String data;
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/activities/ActivityModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/activities/ActivityModel.java
index 08cffe25f..53cdffc6f 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/activities/ActivityModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/activities/ActivityModel.java
@@ -47,7 +47,7 @@ public boolean isDir() {
}
- public static DirentModel converterThis2DirentModel(ActivityModel model){
+ public static DirentModel convert2DirentModel(ActivityModel model){
DirentModel d = new DirentModel();
d.full_path = model.path;
d.type = model.obj_type;
@@ -55,7 +55,7 @@ public static DirentModel converterThis2DirentModel(ActivityModel model){
d.name = model.name;
d.repo_id = model.repo_id;
d.repo_name = model.repo_name;
-
+ d.parent_dir = Utils.getParentPath(model.path);
return d;
}
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocCommentModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentModel.java
similarity index 70%
rename from app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocCommentModel.java
rename to app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentModel.java
index 9260574cd..06c7b55cb 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocCommentModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentModel.java
@@ -1,13 +1,15 @@
-package com.seafile.seadroid2.framework.data.model.sdoc;
+package com.seafile.seadroid2.framework.data.model.docs_comment;
import com.google.gson.annotations.JsonAdapter;
import com.seafile.seadroid2.framework.data.model.adapter.OffsetDateTimeAdapter;
+import com.seafile.seadroid2.framework.data.model.sdoc.SDocCommentReplyModel;
+import com.seafile.seadroid2.view.rich_edittext.RichEditText;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
-public class SDocCommentModel {
+public class DocsCommentModel {
public int id;
public String item_name;
public String parent_path;
@@ -16,7 +18,7 @@ public class SDocCommentModel {
public List replies;
public String comment;
public String repo_id;
- public String resolved;
+ public boolean resolved;
public String user_contact_email;
public String user_email;
public String user_name;
@@ -29,6 +31,10 @@ public class SDocCommentModel {
public String detail;
+
+ public boolean isContainImage = false;
+ public List commentList;
+
public String getCreatedAtFriendlyText() {
return created_at.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace("T", " ");
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentWrapperModel.java
new file mode 100644
index 000000000..e3506abb4
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentWrapperModel.java
@@ -0,0 +1,5 @@
+package com.seafile.seadroid2.framework.data.model.docs_comment;
+
+public class DocsCommentWrapperModel {
+ public DocsCommentModel comment;
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentsWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentsWrapperModel.java
new file mode 100644
index 000000000..4ec05381b
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsCommentsWrapperModel.java
@@ -0,0 +1,7 @@
+package com.seafile.seadroid2.framework.data.model.docs_comment;
+
+import java.util.List;
+
+public class DocsCommentsWrapperModel {
+ public List comments;
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsUploadResultModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsUploadResultModel.java
new file mode 100644
index 000000000..a5d8c2974
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/docs_comment/DocsUploadResultModel.java
@@ -0,0 +1,7 @@
+package com.seafile.seadroid2.framework.data.model.docs_comment;
+
+import java.util.List;
+
+public class DocsUploadResultModel {
+ public List relative_path;
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionListWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionListWrapperModel.java
index 8694d5045..902a6a4f3 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionListWrapperModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionListWrapperModel.java
@@ -1,9 +1,7 @@
package com.seafile.seadroid2.framework.data.model.permission;
-import com.seafile.seadroid2.framework.data.db.entities.PermissionEntity;
-
import java.util.List;
public class PermissionListWrapperModel {
- public List permission_list;
+ public List permission_list;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionParentModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionParentModel.java
new file mode 100644
index 000000000..60171f14a
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionParentModel.java
@@ -0,0 +1,8 @@
+package com.seafile.seadroid2.framework.data.model.permission;
+
+public class PermissionParentModel {
+ public int id;
+ public String description;
+ public String name;
+ public PermissionModel permission;
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionWrapperModel.java
index 46f14fdb5..e14ddd5fd 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionWrapperModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/permission/PermissionWrapperModel.java
@@ -1,8 +1,5 @@
package com.seafile.seadroid2.framework.data.model.permission;
public class PermissionWrapperModel {
- public int id;
- public String description;
- public String name;
- public PermissionModel permission;
+ public PermissionParentModel permission;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocDetailModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileDetailModel.java
similarity index 91%
rename from app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocDetailModel.java
rename to app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileDetailModel.java
index 9f9aa26ba..77ea5f381 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocDetailModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileDetailModel.java
@@ -13,7 +13,7 @@
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
-public class SDocDetailModel implements Parcelable {
+public class FileDetailModel implements Parcelable {
private String type;
private String id;
@@ -183,10 +183,10 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte(this.canEdit ? (byte) 1 : (byte) 0);
}
- public SDocDetailModel() {
+ public FileDetailModel() {
}
- protected SDocDetailModel(Parcel in) {
+ protected FileDetailModel(Parcel in) {
this.type = in.readString();
this.id = in.readString();
this.name = in.readString();
@@ -203,15 +203,15 @@ protected SDocDetailModel(Parcel in) {
this.canEdit = in.readByte() != 0;
}
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
@Override
- public SDocDetailModel createFromParcel(Parcel source) {
- return new SDocDetailModel(source);
+ public FileDetailModel createFromParcel(Parcel source) {
+ return new FileDetailModel(source);
}
@Override
- public SDocDetailModel[] newArray(int size) {
- return new SDocDetailModel[size];
+ public FileDetailModel[] newArray(int size) {
+ return new FileDetailModel[size];
}
};
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileProfileConfigModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileProfileConfigModel.java
new file mode 100644
index 000000000..13a9549dd
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileProfileConfigModel.java
@@ -0,0 +1,33 @@
+package com.seafile.seadroid2.framework.data.model.sdoc;
+
+import com.seafile.seadroid2.framework.data.model.user.UserWrapperModel;
+
+public class FileProfileConfigModel {
+ public UserWrapperModel users;
+ public FileDetailModel detail;
+ public MetadataConfigModel metadataConfigModel;
+
+ public MetadataConfigModel getMetadataConfigModel() {
+ return metadataConfigModel;
+ }
+
+ public void setMetadataConfigModel(MetadataConfigModel metadataConfigModel) {
+ this.metadataConfigModel = metadataConfigModel;
+ }
+
+ public UserWrapperModel getUsers() {
+ return users;
+ }
+
+ public void setUsers(UserWrapperModel users) {
+ this.users = users;
+ }
+
+ public FileDetailModel getDetail() {
+ return detail;
+ }
+
+ public void setDetail(FileDetailModel detail) {
+ this.detail = detail;
+ }
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocRecordWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileRecordWrapperModel.java
similarity index 57%
rename from app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocRecordWrapperModel.java
rename to app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileRecordWrapperModel.java
index 4f1748c07..a104efff1 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocRecordWrapperModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/FileRecordWrapperModel.java
@@ -5,7 +5,7 @@
import java.util.List;
-public class SDocRecordWrapperModel implements Parcelable {
+public class FileRecordWrapperModel implements Parcelable {
public List metadata;
public List results;
@@ -20,23 +20,23 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(this.results);
}
- public SDocRecordWrapperModel() {
+ public FileRecordWrapperModel() {
}
- protected SDocRecordWrapperModel(Parcel in) {
+ protected FileRecordWrapperModel(Parcel in) {
this.metadata = in.createTypedArrayList(MetadataModel.CREATOR);
this.results = in.createTypedArrayList(RecordResultModel.CREATOR);
}
- public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
@Override
- public SDocRecordWrapperModel createFromParcel(Parcel source) {
- return new SDocRecordWrapperModel(source);
+ public FileRecordWrapperModel createFromParcel(Parcel source) {
+ return new FileRecordWrapperModel(source);
}
@Override
- public SDocRecordWrapperModel[] newArray(int size) {
- return new SDocRecordWrapperModel[size];
+ public FileRecordWrapperModel[] newArray(int size) {
+ return new FileRecordWrapperModel[size];
}
};
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/MetadataConfigModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/MetadataConfigModel.java
index 78fbf7894..74fe5d623 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/MetadataConfigModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/MetadataConfigModel.java
@@ -2,4 +2,8 @@
public class MetadataConfigModel {
public boolean enabled;
+ //public boolean tags_enabled;
+ //public String tags_lang;
+ //public String details_settings;
+ //public boolean ocr_enabled;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/OutlineItemModel.java
similarity index 74%
rename from app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocModel.java
rename to app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/OutlineItemModel.java
index d8b316122..9ef5cea74 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/OutlineItemModel.java
@@ -4,11 +4,11 @@
import java.util.List;
-public class SDocModel extends BaseModel {
+public class OutlineItemModel extends BaseModel {
public String id;
public String type;
public String text;
public boolean indent;
- public List children;
+ public List children;
public SDocDataModel data;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/RecordResultModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/RecordResultModel.java
index 11386d1ed..e602da6ef 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/RecordResultModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/RecordResultModel.java
@@ -37,6 +37,7 @@ public class RecordResultModel implements Parcelable {
public String _suffix;
public String _description;
public List _owner;
+ public List _reviewer;
@JsonAdapter(RecordResultDeserializer.class)
public Map dynamicFields;
@@ -49,6 +50,7 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringList(this._collaborators);
+ dest.writeStringList(this._reviewer);
dest.writeString(this._creator);
dest.writeString(this._ctime);
dest.writeString(this._file_creator);
@@ -80,6 +82,7 @@ public RecordResultModel() {
protected RecordResultModel(Parcel in) {
this._collaborators = in.createStringArrayList();
+ this._reviewer = in.createStringArrayList();
this._creator = in.readString();
this._ctime = in.readString();
this._file_creator = in.readString();
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocCommentWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocCommentWrapperModel.java
deleted file mode 100644
index 796389d0c..000000000
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocCommentWrapperModel.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.seafile.seadroid2.framework.data.model.sdoc;
-
-import java.util.List;
-
-public class SDocCommentWrapperModel {
- public List comments;
-}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocWrapperModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocOutlineWrapperModel.java
similarity index 67%
rename from app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocWrapperModel.java
rename to app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocOutlineWrapperModel.java
index 03e7cfdea..3452258f7 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocWrapperModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocOutlineWrapperModel.java
@@ -2,9 +2,9 @@
import java.util.List;
-public class SDocWrapperModel {
+public class SDocOutlineWrapperModel {
public int version;
public int format_version;
public String last_modify_user;
- public List elements;
+ public List elements;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocPageOptionsModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocPageOptionsModel.java
index 74e1c0119..cdb715378 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocPageOptionsModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocPageOptionsModel.java
@@ -13,6 +13,8 @@ public class SDocPageOptionsModel implements Parcelable {
public boolean isLocked;
public boolean isStarred;
+ public boolean enableMetadataManagement;
+
@Override
public String toString() {
return "SDocPageOptionsModel{" +
@@ -42,6 +44,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.repoName);
dest.writeByte(this.isLocked ? (byte) 1 : (byte) 0);
dest.writeByte(this.isStarred ? (byte) 1 : (byte) 0);
+ dest.writeByte(this.enableMetadataManagement ? (byte) 1 : (byte) 0);
}
public SDocPageOptionsModel() {
@@ -56,6 +59,7 @@ protected SDocPageOptionsModel(Parcel in) {
this.repoName = in.readString();
this.isLocked = in.readByte() != 0;
this.isStarred = in.readByte() != 0;
+ this.enableMetadataManagement = in.readByte() != 0;
}
public static final Creator CREATOR = new Creator() {
@@ -69,180 +73,4 @@ public SDocPageOptionsModel[] newArray(int size) {
return new SDocPageOptionsModel[size];
}
};
-}
-
-//
-//
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocProfileConfigModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocProfileConfigModel.java
deleted file mode 100644
index 658ef12cd..000000000
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/sdoc/SDocProfileConfigModel.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.seafile.seadroid2.framework.data.model.sdoc;
-
-import com.seafile.seadroid2.framework.data.model.user.UserWrapperModel;
-
-public class SDocProfileConfigModel {
- public UserWrapperModel users;
- public MetadataConfigModel metadata;
- public SDocDetailModel detail;
-
- public UserWrapperModel getUsers() {
- return users;
- }
-
- public void setUsers(UserWrapperModel users) {
- this.users = users;
- }
-
- public MetadataConfigModel getMetadata() {
- return metadata;
- }
-
- public void setMetadata(MetadataConfigModel metadata) {
- this.metadata = metadata;
- }
-
- public SDocDetailModel getDetail() {
- return detail;
- }
-
- public void setDetail(SDocDetailModel detail) {
- this.detail = detail;
- }
-}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/model/search/SearchModel.java b/app/src/main/java/com/seafile/seadroid2/framework/data/model/search/SearchModel.java
index 51d5cb61d..45230ee61 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/model/search/SearchModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/data/model/search/SearchModel.java
@@ -6,6 +6,7 @@
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.framework.data.db.entities.DirentModel;
+import com.seafile.seadroid2.framework.data.db.entities.RepoModel;
import com.seafile.seadroid2.framework.data.model.BaseModel;
import com.seafile.seadroid2.framework.util.Icons;
import com.seafile.seadroid2.framework.util.Utils;
@@ -66,7 +67,23 @@ public int getIcon() {
return Icons.getFileIcon(getTitle());
}
- public static DirentModel converterThis2DirentModel(SearchModel model) {
+ public static RepoModel convert2RepoModel(SearchModel model) {
+ RepoModel d = new RepoModel();
+ d.type = model.repo_type;
+ d.repo_id = model.repo_id;
+ d.repo_name = model.repo_name;
+ d.related_account = "";//?
+// d.last_modified = model.last_modified;
+ d.size = model.size;
+
+ d.owner_email = model.repo_owner_email;
+ d.owner_name = model.repo_owner_name;
+ d.owner_contact_email = model.repo_owner_contact_email;
+
+ return d;
+ }
+
+ public static DirentModel convert2DirentModel(SearchModel model) {
DirentModel d = new DirentModel();
d.full_path = model.fullpath;
d.type = model.is_dir ? "dir" : "file";
@@ -76,6 +93,7 @@ public static DirentModel converterThis2DirentModel(SearchModel model) {
d.repo_name = model.repo_name;
d.last_modified_at = model.last_modified;
d.size = model.size;
+ d.parent_dir = Utils.getParentPath(model.fullpath);
return d;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/data/repository/DirentsRepository.java b/app/src/main/java/com/seafile/seadroid2/framework/data/repository/DirentsRepository.java
deleted file mode 100644
index 809e37401..000000000
--- a/app/src/main/java/com/seafile/seadroid2/framework/data/repository/DirentsRepository.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.seafile.seadroid2.framework.data.repository;
-
-import com.seafile.seadroid2.framework.data.db.dao.DirentDAO;
-import com.seafile.seadroid2.framework.data.db.entities.DirentModel;
-import com.seafile.seadroid2.framework.data.model.repo.DirentWrapperModel;
-import com.seafile.seadroid2.ui.repo.RepoService;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import io.reactivex.Completable;
-import io.reactivex.Single;
-import io.reactivex.android.schedulers.AndroidSchedulers;
-import io.reactivex.functions.Consumer;
-import io.reactivex.functions.Function;
-import io.reactivex.schedulers.Schedulers;
-
-public class DirentsRepository {
- private DirentDAO dao;
- private RepoService service;
-
- public DirentsRepository(RepoService service, DirentDAO dao) {
- this.service = service;
- this.dao = dao;
- }
-
- public Single> getDirents(String repoId, String parent_dir) {
- // 先尝试从数据库中获取数据
- Single> localData = dao.getListByParentPath(repoId, parent_dir)
- .onErrorResumeNext(throwable -> Single.just(Collections.emptyList()));
-
- // 发起网络请求并保存到数据库
- Single> remoteData = service.getDirents(repoId, parent_dir)
- .map(new Function>() {
- @Override
- public List apply(DirentWrapperModel direntWrapperModel) throws Exception {
- return direntWrapperModel.dirent_list;
- }
- })
- .doOnSuccess(new Consumer>() {
- @Override
- public void accept(List direntModels) throws Exception {
-
-// dao.insertAll(dirents)
- }
- });
-
- return Single.concat(localData, remoteData).first(Collections.emptyList());
- }
-
- public void insert(List dirents) {
- Completable.fromCallable(new Callable() {
- @Override
- public Boolean call() throws Exception {
- dao.insertAll(dirents);
- return true;
- }
- }).subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe();
- }
-
- public void deleteAll() {
- dao.deleteAll();
- }
-}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreKeys.java b/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreKeys.java
index 243f74ebf..35871b1be 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreKeys.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/datastore/DataStoreKeys.java
@@ -36,4 +36,6 @@ public class DataStoreKeys {
public static final String KEY_DARK_MODE = "key_dark_mode";
public static final String KEY_SERVER_CERT_INFO = "key_server_cert_info";
+
+ public static final String KEY_NAV_CONTEXT_STACK = "key_nav_context_stack";
}
\ No newline at end of file
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/datastore/sp_livedata/FolderBackupSharePreferenceHelper.java b/app/src/main/java/com/seafile/seadroid2/framework/datastore/sp_livedata/FolderBackupSharePreferenceHelper.java
index 4fe6e2b00..4e0316935 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/datastore/sp_livedata/FolderBackupSharePreferenceHelper.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/datastore/sp_livedata/FolderBackupSharePreferenceHelper.java
@@ -17,6 +17,8 @@
import java.lang.reflect.Type;
import java.util.List;
+import java.util.Map;
+import java.util.function.BiConsumer;
public class FolderBackupSharePreferenceHelper {
@@ -155,6 +157,23 @@ public static void writeLastScanTimeForPath(String absPath) {
sp.edit().putLong(k, System.currentTimeMillis()).apply();
}
+ public static void clearLastScanTimeForAllPath() {
+ SharedPreferences sp = Settings.getUserSharedPreferences();
+ if (sp == null) {
+ return;
+ }
+
+ Map m = sp.getAll();
+ m.forEach(new BiConsumer() {
+ @Override
+ public void accept(String key, Object o) {
+ if (key.startsWith(SettingsManager.FOLDER_BACKUP_LAST_TIME_PREFIX)) {
+ sp.edit().remove(key).apply();
+ }
+ }
+ });
+ }
+
public static void clearLastScanTimeForPath(String absPath) {
SharedPreferences sp = Settings.getUserSharedPreferences();
if (sp == null) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java
index 18a4d3b0f..bc361263f 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/FileSyncService.java
@@ -18,7 +18,6 @@
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.observer.MediaContentObserver;
import com.seafile.seadroid2.ui.camera_upload.CameraUploadManager;
import org.apache.commons.io.monitor.FileAlterationListener;
@@ -118,10 +117,10 @@ public void onCreate() {
BackgroundJobManagerImpl.getInstance().startDownloadChainWorker();
//folder backup upload worker
- BackgroundJobManagerImpl.getInstance().startFolderChainWorker(false);
+ BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(false);
//file upload backup
- BackgroundJobManagerImpl.getInstance().startFileUploadWorker();
+ BackgroundJobManagerImpl.getInstance().startFileManualUploadWorker();
//bus
TransferBusHelper.getTransferObserver().observeForever(transferOpTypeObserver);
@@ -142,7 +141,7 @@ private void onBusEvent(TransferOpType opType) {
resetFolderMonitor();
- BackgroundJobManagerImpl.getInstance().cancelAllFolderUploadWorker();
+ BackgroundJobManagerImpl.getInstance().cancelFolderAutoUploadWorker();
}
}
@@ -162,14 +161,14 @@ private void onBusEvent(TransferOpType opType) {
private void startFolderMonitor() {
boolean isBackupEnable = FolderBackupSharePreferenceHelper.readBackupSwitch();
- if (isBackupEnable){
+ if (isBackupEnable) {
List pathList = FolderBackupSharePreferenceHelper.readBackupPathsAsList();
boolean isFound = pathList.stream().anyMatch(IGNORE_PATHS::contains);
if (!isFound) {
pathList.add(IGNORE_PATHS.get(0));
}
startFolderMonitor(pathList);
- }else{
+ } else {
resetFolderMonitor();
}
}
@@ -233,7 +232,7 @@ private void doBackup(String action, File file) {
BackgroundJobManagerImpl.getInstance().startCheckDownloadedFileChainWorker(file.getAbsolutePath());
}
} else {
- BackgroundJobManagerImpl.getInstance().startFolderChainWorker(true);
+ BackgroundJobManagerImpl.getInstance().startFolderAutoBackupWorkerChain(true);
}
}
@@ -294,6 +293,7 @@ public void onStop(FileAlterationObserver observer) {
public void onDestroy() {
super.onDestroy();
+ SLogs.e("file monitor service destroy");
stopFolderMonitor();
//
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/observer/MediaContentObserver.java b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/MediaContentObserver.java
similarity index 85%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/observer/MediaContentObserver.java
rename to app/src/main/java/com/seafile/seadroid2/framework/file_monitor/MediaContentObserver.java
index 449e2d7fc..f7b861819 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/observer/MediaContentObserver.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/MediaContentObserver.java
@@ -1,4 +1,4 @@
-package com.seafile.seadroid2.framework.worker.observer;
+package com.seafile.seadroid2.framework.file_monitor;
import android.content.ContentResolver;
import android.content.Context;
@@ -6,10 +6,10 @@
import android.net.Uri;
import android.os.Handler;
import android.provider.MediaStore;
+import android.widget.Toast;
-import com.seafile.seadroid2.framework.datastore.sp_livedata.AlbumBackupSharePreferenceHelper;
+import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.framework.util.SLogs;
-import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
import com.seafile.seadroid2.ui.camera_upload.CameraUploadManager;
/**
@@ -39,7 +39,9 @@ public MediaContentObserver(Context context, Handler handler) {
public void onChange(boolean selfChange) {
super.onChange(selfChange);
- SLogs.d("A new file is detected and the Media task begins");
+ String newVer = MediaStore.getVersion(SeadroidApplication.getAppContext());
+ SLogs.e("媒体库新版本:"+newVer);
+ SLogs.e("A new file is detected and the Media task begins");
CameraUploadManager.getInstance().performFullSync();
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/observer/RecursiveFileObserver.java b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/RecursiveFileObserver.java
similarity index 98%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/observer/RecursiveFileObserver.java
rename to app/src/main/java/com/seafile/seadroid2/framework/file_monitor/RecursiveFileObserver.java
index 749189476..744e4e447 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/observer/RecursiveFileObserver.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/RecursiveFileObserver.java
@@ -1,4 +1,4 @@
-package com.seafile.seadroid2.framework.worker.observer;
+package com.seafile.seadroid2.framework.file_monitor;
import android.os.Build;
import android.os.FileObserver;
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/observer/SingleFolderPathFileObserver.java b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/SingleFolderPathFileObserver.java
similarity index 95%
rename from app/src/main/java/com/seafile/seadroid2/framework/worker/observer/SingleFolderPathFileObserver.java
rename to app/src/main/java/com/seafile/seadroid2/framework/file_monitor/SingleFolderPathFileObserver.java
index a0a87a6ed..04c2ac62d 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/observer/SingleFolderPathFileObserver.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/file_monitor/SingleFolderPathFileObserver.java
@@ -1,4 +1,4 @@
-package com.seafile.seadroid2.framework.worker.observer;
+package com.seafile.seadroid2.framework.file_monitor;
import org.apache.commons.io.IOCase;
import org.apache.commons.io.monitor.FileAlterationObserver;
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/http/BaseOkHttpClient.java b/app/src/main/java/com/seafile/seadroid2/framework/http/BaseOkHttpClient.java
index 1e3f73424..236bb76c4 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/http/BaseOkHttpClient.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/http/BaseOkHttpClient.java
@@ -43,17 +43,24 @@ public BaseOkHttpClient(Account account) {
protected List getInterceptors() {
+ List interceptors = getInterceptorsWithoutToken();
+ if (account != null && !TextUtils.isEmpty(account.token)) {
+ interceptors.add(new HeaderInterceptor(account.token));
+ }
+
+ return interceptors;
+ }
+
+ protected List getInterceptorsWithoutToken() {
+
List interceptors = new ArrayList<>();
//print log
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
- loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.BASIC);
+// loggingInterceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.BASIC);
interceptors.add(loggingInterceptor);
- if (account != null && !TextUtils.isEmpty(account.token)) {
- interceptors.add(new HeaderInterceptor(account.token));
- }
// interceptors.add(new AddCookiesInterceptor());
// interceptors.add(new ReceivedCookiesInterceptor());
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/http/HttpIO.java b/app/src/main/java/com/seafile/seadroid2/framework/http/HttpIO.java
index 00702a34a..2fd29011f 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/http/HttpIO.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/http/HttpIO.java
@@ -80,6 +80,14 @@ public static HttpIO getCurrentInstance() {
return INSTANCE;
}
+ public static void removeInstanceByAccount(Account account) {
+ if (account == null) {
+ return;
+ }
+
+ IO_MAP.remove(account.getSignature());
+ }
+
/**
* Not logged in/Log in to another server
*/
@@ -153,6 +161,7 @@ public T execute(Class clazz) {
private Retrofit createRetrofit() {
Retrofit.Builder rBuilder = new Retrofit.Builder();
+
rBuilder.baseUrl(getServerUrl());
rBuilder.addConverterFactory(ConverterFactory.create());
rBuilder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());
@@ -162,7 +171,6 @@ private Retrofit createRetrofit() {
return rBuilder.build();
}
-
public void downloadBinarySync(String url, File destinationFile, ProgressListener callback) throws IOException {
OkHttpClient client = getOkHttpClient().getOkClient();
@@ -178,7 +186,6 @@ public void onProgress(long transferSize, long totalSize) {
try (BinaryFileDownloader fileDownloader = new BinaryFileDownloader(client, fileWriter)) {
fileDownloader.download(url);
-
} catch (Exception e) {
if (callback != null) {
callback.isCancelled();
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/http/SafeOkHttpClient.java b/app/src/main/java/com/seafile/seadroid2/framework/http/SafeOkHttpClient.java
index 25524a5c1..cc46d68b6 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/http/SafeOkHttpClient.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/http/SafeOkHttpClient.java
@@ -2,6 +2,7 @@
import com.blankj.utilcode.util.CollectionUtils;
import com.seafile.seadroid2.account.Account;
+import com.seafile.seadroid2.ssl.CertsManager;
import com.seafile.seadroid2.ssl.SSLSeafileSocketFactory;
import com.seafile.seadroid2.ssl.SSLTrustManager;
@@ -12,6 +13,7 @@
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -31,8 +33,28 @@
import okhttp3.Request;
public class SafeOkHttpClient extends BaseOkHttpClient {
+ private final List _interceptors = new ArrayList<>();
+
public SafeOkHttpClient(Account account) {
super(account);
+
+ _interceptors.addAll(getInterceptors());
+ }
+
+ public SafeOkHttpClient(Account account, boolean isCustomToken) {
+ super(account);
+
+ if (isCustomToken) {
+ _interceptors.addAll(getInterceptorsWithoutToken());
+ } else {
+ _interceptors.addAll(getInterceptors());
+ }
+ }
+
+ public void addInterceptors(List s) {
+ if (s != null) {
+ _interceptors.addAll(s);
+ }
}
public static TrustManager[] getTrustManagers() {
@@ -69,24 +91,15 @@ public OkHttpClient getOkClient() {
//https
if (account.getServer().startsWith("https://")) {
//ssl
-
SSLSocketFactory factory = SSLTrustManager.instance().getSSLSocketFactory(account);
TrustManager[] trustManagers = SSLTrustManager.instance().getTrustManagers(account);
X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
builder.sslSocketFactory(factory, trustManager);
-
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
- //check host
- if (account.getServerDomainName().equals(hostname)) {
- return true;
- }
-
- //check by default verifier
- HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
- return verifier.verify(hostname, session);
+ return true;
}
});
}
@@ -129,9 +142,8 @@ public boolean verify(String hostname, SSLSession session) {
builder.networkInterceptors().add(REWRITE_CACHE_CONTROL_INTERCEPTOR);
//add interceptors
- List interceptors = getInterceptors();
- if (!CollectionUtils.isEmpty(interceptors)) {
- for (Interceptor i : interceptors) {
+ if (!CollectionUtils.isEmpty(_interceptors)) {
+ for (Interceptor i : _interceptors) {
builder.interceptors().add(i);
}
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/notification/base/BaseNotification.java b/app/src/main/java/com/seafile/seadroid2/framework/notification/base/BaseNotification.java
index 7e1707778..d8f1b9b1d 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/notification/base/BaseNotification.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/notification/base/BaseNotification.java
@@ -46,7 +46,6 @@ public BaseNotification(Context context) {
hasPermission = i == android.content.pm.PackageManager.PERMISSION_GRANTED;
}
-
init();
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/ContentResolvers.java b/app/src/main/java/com/seafile/seadroid2/framework/util/ContentResolvers.java
new file mode 100644
index 000000000..de86a85ee
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/ContentResolvers.java
@@ -0,0 +1,55 @@
+package com.seafile.seadroid2.framework.util;
+
+import android.content.ContentResolver;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.MediaStore;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ContentResolvers {
+
+ public static String getFileNameFromUri(ContentResolver contentResolver, Uri uri) {
+ String fileName = null;
+ String[] projection = {MediaStore.MediaColumns.DISPLAY_NAME};
+ try (Cursor cursor = contentResolver.query(uri, projection, null, null, null)) {
+ if (cursor != null && cursor.moveToFirst()) {
+ int index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME);
+ fileName = cursor.getString(index);
+ }
+ }
+
+ return fileName;
+ }
+
+ // 获取文件内容的方法
+ public static byte[] getFileContentFromUri(ContentResolver contentResolver, Uri uri) {
+ byte[] fileContent = null;
+ InputStream inputStream = null;
+ try {
+ inputStream = contentResolver.openInputStream(uri);
+ if (inputStream != null) {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ fileContent = outputStream.toByteArray();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return fileContent;
+ }
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/GlideCache.java b/app/src/main/java/com/seafile/seadroid2/framework/util/GlideCache.java
index f69075797..e18e22d25 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/util/GlideCache.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/GlideCache.java
@@ -45,8 +45,7 @@ public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder
File[] externalMediaDirs = SeadroidApplication.getAppContext().getExternalMediaDirs();
String rootPath = externalMediaDirs[0].getAbsolutePath();
File dirPath = new File(rootPath + "/GlideCache/");
- builder.setDiskCache(new DiskLruCacheFactory(dirPath.getAbsolutePath(), 1024 * 1024 * 100));
- GlideApp.tearDown();
+ builder.setDiskCache(new DiskLruCacheFactory(dirPath.getAbsolutePath(), 1024 * 1024 * 500));
}
@Override
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/Logs.java b/app/src/main/java/com/seafile/seadroid2/framework/util/Logs.java
index 6f0f36604..9eb6ad4d0 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/util/Logs.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/Logs.java
@@ -38,12 +38,11 @@ public class Logs {
/**
* will delete log files that have not been modified for a period of time
*/
- private static final long MAX_TIME = 30L * 24 * 60 * 60 * 1000;
+ private static final long MAX_TIME = 30L * 24 * 60 * 60 * 1000;// 30 days
public static void init() {
LogConfiguration config = new LogConfiguration.Builder()
- .logLevel(BuildConfig.DEBUG ? LogLevel.ALL
- : LogLevel.ERROR)
+ .logLevel(BuildConfig.DEBUG ? LogLevel.ALL : LogLevel.INFO)
.tag(LOG_TAG)
// .enableThreadInfo()
// .enableStackTrace(2)
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/Objs.java b/app/src/main/java/com/seafile/seadroid2/framework/util/Objs.java
index 275987c7f..bbe327bb1 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/util/Objs.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/Objs.java
@@ -41,6 +41,7 @@
import com.seafile.seadroid2.ui.dialog_fragment.AppChoiceDialogFragment;
import com.seafile.seadroid2.ui.dialog_fragment.GetShareLinkPasswordDialogFragment;
import com.seafile.seadroid2.ui.repo.RepoService;
+import com.seafile.seadroid2.ui.comparator.NaturalOrderComparator;
import com.seafile.seadroid2.ui.star.StarredService;
import java.io.File;
@@ -170,7 +171,7 @@ public SingleSource> apply(RepoWrapperModel repoWrapperModel) th
});
}
- public static List parseRepoListForAdapter(List list, String related_account, boolean isFilter) {
+ public static List parseRepoListForAdapter(List list, String related_account, boolean isFilterUnavailable) {
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
@@ -179,7 +180,7 @@ public static List parseRepoListForAdapter(List list, Stri
list.get(i).related_account = related_account;
}
- if (isFilter) {
+ if (isFilterUnavailable) {
list = list.stream().filter(f -> !f.encrypted && f.hasWritePermission()).collect(Collectors.toList());
}
@@ -332,41 +333,32 @@ private static List sortRepos(List repos) {
boolean isAscending = Settings.FILE_LIST_SORT_ASCENDING.queryValue();
if (SortBy.NAME == by) {
- newRepos = repos.stream().sorted(new Comparator() {
- @Override
- public int compare(RepoModel o1, RepoModel o2) {
- if (isAscending) {
- return o1.repo_name.compareTo(o2.repo_name);
- }
- return -o1.repo_name.compareTo(o2.repo_name);
- }
- }).collect(Collectors.toList());
+ if (isAscending) {
+ newRepos = repos.stream().sorted(new NaturalOrderComparator()).collect(Collectors.toList());
+ } else {
+ newRepos = repos.stream().sorted(new NaturalOrderComparator().reversed()).collect(Collectors.toList());
+ }
} else if (SortBy.TYPE == by) {
//todo not supported
} else if (SortBy.SIZE == by) {
newRepos = repos.stream().sorted(new Comparator() {
@Override
public int compare(RepoModel o1, RepoModel o2) {
- if (o1.size == o2.size) {
- return 0;
- }
if (isAscending) {
- return o1.size < o2.size ? -1 : 1;
+ return Long.compare(o1.size, o2.size);
}
- return o1.size > o2.size ? -1 : 1;
+ return -Long.compare(o1.size, o2.size);
}
}).collect(Collectors.toList());
} else if (SortBy.LAST_MODIFIED == by) {
newRepos = repos.stream().sorted(new Comparator() {
@Override
public int compare(RepoModel o1, RepoModel o2) {
- if (o1.last_modified_long == o2.last_modified_long) {
- return 0;
- }
+
if (isAscending) {
- return o1.last_modified_long < o2.last_modified_long ? -1 : 1;
+ return Long.compare(o1.last_modified_long, o2.last_modified_long);
}
- return o1.last_modified_long > o2.last_modified_long ? -1 : 1;
+ return -Long.compare(o1.last_modified_long, o2.last_modified_long);
}
}).collect(Collectors.toList());
}
@@ -614,15 +606,11 @@ private static List sortDirents(List list) {
boolean isAscending = Settings.FILE_LIST_SORT_ASCENDING.queryValue();
if (SortBy.NAME == by) {
- newList = list.stream().sorted(new Comparator() {
- @Override
- public int compare(DirentModel o1, DirentModel o2) {
- if (isAscending) {
- return o1.name.compareTo(o2.name);
- }
- return -o1.name.compareTo(o2.name);
- }
- }).collect(Collectors.toList());
+ if (isAscending) {
+ newList = list.stream().sorted(new NaturalOrderComparator()).collect(Collectors.toList());
+ } else {
+ newList = list.stream().sorted(new NaturalOrderComparator().reversed()).collect(Collectors.toList());
+ }
} else if (SortBy.TYPE == by) {
//todo not supported
} else if (SortBy.SIZE == by) {
@@ -646,7 +634,6 @@ public int compare(DirentModel o1, DirentModel o2) {
}
}).collect(Collectors.toList());
}
-
return newList;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/StringUtils.java b/app/src/main/java/com/seafile/seadroid2/framework/util/StringUtils.java
index 6d8d5c876..975d1926b 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/util/StringUtils.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/StringUtils.java
@@ -129,9 +129,13 @@ public static String trimStart(String input, String character) {
}
/**
- *
- * ""string"" => "string"
- *
+ *
+ *
+ * ""string"" => "string"
+ * null => null
+ * "" => ""
+ *
+ *
*/
public static String deString(String input) {
if (TextUtils.isEmpty(input)) {
@@ -143,6 +147,25 @@ public static String deString(String input) {
return input;
}
+ /**
+ *
+ *
+ * ""string"" => "string"
+ * null => ""
+ * "" => ""
+ *
+ *
+ */
+ public static String deStringReturnNonNull(String input) {
+ if (TextUtils.isEmpty(input)) {
+ return "";
+ }
+
+ input = trim(input, "\"");
+
+ return input;
+ }
+
public static int getStringAsciiSum(String input) {
int sum = 0;
for (int i = 0; i < input.length(); i++) {
@@ -151,7 +174,7 @@ public static int getStringAsciiSum(String input) {
}
return sum;
}
-
+
public static int getHexStringAsciiSum(String input) {
byte[] bytes = hexStringToByteArray(input);
@@ -173,4 +196,18 @@ public static byte[] hexStringToByteArray(String s) {
}
return data;
}
+
+ /**
+ * => org.apache.commons.lang3.StringUtils#countMatches(c,c)
+ */
+ public static int countMatches(String inputStr, String matchStr) {
+ if (TextUtils.isEmpty(inputStr)) {
+ return 0;
+ }
+ if (TextUtils.isEmpty(matchStr)) {
+ return 0;
+ }
+
+ return org.apache.commons.lang3.StringUtils.countMatches(inputStr, matchStr);
+ }
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/TakeCameras.java b/app/src/main/java/com/seafile/seadroid2/framework/util/TakeCameras.java
index 6ae1bdc0d..3c147fdea 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/util/TakeCameras.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/TakeCameras.java
@@ -7,6 +7,8 @@
import androidx.core.content.FileProvider;
import com.blankj.utilcode.util.PathUtils;
+import com.blankj.utilcode.util.TimeUtils;
+import com.google.android.gms.common.util.DataUtils;
import com.seafile.seadroid2.BuildConfig;
import java.io.File;
@@ -35,15 +37,22 @@ public static File getMediaStoragePath(String folderName) {
public static Pair buildTakePhotoUri(Context context) {
File parentFolder = getMediaStoragePath("images");
- String fileName = "sf_photo_" + System.currentTimeMillis() + ".jpg";
+ String fileName = getOneNewName("jpg");
File file = new File(parentFolder, fileName);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.FILE_PROVIDER_AUTHORITIES, file);
return new Pair<>(uri, file);
}
+ private static String getOneNewName(String prefix) {
+ long mills = System.currentTimeMillis();
+ long seconds = mills / 1000;
+ String date = TimeUtils.millis2String(mills, "yyyyMMdd");
+ return date + "_" + seconds + "." + prefix;
+ }
+
public static Pair buildTakeVideoUri(Context context) {
File parentFolder = getMediaStoragePath("videos");
- String fileName = "sf_video" + System.currentTimeMillis() + ".mp4";
+ String fileName = getOneNewName("mp4");
File file = new File(parentFolder, fileName);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.FILE_PROVIDER_AUTHORITIES, file);
return new Pair<>(uri, file);
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/ThumbnailUtils.java b/app/src/main/java/com/seafile/seadroid2/framework/util/ThumbnailUtils.java
new file mode 100644
index 000000000..28218c789
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/ThumbnailUtils.java
@@ -0,0 +1,11 @@
+package com.seafile.seadroid2.framework.util;
+
+import com.blankj.utilcode.util.EncodeUtils;
+
+public class ThumbnailUtils {
+
+ public static String convertThumbnailUrl(String serverUrl, String repoId, String fullPath) {
+ String newFilePath = EncodeUtils.urlEncode(fullPath);
+ return String.format("%sapi2/repos/%s/thumbnail/?p=%s&size=%s", serverUrl, repoId, newFilePath, 128);
+ }
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java b/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java
index 886356dbf..f8e928077 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/util/Utils.java
@@ -96,6 +96,7 @@ public static String getPathFromFullPath(String path) {
} else
return parent;
}
+
public static String getParentPath(String path) {
if (path == null) {
// the caller should not give null
@@ -107,6 +108,10 @@ public static String getParentPath(String path) {
return "/";
}
+ if ("/".equals(path)) {
+ return "/";
+ }
+
if (path.endsWith("/")) {
path = path.substring(0, path.lastIndexOf("/"));
}
@@ -521,8 +526,6 @@ public static void hideSystemNavigationBar(Activity activity) {
}
-
-
public static void startCameraSyncJob(Context context) {
// JobScheduler mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
// JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, new ComponentName(context.getPackageName(), MediaSchedulerService.class.getName()));
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java
index bb5a51740..4fec53302 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/BackgroundJobManagerImpl.java
@@ -2,6 +2,7 @@
import android.text.TextUtils;
+import androidx.work.BackoffPolicy;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingWorkPolicy;
@@ -107,8 +108,8 @@ public WorkManager getWorkManager() {
///////////////////
/// media worker
///////////////////
- public void startMediaChainWorker(boolean isForce) {
- cancelAllMediaWorker();
+ public void startMediaWorkerChain(boolean isForce) {
+ cancelMediaWorker();
OneTimeWorkRequest scanRequest = getMediaScanRequest(isForce);
OneTimeWorkRequest uploadRequest = getMediaUploadRequest();
@@ -136,7 +137,8 @@ private OneTimeWorkRequest getMediaScanRequest(boolean isForce) {
private OneTimeWorkRequest getMediaUploadRequest() {
NetworkType networkType = NetworkType.UNMETERED;
- if (AlbumBackupSharePreferenceHelper.readAllowDataPlanSwitch()) {
+ boolean isAllowData = AlbumBackupSharePreferenceHelper.readAllowDataPlanSwitch();
+ if (isAllowData) {
networkType = NetworkType.CONNECTED;
}
@@ -149,13 +151,14 @@ private OneTimeWorkRequest getMediaUploadRequest() {
return oneTimeRequestBuilder(UploadMediaFileAutomaticallyWorker.class)
.setConstraints(constraints)
+ .setBackoffCriteria(BackoffPolicy.LINEAR, 5, TimeUnit.SECONDS)
.setInitialDelay(1, TimeUnit.SECONDS)
.setId(UploadMediaFileAutomaticallyWorker.UID)
.build();
}
//cancel media
- public void cancelAllMediaWorker() {
+ public void cancelMediaWorker() {
cancelById(UploadMediaFileAutomaticallyWorker.UID);
cancelById(MediaBackupScannerWorker.UID);
}
@@ -163,8 +166,8 @@ public void cancelAllMediaWorker() {
///////////////////
/// upload folder
///////////////////
- public void startFolderChainWorker(boolean isForce) {
- cancelAllFolderUploadWorker();
+ public void startFolderAutoBackupWorkerChain(boolean isForce) {
+ cancelFolderAutoUploadWorker();
OneTimeWorkRequest scanRequest = getFolderScanRequest(isForce);
OneTimeWorkRequest uploadRequest = getFolderUploadRequest();
@@ -204,12 +207,13 @@ private OneTimeWorkRequest getFolderUploadRequest() {
return oneTimeRequestBuilder(UploadFolderFileAutomaticallyWorker.class)
.setConstraints(constraints)
+ .setBackoffCriteria(BackoffPolicy.LINEAR, 5, TimeUnit.SECONDS)
.setInitialDelay(1, TimeUnit.SECONDS)
.setId(UploadFolderFileAutomaticallyWorker.UID)
.build();
}
- public void cancelAllFolderUploadWorker() {
+ public void cancelFolderAutoUploadWorker() {
cancelById(FolderBackupScannerWorker.UID);
cancelById(UploadFolderFileAutomaticallyWorker.UID);
}
@@ -217,7 +221,7 @@ public void cancelAllFolderUploadWorker() {
///////////////////
/// upload file
///////////////////
- public void startFileUploadWorker() {
+ public void startFileManualUploadWorker() {
String workerName = UploadFileManuallyWorker.class.getSimpleName();
OneTimeWorkRequest request = getFileUploadRequest();
getWorkManager().enqueueUniqueWork(workerName, ExistingWorkPolicy.KEEP, request);
@@ -229,6 +233,10 @@ private OneTimeWorkRequest getFileUploadRequest() {
.build();
}
+ public void cancelFileManualUploadWorker() {
+ cancelById(UploadFileManuallyWorker.UID);
+ }
+
///////////////////
/// download
///////////////////
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/TransferEvent.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/TransferEvent.java
index 6adf0e260..a747ff15b 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/TransferEvent.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/TransferEvent.java
@@ -41,11 +41,16 @@ public class TransferEvent {
/**
* because of an OUT_OF_QUOTA error, the current upload worker was canceled
*/
- public static final String EVENT_CANCEL_OUT_OF_QUOTA = "transfer_cancel_with_out_of_quota";
+ public static final String EVENT_CANCEL_WITH_OUT_OF_QUOTA = "transfer_cancel_with_out_of_quota";
/**
* because of an NETWORK error, the current upload worker was canceled
*/
public static final String EVENT_CANCEL_WITH_NETWORK_ERR = "transfer_cancel_with_network_err";
+ /**
+ * Manual or passive cancellation
+ */
+ public static final String EVENT_CANCEL_WITH_BY_STOPPED = "transfer_cancel_with_stopped";
+
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/BaseDownloadWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/BaseDownloadWorker.java
index 976508f3d..b108685fd 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/BaseDownloadWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/BaseDownloadWorker.java
@@ -90,7 +90,7 @@ public String isInterrupt(TransferResult result) {
} else if (result == TransferResult.FILE_NOT_FOUND) {
// finishFlagEvent = null;
} else if (result == TransferResult.OUT_OF_QUOTA) {
- finishFlagEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
+ finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_OUT_OF_QUOTA;
} else if (result == TransferResult.NETWORK_CONNECTION) {
finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_NETWORK_ERR;
} else if (result == TransferResult.SSL_EXCEPTION) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadFileScanWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadFileScanWorker.java
index ea14e5b4e..6def872f9 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadFileScanWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadFileScanWorker.java
@@ -172,33 +172,30 @@ private void insertIntoDbWhenDirentIsFile(Account account, DirentModel direntMod
}
RepoModel repoModel = repoModels.get(0);
- DirentFileModel direntFileModel = fetchFile(direntModel);
- if (direntFileModel == null) {
- return;
- }
-
- FileTransferEntity transferEntity = FileTransferEntity.convertDirentModel2This(repoModel.canLocalDecrypt(), direntModel);
-
- //newest file id
- transferEntity.file_id = direntFileModel.id;
- transferEntity.file_size = direntFileModel.size;
- transferEntity.target_path = DataManager.getLocalRepoFile(account, transferEntity).getAbsolutePath();
+ List existsList = AppDatabase.getInstance().fileTransferDAO().getListByFullPathsSync(direntModel.repo_id, CollectionUtils.newArrayList(direntModel.full_path), TransferAction.DOWNLOAD);
+ if (!CollectionUtils.isEmpty(existsList)) {
- List existsList = AppDatabase.getInstance().fileTransferDAO().getListByFullPathsSync(direntModel.repo_id, CollectionUtils.newArrayList(transferEntity.full_path), TransferAction.DOWNLOAD);
+ DirentFileModel direntFileModel = fetchFile(direntModel);
+ if (direntFileModel == null) {
+ return;
+ }
- if (!CollectionUtils.isEmpty(existsList)) {
FileTransferEntity existEntity = existsList.get(0);
if (TransferStatus.SUCCEEDED == existEntity.transfer_status) {
- if (TextUtils.equals(existsList.get(0).file_id, transferEntity.file_id)) {
- //it's the same file,do not insert into db.
- SLogs.d("file download: skip file(local exists): " + transferEntity.full_path);
- ToastUtils.showLong(R.string.download_finished);
+ if (TextUtils.equals(existsList.get(0).file_id, direntFileModel.id)) {
+ SLogs.d("file download: skip file(local exists): " + existEntity.full_path);
return;
}
}
}
+
+ FileTransferEntity transferEntity = FileTransferEntity.convertDirentModel2This(repoModel.canLocalDecrypt(), direntModel);
+ //newest file id
+ transferEntity.file_id = direntModel.id;
+ transferEntity.file_size = direntModel.size;
+ transferEntity.target_path = DataManager.getLocalRepoFile(account, transferEntity).getAbsolutePath();
transferEntity.transfer_status = TransferStatus.WAITING;
transferEntity.transfer_result = TransferResult.NO_RESULT;
transferEntity.transferred_size = 0;
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java
index 941089ba9..6bb3141fe 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/download/DownloadWorker.java
@@ -47,6 +47,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -97,7 +98,7 @@ public Result doWork() {
//count
int pendingCount = AppDatabase.getInstance().fileTransferDAO().countPendingDownloadListSync(account.getSignature());
if (pendingCount <= 0) {
- SLogs.eDebug("download list is empty.");
+ SLogs.i("download list is empty.");
return Result.success(getFinishData(false));
}
@@ -119,7 +120,7 @@ public Result doWork() {
List list = AppDatabase
.getInstance()
.fileTransferDAO()
- .getOnePendingDownloadByActionSync(account.getSignature());
+ .getOnePendingDownloadByAccountSync(account.getSignature());
if (CollectionUtils.isEmpty(list)) {
break;
}
@@ -150,7 +151,7 @@ public Result doWork() {
}
}
- SLogs.d("all task run");
+ SLogs.i("all task run");
//
if (isDownloaded) {
@@ -174,7 +175,7 @@ private Data getFinishData(boolean isDownloaded) {
private final FileTransferProgressListener.TransferProgressListener progressListener = new FileTransferProgressListener.TransferProgressListener() {
@Override
public void onProgressNotify(FileTransferEntity fileTransferEntity, int percent, long transferredSize, long totalSize) {
- SLogs.d(fileTransferEntity.file_name + " -> progress:" + percent);
+ SLogs.i(fileTransferEntity.file_name + " -> progress:" + percent);
int diff = AppDatabase.getInstance().fileTransferDAO().countPendingDownloadListSync(fileTransferEntity.related_account);
@@ -190,7 +191,7 @@ public void onProgressNotify(FileTransferEntity fileTransferEntity, int percent,
};
private void transferFile(Account account, FileTransferEntity transferEntity) throws Exception {
- SLogs.d("download start:" + transferEntity.full_path);
+ SLogs.i("download start:" + transferEntity.full_path);
//show notification
int diff = AppDatabase.getInstance().fileTransferDAO().countPendingDownloadListSync(transferEntity.related_account);
@@ -200,7 +201,7 @@ private void transferFile(Account account, FileTransferEntity transferEntity) th
List repoModels = AppDatabase.getInstance().repoDao().getByIdSync(transferEntity.repo_id);
if (CollectionUtils.isEmpty(repoModels)) {
- SLogs.d("no repo for repoId: " + transferEntity.repo_id);
+ SLogs.i("no repo for repoId: " + transferEntity.repo_id);
return;
}
@@ -224,13 +225,13 @@ private void downloadFile(Account account, FileTransferEntity transferEntity) th
File localFile = DataManager.getLocalRepoFile(account, transferEntity);
if (localFile.exists() && transferEntity.file_strategy == ExistingFileStrategy.SKIP) {
- SLogs.d("skip this file, file_strategy is SKIP :" + localFile.getAbsolutePath());
+ SLogs.i("skip this file, file_strategy is SKIP :" + localFile.getAbsolutePath());
return;
}
download(transferEntity, dlink, localFile);
- SLogs.d("download finish:" + transferEntity.full_path);
+ SLogs.i("download finish:" + transferEntity.full_path);
}
private Pair getDownloadLink(FileTransferEntity transferEntity, boolean isReUsed) throws SeafException, IOException {
@@ -267,8 +268,6 @@ private Pair getDownloadLink(FileTransferEntity transferEntity,
}
private void download(FileTransferEntity fileTransferEntity, String dlink, File localFile) throws Exception {
-
-
fileTransferProgressListener.setFileTransferEntity(fileTransferEntity);
fileTransferEntity.transfer_status = TransferStatus.IN_PROGRESS;
@@ -293,8 +292,8 @@ private void download(FileTransferEntity fileTransferEntity, String dlink, File
long fileSize = responseBody.contentLength();
if (fileSize == -1) {
- SLogs.d("download file error -> contentLength is -1");
- SLogs.d(localFile.getAbsolutePath());
+ SLogs.e("download file error -> contentLength is -1");
+ SLogs.e(localFile.getAbsolutePath());
fileSize = fileTransferEntity.file_size;
@@ -328,10 +327,12 @@ private void download(FileTransferEntity fileTransferEntity, String dlink, File
//important
tempFile.renameTo(localFile);
+// Path path = java.nio.file.Files.move(tempFile.toPath(), localFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING);
+// boolean isSuccess = path.toFile().exists();
if (localFile.length() != fileSize) {
- SLogs.d("download file error -> localFile.size != downloadedSize");
- SLogs.d(localFile.getAbsolutePath());
+ SLogs.e("download file error -> localFile.size != downloadedSize");
+ SLogs.e(localFile.getAbsolutePath());
updateEntityErrorState(fileTransferEntity);
} else {
updateEntitySuccessState(fileTransferEntity, localFile);
@@ -393,7 +394,7 @@ private void downloadFileByBlock(Account account, FileTransferEntity transferEnt
File localFile = DataManager.getLocalRepoFile(account, transferEntity);
if (localFile.exists() && transferEntity.file_strategy == ExistingFileStrategy.SKIP) {
- SLogs.d("skip this file, file_strategy is SKIP :" + localFile.getAbsolutePath());
+ SLogs.i("skip this file, file_strategy is SKIP :" + localFile.getAbsolutePath());
return;
}
@@ -498,7 +499,7 @@ private void downloadBlock(FileBlocks fileBlocks, String blockId, String dlink,
responseBody.close();
if (localFile.length() != tempFileSize) {
- SLogs.d("Rename file error : " + localFile.getAbsolutePath());
+ SLogs.i("Rename file error : " + localFile.getAbsolutePath());
throw SeafException.networkException;
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/BaseUploadWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/BaseUploadWorker.java
index d3742b207..541ab61af 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/BaseUploadWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/BaseUploadWorker.java
@@ -49,6 +49,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.file.Files;
import java.security.NoSuchAlgorithmException;
@@ -102,7 +103,14 @@ private TransferResult parseTransferException(Exception e) {
return TransferResult.SSL_EXCEPTION;
} else if (e instanceof SocketTimeoutException) {
return TransferResult.NETWORK_CONNECTION;
+ } else if (e instanceof SocketException) {
+// SocketException exception = (SocketException) e;
+// SLogs.e(exception);
+ return TransferResult.USER_CANCELLED;
} else if (e instanceof IOException) {
+ if (TextUtils.equals("Canceled", e.getMessage())) {
+ return TransferResult.USER_CANCELLED;
+ }
return TransferResult.NETWORK_CONNECTION;
}
@@ -140,7 +148,7 @@ public String isInterrupt(TransferResult result) {
} else if (result == TransferResult.FILE_NOT_FOUND) {
// finishFlagEvent = null;
} else if (result == TransferResult.OUT_OF_QUOTA) {
- finishFlagEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
+ finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_OUT_OF_QUOTA;
} else if (result == TransferResult.NETWORK_CONNECTION) {
finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_NETWORK_ERR;
} else if (result == TransferResult.SSL_EXCEPTION) {
@@ -151,6 +159,8 @@ public String isInterrupt(TransferResult result) {
finishFlagEvent = TransferEvent.EVENT_FINISH;
} else if (result == TransferResult.UNKNOWN) {
finishFlagEvent = TransferEvent.EVENT_FINISH;
+ } else if (result == TransferResult.USER_CANCELLED) {
+ finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_BY_STOPPED;
}
return finishFlagEvent;
@@ -361,6 +371,11 @@ public void onStopped() {
// cancelNotification();
+ SLogs.e("BaseUploadWorker onStopped");
+ currentTransferEntity.transfer_status = TransferStatus.CANCELLED;
+ currentTransferEntity.transfer_result = TransferResult.USER_CANCELLED;
+ AppDatabase.getInstance().fileTransferDAO().update(currentTransferEntity);
+
if (newCall != null && !newCall.isCanceled()) {
newCall.cancel();
}
@@ -376,59 +391,67 @@ private void notifyProgress(String fileName, int percent) {
showForegroundAsync(f);
}
+ private FileTransferEntity currentTransferEntity;
+
public void transferFile(Account account, FileTransferEntity transferEntity) throws IOException, SeafException, JSONException {
SLogs.d("start transfer, full_path: " + transferEntity.full_path);
+ currentTransferEntity = transferEntity;
List repoModels = AppDatabase.getInstance().repoDao().getByIdSync(transferEntity.repo_id);
if (CollectionUtils.isEmpty(repoModels)) {
- SLogs.d("no repo for repoId: " + transferEntity.repo_id);
+ SLogs.d("no repo for repoId: " + currentTransferEntity.repo_id);
- transferEntity.transfer_status = TransferStatus.FAILED;
- transferEntity.transfer_result = TransferResult.CANCELLED;
- AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
+ currentTransferEntity.transfer_status = TransferStatus.FAILED;
+ currentTransferEntity.transfer_result = TransferResult.CANCELLED;
+ AppDatabase.getInstance().fileTransferDAO().update(currentTransferEntity);
return;
}
//update modified_at field
- transferEntity.modified_at = System.currentTimeMillis();
- AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
- notifyProgress(transferEntity.file_name, 0);
- SLogs.d("start transfer, target_path: " + transferEntity.target_path);
+ currentTransferEntity.modified_at = System.currentTimeMillis();
+ AppDatabase.getInstance().fileTransferDAO().update(currentTransferEntity);
+//
+ //show notification
+ notifyProgress(currentTransferEntity.file_name, 0);
+ SLogs.d("start transfer, target_path: " + currentTransferEntity.target_path);
RepoModel repo = repoModels.get(0);
- if (repo.canLocalDecrypt()) {
- uploadBlockFile(account, repo, transferEntity);
- } else {
- uploadFile(account, repo, transferEntity);
- }
+ uploadFile(account, repo);
+
+// RepoModel repo = repoModels.get(0);
+// if (repo.canLocalDecrypt()) {
+// uploadBlockFile(account, repo, transferEntity);
+// } else {
+// uploadFile(account, repo, transferEntity);
+// }
}
/**
* upload file
*/
- private void uploadFile(Account account, RepoModel repoModel, FileTransferEntity transferEntity) throws IOException, SeafException {
+ private void uploadFile(Account account, RepoModel repoModel) throws IOException, SeafException {
if (isStopped()) {
return;
}
- File file = new File(transferEntity.full_path);
+ File file = new File(currentTransferEntity.full_path);
if (!file.exists()) {
throw SeafException.notFoundException;
}
- ExistingFileStrategy fileStrategy = transferEntity.file_strategy;
+ ExistingFileStrategy fileStrategy = currentTransferEntity.file_strategy;
if (fileStrategy == ExistingFileStrategy.AUTO) {
- fileStrategy = checkRemoteFileExists(account, repoModel, transferEntity);
+ fileStrategy = checkRemoteFileExists(account, repoModel, currentTransferEntity);
}
if (fileStrategy == ExistingFileStrategy.SKIP) {
- SLogs.d("folder backup: skip file(remote exists): " + transferEntity.target_path);
+ SLogs.d("folder backup: skip file(remote exists): " + currentTransferEntity.target_path);
- transferEntity.transfer_status = TransferStatus.SUCCEEDED;
- transferEntity.transfer_result = TransferResult.TRANSMITTED;
- AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
+ currentTransferEntity.transfer_status = TransferStatus.SUCCEEDED;
+ currentTransferEntity.transfer_result = TransferResult.TRANSMITTED;
+ AppDatabase.getInstance().fileTransferDAO().update(currentTransferEntity);
return;
}
@@ -437,8 +460,8 @@ private void uploadFile(Account account, RepoModel repoModel, FileTransferEntity
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
- if (transferEntity.file_strategy == ExistingFileStrategy.REPLACE) {
- builder.addFormDataPart("target_file", transferEntity.target_path);
+ if (currentTransferEntity.file_strategy == ExistingFileStrategy.REPLACE) {
+ builder.addFormDataPart("target_file", currentTransferEntity.target_path);
} else {
//parent_dir: / is repo root
builder.addFormDataPart("parent_dir", "/");
@@ -446,7 +469,7 @@ private void uploadFile(Account account, RepoModel repoModel, FileTransferEntity
// parent_dir is the root directory.
// when select the root of the repo, relative_path is null.
- String dir = transferEntity.getParent_path();
+ String dir = currentTransferEntity.getParent_path();
dir = StringUtils.removeStart(dir, "/");
//
builder.addFormDataPart("relative_path", dir);
@@ -454,11 +477,11 @@ private void uploadFile(Account account, RepoModel repoModel, FileTransferEntity
//
- fileTransferProgressListener.setFileTransferEntity(transferEntity);
+ fileTransferProgressListener.setFileTransferEntity(currentTransferEntity);
//db
- transferEntity.transfer_status = TransferStatus.IN_PROGRESS;
- AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
+ currentTransferEntity.transfer_status = TransferStatus.IN_PROGRESS;
+ AppDatabase.getInstance().fileTransferDAO().update(currentTransferEntity);
ProgressRequestBody progressRequestBody = new ProgressRequestBody(file, fileTransferProgressListener);
@@ -467,7 +490,7 @@ private void uploadFile(Account account, RepoModel repoModel, FileTransferEntity
RequestBody requestBody = builder.build();
//get upload link
- String uploadUrl = getFileUploadUrl(transferEntity.repo_id, transferEntity.getParent_path(), transferEntity.file_strategy == ExistingFileStrategy.REPLACE);
+ String uploadUrl = getFileUploadUrl(currentTransferEntity.repo_id, currentTransferEntity.getParent_path(), currentTransferEntity.file_strategy == ExistingFileStrategy.REPLACE);
if (TextUtils.isEmpty(uploadUrl)) {
throw SeafException.networkException;
}
@@ -485,34 +508,34 @@ private void uploadFile(Account account, RepoModel repoModel, FileTransferEntity
.build();
newCall = HttpIO.getCurrentInstance().getOkHttpClient().getOkClient().newCall(request);
- Response response = newCall.execute();
+ String str;
+ try (Response response = newCall.execute()) {
+ if (!response.isSuccessful()) {
+ String b = response.body() != null ? response.body().string() : null;
+ SLogs.d("result,failed:" + b);
- if (!response.isSuccessful()) {
- String b = response.body() != null ? response.body().string() : null;
- SLogs.d("result,failed:" + b);
+ //
+ newCall.cancel();
- //
- newCall.cancel();
+ //[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;
+ str = response.body().string();
}
-
- String str = response.body().string();
String fileId = str.replace("\"", "");
SLogs.d("result,file ID:" + str);
- updateSuccess(transferEntity, fileId, file);
+ updateSuccess(fileId, file);
} catch (Exception e) {
throw e;
}
}
-
private void uploadBlockFile(Account account, RepoModel repoModel, FileTransferEntity transferEntity) throws SeafException, IOException, JSONException {
if (isStopped()) {
return;
@@ -744,37 +767,35 @@ private void commitUpload(String link, List blkIds, FileTransferEntity t
String fileId = response.body().string();
- updateSuccess(transferEntity, fileId, file);
+ updateSuccess(fileId, file);
} catch (Exception e) {
throw e;
}
}
- private void updateSuccess(FileTransferEntity transferEntity, String fileId, File file) {
+ private void updateSuccess(String fileId, File file) {
//db
- transferEntity.file_id = fileId;
- transferEntity.transferred_size = file.length();
- transferEntity.action_end_at = System.currentTimeMillis();
- transferEntity.modified_at = transferEntity.action_end_at;
- transferEntity.file_original_modified_at = file.lastModified();
- transferEntity.transfer_result = TransferResult.TRANSMITTED;
- transferEntity.transfer_status = TransferStatus.SUCCEEDED;
+ currentTransferEntity.file_id = fileId;
+ currentTransferEntity.transferred_size = file.length();
+ currentTransferEntity.action_end_at = System.currentTimeMillis();
+ currentTransferEntity.modified_at = currentTransferEntity.action_end_at;
+ currentTransferEntity.file_original_modified_at = file.lastModified();
+ currentTransferEntity.transfer_result = TransferResult.TRANSMITTED;
+ currentTransferEntity.transfer_status = TransferStatus.SUCCEEDED;
- AppDatabase.getInstance().fileTransferDAO().update(transferEntity);
+ AppDatabase.getInstance().fileTransferDAO().update(currentTransferEntity);
//update
- List direntList = AppDatabase.getInstance().direntDao().getListByFullPathSync(transferEntity.repo_id, transferEntity.full_path);
+ List direntList = AppDatabase.getInstance().direntDao().getListByFullPathSync(currentTransferEntity.repo_id, currentTransferEntity.full_path);
if (!CollectionUtils.isEmpty(direntList)) {
DirentModel direntModel = direntList.get(0);
- direntModel.last_modified_at = transferEntity.modified_at;
+ direntModel.last_modified_at = currentTransferEntity.modified_at;
direntModel.id = fileId;
- direntModel.size = transferEntity.file_size;
- direntModel.transfer_status = transferEntity.transfer_status;
+ direntModel.size = currentTransferEntity.file_size;
+ direntModel.transfer_status = currentTransferEntity.transfer_status;
AppDatabase.getInstance().direntDao().update(direntModel);
}
-
-
}
private final int BUFFER_SIZE = 2 * 1024 * 1024;
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
index 576941ec5..fb3f1472d 100644
--- 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
@@ -126,8 +126,8 @@ private Data getOutData() {
}
private boolean checkCanScan() {
- boolean isOpenBackup = FolderBackupSharePreferenceHelper.readBackupSwitch();
- if (!isOpenBackup) {
+ boolean isTurnOn = FolderBackupSharePreferenceHelper.readBackupSwitch();
+ if (!isTurnOn) {
return false;
}
@@ -178,7 +178,7 @@ private void traverseBackupPath(Account account, RepoConfig repoConfig, List tList = CollectionUtils.newArrayList();
for (File file : subFiles) {
- FileTransferEntity fEntity = FileTransferEntity.convert2ThisForUploadFileSyncWorker(account, repoModel, file, backupPath);
+ FileTransferEntity fEntity = FileTransferEntity.convert2ThisForUploadFileSyncWorker(account, file, backupPath);
if (fEntity != null) {
tList.add(fEntity);
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java
index a54daf2a8..6f0224a1d 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/MediaBackupScannerWorker.java
@@ -97,7 +97,6 @@ public Result doWork() {
return Result.success(getOutData());
}
- //todo
String title = getApplicationContext().getString(R.string.settings_camera_upload_info_title);
String subTitle = getApplicationContext().getString(R.string.is_scanning);
@@ -517,7 +516,7 @@ private void checkAndInsert(String parent, List> fi
String parentPath = Utils.pathJoin(parent, "/");
- FileTransferEntity fileTransferEntity = FileTransferEntity.convert2ThisForUploadMediaSyncWorker(account, repoConfig.getRepoID(), repoConfig.getRepoName(), file, parentPath, absPathPair.getThird(), isRemoteExists);
+ FileTransferEntity fileTransferEntity = FileTransferEntity.convert2ThisForUploadMediaSyncWorker(account, file, parentPath, absPathPair.getThird(), isRemoteExists);
transferList.add(fileTransferEntity);
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java
index 6333bf534..8093e0f9f 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFileManuallyWorker.java
@@ -96,9 +96,9 @@ private ListenableWorker.Result start() {
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);
+ AppDatabase.getInstance().fileTransferDAO().cancelWithFileBackup(transferEntity.related_account, TransferResult.OUT_OF_QUOTA);
- finishFlagEvent = TransferEvent.EVENT_CANCEL_OUT_OF_QUOTA;
+ finishFlagEvent = TransferEvent.EVENT_CANCEL_WITH_OUT_OF_QUOTA;
break;
}
} catch (Exception e) {
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java
index 174e2813f..2af843848 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadFolderFileAutomaticallyWorker.java
@@ -27,6 +27,7 @@
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.folder_backup.RepoConfig;
import java.util.List;
import java.util.UUID;
@@ -65,36 +66,46 @@ public void onStopped() {
super.onStopped();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- SLogs.e("文件夹备份已停止:" + getStopReason());
+ SLogs.e("Folder backup stopped, reason:" + getStopReason());
}
}
+ private boolean isFirstShow = true;
+ private void startShowNotification(){
+ if (!isFirstShow) {
+ return;
+ }
+
+ isFirstShow = false;
+ ForegroundInfo foregroundInfo = notificationManager.getForegroundNotification();
+ showForegroundAsync(foregroundInfo);
+
+
+ sendEvent(TransferEvent.EVENT_TRANSFERRING, TransferDataSource.FILE_BACKUP);
+ }
+
private Result start() {
// notificationManager.cancel();
+ SLogs.d("start upload file worker");
Account account = SupportAccountManager.getInstance().getCurrentAccount();
if (account == null) {
return Result.success();
}
- boolean isEnable = FolderBackupSharePreferenceHelper.readBackupSwitch();
- if (!isEnable) {
+ boolean canExec = can();
+ if (!canExec) {
return Result.success();
}
- boolean isUploaded = false;
-
-
- ForegroundInfo foregroundInfo = notificationManager.getForegroundNotification();
- showForegroundAsync(foregroundInfo);
+ if (repoConfig == null) {
+ return Result.success();
+ }
-// notificationManager.showNotification();
+ boolean isUploaded = false;
String finishFlagEvent = null;
- SLogs.d("start upload file worker");
- sendEvent(TransferEvent.EVENT_TRANSFERRING, TransferDataSource.FILE_BACKUP);
-
while (true) {
if (isStopped()) {
break;
@@ -113,9 +124,14 @@ private Result start() {
break;
}
- FileTransferEntity transferEntity = transferList.get(0);
+ startShowNotification();
+
isUploaded = true;
+ FileTransferEntity transferEntity = transferList.get(0);
+ transferEntity.repo_id = repoConfig.getRepoID();
+ transferEntity.repo_name = repoConfig.getRepoName();
+
try {
transferFile(account, transferEntity);
@@ -126,15 +142,19 @@ private Result start() {
TransferResult transferResult = onException(transferEntity, e);
- notifyError(transferResult);
+ if (!isStopped()) {
+
+ notifyError(transferResult);
- sendTransferEvent(transferEntity, false);
+ sendTransferEvent(transferEntity, false);
+ }
String finishFlag = isInterrupt(transferResult);
if (!TextUtils.isEmpty(finishFlag)) {
finishFlagEvent = finishFlag;
break;
}
+
}
}
@@ -170,4 +190,25 @@ private Result start() {
return Result.success(outputData);
}
+ private RepoConfig repoConfig;
+
+ private boolean can() {
+ boolean isTurnOn = FolderBackupSharePreferenceHelper.readBackupSwitch();
+ if (!isTurnOn) {
+ return false;
+ }
+
+ List backupPaths = FolderBackupSharePreferenceHelper.readBackupPathsAsList();
+ if (CollectionUtils.isEmpty(backupPaths)) {
+ return false;
+ }
+
+ repoConfig = FolderBackupSharePreferenceHelper.readRepoConfig();
+ if (repoConfig == null) {
+ return false;
+ }
+
+ return true;
+ }
+
}
diff --git a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java
index dd568ac18..9a6c6f590 100644
--- a/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java
+++ b/app/src/main/java/com/seafile/seadroid2/framework/worker/upload/UploadMediaFileAutomaticallyWorker.java
@@ -22,12 +22,14 @@
import com.seafile.seadroid2.enums.TransferDataSource;
import com.seafile.seadroid2.enums.TransferResult;
import com.seafile.seadroid2.framework.datastore.sp_livedata.AlbumBackupSharePreferenceHelper;
+import com.seafile.seadroid2.framework.datastore.sp_livedata.FolderBackupSharePreferenceHelper;
import com.seafile.seadroid2.framework.notification.AlbumBackupNotificationHelper;
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 com.seafile.seadroid2.ui.folder_backup.RepoConfig;
import java.util.List;
import java.util.UUID;
@@ -54,9 +56,24 @@ public BaseTransferNotificationHelper getNotification() {
return albumNotificationHelper;
}
+ boolean isFirstShow = true;
+ private void startShowNotification(){
+ if (!isFirstShow) {
+ return;
+ }
+
+ //send start transfer event
+ sendEvent(TransferEvent.EVENT_TRANSFERRING, TransferDataSource.ALBUM_BACKUP);
+
+ // show foreground notification
+ ForegroundInfo foregroundInfo = albumNotificationHelper.getForegroundNotification();
+ showForegroundAsync(foregroundInfo);
+ }
+
@NonNull
@Override
public ListenableWorker.Result doWork() {
+ SLogs.d("start upload media worker");
Account account = SupportAccountManager.getInstance().getCurrentAccount();
if (account == null) {
@@ -66,17 +83,14 @@ public ListenableWorker.Result doWork() {
return ListenableWorker.Result.success();
}
- boolean isEnable = AlbumBackupSharePreferenceHelper.readBackupSwitch();
- if (!isEnable) {
- return ListenableWorker.Result.success();
+ boolean canExec = can();
+ if (!canExec) {
+ return Result.success();
}
- //send start transfer event
- sendEvent(TransferEvent.EVENT_TRANSFERRING, TransferDataSource.ALBUM_BACKUP);
-
- // show foreground notification
- ForegroundInfo foregroundInfo = albumNotificationHelper.getForegroundNotification();
- showForegroundAsync(foregroundInfo);
+ if (repoConfig == null) {
+ return Result.success();
+ }
//
String finishFlagEvent = null;
@@ -86,8 +100,6 @@ public ListenableWorker.Result doWork() {
break;
}
- SLogs.d("start upload media worker");
-
List transferList = AppDatabase
.getInstance()
.fileTransferDAO()
@@ -99,11 +111,15 @@ public ListenableWorker.Result doWork() {
break;
}
- FileTransferEntity transferEntity = transferList.get(0);
+ startShowNotification();
isUploaded = true;
- try {
+ FileTransferEntity transferEntity = transferList.get(0);
+ transferEntity.repo_id = repoConfig.getRepoID();
+ transferEntity.repo_name = repoConfig.getRepoName();
+
+ try {
transferFile(account, transferEntity);
sendTransferEvent(transferEntity, true);
@@ -113,9 +129,11 @@ public ListenableWorker.Result doWork() {
TransferResult transferResult = onException(transferEntity, e);
- notifyError(transferResult);
+ if (!isStopped()) {
+ notifyError(transferResult);
- sendTransferEvent(transferEntity, false);
+ sendTransferEvent(transferEntity, false);
+ }
String finishFlag = isInterrupt(transferResult);
if (!TextUtils.isEmpty(finishFlag)) {
@@ -156,4 +174,20 @@ public ListenableWorker.Result doWork() {
.build();
return Result.success(outputData);
}
+
+ private RepoConfig repoConfig;
+
+ private boolean can() {
+ boolean isTurnOn = AlbumBackupSharePreferenceHelper.readBackupSwitch();
+ if (!isTurnOn) {
+ return false;
+ }
+
+ repoConfig = AlbumBackupSharePreferenceHelper.readRepoConfig();
+ if (repoConfig == null) {
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/app/src/main/java/com/seafile/seadroid2/listener/FileTransferProgressListener.java b/app/src/main/java/com/seafile/seadroid2/listener/FileTransferProgressListener.java
index 67ea45d50..426afc6cd 100644
--- a/app/src/main/java/com/seafile/seadroid2/listener/FileTransferProgressListener.java
+++ b/app/src/main/java/com/seafile/seadroid2/listener/FileTransferProgressListener.java
@@ -43,10 +43,26 @@ public void onProgressNotify(long cur, long total) {
fileTransferEntity.transferred_size = cur;
- int percent = (int) ((float) cur / (float) total * 100);
+ int percent = calcu(cur, total);
progressListener.onProgressNotify(fileTransferEntity, percent, cur, total);
}
+ public int onProgress(long cur, long total) {
+
+ long nowt = System.currentTimeMillis();
+ if (nowt - temp < 1000) {
+ return -1;
+ }
+
+ temp = nowt;
+ return calcu(cur, total);
+ }
+
+ public int calcu(long cur, long total) {
+ int percent = (int) ((float) cur / (float) total * 100);
+ return percent;
+ }
+
public interface TransferProgressListener {
void onProgressNotify(FileTransferEntity fileTransferEntity, int percent, long transferredSize, long totalSize);
}
diff --git a/app/src/main/java/com/seafile/seadroid2/preferences/ContextStackPreferenceHelper.java b/app/src/main/java/com/seafile/seadroid2/preferences/ContextStackPreferenceHelper.java
new file mode 100644
index 000000000..745bf1776
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/preferences/ContextStackPreferenceHelper.java
@@ -0,0 +1,34 @@
+package com.seafile.seadroid2.preferences;
+
+import com.blankj.utilcode.util.GsonUtils;
+import com.google.gson.reflect.TypeToken;
+import com.seafile.seadroid2.framework.data.model.ContextModel;
+import com.seafile.seadroid2.framework.datastore.DataStoreKeys;
+
+import java.lang.reflect.Type;
+import java.util.Stack;
+
+public class ContextStackPreferenceHelper {
+ private static final String STACK_KEY = DataStoreKeys.KEY_NAV_CONTEXT_STACK;
+
+ // save Stack to SharedPreferences
+ public static void saveStack(Stack stack) {
+ String json = GsonUtils.toJson(stack);
+ Settings.getCommonPreferences().edit().putString(STACK_KEY, json).apply();
+ }
+
+ public static void clearStack() {
+ Settings.getCommonPreferences().edit().remove(STACK_KEY).apply();
+ }
+
+ public static Stack getStack() {
+ String json = Settings.getCommonPreferences().getString(STACK_KEY, null);
+ if (json == null) {
+ return new Stack<>();
+ }
+
+ Type type = new TypeToken>() {
+ }.getType();
+ return GsonUtils.fromJson(json, type);
+ }
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/preferences/Settings.java b/app/src/main/java/com/seafile/seadroid2/preferences/Settings.java
index 2519d4d0c..86be26851 100644
--- a/app/src/main/java/com/seafile/seadroid2/preferences/Settings.java
+++ b/app/src/main/java/com/seafile/seadroid2/preferences/Settings.java
@@ -47,8 +47,11 @@ public Settings() {
//////////////////
public static SettingsLiveData USER_INFO;
public static SettingsLiveData SPACE_INFO;
+ public static SettingsLiveData USER_SERVER_INFO;
public static SettingsLiveData NIGHT_MODE;
public static SettingsLiveData APP_NIGHT_MODE;
+
+ @Deprecated
public static SettingsLiveData USER_GESTURE_LOCK_SWITCH;
// public static SettingsLiveData USER_GESTURE_LOCK_TIMESTAMP;
@@ -135,11 +138,12 @@ public static void initUserSettings(Account account) {
//user
USER_INFO = new StringSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_user_info, R.string.settings_account_info_load_data);
SPACE_INFO = new StringSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_user_space, R.string.settings_account_info_load_data);
+ USER_SERVER_INFO = new StringSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_user_server, Resources.ID_NULL);
NIGHT_MODE = new EnumSettingLiveData<>(NightMode.class, _account.getEncryptSignature(), R.string.pref_key_night_mode, R.string.pref_default_value_night_mode);
APP_NIGHT_MODE = new EnumSettingLiveData<>(NightMode.class, _account.getEncryptSignature(), R.string.pref_key_current_night_mode, R.string.pref_default_value_night_mode);
- CLIENT_ENCRYPT_SWITCH = new BooleanSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_security_client_encrypt);
+// CLIENT_ENCRYPT_SWITCH = new BooleanSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_security_client_encrypt);
- USER_GESTURE_LOCK_SWITCH = new BooleanSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_gesture_lock);
+// USER_GESTURE_LOCK_SWITCH = new BooleanSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_gesture_lock);
// USER_GESTURE_LOCK_TIMESTAMP = new LongSettingLiveData(_account.getEncryptSignature(), R.string.pref_key_gesture_lock_timestamp, R.string.pref_default_value_key_gesture_lock_timestamp);
@@ -167,11 +171,12 @@ public static void initUserSettings(Account account) {
REGISTER_LIST.add(USER_INFO);
REGISTER_LIST.add(SPACE_INFO);
+ REGISTER_LIST.add(USER_SERVER_INFO);
REGISTER_LIST.add(NIGHT_MODE);
REGISTER_LIST.add(APP_NIGHT_MODE);
- REGISTER_LIST.add(USER_GESTURE_LOCK_SWITCH);
+// REGISTER_LIST.add(USER_GESTURE_LOCK_SWITCH);
// REGISTER_LIST.add(USER_GESTURE_LOCK_TIMESTAMP);
- REGISTER_LIST.add(CLIENT_ENCRYPT_SWITCH);
+// REGISTER_LIST.add(CLIENT_ENCRYPT_SWITCH);
REGISTER_LIST.add(ALBUM_BACKUP_SWITCH);
REGISTER_LIST.add(ALBUM_BACKUP_SELECTED_REPO);
REGISTER_LIST.add(ALBUM_BACKUP_STATE);
diff --git a/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java b/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java
index afcccb1be..388e701ca 100644
--- a/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java
+++ b/app/src/main/java/com/seafile/seadroid2/provider/SeafileProvider.java
@@ -917,13 +917,17 @@ private void includeStarredFileDirent(MatrixCursor result, Account account, Star
* @param path the path of the directory.
* @param result Cursor object over which to signal the client.
*/
- private void fetchDirentAsync(Account account, RepoModel repoModel, final String path, MatrixCursor result) {
+ private void fetchDirentAsync(Account account, RepoModel repoModel, String path, MatrixCursor result) {
String id = DocumentIdParser.buildId(account, repoModel.repo_id, path);
final Uri uri = DocumentsContract.buildChildDocumentsUri(AUTHORITY_OF_DOCUMENTS, id);
result.setNotificationUri(getContext().getContentResolver(), uri);
+ if (!path.endsWith("/")) {
+ path = path + "/";
+ }
+
Single> resultSingle = Objs.getDirentsSingleFromServer(account, repoModel.repo_id, repoModel.repo_name, path);
Disposable disposable = resultSingle.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
diff --git a/app/src/main/java/com/seafile/seadroid2/ssl/CertsManager.java b/app/src/main/java/com/seafile/seadroid2/ssl/CertsManager.java
index d39f018d5..2cdf472a6 100644
--- a/app/src/main/java/com/seafile/seadroid2/ssl/CertsManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/ssl/CertsManager.java
@@ -17,7 +17,7 @@
*/
public final class CertsManager {
- private final Map cachedCerts = Maps.newConcurrentMap();
+ private final Map cachedCerts = Maps.newConcurrentMap();
private static CertsManager instance;
@@ -36,7 +36,7 @@ public void saveCertForAccount(final Account account, boolean rememberChoice) {
}
final X509Certificate cert = certs.get(0);
- cachedCerts.put(account, cert);
+ cachedCerts.put(account.getServer(), cert);
if (rememberChoice) {
// save cert info to shared preferences
@@ -46,12 +46,23 @@ public void saveCertForAccount(final Account account, boolean rememberChoice) {
}
}
+ public void deleteCertForAccount(final Account account) {
+ if (account == null) {
+ return;
+ }
+
+ cachedCerts.remove(account.getServer());
+
+ String keyPrefix = EncryptUtils.encryptMD5ToString(account.getServer());
+ Settings.getCommonPreferences().edit().remove(DataStoreKeys.KEY_SERVER_CERT_INFO + "_" + keyPrefix).apply();
+ }
public X509Certificate getCertificate(Account account) {
- X509Certificate cert = cachedCerts.get(account);
+ X509Certificate cert = cachedCerts.get(account.getServer());
if (cert != null) {
return cert;
}
+
String keyPrefix = EncryptUtils.encryptMD5ToString(account.getServer());
String certBase64 = Settings.getCommonPreferences().getString(DataStoreKeys.KEY_SERVER_CERT_INFO + "_" + keyPrefix, null);
if (TextUtils.isEmpty(certBase64)) {
@@ -60,7 +71,7 @@ public X509Certificate getCertificate(Account account) {
cert = CertsHelper.convertToCert(certBase64);
if (cert != null) {
- cachedCerts.put(account, cert);
+ cachedCerts.put(account.getServer(), cert);
}
return cert;
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 fc0ea4f36..c75f1312c 100644
--- a/app/src/main/java/com/seafile/seadroid2/ssl/SSLTrustManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/ssl/SSLTrustManager.java
@@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Set;
+import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java
index b96d0ce27..7dc20596b 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountDetailActivity.java
@@ -1,40 +1,24 @@
package com.seafile.seadroid2.ui.account;
-import android.app.Dialog;
import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
-import android.text.method.HideReturnsTransformationMethod;
-import android.text.method.PasswordTransformationMethod;
import android.util.Log;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
-import android.widget.Button;
-import android.widget.CheckBox;
import android.widget.CompoundButton;
-import android.widget.EditText;
-import android.widget.ImageView;
-import android.widget.TextView;
-import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.NavUtils;
import androidx.core.app.TaskStackBuilder;
import androidx.lifecycle.Observer;
-import com.blankj.utilcode.constant.RegexConstants;
import com.blankj.utilcode.util.NetworkUtils;
-import com.blankj.utilcode.util.RegexUtils;
-import com.google.android.material.button.MaterialButton;
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-import com.google.android.material.textfield.TextInputEditText;
-import com.google.android.material.textfield.TextInputLayout;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.account.Account;
@@ -150,9 +134,9 @@ private void initViewModel() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
- showProgressDialog();
+ showLoadingDialog();
} else {
- dismissProgressDialog();
+ dismissLoadingDialog();
}
}
});
@@ -274,7 +258,7 @@ private void onLoggedIn(Account loginAccount) {
@Override
protected void onDestroy() {
- dismissProgressDialog();
+ dismissLoadingDialog();
super.onDestroy();
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountViewModel.java b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountViewModel.java
index a79bcc7e0..db2cfc8dc 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountViewModel.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountViewModel.java
@@ -17,6 +17,8 @@
import com.seafile.seadroid2.framework.http.HttpIO;
import com.seafile.seadroid2.account.AccountUtils;
import com.seafile.seadroid2.framework.util.DeviceIdManager;
+import com.seafile.seadroid2.preferences.ContextStackPreferenceHelper;
+import com.seafile.seadroid2.ssl.CertsManager;
import com.seafile.seadroid2.ui.base.viewmodel.BaseViewModel;
import com.seafile.seadroid2.ui.dialog_fragment.SignOutDialogFragment;
import com.seafile.seadroid2.ui.main.MainService;
@@ -181,7 +183,7 @@ private Call getLoginCall(Account tempAccount, String pwd, String to
body.put("client_version", appVersion);
body.put("platform_version", Build.VERSION.RELEASE);
- Map requestBody = generateRequestBody(body);
+ Map requestBody = genRequestBody(body);
return HttpIO.getInstanceByAccount(tempAccount).execute(AccountService.class).login(headers, requestBody);
}
@@ -214,9 +216,6 @@ public void accept(Throwable throwable) throws Exception {
});
}
- /**
- * @see SignOutDialogFragment#onPositiveClick()
- */
public void deleteAccount(Account account) {
Account curAccount = SupportAccountManager.getInstance().getCurrentAccount();
@@ -224,6 +223,9 @@ public void deleteAccount(Account account) {
if (curAccount != null && curAccount.equals(account)) {
//
AccountUtils.logout(account);
+ } else {
+ HttpIO.removeInstanceByAccount(account);
+ CertsManager.instance().deleteCertForAccount(account);
}
//delete local account
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java
index 97ee1984d..ce5e726df 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/account/AccountsActivity.java
@@ -3,7 +3,6 @@
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.OnAccountsUpdateListener;
-import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@@ -21,7 +20,6 @@
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.framework.data.ServerInfo;
import com.seafile.seadroid2.framework.datastore.sp.AppDataManager;
@@ -157,9 +155,9 @@ private void initViewModel() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
- showProgressDialog();
+ showLoadingDialog();
} else {
- dismissProgressDialog();
+ dismissLoadingDialog();
}
}
});
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/account/SeafileAuthenticatorActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/account/SeafileAuthenticatorActivity.java
index a993ea2a5..6267eb6c1 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/account/SeafileAuthenticatorActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/account/SeafileAuthenticatorActivity.java
@@ -23,13 +23,13 @@
import androidx.core.app.NavUtils;
import androidx.core.app.TaskStackBuilder;
-import com.google.firebase.analytics.FirebaseAnalytics;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.account.Authenticator;
import com.seafile.seadroid2.account.SupportAccountManager;
import com.seafile.seadroid2.config.Constants;
import com.seafile.seadroid2.framework.http.HttpIO;
import com.seafile.seadroid2.framework.util.SLogs;
+import com.seafile.seadroid2.preferences.ContextStackPreferenceHelper;
import com.seafile.seadroid2.ui.camera_upload.CameraUploadManager;
import java.util.Locale;
@@ -294,6 +294,8 @@ private void finishLogin(Intent intent) {
SupportAccountManager.getInstance().setUserData(newAccount, Authenticator.KEY_SHIB, "shib");
}
+ //
+ ContextStackPreferenceHelper.clearStack();
//save current account
SupportAccountManager.getInstance().saveCurrentAccount(newAccountName);
//reset httpio instance
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 24d1dfbc4..923e76dcb 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
@@ -40,7 +40,7 @@
import com.seafile.seadroid2.ui.file.FileActivity;
import com.seafile.seadroid2.ui.main.MainActivity;
import com.seafile.seadroid2.ui.markdown.MarkdownActivity;
-import com.seafile.seadroid2.ui.media.image_preview.ImagePreviewActivity;
+import com.seafile.seadroid2.ui.media.image_preview2.CarouselImagePreviewActivity;
import com.seafile.seadroid2.ui.media.player.exoplayer.CustomExoVideoPlayerActivity;
import com.seafile.seadroid2.ui.sdoc.SDocWebViewActivity;
import com.seafile.seadroid2.view.TipsViews;
@@ -97,12 +97,12 @@ public void onFirstResume() {
private void initAdapter() {
adapter = new ActivityAdapter();
+
TextView tipView = TipsViews.getTipTextView(requireContext());
tipView.setText(R.string.no_starred_file);
tipView.setOnClickListener(v -> reload());
adapter.setStateView(tipView);
adapter.setStateViewEnable(false);
- adapter.setAnimationEnable(true);
adapter.setOnItemClickListener((baseQuickAdapter, view, i) -> {
ActivityModel activityModel = (ActivityModel) adapter.getItems().get(i);
@@ -274,7 +274,7 @@ private void open(RepoModel repoModel, ActivityModel activityModel) {
} else if (Utils.isViewableImage(activityModel.name)) {
- Intent getIntent = ImagePreviewActivity.startThisFromActivity(requireContext(), activityModel);
+ Intent getIntent = CarouselImagePreviewActivity.startThisFromActivity(requireContext(), activityModel);
imagePreviewActivityLauncher.launch(getIntent);
} else if (activityModel.name.endsWith(Constants.Format.DOT_SDOC)) {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activities/MineActivitiesFragment.java b/app/src/main/java/com/seafile/seadroid2/ui/activities/MineActivitiesFragment.java
index 69369814b..882e38022 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/activities/MineActivitiesFragment.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/activities/MineActivitiesFragment.java
@@ -12,15 +12,17 @@
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeafException;
-import com.seafile.seadroid2.ui.base.fragment.BaseFragmentWithVM;
+import com.seafile.seadroid2.annotation.NotSupport;
import com.seafile.seadroid2.databinding.LayoutFrameSwipeRvBinding;
import com.seafile.seadroid2.framework.data.model.activities.ActivityModel;
+import com.seafile.seadroid2.ui.base.fragment.BaseFragmentWithVM;
import com.seafile.seadroid2.view.TipsViews;
import java.util.List;
import kotlin.Pair;
+@NotSupport
@Deprecated
public class MineActivitiesFragment extends BaseFragmentWithVM {
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java
index db0bf401e..34702fc2e 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/base/BaseActivity.java
@@ -3,15 +3,12 @@
import android.app.Dialog;
import android.os.Bundle;
-import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.seafile.seadroid2.R;
-import com.seafile.seadroid2.framework.helper.NightModeHelper;
/**
* A base activity that handles common functionality in the app. This includes Action Bar tweaks.
@@ -50,31 +47,31 @@ public void setContentView(int layoutResID) {
getActionBarToolbar();
}
- private Dialog dialog;
+ private Dialog loadingDialog;
- public void showProgressDialog(boolean isShow) {
+ public void showLoadingDialog(boolean isShow) {
if (isShow) {
- showProgressDialog();
+ showLoadingDialog();
} else {
- dismissProgressDialog();
+ dismissLoadingDialog();
}
}
- public void showProgressDialog() {
- if (dialog == null) {
+ public void showLoadingDialog() {
+ if (loadingDialog == null) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this);
builder.setView(R.layout.layout_dialog_progress_bar);
- dialog = builder.create();
+ loadingDialog = builder.create();
}
- if (!dialog.isShowing()) {
- dialog.show();
+ if (!loadingDialog.isShowing()) {
+ loadingDialog.show();
}
}
- public void dismissProgressDialog() {
- if (dialog != null && dialog.isShowing()) {
- dialog.dismiss();
+ public void dismissLoadingDialog() {
+ if (loadingDialog != null && loadingDialog.isShowing()) {
+ loadingDialog.dismiss();
}
}
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/BaseMediaSelectorActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/base/BaseMediaSelectorActivity.java
new file mode 100644
index 000000000..e38c5bb2e
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/ui/base/BaseMediaSelectorActivity.java
@@ -0,0 +1,174 @@
+package com.seafile.seadroid2.ui.base;
+
+import android.Manifest;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.MenuItem;
+
+import androidx.activity.result.ActivityResultCallback;
+import androidx.activity.result.ActivityResultLauncher;
+import androidx.activity.result.PickVisualMediaRequest;
+import androidx.activity.result.contract.ActivityResultContracts;
+
+import com.blankj.utilcode.util.ToastUtils;
+import com.seafile.seadroid2.R;
+import com.seafile.seadroid2.framework.util.SLogs;
+import com.seafile.seadroid2.framework.util.TakeCameras;
+import com.seafile.seadroid2.ui.base.viewmodel.BaseViewModel;
+import com.seafile.seadroid2.ui.bottomsheetmenu.BottomSheetHelper;
+import com.seafile.seadroid2.ui.bottomsheetmenu.OnMenuClickListener;
+
+import java.io.File;
+import java.util.List;
+
+import kotlin.Pair;
+
+public class BaseMediaSelectorActivity extends BaseActivityWithVM {
+ private ActivityResultLauncher cameraPermissionLauncher, cameraPermissionLauncher1, storagePermissionLauncher;
+ private ActivityResultLauncher takePhotoLauncher;
+ private ActivityResultLauncher shootVideoLauncher;
+ private ActivityResultLauncher pickMediaLauncher;
+ private ActivityResultLauncher pickMultipleMediaLauncher;
+ private ActivityResultLauncher fileChooseLauncher;
+ private Pair uriPair;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ initLauncher();
+ }
+
+ private void initLauncher() {
+ cameraPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Boolean result) {
+ if (result) {
+ uriPair = TakeCameras.buildTakePhotoUri(BaseMediaSelectorActivity.this);
+ takePhotoLauncher.launch(uriPair.getFirst());
+ } else {
+ ToastUtils.showLong(R.string.permission_camera);
+ }
+ }
+ });
+
+ cameraPermissionLauncher1 = registerForActivityResult(new ActivityResultContracts.RequestPermission(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Boolean result) {
+ if (result) {
+ uriPair = TakeCameras.buildTakePhotoUri(BaseMediaSelectorActivity.this);
+ shootVideoLauncher.launch(uriPair.getFirst());
+ } else {
+ ToastUtils.showLong(R.string.permission_camera);
+ }
+ }
+ });
+
+ storagePermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Boolean o) {
+ if (o) {
+ fileChooseLauncher.launch("*/*");
+ } else {
+ ToastUtils.showLong(R.string.permission_manage_external_storage_rationale);
+ }
+ }
+ });
+
+ takePhotoLauncher = registerForActivityResult(new ActivityResultContracts.TakePicture(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Boolean o) {
+ if (!o) {
+ return;
+ }
+ onMediaPicked(uriPair.getFirst());
+ }
+ });
+
+ shootVideoLauncher = registerForActivityResult(new ActivityResultContracts.CaptureVideo(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Boolean o) {
+ if (!o) {
+ return;
+ }
+ onMediaPicked(uriPair.getFirst());
+ }
+ });
+
+ pickMediaLauncher = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Uri o) {
+ onMediaPicked(o);
+ }
+ });
+
+ pickMultipleMediaLauncher = registerForActivityResult(new ActivityResultContracts.PickMultipleVisualMedia(9), new ActivityResultCallback>() {
+ @Override
+ public void onActivityResult(List o) {
+ for (Uri uri : o) {
+ onMediaPicked(uri);
+ }
+ }
+ });
+
+ fileChooseLauncher = registerForActivityResult(new ActivityResultContracts.GetContent(), new ActivityResultCallback() {
+ @Override
+ public void onActivityResult(Uri o) {
+ onMediaPicked(o);
+ }
+ });
+ }
+
+ public void onMediaPicked(Uri uri) {
+ SLogs.d(uri.toString());
+ }
+
+ ///////////////////////////////////////////////////////
+
+ public void showPickPhotoSheetDialog(boolean isPickMultiWhenMenuIdIsViewFile) {
+ BottomSheetHelper.buildSheet(this, R.menu.bottom_sheet_camera_album_select, new OnMenuClickListener() {
+ @Override
+ public void onMenuClick(MenuItem menuItem) {
+ if (menuItem.getItemId() == R.id.take_photo) {
+ cameraPermissionLauncher.launch(Manifest.permission.CAMERA);
+ } else if (menuItem.getItemId() == R.id.view_file) {
+ if (isPickMultiWhenMenuIdIsViewFile) {
+ pickMultipleMediaLauncher.launch(new PickVisualMediaRequest.Builder()
+ .setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
+ .build());
+ } else {
+ pickMediaLauncher.launch(new PickVisualMediaRequest.Builder()
+ .setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
+ .build());
+ }
+ }
+ }
+ }).show(getSupportFragmentManager());
+ }
+
+ public void showPickPhotoAndVideoSheetDialog(boolean isPickMultiWhenMenuIdIsViewFile) {
+ BottomSheetHelper.buildSheet(this, R.menu.bottom_sheet_camera_album_select, new OnMenuClickListener() {
+ @Override
+ public void onMenuClick(MenuItem menuItem) {
+ if (menuItem.getItemId() == R.id.take_photo) {
+ cameraPermissionLauncher.launch(Manifest.permission.CAMERA);
+ } else if (menuItem.getItemId() == R.id.view_file) {
+ if (isPickMultiWhenMenuIdIsViewFile) {
+ pickMultipleMediaLauncher.launch(new PickVisualMediaRequest.Builder()
+ .setMediaType(ActivityResultContracts.PickVisualMedia.ImageAndVideo.INSTANCE)
+ .build());
+ } else {
+ pickMediaLauncher.launch(new PickVisualMediaRequest.Builder()
+ .setMediaType(ActivityResultContracts.PickVisualMedia.ImageAndVideo.INSTANCE)
+ .build());
+ }
+ }
+ }
+ }).show(getSupportFragmentManager());
+ }
+
+ public void pickFile() {
+ storagePermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
+ }
+
+}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/base/adapter/BaseAdapter.java b/app/src/main/java/com/seafile/seadroid2/ui/base/adapter/BaseAdapter.java
index a4e8203a0..6d98aa141 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/base/adapter/BaseAdapter.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/base/adapter/BaseAdapter.java
@@ -8,6 +8,4 @@ public abstract class BaseAdapter extends BaseQuic
public void d(String d) {
SLogs.d(this.getClass().getSimpleName() + " => " + d);
}
-
-
}
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 3de25e4de..d661b7ebc 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
@@ -1,7 +1,11 @@
package com.seafile.seadroid2.ui.base.fragment;
+import android.app.Dialog;
+
import androidx.fragment.app.Fragment;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.seafile.seadroid2.R;
import com.seafile.seadroid2.framework.util.SLogs;
public class BaseFragment extends Fragment {
@@ -29,4 +33,32 @@ public void onFirstResume() {
public void onOtherResume() {
}
+
+ private Dialog dialog;
+
+ public void showLoadingDialog(boolean isShow) {
+ if (isShow) {
+ showLoadingDialog();
+ } else {
+ dismissLoadingDialog();
+ }
+ }
+
+ public void showLoadingDialog() {
+ if (dialog == null) {
+ MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext());
+ builder.setView(R.layout.layout_dialog_progress_bar);
+ dialog = builder.create();
+ }
+
+ if (!dialog.isShowing()) {
+ dialog.show();
+ }
+ }
+
+ public void dismissLoadingDialog() {
+ if (dialog != null && dialog.isShowing()) {
+ dialog.dismiss();
+ }
+ }
}
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 8cbc4d260..d0cf1911f 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
@@ -13,6 +13,7 @@
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.SeafException;
+import com.seafile.seadroid2.annotation.Todo;
import com.seafile.seadroid2.framework.data.model.ResultModel;
import com.seafile.seadroid2.framework.http.HttpIO;
import com.seafile.seadroid2.framework.util.SLogs;
@@ -27,6 +28,7 @@
import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
@@ -118,7 +120,19 @@ protected void onCleared() {
}
}
- public Map generateRequestBody(Map requestDataMap) {
+
+ @Todo
+ public Map genObjRequestBody(Map params) {
+ Map requestBodyMap = new HashMap<>();
+ for (Map.Entry entry : params.entrySet()) {
+ String value = entry.getValue().toString();
+ RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), value);
+ requestBodyMap.put(entry.getKey(), requestBody);
+ }
+ return requestBodyMap;
+ }
+
+ public Map genRequestBody(Map requestDataMap) {
Map requestBodyMap = new HashMap<>();
if (requestDataMap == null || requestDataMap.isEmpty()) {
requestBodyMap.put("x-test", RequestBody.create(MediaType.parse("multipart/form-data"), "test"));
@@ -181,7 +195,6 @@ public void addFlowableDisposable(Flowable flowable, Consumer onNext,
.subscribe(onNext, throwable, onComplete));
}
-
public void addCompletableDisposable(Completable completable, Action action) {
compositeDisposable.add(completable
.subscribeOn(Schedulers.io())
@@ -250,11 +263,16 @@ public SeafException getExceptionByThrowable(Throwable throwable) throws IOExcep
return SeafException.notFoundException;
}
+
//HTTP_STATUS_REPO_PASSWORD_REQUIRED
if (440 == httpException.code()) {
return SeafException.invalidPassword;
}
+// //500: HTTP_INTERNAL_ERROR
+// if (HttpURLConnection.HTTP_INTERNAL_ERROR == httpException.code()) {
+// return SeafException.networkException;
+// }
if (resp != null) {
try {
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 f0c0e647d..a74964f84 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
@@ -6,7 +6,6 @@
import android.content.Context;
import android.content.SyncResult;
import android.os.Bundle;
-import android.util.Log;
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.SupportAccountManager;
@@ -50,14 +49,14 @@ public boolean onUnsyncableAccount() {
public void onSyncCanceled(Thread thread) {
super.onSyncCanceled(thread);
SLogs.e("onSyncCanceled ->" + thread.getName());
- BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker();
+ BackgroundJobManagerImpl.getInstance().cancelMediaWorker();
}
@Override
public void onSyncCanceled() {
super.onSyncCanceled();
SLogs.e("onSyncCanceled");
- BackgroundJobManagerImpl.getInstance().cancelAllMediaWorker();
+ BackgroundJobManagerImpl.getInstance().cancelMediaWorker();
}
@Override
@@ -66,13 +65,11 @@ public void onPerformSync(android.accounts.Account account,
ContentProviderClient provider,
SyncResult syncResult) {
- SLogs.e("onPerformSync!");
+ boolean isForce = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL);
+ SLogs.e("albumBackupAdapter - onPerformSync, isForce -> " + isForce);
Account seafileAccount = SupportAccountManager.getInstance().getSeafileAccount(account);
- /**
- * this should never occur, as camera upload is supposed to be disabled once the camera upload
- * account signs out.
- */
+ // this should never occur, as camera upload is supposed to be disabled once the camera upload account signs out.
if (!seafileAccount.hasValidToken()) {
SLogs.e("This account has no auth token. Disable camera upload.");
syncResult.stats.numAuthExceptions++;
@@ -87,8 +84,7 @@ public void onPerformSync(android.accounts.Account account,
return;
}
- //start
- boolean isForce = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL);
- BackgroundJobManagerImpl.getInstance().startMediaChainWorker(isForce);
+ // start
+ BackgroundJobManagerImpl.getInstance().startMediaWorkerChain(isForce);
}
}
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java
index eef46c498..31fe7d0cc 100644
--- a/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java
+++ b/app/src/main/java/com/seafile/seadroid2/ui/camera_upload/CameraUploadManager.java
@@ -8,6 +8,7 @@
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.SupportAccountManager;
import com.seafile.seadroid2.framework.util.SLogs;
+import com.seafile.seadroid2.framework.worker.BackgroundJobManagerImpl;
import java.util.List;
@@ -122,6 +123,8 @@ public void disableCameraUpload() {
ContentResolver.cancelSync(account.getAndroidAccount(), AUTHORITY);
ContentResolver.setIsSyncable(account.getAndroidAccount(), AUTHORITY, 0);
}
+
+ BackgroundJobManagerImpl.getInstance().cancelMediaWorker();
}
/**
diff --git a/app/src/main/java/com/seafile/seadroid2/ui/comparator/NaturalOrderComparator.java b/app/src/main/java/com/seafile/seadroid2/ui/comparator/NaturalOrderComparator.java
new file mode 100644
index 000000000..fb7936e1e
--- /dev/null
+++ b/app/src/main/java/com/seafile/seadroid2/ui/comparator/NaturalOrderComparator.java
@@ -0,0 +1,98 @@
+package com.seafile.seadroid2.ui.comparator;
+
+import android.text.TextUtils;
+
+import com.seafile.seadroid2.framework.data.db.entities.DirentModel;
+import com.seafile.seadroid2.framework.data.db.entities.RepoModel;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Comparator;
+
+public class NaturalOrderComparator implements Comparator