From c5b4994d3bf8475d991a4d09ee1f2d13b9b93cd4 Mon Sep 17 00:00:00 2001 From: maxiaohong Date: Fri, 25 May 2018 16:09:31 +0800 Subject: [PATCH 1/4] update build version --- app/build.gradle | 38 +++++++++++++++++++------------------- build.gradle | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5b49680d1..e83a6b8a5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -91,25 +91,25 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" - compile "com.android.support:design:${rootProject.ext.supportLibVersion}" - compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' - compile 'com.github.kevinsawicki:http-request:6.0' - compile 'commons-io:commons-io:2.4' - compile 'com.google.guava:guava:18.0' - compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3' - compile 'com.cocosw:bottomsheet:1.3.1' - compile 'us.feras.mdv:markdownview:1.1.0' - compile 'com.commit451:PhotoView:1.2.4' - compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.1' - testCompile 'junit:junit:4.12' - testCompile 'org.robolectric:robolectric:3.0' - compile 'com.madgag.spongycastle:core:1.54.0.0' - compile 'com.madgag.spongycastle:prov:1.54.0.0' - compile 'com.shuyu:gsyVideoPlayer-java:2.1.0' - compile 'com.shuyu:gsyVideoPlayer-ex_so:2.1.0' - compile 'com.squareup.okhttp3:okhttp:3.9.1' + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" + implementation "com.android.support:design:${rootProject.ext.supportLibVersion}" + implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1' + implementation 'com.github.kevinsawicki:http-request:6.0' + implementation 'commons-io:commons-io:2.4' + implementation 'com.google.guava:guava:18.0' + implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.3' + implementation 'com.cocosw:bottomsheet:1.3.1' + implementation 'us.feras.mdv:markdownview:1.1.0' + implementation 'com.commit451:PhotoView:1.2.4' + implementation 'com.joanzapata.iconify:android-iconify-material-community:2.2.1' + testImplementation 'junit:junit:4.12' + testImplementation 'org.robolectric:robolectric:3.0' + implementation 'com.madgag.spongycastle:core:1.54.0.0' + implementation 'com.madgag.spongycastle:prov:1.54.0.0' + implementation 'com.shuyu:gsyVideoPlayer-java:2.1.0' + implementation 'com.shuyu:gsyVideoPlayer-ex_so:2.1.0' + implementation 'com.squareup.okhttp3:okhttp:3.9.1' } } diff --git a/build.gradle b/build.gradle index b888202c7..1ba238bfc 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.1' + classpath 'com.android.tools.build:gradle:3.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -25,5 +25,5 @@ ext { supportLibVersion = '27.0.0' // variable that can be referenced to keep support libs consistent minSdkVersion = 16 targetSdkVersion = 25 - buildToolsVersion = '26.0.2' + buildToolsVersion = '27.0.3' } From 7b4f263ee4af65063afe5096fff8bcabf946c33e Mon Sep 17 00:00:00 2001 From: maxiaohong Date: Fri, 25 May 2018 16:10:03 +0800 Subject: [PATCH 2/4] fix get documents file path error --- .../com/seafile/seadroid2/util/UriFilePath.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/seafile/seadroid2/util/UriFilePath.java b/app/src/main/java/com/seafile/seadroid2/util/UriFilePath.java index c64eceb11..089027a3d 100644 --- a/app/src/main/java/com/seafile/seadroid2/util/UriFilePath.java +++ b/app/src/main/java/com/seafile/seadroid2/util/UriFilePath.java @@ -9,6 +9,7 @@ import android.os.Environment; import android.provider.DocumentsContract; import android.provider.MediaStore; +import android.text.TextUtils; /** * @Description: [ get file path wiht Uri ] @@ -35,8 +36,18 @@ public static String getFileAbsolutePath(Activity context, Uri fileUri) { } } else if (isDownloadsDocument(fileUri)) { String id = DocumentsContract.getDocumentId(fileUri); - Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); - return getDataColumn(context, contentUri, null, null); + if (!TextUtils.isEmpty(id)) { + if (id.startsWith("raw:")) { + return id.replaceFirst("raw:", ""); + } + try { + Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + return getDataColumn(context, contentUri, null, null); + } catch (NumberFormatException e) { + return null; + } + } + return null; } else if (isMediaDocument(fileUri)) { String docId = DocumentsContract.getDocumentId(fileUri); String[] split = docId.split(":"); From 7efd643e8e7d7e4e25e8d4295d38a52044004395 Mon Sep 17 00:00:00 2001 From: maxiaohong Date: Sat, 26 May 2018 11:59:37 +0800 Subject: [PATCH 3/4] fix upload blocks file error to new version server --- .../com/seafile/seadroid2/SeafConnection.java | 156 +++++++++++++----- .../seafile/seadroid2/data/BlockInfoBean.java | 33 ++++ .../seadroid2/data/SeafRepoEncrypt.java | 8 - 3 files changed, 147 insertions(+), 50 deletions(-) create mode 100644 app/src/main/java/com/seafile/seadroid2/data/BlockInfoBean.java diff --git a/app/src/main/java/com/seafile/seadroid2/SeafConnection.java b/app/src/main/java/com/seafile/seadroid2/SeafConnection.java index a3d92bc31..ff407c3b0 100644 --- a/app/src/main/java/com/seafile/seadroid2/SeafConnection.java +++ b/app/src/main/java/com/seafile/seadroid2/SeafConnection.java @@ -14,6 +14,7 @@ import com.google.common.collect.Maps; import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.data.Block; +import com.seafile.seadroid2.data.BlockInfoBean; import com.seafile.seadroid2.data.DataManager; import com.seafile.seadroid2.data.FileBlocks; import com.seafile.seadroid2.data.ProgressMonitor; @@ -21,6 +22,7 @@ import com.seafile.seadroid2.ssl.SSLTrustManager; import com.seafile.seadroid2.util.Utils; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -33,6 +35,7 @@ import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URLEncoder; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -545,9 +548,22 @@ public Pair getBlock(String repoID, } public String uploadByBlocks(String repoID, String dir, String filePath, List blocks, boolean update, ProgressMonitor monitor) throws IOException, SeafException { - String url = getUploadLink(repoID, update, true); - Log.d(DEBUG_TAG, "UploadLink " + url); - return uploadBlocksCommon(url, repoID, dir, filePath, blocks, monitor, update); + + try { + LinkedList blkListId = new LinkedList<>(); + for (Block block : blocks) { + blkListId.addLast(block.getBlockId()); + } + String json = getBlockUploadLink(repoID, update, blkListId); + BlockInfoBean infoBean = BlockInfoBean.fromJson(json); + if (infoBean.blkIds.size() > 0) { + uploadBlocksCommon(infoBean.rawblksurl, infoBean.blkIds, dir, filePath, blocks, monitor, update); + } + commitUpload(infoBean.commiturl, blkListId, dir, filePath, update); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; } private File getFileFromLink(String dlink, String path, String localPath, @@ -752,29 +768,15 @@ public boolean setPassword(String repoID, String passwd) throws SeafException { } private String getUploadLink(String repoID, boolean update) throws SeafException { - return getUploadLink(repoID, update, false); - } - - private String getUploadLink(String repoID, boolean update, boolean byblock) throws SeafException { try { String apiPath; if (update) { - if (byblock) { - apiPath = "api2/repos/" + repoID + "/upload-"; - } else { - apiPath = "api2/repos/" + repoID + "/update-"; - } + apiPath = "api2/repos/" + repoID + "/update-link/"; } else { - apiPath = "api2/repos/" + repoID + "/upload-"; + apiPath = "api2/repos/" + repoID + "/upload-link/"; } - - if (byblock) { - apiPath = apiPath + "blks-link/"; - } else { - apiPath = apiPath + "link/"; - } - - HttpRequest req = prepareApiGetRequest(apiPath); + HttpRequest req; + req = prepareApiGetRequest(apiPath); checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK); String result = new String(req.bytes(), "UTF-8"); @@ -797,6 +799,68 @@ private String getUploadLink(String repoID, boolean update, boolean byblock) thr } } + + private String getBlockUploadLink(String repoID, boolean update, List blocksId) throws SeafException { + try { + String apiPath; + if (update) { + apiPath = "api2/repos/" + repoID + "/update-blks-link/"; + } else { + apiPath = "api2/repos/" + repoID + "/upload-blks-link/"; + } + HttpRequest req = prepareApiPostRequest(apiPath, true, null); + String ids = blocksId.toString().replace("[", "").replace("]", "").replace(" ", ""); + req.form("blklist", ids); + checkRequestResponseStatus(req, HttpURLConnection.HTTP_OK); + return new String(req.bytes(), "UTF-8"); + } catch (SeafException e) { + Log.d(DEBUG_TAG, e.getCode() + e.getMessage()); + throw e; + } catch (Exception e) { + String msg = e.getMessage(); + if (msg != null) + Log.d(DEBUG_TAG, msg); + else + Log.d(DEBUG_TAG, "get upload link error", e); + throw SeafException.unknownException; + } + } + + + /** + * commit blocks to server + */ + private String commitUpload(String link, List blkIds, String dir, String filePath, boolean update) + throws SeafException, IOException { + File file = new File(filePath); + if (!file.exists()) { + throw new SeafException(SeafException.OTHER_EXCEPTION, "File not exists"); + } + + MultipartBody.Builder builder = new MultipartBody.Builder(); + //set type + builder.setType(MultipartBody.FORM); + //set header ,to replace file + if (update) { + builder.addFormDataPart("replace", "1"); + } else { + builder.addFormDataPart("replace", "0"); + } + builder.addFormDataPart("parent_dir", dir); + builder.addFormDataPart("file_size", file.length() + ""); + builder.addFormDataPart("file_name", file.getName()); + JSONArray jsonArray = new JSONArray(blkIds); + builder.addFormDataPart("blockids", jsonArray.toString()); + RequestBody body = builder.build(); + Request request = new Request.Builder().url(link).post(body).build(); + Response response = RequestManager.getInstance().getClient().newCall(request).execute(); + if (response.isSuccessful()) { + return response.body().string(); + } + throw new SeafException(SeafException.OTHER_EXCEPTION, "File upload failed"); + } + + /** * Upload or update a file * @@ -829,12 +893,9 @@ private String uploadFileCommon(String link, String repoID, String dir, //set type builder.setType(MultipartBody.FORM); // "target_file" "parent_dir" must be "/" end off - if (!TextUtils.equals("/", dir)) { - dir = dir + "/"; - } - if (update) { - builder.addFormDataPart("target_file", dir); + String targetFilePath = Utils.pathJoin(dir, file.getName()); + builder.addFormDataPart("target_file", targetFilePath); } else { builder.addFormDataPart("parent_dir", dir); } @@ -844,15 +905,22 @@ private String uploadFileCommon(String link, String repoID, String dir, RequestBody body = builder.build(); //create Request final Request request = new Request.Builder().url(link).post(body).header("Authorization", "Token " + account.token).build(); - Response execute = RequestManager.getInstance().getClient().newCall(request).execute(); - return execute.body().string(); + Response response = RequestManager.getInstance().getClient().newCall(request).execute(); + if (response.isSuccessful()) { + String str = response.body().string(); + if (!TextUtils.isEmpty(str)) { + return str.replace("\"", ""); + } + } + throw new SeafException(SeafException.OTHER_EXCEPTION, "File upload failed"); } /** * Upload file blocks to server */ - private String uploadBlocksCommon(String link, String repoID, String dir, String filePath, List blocks, ProgressMonitor - monitor, boolean update) + private String uploadBlocksCommon(String link, List needUploadId, String dir, String filePath, List blocks, + ProgressMonitor + monitor, boolean update) throws SeafException, IOException { File file = new File(filePath); if (!file.exists()) { @@ -861,22 +929,26 @@ private String uploadBlocksCommon(String link, String repoID, String dir, String MultipartBody.Builder builder = new MultipartBody.Builder(); //set type builder.setType(MultipartBody.FORM); - //set header ,to replace file - if (update) { - builder.addFormDataPart("replace", "1"); - } - builder.addFormDataPart("parent_dir", dir); - builder.addFormDataPart("file_name", file.getName()); - builder.addFormDataPart("file_size", file.length() + ""); - for (Block block : blocks) { - File blk = new File(block.path); - builder.addFormDataPart("file", blk.getName(), RequestManager.getInstance().createProgressRequestBody(monitor, blk)); + builder.addFormDataPart("filename", file.getName()); + + for (int i = 0; i < blocks.size(); i++) { + Block block = blocks.get(i); + for (String s : needUploadId) { + if (s.equals(block.getBlockId())) { + File blk = new File(block.path); + builder.addFormDataPart("file", blk.getName(), RequestManager.getInstance().createProgressRequestBody(monitor, blk)); + break; + } + } } RequestBody body = builder.build(); final Request request = new Request.Builder().url(link).post(body).header("Authorization", "Token " + account.token).build(); - Response execute = RequestManager.getInstance().getClient().newCall(request).execute(); - return execute.body().string(); + Response response = RequestManager.getInstance().getClient().newCall(request).execute(); + if (response.isSuccessful()) { + return response.body().string(); + } + throw new SeafException(SeafException.OTHER_EXCEPTION, "File upload failed"); } public void createNewRepo(String repoName, String description, String password) throws SeafException { diff --git a/app/src/main/java/com/seafile/seadroid2/data/BlockInfoBean.java b/app/src/main/java/com/seafile/seadroid2/data/BlockInfoBean.java new file mode 100644 index 000000000..225af2578 --- /dev/null +++ b/app/src/main/java/com/seafile/seadroid2/data/BlockInfoBean.java @@ -0,0 +1,33 @@ +package com.seafile.seadroid2.data; + +import com.seafile.seadroid2.util.Utils; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + + +public class BlockInfoBean { + public List blkIds; + public String rawblksurl; + public String commiturl; + + public static BlockInfoBean fromJson(String json) throws JSONException { + BlockInfoBean bean = new BlockInfoBean(); + JSONObject obj = Utils.parseJsonObject(json); + bean.rawblksurl = obj.optString("rawblksurl"); + bean.commiturl = obj.optString("commiturl"); + JSONArray jsonArray = obj.optJSONArray("blklist"); + bean.blkIds = new ArrayList<>(); + for (int i = 0; i < jsonArray.length(); i++) { + bean.blkIds.add(jsonArray.getString(i)); + } + return bean; + } + + public BlockInfoBean() { + } +} diff --git a/app/src/main/java/com/seafile/seadroid2/data/SeafRepoEncrypt.java b/app/src/main/java/com/seafile/seadroid2/data/SeafRepoEncrypt.java index aa1fd236b..813a12ec2 100644 --- a/app/src/main/java/com/seafile/seadroid2/data/SeafRepoEncrypt.java +++ b/app/src/main/java/com/seafile/seadroid2/data/SeafRepoEncrypt.java @@ -23,10 +23,6 @@ public class SeafRepoEncrypt { public int encVersion; public long size; public String root; // the id of root directory - private String modifierContactEmail; - private String modifierName; - private String modifierEmail; - private int fileCount; static SeafRepoEncrypt fromJson(JSONObject obj) throws JSONException { SeafRepoEncrypt repo = new SeafRepoEncrypt(); @@ -36,14 +32,10 @@ static SeafRepoEncrypt fromJson(JSONObject obj) throws JSONException { repo.encVersion = obj.optInt("enc_version"); repo.mtime = obj.getLong("mtime"); repo.owner = obj.getString("owner"); - repo.modifierContactEmail = obj.getString("modifier_contact_email"); repo.id = obj.getString("id"); - repo.modifierName = obj.getString("modifier_name"); repo.size = obj.getLong("size"); - repo.modifierEmail = obj.getString("modifier_email"); repo.name = obj.getString("name"); repo.root = obj.getString("root"); - repo.fileCount = obj.optInt("file_count"); repo.encKey = obj.optString("random_key"); repo.isGroupRepo = obj.getString("type").equals("grepo"); repo.isPersonalRepo = obj.getString("type").equals("repo"); From 561d9f2091e3e979bbd1746e544458730bb62ca8 Mon Sep 17 00:00:00 2001 From: maxiaohong Date: Sat, 26 May 2018 18:13:21 +0800 Subject: [PATCH 4/4] fix program always uploading with upload blocks failed --- .../com/seafile/seadroid2/SeafConnection.java | 10 ++-- .../seafile/seadroid2/data/DataManager.java | 10 ++-- .../com/seafile/seadroid2/data/SeafRepo.java | 2 - .../seadroid2/monitor/AutoUpdateInfo.java | 13 ++--- .../seadroid2/monitor/AutoUpdateManager.java | 24 ++++----- .../monitor/CachedFileChangedListener.java | 6 +-- .../seadroid2/monitor/MonitorDBHelper.java | 15 +++--- .../seadroid2/monitor/SeafileObserver.java | 2 +- .../seadroid2/transfer/DownloadTask.java | 6 +-- .../seadroid2/transfer/DownloadTaskInfo.java | 4 +- .../seadroid2/transfer/PendingUploadInfo.java | 13 ----- .../seadroid2/transfer/TransferService.java | 11 ++--- .../seadroid2/transfer/UploadTask.java | 10 ++-- .../seadroid2/transfer/UploadTaskInfo.java | 4 +- .../seadroid2/transfer/UploadTaskManager.java | 17 ++----- .../ui/activity/BrowserActivity.java | 49 +++++++------------ .../ui/activity/ShareToSeafileActivity.java | 24 ++++++--- 17 files changed, 84 insertions(+), 136 deletions(-) diff --git a/app/src/main/java/com/seafile/seadroid2/SeafConnection.java b/app/src/main/java/com/seafile/seadroid2/SeafConnection.java index ff407c3b0..2d4c145ee 100644 --- a/app/src/main/java/com/seafile/seadroid2/SeafConnection.java +++ b/app/src/main/java/com/seafile/seadroid2/SeafConnection.java @@ -554,7 +554,7 @@ public String uploadByBlocks(String repoID, String dir, String filePath, List 0) { uploadBlocksCommon(infoBean.rawblksurl, infoBean.blkIds, dir, filePath, blocks, monitor, update); @@ -800,14 +800,10 @@ private String getUploadLink(String repoID, boolean update) throws SeafException } - private String getBlockUploadLink(String repoID, boolean update, List blocksId) throws SeafException { + private String getBlockUploadLink(String repoID, List blocksId) throws SeafException { try { String apiPath; - if (update) { - apiPath = "api2/repos/" + repoID + "/update-blks-link/"; - } else { - apiPath = "api2/repos/" + repoID + "/upload-blks-link/"; - } + apiPath = "api2/repos/" + repoID + "/upload-blks-link/"; HttpRequest req = prepareApiPostRequest(apiPath, true, null); String ids = blocksId.toString().replace("[", "").replace("]", "").replace(" ", ""); req.form("blklist", ids); diff --git a/app/src/main/java/com/seafile/seadroid2/data/DataManager.java b/app/src/main/java/com/seafile/seadroid2/data/DataManager.java index 9fc2bf887..94909e683 100644 --- a/app/src/main/java/com/seafile/seadroid2/data/DataManager.java +++ b/app/src/main/java/com/seafile/seadroid2/data/DataManager.java @@ -464,7 +464,7 @@ public synchronized File getFile(String repoName, String repoID, String path, } } - public synchronized File getFileByBlocks(String repoName, String repoID, String path, int version, long fileSize, + public synchronized File getFileByBlocks(String repoName, String repoID, String path, long fileSize, ProgressMonitor monitor) throws SeafException, IOException, JSONException, NoSuchAlgorithmException { String cachedFileID = null; @@ -992,7 +992,7 @@ public String getRepoPassword(String repoID) { return null; } - final SeafRepo seafRepo = getCachedRepoByID(repoID); + final SeafRepoEncrypt seafRepo = getCachedRepoEncryptByID(repoID); if (seafRepo != null && seafRepo.canLocalDecrypt()) { final Pair pair = dbHelper.getEnckey(repoID); if (pair == null) @@ -1192,12 +1192,12 @@ private FileBlocks chunkFile(String encKey, String enkIv, String filePath) throw public void uploadByBlocks(String repoName, String repoId, String dir, String filePath, ProgressMonitor monitor, - boolean isUpdate, boolean isCopyToLocal, int version) throws NoSuchAlgorithmException, IOException, SeafException { - uploadByBlocksCommon(repoName, repoId, dir, filePath, monitor, isUpdate, isCopyToLocal, version); + boolean isUpdate, boolean isCopyToLocal) throws NoSuchAlgorithmException, IOException, SeafException { + uploadByBlocksCommon(repoName, repoId, dir, filePath, monitor, isUpdate, isCopyToLocal); } private void uploadByBlocksCommon(String repoName, String repoID, String dir, String filePath, - ProgressMonitor monitor, boolean isUpdate, boolean isCopyToLocal, int version) throws NoSuchAlgorithmException, IOException, SeafException { + ProgressMonitor monitor, boolean isUpdate, boolean isCopyToLocal) throws NoSuchAlgorithmException, IOException, SeafException { final Pair pair = getRepoEncKey(repoID); diff --git a/app/src/main/java/com/seafile/seadroid2/data/SeafRepo.java b/app/src/main/java/com/seafile/seadroid2/data/SeafRepo.java index dfc5cb933..26a147bee 100644 --- a/app/src/main/java/com/seafile/seadroid2/data/SeafRepo.java +++ b/app/src/main/java/com/seafile/seadroid2/data/SeafRepo.java @@ -28,7 +28,6 @@ public class SeafRepo implements SeafItem { public String permission; public String magic; public String encKey; - public int encVersion; public long size; public String root; // the id of root directory @@ -47,7 +46,6 @@ static SeafRepo fromJson(JSONObject obj) throws JSONException{ repo.isSharedRepo = obj.getString("type").equals("srepo"); repo.magic = obj.optString("magic"); repo.encKey = obj.optString("random_key"); - repo.encVersion = obj.optInt("enc_version"); return repo; } diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateInfo.java b/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateInfo.java index a17ab1829..a66a30b5e 100644 --- a/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateInfo.java +++ b/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateInfo.java @@ -1,7 +1,5 @@ package com.seafile.seadroid2.monitor; -import android.text.TextUtils; - import com.google.common.base.Objects; import com.seafile.seadroid2.SettingsManager; import com.seafile.seadroid2.account.Account; @@ -12,22 +10,19 @@ class AutoUpdateInfo { final String repoName; final String parentDir; final String localPath; - final int version; public AutoUpdateInfo(Account account, String repoID, String repoName, String parentDir, - String localPath, int version) { + String localPath) { this.account = account; this.repoID = repoID; this.repoName = repoName; this.parentDir = parentDir; this.localPath = localPath; - this.version = version; } public boolean canLocalDecrypt() { - return version == 2 - && SettingsManager.instance().isEncryptEnabled(); + return SettingsManager.instance().isEncryptEnabled(); } @Override @@ -44,7 +39,7 @@ public boolean equals(Object obj) { return that.account.equals(this.account) && that.repoID.equals(this.repoID) && that.repoName.equals(this.repoName) && that.parentDir.equals(this.parentDir) && - that.localPath.equals(this.localPath) && that.version == this.version; + that.localPath.equals(this.localPath); } private volatile int hashCode = 0; @@ -52,7 +47,7 @@ public boolean equals(Object obj) { @Override public int hashCode() { if (hashCode == 0) { - hashCode = Objects.hashCode(account, repoID, repoName, parentDir, localPath, version); + hashCode = Objects.hashCode(account, repoID, repoName, parentDir, localPath); } return hashCode; diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateManager.java b/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateManager.java index e9c241d54..015146c46 100644 --- a/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateManager.java +++ b/app/src/main/java/com/seafile/seadroid2/monitor/AutoUpdateManager.java @@ -54,8 +54,8 @@ public void stop() { * This method is called by file monitor, so it would be executed in the file monitor thread */ @Override - public void onCachedBlocksChanged(final Account account, final SeafCachedFile cachedFile, final File localFile, int version) { - addTask(account, cachedFile, localFile, version); + public void onCachedBlocksChanged(final Account account, final SeafCachedFile cachedFile, final File localFile) { + addTask(account, cachedFile, localFile); } /** @@ -67,12 +67,8 @@ public void onCachedFileChanged(final Account account, final SeafCachedFile cach } public void addTask(Account account, SeafCachedFile cachedFile, File localFile) { - addTask(account, cachedFile, localFile, -1); - } - - public void addTask(Account account, SeafCachedFile cachedFile, File localFile, int version) { AutoUpdateInfo info = new AutoUpdateInfo(account, cachedFile.repoID, cachedFile.repoName, - Utils.getParentPath(cachedFile.path), localFile.getPath(), version); + Utils.getParentPath(cachedFile.path), localFile.getPath()); synchronized (infos) { if (infos.contains(info)) { @@ -99,7 +95,7 @@ public void run() { for (AutoUpdateInfo info : infos) { if (info.canLocalDecrypt()) { txService.addTaskToUploadQue(info.account, info.repoID, info.repoName, - info.parentDir, info.localPath, true, true, info.version); + info.parentDir, info.localPath, true, true); } else { txService.addUploadTask(info.account, info.repoID, info.repoName, info.parentDir, info.localPath, true, true); @@ -115,17 +111,17 @@ public void run() { public void onFileUpdateSuccess(Account account, String repoID, String repoName, String parentDir, String localPath, int version) { // This file has already been updated on server, so we abort auto update task - if (removeAutoUpdateInfo(account, repoID, repoName, parentDir, localPath, version)) { + if (removeAutoUpdateInfo(account, repoID, repoName, parentDir, localPath)) { Log.d(DEBUG_TAG, "auto updated " + localPath); } } - private static int MAX_UPLOAD_FAILURES = 3; + private static int MAX_UPLOAD_FAILURES = 2; private ConcurrentHashMultiset uploadFailuresByFile = ConcurrentHashMultiset.create(); private boolean maxFailureReached(Account account, String repoID, String repoName, String parentDir, String localPath, int version) { - AutoUpdateInfo info = new AutoUpdateInfo(account, repoID, repoName, parentDir, localPath, version); + AutoUpdateInfo info = new AutoUpdateInfo(account, repoID, repoName, parentDir, localPath); int failures = uploadFailuresByFile.count(info) + 1; if (failures >= MAX_UPLOAD_FAILURES) { uploadFailuresByFile.remove(info); @@ -160,15 +156,15 @@ && maxFailureReached(account, repoID, repoName, parentDir, localPath, version)) return; } - if (removeAutoUpdateInfo(account, repoID, repoName, parentDir, localPath, version)) { + if (removeAutoUpdateInfo(account, repoID, repoName, parentDir, localPath)) { Log.d(DEBUG_TAG, String.format("failed to auto update %s, error %s", localPath, e)); } else { Log.d(DEBUG_TAG, String.format("failed to remove auto update task for %s", localPath)); } } - private boolean removeAutoUpdateInfo(Account account, String repoID, String repoName, String parentDir, String localPath, int version) { - final AutoUpdateInfo info = new AutoUpdateInfo(account, repoID, repoName, parentDir, localPath, version); + private boolean removeAutoUpdateInfo(Account account, String repoID, String repoName, String parentDir, String localPath) { + final AutoUpdateInfo info = new AutoUpdateInfo(account, repoID, repoName, parentDir, localPath); boolean exist = false; synchronized (infos) { diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/CachedFileChangedListener.java b/app/src/main/java/com/seafile/seadroid2/monitor/CachedFileChangedListener.java index 975e614b6..48446d095 100644 --- a/app/src/main/java/com/seafile/seadroid2/monitor/CachedFileChangedListener.java +++ b/app/src/main/java/com/seafile/seadroid2/monitor/CachedFileChangedListener.java @@ -1,12 +1,12 @@ package com.seafile.seadroid2.monitor; -import java.io.File; - import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.data.SeafCachedFile; +import java.io.File; + interface CachedFileChangedListener { - void onCachedBlocksChanged(Account account, SeafCachedFile cf, File file, int version); + void onCachedBlocksChanged(Account account, SeafCachedFile cf, File file); void onCachedFileChanged(Account account, SeafCachedFile cf, File file); } diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/MonitorDBHelper.java b/app/src/main/java/com/seafile/seadroid2/monitor/MonitorDBHelper.java index dc969d989..b2a8d313b 100644 --- a/app/src/main/java/com/seafile/seadroid2/monitor/MonitorDBHelper.java +++ b/app/src/main/java/com/seafile/seadroid2/monitor/MonitorDBHelper.java @@ -1,9 +1,5 @@ package com.seafile.seadroid2.monitor; -import java.io.File; -import java.util.List; -import java.util.Map; - import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -17,6 +13,10 @@ import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.account.AccountManager; +import java.io.File; +import java.util.List; +import java.util.Map; + public class MonitorDBHelper extends SQLiteOpenHelper { private static final String DEBUG_TAG = "MonitorDBHelper"; @@ -109,7 +109,6 @@ public void saveAutoUpdateInfo(AutoUpdateInfo info) { values.put(AUTO_UPDATE_INFO_COLUMN_REPO_NAME, info.repoName); values.put(AUTO_UPDATE_INFO_COLUMN_PARENT_DIR, info.parentDir); values.put(AUTO_UPDATE_INFO_COLUMN_LOCAL_PATH, info.localPath); - values.put(AUTO_UPDATE_INFO_COLUMN_VERSION, info.version); database.insert(AUTO_UPDATE_INFO_TABLE_NAME, null, values); } @@ -124,7 +123,7 @@ public void removeAutoUpdateInfo(AutoUpdateInfo info) { AUTO_UPDATE_INFO_COLUMN_LOCAL_PATH, AUTO_UPDATE_INFO_COLUMN_VERSION); String[] params = { info.account.getSignature(), info.repoID, info.repoName, - info.parentDir, info.localPath, String.valueOf(info.version), }; + info.parentDir, info.localPath, }; database.delete(AUTO_UPDATE_INFO_TABLE_NAME, whereClause, params); } @@ -180,7 +179,6 @@ private AutoUpdateInfo cursorToAutoUpdateInfo(Cursor c, Map acc String repoName = c.getString(2); String parentDir = c.getString(3); String localPath = c.getString(4); - int version = c.getInt(5); // infos whose account or file has been deleted would be removed in the // while loop @@ -189,8 +187,7 @@ private AutoUpdateInfo cursorToAutoUpdateInfo(Cursor c, Map acc } Account account = accounts.get(accountSignature); - AutoUpdateInfo info = new AutoUpdateInfo(account, repoID, repoName, parentDir, - localPath, version); + AutoUpdateInfo info = new AutoUpdateInfo(account, repoID, repoName, parentDir, localPath); return info; } } diff --git a/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java b/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java index 61f9b4e99..da5eea8fd 100644 --- a/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java +++ b/app/src/main/java/com/seafile/seadroid2/monitor/SeafileObserver.java @@ -135,7 +135,7 @@ public void onFileChange(File file) { cachedFile.fileOriginalSize = file.length(); final SeafRepo repo = dataManager.getCachedRepoByID(cachedFile.repoID); if (repo != null && repo.canLocalDecrypt()) { - listener.onCachedBlocksChanged(account, cachedFile, file, repo.encVersion); + listener.onCachedBlocksChanged(account, cachedFile, file); } else { listener.onCachedFileChanged(account, cachedFile, file); } diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTask.java b/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTask.java index 5caa47bc7..bfa9fb264 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTask.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTask.java @@ -22,7 +22,6 @@ public class DownloadTask extends TransferTask { private String localPath; private DownloadStateListener downloadStateListener; private boolean updateTotal; - private int encVersion = -1; public DownloadTask(int taskID, Account account, String repoName, String repoID, String path, DownloadStateListener downloadStateListener) { @@ -51,8 +50,7 @@ protected File doInBackground(Void... params) { DataManager dataManager = new DataManager(account); final SeafRepo repo = dataManager.getCachedRepoByID(repoID); if (repo != null && repo.canLocalDecrypt()) { - encVersion = repo.encVersion; - return dataManager.getFileByBlocks(repoName, repoID, path, encVersion, totalSize, + return dataManager.getFileByBlocks(repoName, repoID, path, totalSize, new ProgressMonitor() { @Override @@ -124,7 +122,7 @@ protected void onCancelled() { @Override public DownloadTaskInfo getTaskInfo() { DownloadTaskInfo info = new DownloadTaskInfo(account, taskID, state, repoID, - repoName, path, localPath, totalSize, finished, err, encVersion); + repoName, path, localPath, totalSize, finished, err); return info; } diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTaskInfo.java b/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTaskInfo.java index dc2f1362e..5508e1574 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTaskInfo.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/DownloadTaskInfo.java @@ -9,7 +9,6 @@ public class DownloadTaskInfo extends TransferTaskInfo { public final String pathInRepo; public final long fileSize, finished; - public int version; /** * Constructor of DownloadTaskInfo @@ -26,13 +25,12 @@ public class DownloadTaskInfo extends TransferTaskInfo { */ public DownloadTaskInfo(Account account, int taskID, TaskState state, String repoID, String repoName, String pathInRepo, - String localPath, long fileSize, long finished, SeafException err, int version) { + String localPath, long fileSize, long finished, SeafException err) { super(account, taskID, state, repoID, repoName, localPath, err); this.pathInRepo = pathInRepo; this.fileSize = fileSize; this.finished = finished; - this.version = version; } @Override diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/PendingUploadInfo.java b/app/src/main/java/com/seafile/seadroid2/transfer/PendingUploadInfo.java index 550bae04a..7f52f07f4 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/PendingUploadInfo.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/PendingUploadInfo.java @@ -8,18 +8,6 @@ public class PendingUploadInfo { public String localFilePath; public boolean isUpdate; public boolean isCopyToLocal; - public int enckVersion; - - public PendingUploadInfo(String repoID, String repoName, String targetDir, - String localFilePath, boolean isUpdate, boolean isCopyToLocal, int enckVersion) { - this.repoID = repoID; - this.repoName = repoName; - this.targetDir = targetDir; - this.localFilePath = localFilePath; - this.isUpdate = isUpdate; - this.isCopyToLocal = isCopyToLocal; - this.enckVersion = enckVersion; - } public PendingUploadInfo(String repoID, String repoName, String targetDir, String localFilePath, boolean isUpdate, boolean isCopyToLocal) { @@ -29,7 +17,6 @@ public PendingUploadInfo(String repoID, String repoName, String targetDir, this.localFilePath = localFilePath; this.isUpdate = isUpdate; this.isCopyToLocal = isCopyToLocal; - this.enckVersion = -1; } } diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/TransferService.java b/app/src/main/java/com/seafile/seadroid2/transfer/TransferService.java index fb3b6f4ef..f14dcc803 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/TransferService.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/TransferService.java @@ -89,9 +89,8 @@ public IBinder onBind(Intent intent) { * @param isCopyToLocal * @return */ - public int addTaskToUploadQue(Account account, String repoID, String repoName, String dir, - String filePath, boolean isUpdate, boolean isCopyToLocal) { - return uploadTaskManager.addTaskToQue(account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal); + public int addTaskToUploadQue(Account account, String repoID, String repoName, String dir, String filePath, boolean isUpdate, boolean isCopyToLocal) { + return uploadTaskManager.addTaskToQue(account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal,false); } /** @@ -109,9 +108,9 @@ public int addTaskToUploadQue(Account account, String repoID, String repoName, S * @param version * @return */ - public int addTaskToUploadQue(Account account, String repoID, String repoName, String dir, - String filePath, boolean isUpdate, boolean isCopyToLocal, int version) { - return uploadTaskManager.addTaskToQue(account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal, version); + public int addTaskToUploadQueBlock(Account account, String repoID, String repoName, String dir, + String filePath, boolean isUpdate, boolean isCopyToLocal) { + return uploadTaskManager.addTaskToQue(account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal, true); } /** diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java index 146734c28..829da85ee 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTask.java @@ -22,32 +22,28 @@ public class UploadTask extends TransferTask { private boolean isUpdate; // true if update an existing file private boolean isCopyToLocal; // false to turn off copy operation private boolean byBlock; - private int version; private UploadStateListener uploadStateListener; private DataManager dataManager; public UploadTask(int taskID, Account account, String repoID, String repoName, - String dir, String filePath, boolean isUpdate, boolean isCopyToLocal, boolean byBlock, int version, + String dir, String filePath, boolean isUpdate, boolean isCopyToLocal, boolean byBlock, UploadStateListener uploadStateListener) { super(taskID, account, repoName, repoID, filePath); this.dir = dir; this.isUpdate = isUpdate; this.isCopyToLocal = isCopyToLocal; this.byBlock = byBlock; - this.version = version; this.uploadStateListener = uploadStateListener; - this.totalSize = new File(filePath).length(); this.finished = 0; - this.dataManager = new DataManager(account); } public UploadTaskInfo getTaskInfo() { UploadTaskInfo info = new UploadTaskInfo(account, taskID, state, repoID, repoName, dir, path, isUpdate, isCopyToLocal, - finished, totalSize, err, version); + finished, totalSize, err); return info; } @@ -88,7 +84,7 @@ public boolean isCancelled() { }; if (byBlock) { - dataManager.uploadByBlocks(repoName, repoID, dir, path, monitor, isUpdate, isCopyToLocal, version); + dataManager.uploadByBlocks(repoName, repoID, dir, path, monitor, isUpdate, isCopyToLocal); } else { dataManager.uploadFile(repoName, repoID, dir, path, monitor, isUpdate, isCopyToLocal); } diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskInfo.java b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskInfo.java index 730fda27d..291b312c4 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskInfo.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskInfo.java @@ -38,8 +38,7 @@ public UploadTaskInfo(Account account, boolean isCopyToLocal, long uploadedSize, long totalSize, - SeafException err, - int version) { + SeafException err) { super(account, taskID, state, repoID, repoName, localPath, err); @@ -48,6 +47,5 @@ public UploadTaskInfo(Account account, this.totalSize = totalSize; this.isUpdate = isUpdate; this.isCopyToLocal = isCopyToLocal; - this.version = version; } } diff --git a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskManager.java b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskManager.java index 349f0d01c..ebce9c544 100644 --- a/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskManager.java +++ b/app/src/main/java/com/seafile/seadroid2/transfer/UploadTaskManager.java @@ -2,7 +2,7 @@ import android.content.Intent; import android.support.v4.content.LocalBroadcastManager; -import android.util.Log; + import com.google.common.collect.Lists; import com.seafile.seadroid2.SeadroidApplication; import com.seafile.seadroid2.account.Account; @@ -24,22 +24,13 @@ public class UploadTaskManager extends TransferManager implements UploadStateLis private static UploadNotificationProvider mNotifyProvider; - public int addTaskToQue(Account account, String repoID, String repoName, String dir, String filePath, boolean isUpdate, boolean isCopyToLocal) { - if (repoID == null || repoName == null) - return 0; - - // create a new one to avoid IllegalStateException - UploadTask task = new UploadTask(++notificationID, account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal, false, -1, this); - addTaskToQue(task); - return task.getTaskID(); - } - public int addTaskToQue(Account account, String repoID, String repoName, String dir, String filePath, boolean isUpdate, boolean isCopyToLocal, int version) { + public int addTaskToQue(Account account, String repoID, String repoName, String dir, String filePath, boolean isUpdate, boolean isCopyToLocal, boolean byBlock) { if (repoID == null || repoName == null) return 0; // create a new one to avoid IllegalStateException - UploadTask task = new UploadTask(++notificationID, account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal, true, version, this); + UploadTask task = new UploadTask(++notificationID, account, repoID, repoName, dir, filePath, isUpdate, isCopyToLocal, byBlock, this); addTaskToQue(task); return task.getTaskID(); } @@ -63,7 +54,7 @@ public void retry(int taskID) { UploadTask task = (UploadTask) getTask(taskID); if (task == null || !task.canRetry()) return; - addTaskToQue(task.getAccount(), task.getRepoID(), task.getRepoName(), task.getDir(), task.getPath(), task.isUpdate(), task.isCopyToLocal()); + addTaskToQue(task.getAccount(), task.getRepoID(), task.getRepoName(), task.getDir(), task.getPath(), task.isUpdate(), task.isCopyToLocal(),false); } private void notifyProgress(int taskID) { diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java index 0d5171cb8..462b07aaa 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/activity/BrowserActivity.java @@ -169,11 +169,11 @@ public void addUpdateTask(String repoID, String repoName, String targetDir, Stri } } - public void addUpdateBlocksTask(String repoID, String repoName, String targetDir, String localFilePath, int version) { + public void addUpdateBlocksTask(String repoID, String repoName, String targetDir, String localFilePath) { if (txService != null) { - txService.addTaskToUploadQue(account, repoID, repoName, targetDir, localFilePath, true, true, version); + txService.addTaskToUploadQueBlock(account, repoID, repoName, targetDir, localFilePath, true, true); } else { - PendingUploadInfo info = new PendingUploadInfo(repoID, repoName, targetDir, localFilePath, true, true, version); + PendingUploadInfo info = new PendingUploadInfo(repoID, repoName, targetDir, localFilePath, true, true); pendingUploads.add(info); } } @@ -188,11 +188,11 @@ private int addUploadTask(String repoID, String repoName, String targetDir, Stri } } - private int addUploadBlocksTask(String repoID, String repoName, String targetDir, String localFilePath, int version) { + private int addUploadBlocksTask(String repoID, String repoName, String targetDir, String localFilePath) { if (txService != null) { - return txService.addTaskToUploadQue(account, repoID, repoName, targetDir, localFilePath, false, true, version); + return txService.addTaskToUploadQueBlock(account, repoID, repoName, targetDir, localFilePath, false, true); } else { - PendingUploadInfo info = new PendingUploadInfo(repoID, repoName, targetDir, localFilePath, false, true, version); + PendingUploadInfo info = new PendingUploadInfo(repoID, repoName, targetDir, localFilePath, false, true); pendingUploads.add(info); return 0; } @@ -783,24 +783,13 @@ public void onServiceConnected(ComponentName className, IBinder service) { Log.d(DEBUG_TAG, "bind TransferService"); for (PendingUploadInfo info : pendingUploads) { - if (info.enckVersion != -1) { - txService.addTaskToUploadQue(account, - info.repoID, - info.repoName, - info.targetDir, - info.localFilePath, - info.isUpdate, - info.isCopyToLocal, - info.enckVersion); - } else { - txService.addTaskToUploadQue(account, - info.repoID, - info.repoName, - info.targetDir, - info.localFilePath, - info.isUpdate, - info.isCopyToLocal); - } + txService.addTaskToUploadQue(account, + info.repoID, + info.repoName, + info.targetDir, + info.localFilePath, + info.isUpdate, + info.isCopyToLocal); } pendingUploads.clear(); } @@ -1273,7 +1262,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { showShortToast(BrowserActivity.this, getString(R.string.added_to_upload_tasks)); final SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); if (repo != null && repo.canLocalDecrypt()) { - addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), path, repo.encVersion); + addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), path); } else { addUploadTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), path); } @@ -1305,7 +1294,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { showShortToast(BrowserActivity.this, getString(R.string.added_to_upload_tasks)); final SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); if (repo != null && repo.canLocalDecrypt()) { - addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), path,repo.encVersion); + addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), path); }else { addUploadTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), path); } @@ -1365,7 +1354,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { showShortToast(this, getString(R.string.added_to_upload_tasks)); final SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); if (repo != null && repo.canLocalDecrypt()) { - addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), takeCameraPhotoTempFile.getAbsolutePath(), repo.encVersion); + addUploadBlocksTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), takeCameraPhotoTempFile.getAbsolutePath()); } else { addUploadTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), takeCameraPhotoTempFile.getAbsolutePath()); } @@ -1454,7 +1443,7 @@ protected void onPostExecute(File... fileList) { final SeafRepo repo = dataManager.getCachedRepoByID(navContext.getRepoID()); showShortToast(BrowserActivity.this, getString(R.string.added_to_upload_tasks)); if (repo != null && repo.canLocalDecrypt()) { - addUploadBlocksTask(repo.id, repo.name, navContext.getDirPath(), file.getAbsolutePath(), repo.encVersion); + addUploadBlocksTask(repo.id, repo.name, navContext.getDirPath(), file.getAbsolutePath()); } else { addUploadTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), file.getAbsolutePath()); } @@ -1490,7 +1479,7 @@ private void showFileExistDialog(final File file) { public void onClick(DialogInterface dialog, int which) { showShortToast(BrowserActivity.this, getString(R.string.added_to_upload_tasks)); if (repo != null && repo.canLocalDecrypt()) { - addUpdateBlocksTask(repo.id, repo.name, navContext.getDirPath(), file.getAbsolutePath(), repo.encVersion); + addUpdateBlocksTask(repo.id, repo.name, navContext.getDirPath(), file.getAbsolutePath()); } else { addUpdateTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), file.getAbsolutePath()); } @@ -1505,7 +1494,7 @@ public void onClick(DialogInterface dialog, int which) { @Override public void onClick(DialogInterface dialog, int which) { if (repo != null && repo.canLocalDecrypt()) { - addUploadBlocksTask(repo.id, repo.name, navContext.getDirPath(), file.getAbsolutePath(), repo.encVersion); + addUploadBlocksTask(repo.id, repo.name, navContext.getDirPath(), file.getAbsolutePath()); } else { addUploadTask(navContext.getRepoID(), navContext.getRepoName(), navContext.getDirPath(), file.getAbsolutePath()); } diff --git a/app/src/main/java/com/seafile/seadroid2/ui/activity/ShareToSeafileActivity.java b/app/src/main/java/com/seafile/seadroid2/ui/activity/ShareToSeafileActivity.java index dd089a0fd..f7cd48308 100644 --- a/app/src/main/java/com/seafile/seadroid2/ui/activity/ShareToSeafileActivity.java +++ b/app/src/main/java/com/seafile/seadroid2/ui/activity/ShareToSeafileActivity.java @@ -1,28 +1,39 @@ package com.seafile.seadroid2.ui.activity; -import android.support.v7.app.AlertDialog; -import android.content.*; +import android.content.ComponentName; +import android.content.ContentResolver; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.ServiceConnection; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.os.IBinder; import android.provider.MediaStore.Images; +import android.support.v7.app.AlertDialog; import android.util.Log; + import com.google.common.collect.Lists; -import com.seafile.seadroid2.data.SeafRepo; -import com.seafile.seadroid2.util.ConcurrentAsyncTask; import com.seafile.seadroid2.R; import com.seafile.seadroid2.SeafException; import com.seafile.seadroid2.account.Account; import com.seafile.seadroid2.data.DataManager; import com.seafile.seadroid2.data.SeafDirent; +import com.seafile.seadroid2.data.SeafRepo; import com.seafile.seadroid2.transfer.TransferService; import com.seafile.seadroid2.transfer.TransferService.TransferBinder; +import com.seafile.seadroid2.util.ConcurrentAsyncTask; import com.seafile.seadroid2.util.Utils; + import org.apache.commons.io.IOUtils; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; @@ -209,8 +220,7 @@ public void onServiceConnected(ComponentName className, IBinder service) { final SeafRepo repo = dataManager.getCachedRepoByID(repoID); if (repo != null && repo.canLocalDecrypt()) { - mTxService.addTaskToUploadQue(account, repoID, repoName, - targetDir, path, update, false, repo.encVersion); + mTxService.addTaskToUploadQueBlock(account, repoID, repoName, targetDir, path, update, false); } else { mTxService.addUploadTask(account, repoID, repoName, targetDir, path, update, false);