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

Commit 9ad361f2 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

Try a new 'ListRemoteFile' method end ask for less metadata

parent e5780b6d
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@
      </value>
    </option>
  </component>
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/build/classes" />
  </component>
  <component name="ProjectType">

android-nc-lib @ e99c7bd2

Original line number Diff line number Diff line
Subproject commit 643d25be260f9bb0157a04b82e6e7a21d004d7c1
Subproject commit e99c7bd2d44272a92e128f49dd4fb6aa137a0bac
+2 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import android.util.Log;
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.resources.files.LightReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;

@@ -76,7 +77,7 @@ public class ListRemoteFileOperation extends RemoteOperation {
                }
                if(syncedFolder.getId() > 0){
                    //Create ReadRemoteOperation
                    ReadFolderRemoteOperation operation = new ReadFolderRemoteOperation(syncedFolder.getRemoteFolder());
                    LightReadFolderRemoteOperation operation = new LightReadFolderRemoteOperation(syncedFolder.getRemoteFolder(), 1);
                    RemoteOperationResult result = operation.execute(ownCloudClient);

                    if(result.isSuccess() ){
+111 −0
Original line number Diff line number Diff line
/*
 * Copyright © Vincent Bourgmayer (/e/ foundation).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 */

package io.eelo.drive.operations;

import android.content.Context;
import android.util.Log;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.LightReadFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;

import org.apache.jackrabbit.webdav.property.DavPropertyName;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import io.eelo.drive.database.DbHelper;
import io.eelo.drive.models.SyncedFolder;

/**
 *
 * @author Vincent Bourgmayer
 * Created by Vincent on 04/05/2018.
 */

public class ListRemoteFileOperation_v2 extends RemoteOperation {
    private final String TAG = ListRemoteFileOperation_v2.class.getSimpleName();

    private final List<SyncedFolder> mSyncedFolders;
    private final Context mContext;
    private final int initialFolderNumber;

    public ListRemoteFileOperation_v2(List<SyncedFolder> syncedFolders, Context context, int initialFolderNumber){
        Log.i(TAG, "Constructor of ListRemoteFileOperation");
        this.mSyncedFolders = syncedFolders;
        this.mContext = context;
        this.initialFolderNumber = initialFolderNumber;
    }

    /**
     * Execute l'operation
     * @param ownCloudClient DAV client
     * @return List containing remoteFolder followed by remote files
     */
    @Override
    protected RemoteOperationResult run(OwnCloudClient ownCloudClient){
        Log.i(TAG, "run()");
        ArrayList<Object> mRemoteFiles =  new ArrayList<>();
        RemoteOperationResult finalResult;

        boolean atLeastOneDirAsChanged = false;
        ListIterator<SyncedFolder> mSyncedFolderIterator = mSyncedFolders.listIterator();

        LightReadFolderRemoteOperation operation = new LightReadFolderRemoteOperation("/", DavPropertyName.DEPTH_INFINITY);
        RemoteOperationResult result = operation.execute(ownCloudClient);


        if(result.isSuccess()){

            ArrayList<Object> datas = result.getData();
            int dataSize = datas.size();
            Log.d(TAG, "data size: "+dataSize );
            if(dataSize > 1) { //There is at least one subfiles. Note: data[0] contains the folder.
                RemoteFile directory = (RemoteFile) datas.get(0);
                //loop through subelements
                for (int i = 0; ++i < dataSize; ) {

                    Log.d(TAG, "Loop through result of request");

                    RemoteFile remoteFile = (RemoteFile) datas.get(i);

                    if (remoteFile.getMimeType().equals("DIR")) {
                        Log.d(TAG, "Current data is a Directory :" + remoteFile.getRemotePath());
                        /*String suffixPath = remoteFile.getRemotePath().substring( syncedFolder.getRemoteFolder().length() );

                        SyncedFolder subSyncedFolder = new SyncedFolder(syncedFolder, suffixPath, 0L, "" ); //need to set empty etag to allow it to be scan
                        mSyncedFolderIterator.add(subSyncedFolder);
                        mSyncedFolderIterator.previous();*/

                    } else {
                        //If it's a file just add it to mRemoteFiles.
                        Log.d(TAG, "current data is a file");
                    }
                }
            }
        }

        //Loop through list of SyncedFolder

        finalResult = new RemoteOperationResult(RemoteOperationResult.ResultCode.OK);

        if( atLeastOneDirAsChanged ) {
            DbHelper.updateSyncedFolders(this.mSyncedFolders, this.mContext);
            finalResult.setData(new ArrayList<Object>(mRemoteFiles) );
        }

        Log.v(TAG, "end of run()");
        return finalResult;
    }
}
Loading