* Flag signaling if the ownCloud server can be accessed with session cookies from SAML-based web single-sign-on.
*/
public static final String KEY_SUPPORTS_SAML_WEB_SSO = "oc_supports_saml_web_sso";
+ /**
+ * Flag signaling if the ownCloud server supports Share API"
+ */
+ public static final String KEY_SUPPORTS_SHARE_API = "oc_supports_share_api";
}
private String mAuthTokenType;
import com.owncloud.android.oc_framework.network.webdav.WebdavEntry;
import com.owncloud.android.oc_framework.utils.FileUtils;
+/**
+ * Contains the data of a Share Remote File from the Share API
+ *
+ * @author masensio
+ *
+ */
public class ShareRemoteFile extends RemoteFile {
/**
--- /dev/null
+/* ownCloud Android Library is available under MIT license
+ * Copyright (C) 2014 ownCloud (http://www.owncloud.org/)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ */
+
+package com.owncloud.android.oc_framework.operations.remote;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.http.HttpStatus;
+
+import android.util.Log;
+
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.operations.RemoteOperation;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.ShareRemoteFile;
+
+/**
+ * Get the data from the server to know shared files/folders
+ *
+ * @author masensio
+ *
+ */
+
+public class GetRemoteSharedFilesOperation extends RemoteOperation {
+
+ private static final String TAG = GetRemoteSharedFilesOperation.class.getSimpleName();
+
+ // OCS Route
+ private static final String SHAREAPI_ROUTE ="/ocs/v1.php/apps/files/files_sharing/api/v1/shares";
+
+ private ArrayList<ShareRemoteFile> mSharedFiles; // List of files for result
+
+ public GetRemoteSharedFilesOperation() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ protected RemoteOperationResult run(WebdavClient client) {
+ RemoteOperationResult result = null;
+ int status = -1;
+
+ // Get Method
+ GetMethod get = new GetMethod(client.getBaseUri() + SHAREAPI_ROUTE);
+ Log.d(TAG, "URL ------> " + client.getBaseUri() + SHAREAPI_ROUTE);
+
+ // Get the response
+ try{
+ status = client.executeMethod(get);
+ if(isSuccess(status)) {
+ Log.d(TAG, "Obtain RESPONSE");
+ String response = get.getResponseBodyAsString();
+ Log.d(TAG, response);
+ }
+ } catch (HttpException e) {
+ result = new RemoteOperationResult(e);
+ e.printStackTrace();
+ } catch (IOException e) {
+ result = new RemoteOperationResult(e);
+ e.printStackTrace();
+ } finally {
+ get.releaseConnection();
+ }
+ return result;
+ }
+
+ private boolean isSuccess(int status) {
+ return (status == HttpStatus.SC_OK);
+ }
+}
mHostUrlInput.setText(mHostBaseUrl);\r
String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
mUsernameInput.setText(userName);\r
+ mIsSharedSupported = Boolean.getBoolean(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API));\r
+ \r
}\r
initAuthorizationMethod(); // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
mJustCreated = true;\r
/// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION, mDiscoveredVersion.toString());\r
mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL, mHostBaseUrl);\r
+ mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API, Boolean.toString(mIsSharedSupported));\r
if (isSaml) {\r
mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
} else if (isOAuth) {\r
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.operations;
+
+import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
+import com.owncloud.android.oc_framework.operations.RemoteOperation;
+import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.remote.GetRemoteSharedFilesOperation;
+
+/**
+ * Access to remote operation to get the share files/folders
+ * Save the data in Database
+ *
+ * @author masensio
+ */
+
+public class GetSharedFilesOperation extends RemoteOperation {
+
+ public GetSharedFilesOperation() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ protected RemoteOperationResult run(WebdavClient client) {
+ GetRemoteSharedFilesOperation operation = new GetRemoteSharedFilesOperation();
+ RemoteOperationResult result = operation.execute(client);
+
+ if (result.isSuccess()) {
+
+ } else {
+
+ }
+
+ return null;
+ }
+
+}
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.oc_framework.accounts.OwnCloudAccount;
import com.owncloud.android.oc_framework.network.webdav.WebdavUtils;
import com.owncloud.android.utils.Log_OC;
/** Flag to signal if the activity is launched by a notification */
private boolean mFromNotification;
+
+ /** Flag to signal if the server supports the Share API */
+ private boolean mIsSharedSupported;
+
+
/**
*/
private void swapToDefaultAccount() {
// default to the most recently used account
+ AccountManager accountManager = AccountManager.get(this);
Account newAccount = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext());
if (newAccount == null) {
/// no account available: force account creation
mAccountWasRestored = (newAccount.equals(mAccount));
mAccount = newAccount;
}
+ setIsSharedSupported( Boolean.getBoolean(accountManager.getUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SHARE_API)));
}
/**
+ * @return 'True' if the server supports the Share API
+ */
+ public boolean isSharedSupported() {
+ return mIsSharedSupported;
+ }
+
+
+ public void setIsSharedSupported(boolean mIsSharedSupported) {
+ this.mIsSharedSupported = mIsSharedSupported;
+ }
+
+ /**
* Helper class handling a callback from the {@link AccountManager} after the creation of
* a new ownCloud {@link Account} finished, successfully or not.
*
import com.owncloud.android.oc_framework.operations.RemoteOperation;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;
+import com.owncloud.android.operations.GetSharedFilesOperation;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.operations.RenameFileOperation;
import com.owncloud.android.operations.SynchronizeFileOperation;
protected void onAccountSet(boolean stateWasRecovered) {
if (getAccount() != null) {
mStorageManager = new FileDataStorageManager(getAccount(), getContentResolver());
-
+
/// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
OCFile file = getFile();
// get parent from path
}
setFile(file);
setNavigationListWithFolder(file);
+
+ /// get the shared files
+ if (isSharedSupported()) {
+ startGetSharedFiles();
+ }
+
if (!stateWasRecovered) {
Log_OC.e(TAG, "Initializing Fragments in onAccountChanged..");
initFragmentsWithFile();
} else if (operation instanceof CreateFolderOperation) {
onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
- }
+ } else if (operation instanceof GetSharedFilesOperation) {
+ onGetSharedFilesOperationFinish((GetSharedFilesOperation) operation, result);
+ }
}
+ /** Updates the data about shared files
+ *
+ * @param operation Get Shared Files
+ * @param result Result of the operation
+ */
+ private void onGetSharedFilesOperationFinish(GetSharedFilesOperation operation, RemoteOperationResult result) {
+ // TODO
+ // Refresh the filelist with the information
+ refeshListOfFilesFragment();
+
+ }
+
/**
* Updates the view associated to the activity after the finish of an operation trying to remove a
* file.
}
+ private void startGetSharedFiles() {
+ // Get shared files/folders
+ RemoteOperation getSharedFiles = new GetSharedFilesOperation();
+ getSharedFiles.execute(getAccount(), this, null, null, this);
+
+ }
+
// public void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
// int childCount = viewGroup.getChildCount();
// for (int i = 0; i < childCount; i++) {