mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Add support for optional name in public shares (WIP)
This commit is contained in:
parent
0dce40b160
commit
188ce07155
@ -1,5 +1,5 @@
|
||||
/* ownCloud Android Library is available under MIT license
|
||||
* Copyright (C) 2016 ownCloud GmbH.
|
||||
* Copyright (C) 2017 ownCloud GmbH.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
package com.owncloud.android.lib.resources.shares;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.os.Parcel;
|
||||
@ -37,7 +38,7 @@ import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
* Contains the data of a Share from the Share API
|
||||
*
|
||||
* @author masensio
|
||||
*
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
public class OCShare implements Parcelable, Serializable {
|
||||
|
||||
@ -57,32 +58,26 @@ public class OCShare implements Parcelable, Serializable {
|
||||
public static final int MAXIMUM_PERMISSIONS_FOR_FILE =
|
||||
READ_PERMISSION_FLAG +
|
||||
UPDATE_PERMISSION_FLAG +
|
||||
SHARE_PERMISSION_FLAG
|
||||
;
|
||||
SHARE_PERMISSION_FLAG;
|
||||
public static final int MAXIMUM_PERMISSIONS_FOR_FOLDER =
|
||||
MAXIMUM_PERMISSIONS_FOR_FILE +
|
||||
CREATE_PERMISSION_FLAG +
|
||||
DELETE_PERMISSION_FLAG
|
||||
;
|
||||
DELETE_PERMISSION_FLAG;
|
||||
public static final int FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9 =
|
||||
READ_PERMISSION_FLAG +
|
||||
UPDATE_PERMISSION_FLAG
|
||||
;
|
||||
UPDATE_PERMISSION_FLAG;
|
||||
public static final int FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9 =
|
||||
READ_PERMISSION_FLAG +
|
||||
UPDATE_PERMISSION_FLAG +
|
||||
SHARE_PERMISSION_FLAG
|
||||
;
|
||||
SHARE_PERMISSION_FLAG;
|
||||
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 =
|
||||
READ_PERMISSION_FLAG +
|
||||
UPDATE_PERMISSION_FLAG +
|
||||
CREATE_PERMISSION_FLAG +
|
||||
DELETE_PERMISSION_FLAG
|
||||
;
|
||||
DELETE_PERMISSION_FLAG;
|
||||
public static final int FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 =
|
||||
FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 +
|
||||
SHARE_PERMISSION_FLAG
|
||||
;
|
||||
SHARE_PERMISSION_FLAG;
|
||||
|
||||
private long mId;
|
||||
private long mFileSource;
|
||||
@ -95,6 +90,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
private long mExpirationDate;
|
||||
private String mToken;
|
||||
private String mSharedWithDisplayName;
|
||||
private String mName;
|
||||
private boolean mIsFolder;
|
||||
private long mUserId;
|
||||
private long mRemoteId;
|
||||
@ -133,6 +129,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mUserId = -1;
|
||||
mRemoteId = -1;
|
||||
mShareLink = "";
|
||||
mName = "";
|
||||
}
|
||||
|
||||
/// Getters and Setters
|
||||
@ -141,7 +138,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public void setId(long id){
|
||||
public void setId(long id) {
|
||||
mId = id;
|
||||
}
|
||||
|
||||
@ -225,6 +222,20 @@ public class OCShare implements Parcelable, Serializable {
|
||||
this.mSharedWithDisplayName = (sharedWithDisplayName != null) ? sharedWithDisplayName : "";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (mName.length() > 0) {
|
||||
return mName;
|
||||
}
|
||||
if (mPath.length() > 0) {
|
||||
return (new File(mPath)).getName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
mName = (name != null) ? name : "";
|
||||
}
|
||||
|
||||
public boolean isFolder() {
|
||||
return mIsFolder;
|
||||
}
|
||||
@ -306,6 +317,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
mUserId = source.readLong();
|
||||
mRemoteId = source.readLong();
|
||||
mShareLink = source.readString();
|
||||
mName = source.readString();
|
||||
}
|
||||
|
||||
|
||||
@ -332,6 +344,7 @@ public class OCShare implements Parcelable, Serializable {
|
||||
dest.writeLong(mUserId);
|
||||
dest.writeLong(mRemoteId);
|
||||
dest.writeString(mShareLink);
|
||||
dest.writeString(mName);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ public class ShareToRemoteOperationResultParser {
|
||||
share.getShareLink().length() <= 0) &&
|
||||
share.getToken().length() > 0
|
||||
) {
|
||||
// TODO - deal with https://github.com/owncloud/android/issues/1811
|
||||
if (mServerBaseUri != null) {
|
||||
String sharingLinkPath = ShareUtils.getSharingLinkPath(mOwnCloudVersion);
|
||||
share.setShareLink(mServerBaseUri + sharingLinkPath + share.getToken());
|
||||
|
@ -76,6 +76,7 @@ public class ShareXMLParser {
|
||||
private static final String NODE_STORAGE = "storage";
|
||||
private static final String NODE_MAIL_SEND = "mail_send";
|
||||
private static final String NODE_SHARE_WITH_DISPLAY_NAME = "share_with_displayname";
|
||||
private static final String NODE_NAME = "name";
|
||||
|
||||
private static final String NODE_URL = "url";
|
||||
|
||||
@ -356,6 +357,9 @@ public class ShareXMLParser {
|
||||
String value = readNode(parser, NODE_URL);
|
||||
share.setShareLink(value);
|
||||
|
||||
} else if (name.equalsIgnoreCase(NODE_NAME)) {
|
||||
share.setName(readNode(parser, NODE_NAME));
|
||||
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
/**
|
||||
@ -54,6 +55,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
||||
|
||||
private static final String TAG = GetRemoteShareOperation.class.getSimpleName();
|
||||
|
||||
private static final String PARAM_NAME = "name";
|
||||
private static final String PARAM_PASSWORD = "password";
|
||||
private static final String PARAM_EXPIRATION_DATE = "expireDate";
|
||||
private static final String PARAM_PERMISSIONS = "permissions";
|
||||
@ -87,6 +89,7 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
||||
* Upload permissions for the public link (only folders)
|
||||
*/
|
||||
private Boolean mPublicUpload;
|
||||
private String mName;
|
||||
|
||||
|
||||
/**
|
||||
@ -102,6 +105,17 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set name to update in Share resource. Ignored by servers previous to version 10.0.0
|
||||
*
|
||||
* @param name Name to set to the target share.
|
||||
* Empty string clears the current name.
|
||||
* Null results in no update applied to the name.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.mName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set password to update in Share resource.
|
||||
*
|
||||
@ -150,38 +164,41 @@ public class UpdateRemoteShareOperation extends RemoteOperation {
|
||||
@Override
|
||||
protected RemoteOperationResult run(OwnCloudClient client) {
|
||||
RemoteOperationResult result = null;
|
||||
int status = -1;
|
||||
int status;
|
||||
|
||||
/// prepare array of parameters to update
|
||||
List<Pair<String, String>> parametersToUpdate = new ArrayList<Pair<String, String>>();
|
||||
List<Pair<String, String>> parametersToUpdate = new ArrayList<>();
|
||||
if (mName != null) {
|
||||
parametersToUpdate.add(new Pair<>(PARAM_NAME, mName));
|
||||
}
|
||||
if (mPassword != null) {
|
||||
parametersToUpdate.add(new Pair<String, String>(PARAM_PASSWORD, mPassword));
|
||||
parametersToUpdate.add(new Pair<>(PARAM_PASSWORD, mPassword));
|
||||
}
|
||||
if (mExpirationDateInMillis < 0) {
|
||||
// clear expiration date
|
||||
parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, ""));
|
||||
parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, ""));
|
||||
|
||||
} else if (mExpirationDateInMillis > 0) {
|
||||
// set expiration date
|
||||
DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE);
|
||||
DateFormat dateFormat = new SimpleDateFormat(FORMAT_EXPIRATION_DATE, Locale.GERMAN);
|
||||
Calendar expirationDate = Calendar.getInstance();
|
||||
expirationDate.setTimeInMillis(mExpirationDateInMillis);
|
||||
String formattedExpirationDate = dateFormat.format(expirationDate.getTime());
|
||||
parametersToUpdate.add(new Pair(PARAM_EXPIRATION_DATE, formattedExpirationDate));
|
||||
parametersToUpdate.add(new Pair<>(PARAM_EXPIRATION_DATE, formattedExpirationDate));
|
||||
|
||||
} // else, ignore - no update
|
||||
if (mPermissions > 0) {
|
||||
// set permissions
|
||||
parametersToUpdate.add(new Pair(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
|
||||
parametersToUpdate.add(new Pair<>(PARAM_PERMISSIONS, Integer.toString(mPermissions)));
|
||||
}
|
||||
|
||||
if (mPublicUpload != null) {
|
||||
parametersToUpdate.add(new Pair(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)));
|
||||
parametersToUpdate.add(new Pair<>(PARAM_PUBLIC_UPLOAD, Boolean.toString(mPublicUpload)));
|
||||
}
|
||||
|
||||
/// perform required PUT requests
|
||||
PutMethod put = null;
|
||||
String uriString = null;
|
||||
String uriString;
|
||||
|
||||
try {
|
||||
Uri requestUri = client.getBaseUri();
|
||||
|
Loading…
x
Reference in New Issue
Block a user