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

Unverified Commit 2b72d2b4 authored by AndyScherzinger's avatar AndyScherzinger
Browse files

cleanup code

parent de1625d4
Loading
Loading
Loading
Loading
+34 −25
Original line number Diff line number Diff line
@@ -110,28 +110,9 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
                    mPutMethod.releaseConnection();     // let the connection available
                                                        // for other methods
                }
                mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
                if (mRequiredEtag != null && mRequiredEtag.length() > 0) {
                    mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\"");
                }
                mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
                mPutMethod.addRequestHeader(OC_CHUNK_SIZE_HEADER, chunkSizeStr);
                mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, totalLengthStr);
                mPutMethod.addRequestHeader(OC_CHUNK_X_OC_MTIME_HEADER, mFileLastModifTimestamp);

                ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
                mPutMethod.setRequestEntity(mEntity);
                if (mCancellationRequested.get()) {
                    mPutMethod.abort();
                    // next method will throw an exception
                }

                if (chunkIndex == chunkCount - 1) {
                    // Added a high timeout to the last chunk due to when the last chunk
                    // arrives to the server with the last PUT, all chunks get assembled
                    // within that PHP request, so last one takes longer.
                    mPutMethod.getParams().setSoTimeout(LAST_CHUNK_TIMEOUT);
                }
                mPutMethod = createPutMethod(uriPrefix, chunkCount, chunkIndex, chunkSizeStr, totalLengthStr, offset);

                status = client.executeMethod(mPutMethod);

@@ -143,11 +124,9 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
                        ", HTTP result status " + status);

                if (isSuccess(status)) {

                    successfulChunks.add(String.valueOf(chunkIndex) + "_" + getDateAsString());
                } else {
                    SharedPreferences.Editor editor = sharedPref.edit();
                    editor.putStringSet(chunkId, successfulChunks).apply();
                    sharedPref.edit().putStringSet(chunkId, successfulChunks).apply();
                    break;
                }
            }
@@ -178,6 +157,36 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
        return result;
    }

    private PutMethod createPutMethod(String uriPrefix,
                                      long chunkCount,
                                      int chunkIndex,
                                      String chunkSizeStr,
                                      String totalLengthStr,
                                      long offset) {
        PutMethod putMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
        if (mRequiredEtag != null && mRequiredEtag.length() > 0) {
            mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\"");
        }
        mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
        mPutMethod.addRequestHeader(OC_CHUNK_SIZE_HEADER, chunkSizeStr);
        mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, totalLengthStr);
        ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
        mPutMethod.setRequestEntity(mEntity);
        if (mCancellationRequested.get()) {
            mPutMethod.abort();
            // next method will throw an exception
        }

        if (chunkIndex == chunkCount - 1) {
            // Added a high timeout to the last chunk due to when the last chunk
            // arrives to the server with the last PUT, all chunks get assembled
            // within that PHP request, so last one takes longer.
            mPutMethod.getParams().setSoTimeout(LAST_CHUNK_TIMEOUT);
        }

        return putMethod;
    }

    private String getDateAsString() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR) + "-"
+3 −8
Original line number Diff line number Diff line
@@ -26,26 +26,21 @@

package com.owncloud.android.lib.resources.shares;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * Get the data from the server about ALL the known shares owned by the requester.
 */

public class GetRemoteSharesOperation extends RemoteOperation {

    private static final String TAG = GetRemoteSharesOperation.class.getSimpleName();


    public GetRemoteSharesOperation() {
    }

    @Override
    protected RemoteOperationResult run(OwnCloudClient client) {
        RemoteOperationResult result = null;
+0 −3
Original line number Diff line number Diff line
@@ -46,13 +46,11 @@ import java.util.ArrayList;
/**
 * Gets avatar about the user logged in, if available
 */

public class GetRemoteUserAvatarOperation extends RemoteOperation {

    private static final String TAG = GetRemoteUserAvatarOperation.class.getSimpleName();

    private static final String NON_OFFICIAL_AVATAR_PATH = "/index.php/avatar/";
    private static final String IF_NONE_MATCH_HEADER = "If-None-Match";

    /** Desired size in pixels of the squared image */
    private int mDimension;
@@ -63,7 +61,6 @@ public class GetRemoteUserAvatarOperation extends RemoteOperation {
     */
    //private String mCurrentEtag;


    public GetRemoteUserAvatarOperation(int dimension, String currentEtag) {
        mDimension = dimension;
        //mCurrentEtag = currentEtag;