Loading app/build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ android { minSdkVersion 26 versionCode 1 //versionName "1.0" versionName "alpha-${versionMajor}-build-${buildTime()}" versionName "beta-${versionMajor}-build-o-${buildTime()}" setProperty("archivesBaseName", "$applicationId.$versionName") } Loading app/src/main/java/foundation/e/drive/models/SyncedFileState.java +44 −1 Original line number Diff line number Diff line Loading @@ -8,12 +8,15 @@ package foundation.e.drive.models; import android.os.Parcel; import android.os.Parcelable; /** * @author Vincent Bourgmayer * Describe a file state which will be Synchronized (= Synced) or which has already been synced one times */ public class SyncedFileState { public class SyncedFileState implements Parcelable { protected SyncedFileState(){}; //@ToRemove. Test Only. It's to allow to make a mock SyncedFileState Class in test. Loading Loading @@ -47,6 +50,41 @@ public class SyncedFileState { this.isMediaType = isMediaType; } protected SyncedFileState(Parcel in) { id = in.readInt(); name = in.readString(); localPath = in.readString(); remotePath = in.readString(); lastETAG = in.readString(); localLastModified = in.readLong(); syncedFolderId = in.readLong(); isMediaType = in.readByte() != 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeString(name); dest.writeString(localPath); dest.writeString(remotePath); dest.writeString(lastETAG); dest.writeLong(localLastModified); dest.writeLong(syncedFolderId); dest.writeByte((byte) (isMediaType ? 1 : 0)); } public static final Creator<SyncedFileState> CREATOR = new Creator<SyncedFileState>() { @Override public SyncedFileState createFromParcel(Parcel in) { return new SyncedFileState(in); } @Override public SyncedFileState[] newArray(int size) { return new SyncedFileState[size]; } }; public int getId() { return id; } Loading Loading @@ -127,4 +165,9 @@ public class SyncedFileState { +"\nisMediaType: "+this.isMediaType; } @Override public int describeContents() { return 0; } } app/src/main/java/foundation/e/drive/operations/ComparableOperation.java +0 −12 Original line number Diff line number Diff line Loading @@ -4,18 +4,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; public interface ComparableOperation { /** * Return the path that point on a remote file * @return String URI of the file */ public String getRemotePath(); /** * Return the path that point on a local file * @return String URI of the file */ public String getLocalPath(); /** * Say if File affected by operation is a media or a settings * @return Loading app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java +45 −46 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ package foundation.e.drive.operations; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; Loading @@ -24,61 +26,63 @@ import foundation.e.drive.utils.CommonUtils; * @author Vincent Bourgmayer * Encapsulate a global download process for a file */ public class DownloadFileOperation extends RemoteOperation implements ComparableOperation{ public class DownloadFileOperation extends RemoteOperation implements ComparableOperation, Parcelable { private final static String TAG = DownloadFileOperation.class.getSimpleName(); private final RemoteFile mRFile; private final Context mContext; private Context mContext; private String mTargetPath; private int restartCounter =0; private SyncedFileState mSyncedState; private String previousEtag; /** * Constructor download operation for new file * @param remoteFile Must not be null. File to download * @param targetPath Local Path where to download the file Must not be null or empty * @param context context of the app not service context * COnstructor of download operation where syncedFileState is already known * @param remoteFile remote file to Download * @param syncedFileState SyncedFileState corresponding to remote file */ public DownloadFileOperation(RemoteFile remoteFile, String targetPath, Long syncedFolderId,boolean syncedFolderIsMediaType, Context context){ this.mContext = context; this.mRFile = remoteFile; String remotePath = remoteFile.getRemotePath(); this.mSyncedState = DbHelper.loadSyncedFile(mContext, remotePath, false ); this.mTargetPath = targetPath; public DownloadFileOperation(RemoteFile remoteFile, SyncedFileState syncedFileState){ this.mRFile = remoteFile; this.mSyncedState = syncedFileState; this.previousEtag = mSyncedState.getLastETAG(); this.mTargetPath = this.mSyncedState.getLocalPath(); } if(this.mSyncedState == null){ //It's the first synchronisation of this file Log.d(TAG, " no SyncedFileState stored in DB for: "+remoteFile.getRemotePath() +"\n so it's first synchronisation of this file"); protected DownloadFileOperation(Parcel in) { mRFile = in.readParcelable(RemoteFile.class.getClassLoader()); mTargetPath = in.readString(); restartCounter = in.readInt(); mSyncedState = in.readParcelable(SyncedFileState.class.getClassLoader()); previousEtag = in.readString(); } this.mSyncedState = new SyncedFileState(-1, CommonUtils.getFileNameFromPath( remotePath ), //No need to check if null. It has already be done in ObserverService this.mTargetPath, remotePath, this.mRFile.getEtag(), 0L, syncedFolderId, syncedFolderIsMediaType); @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(mRFile, flags); dest.writeString(mTargetPath); dest.writeInt(restartCounter); dest.writeParcelable(mSyncedState, flags); dest.writeString(previousEtag); } this.previousEtag = mSyncedState.getLastETAG(); public static final Creator<DownloadFileOperation> CREATOR = new Creator<DownloadFileOperation>() { @Override public DownloadFileOperation createFromParcel(Parcel in) { return new DownloadFileOperation(in); } @Override public DownloadFileOperation[] newArray(int size) { return new DownloadFileOperation[size]; } }; /** * COnstructor of download operation where syncedFileState is already known * @param remoteFile remote file to Download * @param targetPath can be null if defined in syncedFileState * @param context calling context * @param syncedFileState SyncedFileState corresponding to remote file */ public DownloadFileOperation(RemoteFile remoteFile, String targetPath, Context context, SyncedFileState syncedFileState){ this.mRFile = remoteFile; public void setContext(Context context){ this.mContext = context; this.mSyncedState = syncedFileState; this.previousEtag = mSyncedState.getLastETAG(); this.mTargetPath = (targetPath == null)?this.mSyncedState.getLocalPath(): targetPath; } @Override protected RemoteOperationResult run(OwnCloudClient ownCloudClient) { Log.i(TAG, "run(ownCloudClient)"); Loading Loading @@ -177,17 +181,12 @@ public class DownloadFileOperation extends RemoteOperation implements Comparable } @Override public String getRemotePath() { return mSyncedState.getRemotePath(); } @Override public String getLocalPath() { return mTargetPath; public RemoteOperation toRemoteOperation() { return this; } @Override public RemoteOperation toRemoteOperation() { return this; public int describeContents() { return 0; } } app/src/main/java/foundation/e/drive/operations/RemoveFileOperation.java +32 −13 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ package foundation.e.drive.operations; import android.os.Parcel; import android.os.Parcelable; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation; import foundation.e.drive.models.SyncedFileState; Loading @@ -18,7 +21,7 @@ import foundation.e.drive.models.SyncedFileState; * Created by Vincent on 19/06/2018. * Class to be able to wrap concerned SyncedFileState in operation, so it can be retrieve at the end */ public class RemoveFileOperation extends RemoveFileRemoteOperation implements ComparableOperation{ public class RemoveFileOperation extends RemoveFileRemoteOperation implements ComparableOperation, Parcelable { private SyncedFileState mSyncedFileState; Loading @@ -27,6 +30,34 @@ public class RemoveFileOperation extends RemoveFileRemoteOperation implements Co this.mSyncedFileState = syncedFileState; } protected RemoveFileOperation(Parcel in) { super(in.readString()); mSyncedFileState = in.readParcelable(SyncedFileState.class.getClassLoader()); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(mSyncedFileState.getRemotePath()); dest.writeParcelable(mSyncedFileState, flags); } @Override public int describeContents() { return 0; } public static final Creator<RemoveFileOperation> CREATOR = new Creator<RemoveFileOperation>() { @Override public RemoveFileOperation createFromParcel(Parcel in) { return new RemoveFileOperation(in); } @Override public RemoveFileOperation[] newArray(int size) { return new RemoveFileOperation[size]; } }; public SyncedFileState getSyncedFileState() { return mSyncedFileState; } Loading @@ -40,18 +71,6 @@ public class RemoveFileOperation extends RemoveFileRemoteOperation implements Co return this.mSyncedFileState.isMediaType(); } @Override public String getRemotePath() { return this.mSyncedFileState.getRemotePath(); } /** * @inherited */ @Override public String getLocalPath() { return getSyncedFileState().getLocalPath(); } @Override public RemoteOperation toRemoteOperation() { return this; Loading Loading
app/build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ android { minSdkVersion 26 versionCode 1 //versionName "1.0" versionName "alpha-${versionMajor}-build-${buildTime()}" versionName "beta-${versionMajor}-build-o-${buildTime()}" setProperty("archivesBaseName", "$applicationId.$versionName") } Loading
app/src/main/java/foundation/e/drive/models/SyncedFileState.java +44 −1 Original line number Diff line number Diff line Loading @@ -8,12 +8,15 @@ package foundation.e.drive.models; import android.os.Parcel; import android.os.Parcelable; /** * @author Vincent Bourgmayer * Describe a file state which will be Synchronized (= Synced) or which has already been synced one times */ public class SyncedFileState { public class SyncedFileState implements Parcelable { protected SyncedFileState(){}; //@ToRemove. Test Only. It's to allow to make a mock SyncedFileState Class in test. Loading Loading @@ -47,6 +50,41 @@ public class SyncedFileState { this.isMediaType = isMediaType; } protected SyncedFileState(Parcel in) { id = in.readInt(); name = in.readString(); localPath = in.readString(); remotePath = in.readString(); lastETAG = in.readString(); localLastModified = in.readLong(); syncedFolderId = in.readLong(); isMediaType = in.readByte() != 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeString(name); dest.writeString(localPath); dest.writeString(remotePath); dest.writeString(lastETAG); dest.writeLong(localLastModified); dest.writeLong(syncedFolderId); dest.writeByte((byte) (isMediaType ? 1 : 0)); } public static final Creator<SyncedFileState> CREATOR = new Creator<SyncedFileState>() { @Override public SyncedFileState createFromParcel(Parcel in) { return new SyncedFileState(in); } @Override public SyncedFileState[] newArray(int size) { return new SyncedFileState[size]; } }; public int getId() { return id; } Loading Loading @@ -127,4 +165,9 @@ public class SyncedFileState { +"\nisMediaType: "+this.isMediaType; } @Override public int describeContents() { return 0; } }
app/src/main/java/foundation/e/drive/operations/ComparableOperation.java +0 −12 Original line number Diff line number Diff line Loading @@ -4,18 +4,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; public interface ComparableOperation { /** * Return the path that point on a remote file * @return String URI of the file */ public String getRemotePath(); /** * Return the path that point on a local file * @return String URI of the file */ public String getLocalPath(); /** * Say if File affected by operation is a media or a settings * @return Loading
app/src/main/java/foundation/e/drive/operations/DownloadFileOperation.java +45 −46 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ package foundation.e.drive.operations; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; Loading @@ -24,61 +26,63 @@ import foundation.e.drive.utils.CommonUtils; * @author Vincent Bourgmayer * Encapsulate a global download process for a file */ public class DownloadFileOperation extends RemoteOperation implements ComparableOperation{ public class DownloadFileOperation extends RemoteOperation implements ComparableOperation, Parcelable { private final static String TAG = DownloadFileOperation.class.getSimpleName(); private final RemoteFile mRFile; private final Context mContext; private Context mContext; private String mTargetPath; private int restartCounter =0; private SyncedFileState mSyncedState; private String previousEtag; /** * Constructor download operation for new file * @param remoteFile Must not be null. File to download * @param targetPath Local Path where to download the file Must not be null or empty * @param context context of the app not service context * COnstructor of download operation where syncedFileState is already known * @param remoteFile remote file to Download * @param syncedFileState SyncedFileState corresponding to remote file */ public DownloadFileOperation(RemoteFile remoteFile, String targetPath, Long syncedFolderId,boolean syncedFolderIsMediaType, Context context){ this.mContext = context; this.mRFile = remoteFile; String remotePath = remoteFile.getRemotePath(); this.mSyncedState = DbHelper.loadSyncedFile(mContext, remotePath, false ); this.mTargetPath = targetPath; public DownloadFileOperation(RemoteFile remoteFile, SyncedFileState syncedFileState){ this.mRFile = remoteFile; this.mSyncedState = syncedFileState; this.previousEtag = mSyncedState.getLastETAG(); this.mTargetPath = this.mSyncedState.getLocalPath(); } if(this.mSyncedState == null){ //It's the first synchronisation of this file Log.d(TAG, " no SyncedFileState stored in DB for: "+remoteFile.getRemotePath() +"\n so it's first synchronisation of this file"); protected DownloadFileOperation(Parcel in) { mRFile = in.readParcelable(RemoteFile.class.getClassLoader()); mTargetPath = in.readString(); restartCounter = in.readInt(); mSyncedState = in.readParcelable(SyncedFileState.class.getClassLoader()); previousEtag = in.readString(); } this.mSyncedState = new SyncedFileState(-1, CommonUtils.getFileNameFromPath( remotePath ), //No need to check if null. It has already be done in ObserverService this.mTargetPath, remotePath, this.mRFile.getEtag(), 0L, syncedFolderId, syncedFolderIsMediaType); @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(mRFile, flags); dest.writeString(mTargetPath); dest.writeInt(restartCounter); dest.writeParcelable(mSyncedState, flags); dest.writeString(previousEtag); } this.previousEtag = mSyncedState.getLastETAG(); public static final Creator<DownloadFileOperation> CREATOR = new Creator<DownloadFileOperation>() { @Override public DownloadFileOperation createFromParcel(Parcel in) { return new DownloadFileOperation(in); } @Override public DownloadFileOperation[] newArray(int size) { return new DownloadFileOperation[size]; } }; /** * COnstructor of download operation where syncedFileState is already known * @param remoteFile remote file to Download * @param targetPath can be null if defined in syncedFileState * @param context calling context * @param syncedFileState SyncedFileState corresponding to remote file */ public DownloadFileOperation(RemoteFile remoteFile, String targetPath, Context context, SyncedFileState syncedFileState){ this.mRFile = remoteFile; public void setContext(Context context){ this.mContext = context; this.mSyncedState = syncedFileState; this.previousEtag = mSyncedState.getLastETAG(); this.mTargetPath = (targetPath == null)?this.mSyncedState.getLocalPath(): targetPath; } @Override protected RemoteOperationResult run(OwnCloudClient ownCloudClient) { Log.i(TAG, "run(ownCloudClient)"); Loading Loading @@ -177,17 +181,12 @@ public class DownloadFileOperation extends RemoteOperation implements Comparable } @Override public String getRemotePath() { return mSyncedState.getRemotePath(); } @Override public String getLocalPath() { return mTargetPath; public RemoteOperation toRemoteOperation() { return this; } @Override public RemoteOperation toRemoteOperation() { return this; public int describeContents() { return 0; } }
app/src/main/java/foundation/e/drive/operations/RemoveFileOperation.java +32 −13 Original line number Diff line number Diff line Loading @@ -8,6 +8,9 @@ package foundation.e.drive.operations; import android.os.Parcel; import android.os.Parcelable; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation; import foundation.e.drive.models.SyncedFileState; Loading @@ -18,7 +21,7 @@ import foundation.e.drive.models.SyncedFileState; * Created by Vincent on 19/06/2018. * Class to be able to wrap concerned SyncedFileState in operation, so it can be retrieve at the end */ public class RemoveFileOperation extends RemoveFileRemoteOperation implements ComparableOperation{ public class RemoveFileOperation extends RemoveFileRemoteOperation implements ComparableOperation, Parcelable { private SyncedFileState mSyncedFileState; Loading @@ -27,6 +30,34 @@ public class RemoveFileOperation extends RemoveFileRemoteOperation implements Co this.mSyncedFileState = syncedFileState; } protected RemoveFileOperation(Parcel in) { super(in.readString()); mSyncedFileState = in.readParcelable(SyncedFileState.class.getClassLoader()); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(mSyncedFileState.getRemotePath()); dest.writeParcelable(mSyncedFileState, flags); } @Override public int describeContents() { return 0; } public static final Creator<RemoveFileOperation> CREATOR = new Creator<RemoveFileOperation>() { @Override public RemoveFileOperation createFromParcel(Parcel in) { return new RemoveFileOperation(in); } @Override public RemoveFileOperation[] newArray(int size) { return new RemoveFileOperation[size]; } }; public SyncedFileState getSyncedFileState() { return mSyncedFileState; } Loading @@ -40,18 +71,6 @@ public class RemoveFileOperation extends RemoveFileRemoteOperation implements Co return this.mSyncedFileState.isMediaType(); } @Override public String getRemotePath() { return this.mSyncedFileState.getRemotePath(); } /** * @inherited */ @Override public String getLocalPath() { return getSyncedFileState().getLocalPath(); } @Override public RemoteOperation toRemoteOperation() { return this; Loading