Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.Calendar;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down Expand Up @@ -70,7 +71,8 @@ protected int uploadFile(OwnCloudClient client) throws IOException {
RandomAccessFile raf = null;

File file = new File(mLocalPath);
SharedPreferences sharedPref = mContext.getApplicationContext().getSharedPreferences("com.nextcloud.PREFERENCE_upload", Context.MODE_PRIVATE);
SharedPreferences sharedPref = mContext.getApplicationContext().
getSharedPreferences("com.nextcloud.PREFERENCE_upload", Context.MODE_PRIVATE);
String chunkId = String.format("%08d", Math.abs(file.getName().hashCode()));
Set<String> successfulChunks = sharedPref.getStringSet(chunkId, new LinkedHashSet<String>());

Expand All @@ -91,7 +93,7 @@ protected int uploadFile(OwnCloudClient client) throws IOException {
String chunkSizeStr = String.valueOf(CHUNK_SIZE);
String totalLengthStr = String.valueOf(file.length());
for (int chunkIndex = 0; chunkIndex < chunkCount ; chunkIndex++, offset += CHUNK_SIZE) {
if (successfulChunks.contains(String.valueOf(chunkIndex))){
if (successfulChunks.contains(String.valueOf(chunkIndex + "_" + getDateAsString()))){
((ChunkFromFileChannelRequestEntity) mEntity).setmTransferred(offset);
continue;
}
Expand Down Expand Up @@ -146,23 +148,21 @@ protected int uploadFile(OwnCloudClient client) throws IOException {
", HTTP result status " + status);

if (isSuccess(status)){
successfulChunks.add(String.valueOf(chunkIndex));

successfulChunks.add(String.valueOf(chunkIndex) + "_" + getDateAsString());
} else {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putStringSet(chunkId, successfulChunks).apply();

break;
}
}

if (isSuccess(status)){
SharedPreferences.Editor editor = sharedPref.edit();
editor.remove(chunkId).apply();
}

} finally {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putStringSet(chunkId, successfulChunks).apply();
if (this.isSuccess(status)) {
editor.remove(chunkId).apply();
} else {
editor.putStringSet(chunkId, successfulChunks).apply();
}

if (channel != null)
channel.close();
Expand All @@ -174,4 +174,11 @@ protected int uploadFile(OwnCloudClient client) throws IOException {
return status;
}

private String getDateAsString() {
Calendar calendar = Calendar.getInstance();
return calendar.get(Calendar.YEAR) + "-"
+ calendar.get(Calendar.MONTH) + "-"
+ calendar.get(Calendar.DAY_OF_MONTH);
}

}