Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 463d85fa authored by Andy Scherzinger's avatar Andy Scherzinger Committed by GitHub
Browse files

Merge branch 'master' into patch-1

parents 3c98f514 e3c51c24
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ group_defaults:
groups:
  code-review:
    required: 2
    reject_value: -99
    users:
      - AndyScherzinger
      - tobiasKaminsky
+18 −11
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import java.io.IOException;
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;

@@ -70,7 +71,8 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
        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>());

@@ -91,7 +93,7 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
            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;
                }
@@ -146,23 +148,21 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
                        ", 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();
            if (this.isSuccess(status)) {
                editor.remove(chunkId).apply();
            } else {
                editor.putStringSet(chunkId, successfulChunks).apply();
            }

            if (channel != null)
                channel.close();
@@ -174,4 +174,11 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
        return status;
    }

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

}
+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class OwnCloudVersion implements Comparable<OwnCloudVersion> {

    public static final int MINIMUM_VERSION_CAPABILITIES_API = 0x08010000; // 8.1

    public static final int MINIMUM_SELF_API = 0x11000200;
    public static final int MINIMUM_SELF_API = 0x0B000200;
    
    private static final int MAX_DOTS = 3;