1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-14 19:36:13 +00:00

Merge pull request #193 from owncloud/master

Release 0.9.20 stable
This commit is contained in:
David González Verdugo 2018-07-19 14:54:40 +02:00 committed by GitHub
commit d2db461c74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 648 additions and 267 deletions

View File

@ -34,7 +34,7 @@
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" /> <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-sdk <uses-sdk
android:minSdkVersion="8" android:minSdkVersion="14"
android:targetSdkVersion="26" /> android:targetSdkVersion="26" />
</manifest> </manifest>

View File

@ -1,25 +1,29 @@
buildscript { buildscript {
repositories { repositories {
jcenter() jcenter()
google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.android.tools.build:gradle:3.1.2'
} }
} }
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
repositories { allprojects {
jcenter() repositories {
google()
jcenter()
}
} }
dependencies { dependencies {
compile 'org.apache.jackrabbit:jackrabbit-webdav:2.12.4' api 'org.apache.jackrabbit:jackrabbit-webdav:2.12.4'
api 'com.squareup.okhttp3:okhttp:3.10.0'
} }
android { android {
compileSdkVersion 26 compileSdkVersion 26
buildToolsVersion '26.0.2'
sourceSets { sourceSets {
main { main {
@ -33,7 +37,7 @@ android {
} }
// Move the tests to tests/java, tests/res, etc... // Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests') androidTest.setRoot('tests')
// Move the build types to build-types/<type> // Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

View File

@ -24,22 +24,27 @@
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.owncloud.android.lib.sampleclient" package="com.owncloud.android.lib.sampleclient"
android:versionCode="1" android:versionCode="1"
android:versionName="1.0"> android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk <uses-sdk
android:minSdkVersion="8" android:minSdkVersion="14"
android:targetSdkVersion="26" /> android:targetSdkVersion="26"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> <application
<activity android:name="MainActivity" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="portrait" android:theme="@android:style/Theme.Light.NoTitleBar">
android:configChanges="orientation|keyboardHidden" <activity
> android:name="MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait"
>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>

View File

@ -0,0 +1 @@
Testing ownCloud uploads

View File

@ -5,12 +5,11 @@ repositories {
} }
dependencies { dependencies {
compile project(':') implementation project(':')
} }
android { android {
compileSdkVersion 26 compileSdkVersion 26
buildToolsVersion "26.0.2"
sourceSets { sourceSets {
main { main {
@ -24,7 +23,7 @@ android {
} }
// Move the tests to tests/java, tests/res, etc... // Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests') androidTest.setRoot('tests')
// Move the build types to build-types/<type> // Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
@ -43,9 +42,4 @@ android {
packagingOptions { packagingOptions {
exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE.txt'
} }
android {
lintOptions {
abortOnError false
}
}
} }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

View File

@ -24,99 +24,150 @@
--> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
> >
<EditText
android:id="@+id/server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/button_check_server"
android:layout_toStartOf="@+id/button_check_server"
android:ems="10"
android:hint="Server address (with http or https)"
android:inputType="textPersonName"/>
<Button
android:id="@+id/button_check_server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/server_address"
android:layout_alignBottom="@+id/server_address"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:onClick="onClickHandler"
android:text="@string/check_server"/>
<Button <Button
android:id="@+id/button_refresh" android:id="@+id/button_refresh"
style="@style/ButtonStyle"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/refresh"
android:onClick="onClickHandler"
/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/button_refresh" android:layout_alignParentEnd="true"
android:layout_above="@+id/button_upload"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
> android:layout_below="@id/server_address"
</ListView> android:layout_marginTop="10dp"
android:onClick="onClickHandler"
android:text="@string/refresh"/>
<Button <Button
android:id="@+id/button_upload" android:id="@+id/button_upload"
style="@style/ButtonStyle"
android:layout_alignParentLeft="true"
android:layout_above="@+id/frame"
android:text="@string/upload"
android:onClick="onClickHandler"
/>
<TextView
android:id="@+id/upload_progress"
style="@style/ProgressStyle"
android:layout_below="@id/list_view"
android:layout_above="@id/frame"
android:layout_toRightOf="@id/button_upload"
android:layout_toLeftOf="@+id/button_delete_remote"
android:gravity="center"
android:textSize="14sp"
android:text="0%"
/>
<Button
android:id="@id/button_delete_remote"
style="@style/ButtonStyle"
android:layout_alignParentRight="true"
android:layout_above="@id/frame"
android:text="@string/delete_remote_file"
android:onClick="onClickHandler"
/>
<FrameLayout
android:id="@id/frame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/frame_height" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@id/button_refresh"
android:layout_above="@+id/button_download" android:layout_marginTop="10dp"
> android:onClick="onClickHandler"
</FrameLayout> android:text="@string/upload"/>
<Button <Button
android:id="@id/button_download" android:id="@+id/button_download"
style="@style/ButtonStyle" android:layout_width="match_parent"
android:layout_alignParentBottom="true" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:text="@string/download" android:layout_below="@id/button_upload"
android:layout_marginTop="10dp"
android:onClick="onClickHandler" android:onClick="onClickHandler"
/> android:text="@string/download"/>
<TextView
android:id="@+id/download_progress"
style="@style/ProgressStyle"
android:layout_below="@id/frame"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@id/button_download"
android:layout_toLeftOf="@+id/button_delete_local"
android:gravity="center"
android:textSize="14sp"
android:text="0%"
/>
<Button <Button
android:id="@id/button_delete_local" android:id="@+id/button_delete_remote"
style="@style/ButtonStyle" android:layout_width="match_parent"
android:layout_alignParentBottom="true" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentLeft="true"
android:text="@string/delete_local_file" android:layout_below="@id/button_download"
android:layout_marginTop="10dp"
android:onClick="onClickHandler" android:onClick="onClickHandler"
/> android:text="@string/delete_remote_file"/>
<!--<ListView-->
<!--android:id="@+id/list_view"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_alignParentLeft="true"-->
<!--android:layout_alignParentRight="true"-->
<!--android:layout_below="@+id/button_refresh"-->
<!--android:visibility="invisible">-->
<!--</ListView>-->
<!--<TextView-->
<!--android:id="@+id/upload_progress"-->
<!--style="@style/ProgressStyle"-->
<!--android:layout_above="@id/frame"-->
<!--android:layout_below="@id/list_view"-->
<!--android:layout_toLeftOf="@+id/button_delete_remote"-->
<!--android:layout_toRightOf="@id/button_upload"-->
<!--android:enabled="false"-->
<!--android:gravity="center"-->
<!--android:text="0%"-->
<!--android:textSize="14sp"-->
<!--android:visibility="invisible"/>-->
<!--<Button-->
<!--android:id="@id/button_delete_remote"-->
<!--style="@style/ButtonStyle"-->
<!--android:layout_above="@id/frame"-->
<!--android:layout_alignParentRight="true"-->
<!--android:enabled="false"-->
<!--android:onClick="onClickHandler"-->
<!--android:text="@string/delete_remote_file"-->
<!--android:visibility="invisible"/>-->
<!--<FrameLayout-->
<!--android:id="@id/frame"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/frame_height"-->
<!--android:layout_alignParentLeft="true"-->
<!--android:layout_alignParentRight="true"-->
<!--android:layout_above="@+id/button_download"-->
<!--&gt;-->
<!--</FrameLayout>-->
<!--<Button-->
<!--android:id="@id/button_download"-->
<!--style="@style/ButtonStyle"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_alignParentLeft="true"-->
<!--android:enabled="false"-->
<!--android:onClick="onClickHandler"-->
<!--android:text="@string/download"-->
<!--android:visibility="invisible"/>-->
<!--<TextView-->
<!--android:id="@+id/download_progress"-->
<!--style="@style/ProgressStyle"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_below="@id/frame"-->
<!--android:layout_toLeftOf="@+id/button_delete_local"-->
<!--android:layout_toRightOf="@id/button_download"-->
<!--android:enabled="false"-->
<!--android:gravity="center"-->
<!--android:text="0%"-->
<!--android:textSize="14sp"-->
<!--android:visibility="invisible"/>-->
<!--<Button-->
<!--android:id="@id/button_delete_local"-->
<!--style="@style/ButtonStyle"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:layout_alignParentRight="true"-->
<!--android:enabled="false"-->
<!--android:onClick="onClickHandler"-->
<!--android:text="@string/delete_local_file"-->
<!--android:visibility="invisible"/>-->
</RelativeLayout> </RelativeLayout>

View File

@ -26,6 +26,7 @@
<resources> <resources>
<string name="app_name">ownCloud Sample Client</string> <string name="app_name">ownCloud Sample Client</string>
<string name="refresh">Refresh</string> <string name="refresh">Refresh</string>
<string name="check_server">Check server</string>
<string name="upload">Upload</string> <string name="upload">Upload</string>
<string name="delete_remote_file">Delete remote file</string> <string name="delete_remote_file">Delete remote file</string>
<string name="download">Download</string> <string name="download">Download</string>

View File

@ -1,5 +1,7 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH. * Copyright (C) 2018 ownCloud GmbH.
*
* @author David González Verdugo
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -24,6 +26,35 @@
package com.owncloud.android.lib.sampleclient; package com.owncloud.android.lib.sampleclient;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -32,36 +63,31 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import okhttp3.Call;
import com.owncloud.android.lib.common.OwnCloudClientFactory; import okhttp3.Callback;
import com.owncloud.android.lib.common.OwnCloudClient; import okhttp3.Credentials;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; import okhttp3.Headers;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import okhttp3.MediaType;
import com.owncloud.android.lib.resources.files.RemoteFile; import okhttp3.OkHttpClient;
import com.owncloud.android.lib.common.operations.RemoteOperation; import okhttp3.Request;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import okhttp3.RequestBody;
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation; import okhttp3.Response;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.FileUtils;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnRemoteOperationListener, OnDatatransferProgressListener { public class MainActivity extends Activity implements OnRemoteOperationListener, OnDatatransferProgressListener {
private static String LOG_TAG = MainActivity.class.getCanonicalName(); private static String LOG_TAG = MainActivity.class.getCanonicalName();
private static final String NODE_VERSION = "version";
private static final String WEBDAV_PATH_4_0 = "/remote.php/webdav/";
private static final String NEW_WEBDAV_PATH = "/remote.php/dav/files/";
private static final String OC_TOTAL_LENGTH_HEADER = "OC-Total-Length";
private static final String OC_X_OC_MTIME_HEADER = "X-OC-Mtime";
private static final String AUTHORIZATION_HEADER = "Authorization";
private static final String USER_AGENT_HEADER = "User-Agent";
private static final String CONTENT_TYPE_HEADER = "Content-Type";
private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Android) ownCloud-android/2.7.0";
private static final String CONTENT_TYPE_VALUE = "multipart/form-data";
private Handler mHandler; private Handler mHandler;
private OwnCloudClient mClient; private OwnCloudClient mClient;
@ -70,6 +96,10 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private View mFrame; private View mFrame;
private OkHttpClient mOkHttpClient;
private String mCredentials;
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -88,7 +118,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
); );
mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list); mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list);
((ListView)findViewById(R.id.list_view)).setAdapter(mFilesAdapter); // ((ListView)findViewById(R.id.list_view)).setAdapter(mFilesAdapter);
// TODO move to background thread or task // TODO move to background thread or task
AssetManager assets = getAssets(); AssetManager assets = getAssets();
@ -111,7 +141,13 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
Log.e(LOG_TAG, getString(R.string.error_copying_sample_file), e); Log.e(LOG_TAG, getString(R.string.error_copying_sample_file), e);
} }
mFrame = findViewById(R.id.frame); ((TextView) findViewById(R.id.server_address)).setText(getString(R.string.server_base_url));
mOkHttpClient = new OkHttpClient();
mCredentials = Credentials.basic(getString(R.string.username), getString(R.string.password));
// mFrame = findViewById(R.id.frame);
} }
@ -127,63 +163,264 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
public void onClickHandler(View button) { public void onClickHandler(View button) {
switch (button.getId()) { switch (button.getId()) {
case R.id.button_check_server:
startCheck();
break;
case R.id.button_refresh: case R.id.button_refresh:
startRefresh(); startRefresh();
break; break;
case R.id.button_upload: case R.id.button_upload:
startUpload(); startUpload();
break; break;
case R.id.button_download:
startDownload();
break;
case R.id.button_delete_remote: case R.id.button_delete_remote:
startRemoteDeletion(); startRemoteDeletion();
break; break;
case R.id.button_download: // case R.id.button_delete_local:
startDownload(); // startLocalDeletion();
break; // break;
case R.id.button_delete_local:
startLocalDeletion();
break;
default: default:
Toast.makeText(this, R.string.youre_doing_it_wrong, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.youre_doing_it_wrong, Toast.LENGTH_SHORT).show();
} }
} }
private void startRefresh() { private void startCheck() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
refreshOperation.execute(mClient, this, mHandler); if (!validServerAddress()) return;
}
Request request = new Request.Builder()
.url(getString(R.string.server_base_url) + "/status.php")
.get()
.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
showMessage("Response not successful with code: " + response.code());
throw new IOException("Unexpected code " + response);
}
try { // Successful response
String jsonData = response.body().string();
JSONObject Jobject = new JSONObject(jsonData);
final String serverVersion = Jobject.get("version").toString();
showMessage("Server with version " + serverVersion + " detected");
} catch (JSONException e) {
e.printStackTrace();
}
Headers responseHeaders = response.headers();
for (int i = 0, size = responseHeaders.size(); i < size; i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
}
@Override public void onFailure(Call call, final IOException e) {
e.printStackTrace();
showMessage("Something was wrong: " + e.toString());
}
});
}
private void startRefresh() {
// Let's first use OKHttp with the new endpoint without depending on our library operations
// ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
// refreshOperation.execute(mClient, this, mHandler);
if (!validServerAddress()) return;
final Request request = new Request.Builder()
.url(getString(R.string.server_base_url) + NEW_WEBDAV_PATH + getString(R.string.username))
.addHeader(AUTHORIZATION_HEADER, mCredentials)
.addHeader(USER_AGENT_HEADER, USER_AGENT_VALUE)
.method("PROPFIND", null)
.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
showMessage("Response not successful with code: " + response.code());
throw new IOException("Unexpected code " + response);
} else { // Successful response
final String propFindResult = response.body().string();
showMessage(propFindResult);
Headers responseHeaders = response.headers();
for (int i = 0, size = responseHeaders.size(); i < size; i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
}
}
@Override public void onFailure(Call call, IOException e) {
showMessage("Something was wrong: " + e.toString());
e.printStackTrace();
}
});
}
private void startUpload() { private void startUpload() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0]; final File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
String mimeType = getString(R.string.sample_file_mimetype); String mimeType = getString(R.string.sample_file_mimetype);
MediaType mediaType = MediaType.parse(mimeType);
// Get the last modification date of the file from the file system // Get the last modification date of the file from the file system
Long timeStampLong = fileToUpload.lastModified()/1000; Long timeStampLong = fileToUpload.lastModified()/1000;
String timeStamp = timeStampLong.toString(); String timeStamp = timeStampLong.toString();
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp); // Let's first use OKHttp with the new endpoint without depending on our library operations
uploadOperation.addDatatransferProgressListener(this);
uploadOperation.execute(mClient, this, mHandler); // UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp);
// uploadOperation.addDatatransferProgressListener(this);
// uploadOperation.execute(mClient, this, mHandler);
if (!validServerAddress()) return;
RequestBody requestBody = RequestBody.create(mediaType, fileToUpload);
final Request request = new Request.Builder()
.url(getString(R.string.server_base_url) + NEW_WEBDAV_PATH + getString(R.string.username) + remotePath)
.addHeader(AUTHORIZATION_HEADER, mCredentials)
.addHeader(USER_AGENT_HEADER, USER_AGENT_VALUE)
.addHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_VALUE)
.addHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(fileToUpload.length()))
.addHeader(OC_X_OC_MTIME_HEADER, timeStamp)
.put(requestBody)
.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
showMessage("Response not successful with code: " + response.code());
throw new IOException("Unexpected code " + response);
} else { // Successful response
showMessage("Successful upload of " + fileToUpload.getName());
}
}
@Override public void onFailure(Call call, IOException e) {
e.printStackTrace();
showMessage("Something was wrong: " + e.toString());
}
});
} }
private void startRemoteDeletion() { private void startDownload() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
File fileToUpload = upFolder.listFiles()[0]; downFolder.mkdir();
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); final File fileToUpload = upFolder.listFiles()[0];
removeOperation.execute(mClient, this, mHandler); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
}
private void startDownload() { // Let's first use OKHttp with the new endpoint without depending on our library operations
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
downFolder.mkdir(); // DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath());
// downloadOperation.addDatatransferProgressListener(this);
// downloadOperation.execute(mClient, this, mHandler);
if (!validServerAddress()) return;
final Request request = new Request.Builder()
.url(getString(R.string.server_base_url) + NEW_WEBDAV_PATH + getString(R.string.username) + remotePath)
.addHeader(AUTHORIZATION_HEADER, mCredentials)
.addHeader(USER_AGENT_HEADER, USER_AGENT_VALUE)
.get()
.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
showMessage("Response not successful with code: " + response.code());
throw new IOException("Unexpected code " + response);
} else { // Successful response
showMessage("Successful download of " + fileToUpload.getName() + " although local file " +
"won't be created in this stage");
}
}
@Override public void onFailure(Call call, IOException e) {
e.printStackTrace();
showMessage("Something was wrong: " + e.toString());
}
});
}
private void startRemoteDeletion() {
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path)); File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0]; final File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName(); String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath());
downloadOperation.addDatatransferProgressListener(this); // Let's first use OKHttp with the new endpoint without depending on our library operations
downloadOperation.execute(mClient, this, mHandler); // RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
// removeOperation.execute(mClient, this, mHandler);
if (!validServerAddress()) return;
final Request request = new Request.Builder()
.url(getString(R.string.server_base_url) + NEW_WEBDAV_PATH + getString(R.string.username) + remotePath)
.addHeader(AUTHORIZATION_HEADER, mCredentials)
.addHeader(USER_AGENT_HEADER, USER_AGENT_VALUE)
.delete()
.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override public void onResponse(Call call, final Response response) throws IOException {
if (!response.isSuccessful()) {
showMessage("Response not successful with code: " + response.code());
throw new IOException("Unexpected code " + response);
} else { // Successful response
showMessage("Successful deletion of " + fileToUpload.getName());
}
}
@Override public void onFailure(Call call, IOException e) {
e.printStackTrace();
showMessage("Something was wrong: " + e.toString());
}
});
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -193,8 +430,8 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
if (!downloadedFile.delete() && downloadedFile.exists()) { if (!downloadedFile.delete() && downloadedFile.exists()) {
Toast.makeText(this, R.string.error_deleting_local_file, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.error_deleting_local_file, Toast.LENGTH_SHORT).show();
} else { } else {
((TextView) findViewById(R.id.download_progress)).setText("0%"); // ((TextView) findViewById(R.id.download_progress)).setText("0%");
findViewById(R.id.frame).setBackgroundDrawable(null); // findViewById(R.id.frame).setBackgroundDrawable(null);
} }
} }
@ -243,10 +480,10 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void onSuccessfulRemoteDeletion(RemoveRemoteFileOperation operation, RemoteOperationResult result) { private void onSuccessfulRemoteDeletion(RemoveRemoteFileOperation operation, RemoteOperationResult result) {
startRefresh(); startRefresh();
TextView progressView = (TextView) findViewById(R.id.upload_progress); // TextView progressView = (TextView) findViewById(R.id.upload_progress);
if (progressView != null) { // if (progressView != null) {
progressView.setText("0%"); // progressView.setText("0%");
} // }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -266,11 +503,11 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
@Override @Override
public void run() { public void run() {
TextView progressView = null; TextView progressView = null;
if (upload) { // if (upload) {
progressView = (TextView) findViewById(R.id.upload_progress); // progressView = (TextView) findViewById(R.id.upload_progress);
} else { // } else {
progressView = (TextView) findViewById(R.id.download_progress); // progressView = (TextView) findViewById(R.id.download_progress);
} // }
if (progressView != null) { if (progressView != null) {
progressView.setText(Long.toString(percentage) + "%"); progressView.setText(Long.toString(percentage) + "%");
} }
@ -278,4 +515,32 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
}); });
} }
private boolean validServerAddress() {
String serverAddress = ((TextView) findViewById(R.id.server_address)).getText().toString();
if (serverAddress.equals("") || (!serverAddress.contains("http://") && !serverAddress.contains("https://"))) {
showToastMessage("Introduce a proper server address with http/https");
return false;
}
return true;
}
private void showMessage(final String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
showToastMessage(message);
}
});
}
private void showToastMessage(String message) {
Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
} }

View File

@ -1,5 +1,7 @@
/* ownCloud Android Library is available under MIT license /** ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH. *
* @author Christian Schabesberger
* Copyright (C) 2018 ownCloud GmbH.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -164,7 +166,7 @@ public class WebdavEntry {
prop = propSet.get( prop = propSet.get(
EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(NAMESPACE_OC) EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(NAMESPACE_OC)
); );
if (prop != null) { if (prop != null && prop.getValue() != null) {
mPermissions = prop.getValue().toString(); mPermissions = prop.getValue().toString();
} }

View File

@ -140,6 +140,17 @@ public class WebdavUtils {
return propSet; return propSet;
} }
/**
* Builds a DavPropertyNameSet with properties for user quotas
* @return set of quota properties
*/
public static DavPropertyNameSet getQuotaPropSet() {
DavPropertyNameSet propSet = new DavPropertyNameSet();
propSet.add(DavPropertyName.create(WebdavEntry.PROPERTY_QUOTA_AVAILABLE_BYTES));
propSet.add(DavPropertyName.create(WebdavEntry.PROPERTY_QUOTA_USED_BYTES));
return propSet;
}
/** /**
* *
* @param rawEtag * @param rawEtag

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH. * Copyright (C) 2018 ownCloud GmbH.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -55,11 +55,12 @@ import javax.net.ssl.SSLException;
/** /**
* The result of a remote operation required to an ownCloud server. * The result of a remote operation required to an ownCloud server.
* <p/> *
* Provides a common classification of remote operation results for all the * Provides a common classification of remote operation results for all the
* application. * application.
* *
* @author David A. Velasco * @author David A. Velasco
* @author David González Verdugo
*/ */
public class RemoteOperationResult implements Serializable { public class RemoteOperationResult implements Serializable {
@ -378,8 +379,8 @@ public class RemoteOperationResult implements Serializable {
} }
} }
public void setData(ArrayList<Object> files) { public void setData(ArrayList<Object> items) {
mData = files; mData = items;
} }
public ArrayList<Object> getData() { public ArrayList<Object> getData() {

View File

@ -150,7 +150,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation {
remoteFile = fillOCFile(we); remoteFile = fillOCFile(we);
mFolderAndFiles.add(remoteFile); mFolderAndFiles.add(remoteFile);
} }
} }
/** /**

View File

@ -1,6 +1,7 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* @author masensio * @author masensio
* Copyright (C) 2016 ownCloud GmbH. * @author Semih Serhat Karakaya <karakayasemi@itu.edu.tr>
* Copyright (C) 2018 ownCloud GmbH.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -245,8 +246,10 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
capability.setFilesUndelete(CapabilityBooleanType.fromBooleanValue( capability.setFilesUndelete(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_UNDELETE))); respFiles.getBoolean(PROPERTY_UNDELETE)));
} }
capability.setFilesVersioning(CapabilityBooleanType.fromBooleanValue( if (respFiles.has(PROPERTY_VERSIONING)) {
respFiles.getBoolean(PROPERTY_VERSIONING))); capability.setFilesVersioning(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_VERSIONING)));
}
Log_OC.d(TAG, "*** Added " + NODE_FILES); Log_OC.d(TAG, "*** Added " + NODE_FILES);
} }
} }

View File

@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* *
* Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2018 ownCloud Inc.
* Copyright (C) 2015 Bartosz Przybylski * Copyright (C) 2015 Bartosz Przybylski
* Copyright (C) 2014 Marcello Steiner * Copyright (C) 2014 Marcello Steiner
* *
@ -28,24 +28,38 @@
package com.owncloud.android.lib.resources.users; package com.owncloud.android.lib.resources.users;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair; import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.jackrabbit.webdav.MultiStatus;
import org.json.JSONObject; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* @author marcello * @author marcello
* @author David González Verdugo
*/ */
public class GetRemoteUserQuotaOperation extends RemoteOperation { public class GetRemoteUserQuotaOperation extends RemoteOperation {
static public class Quota { static public class Quota {
// Not computed yet, e.g. external storage mounted but folder sizes need scanning
public static final int PENDING_FREE_QUOTA = -1;
// Storage not accessible, e.g. external storage with no API to ask for the free space
public static final int UNKNOWN_FREE_QUOTA = -2;
// Quota using all the storage
public static final int UNLIMITED_FREE_QUOTA = -3;
long mFree, mUsed, mTotal; long mFree, mUsed, mTotal;
double mRelative; double mRelative;
@ -64,72 +78,66 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
private static final String TAG = GetRemoteUserQuotaOperation.class.getSimpleName(); private static final String TAG = GetRemoteUserQuotaOperation.class.getSimpleName();
private static final String NODE_OCS = "ocs"; private String mRemotePath;
private static final String NODE_DATA = "data";
private static final String NODE_QUOTA = "quota";
private static final String NODE_QUOTA_FREE = "free";
private static final String NODE_QUOTA_USED = "used";
private static final String NODE_QUOTA_TOTAL = "total";
private static final String NODE_QUOTA_RELATIVE = "relative";
// OCS Route /**
private static final String OCS_ROUTE ="/ocs/v1.php/cloud/users/"; * Constructor
*
* @param remotePath Remote path of the file.
*/
public GetRemoteUserQuotaOperation(String remotePath) {
mRemotePath = remotePath;
}
@Override @Override
protected RemoteOperationResult run(OwnCloudClient client) { protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null; RemoteOperationResult result = null;
int status; PropFindMethod query = null;
GetMethod get = null;
//Get the user
try { try {
OwnCloudCredentials credentials = client.getCredentials(); // remote request
String url = client.getBaseUri() + OCS_ROUTE + credentials.getUsername(); query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
WebdavUtils.getQuotaPropSet(),
DavConstants.DEPTH_0);
get = new GetMethod(url); int status = client.executeMethod(query);
get.setQueryString(new NameValuePair[]{new NameValuePair("format","json")});
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
if(isSuccess(status)) { if (isSuccess(status)) {
String response = get.getResponseBodyAsString(); // get data from remote folder
MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
Quota quota = readData(dataInServer, client);
// Parse the response // Result of the operation
JSONObject respJSON = new JSONObject(response); result = new RemoteOperationResult(true, query);
JSONObject respOCS = respJSON.getJSONObject(NODE_OCS);
JSONObject respData = respOCS.getJSONObject(NODE_DATA);
JSONObject quota = respData.getJSONObject(NODE_QUOTA);
final Long quotaFree = quota.getLong(NODE_QUOTA_FREE);
final Long quotaUsed = quota.getLong(NODE_QUOTA_USED);
final Long quotaTotal = quota.getLong(NODE_QUOTA_TOTAL);
final Double quotaRelative = quota.getDouble(NODE_QUOTA_RELATIVE);
ArrayList<Object> data = new ArrayList<>();
data.add(quota);
// Result // Add data to the result
result = new RemoteOperationResult(true, get); if (result.isSuccess()) {
//Quota data in data collection result.setData(data);
ArrayList<Object> data = new ArrayList<Object>();
data.add(new Quota(quotaFree, quotaUsed, quotaTotal, quotaRelative));
result.setData(data);
} else {
result = new RemoteOperationResult(false, get);
String response = get.getResponseBodyAsString();
Log_OC.e(TAG, "Failed response while getting user quota information ");
if (response != null) {
Log_OC.e(TAG, "*** status code: " + status + " ; response message: " + response);
} else {
Log_OC.e(TAG, "*** status code: " + status);
} }
} else {
// synchronization failed
result = new RemoteOperationResult(false, query);
} }
} catch (Exception e) { } catch (Exception e) {
result = new RemoteOperationResult(e); result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Exception while getting OC user information", e);
} finally { } finally {
if (get != null) { if (query != null)
get.releaseConnection(); query.releaseConnection(); // let the connection available for other methods
if (result.isSuccess()) {
Log_OC.i(TAG, "Get quota from " + mRemotePath + ": " + result.getLogMessage());
} else {
if (result.isException()) {
Log_OC.e(TAG, "Get quota from " + mRemotePath + ": " + result.getLogMessage(),
result.getException());
} else {
Log_OC.e(TAG, "Get quota from " + mRemotePath + ": " + result.getLogMessage());
}
} }
} }
@ -137,8 +145,47 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
} }
private boolean isSuccess(int status) { private boolean isSuccess(int status) {
return (status == HttpStatus.SC_OK); return status == HttpStatus.SC_MULTI_STATUS || status == HttpStatus.SC_OK;
} }
/**
* Read the data retrieved from the server about the quota
*
* @param remoteData Full response got from the server with the data of the quota
* @param client Client instance to the remote server where the data were retrieved
* @return new Quota instance representing the data read from the server
*/
private Quota readData(MultiStatus remoteData, OwnCloudClient client) {
// parse data from remote folder
WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath());
// If there's a special case, available bytes will contain a negative code
// -1, PENDING: Not computed yet, e.g. external storage mounted but folder sizes need scanning
// -2, UNKNOWN: Storage not accessible, e.g. external storage with no API to ask for the free space
// -3, UNLIMITED: Quota using all the storage
if (we.quotaAvailableBytes().compareTo(new BigDecimal(1)) == -1) {
return new Quota(
we.quotaAvailableBytes().longValue(),
we.quotaUsedBytes().longValue(),
0,
0
);
} else {
BigDecimal totalQuota = we.quotaAvailableBytes().add(we.quotaUsedBytes());
BigDecimal relativeQuota = we.quotaUsedBytes()
.multiply(new BigDecimal(100))
.divide(totalQuota, 2, RoundingMode.HALF_UP);
return new Quota(
we.quotaAvailableBytes().longValue(),
we.quotaUsedBytes().longValue(),
totalQuota.longValue(),
relativeQuota.doubleValue()
);
}
}
} }

View File

@ -38,7 +38,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-sdk <uses-sdk
android:minSdkVersion="8" android:minSdkVersion="14"
android:targetSdkVersion="26" /> android:targetSdkVersion="26" />
<application <application

View File

@ -6,13 +6,11 @@ repositories {
} }
dependencies { dependencies {
compile 'commons-httpclient:commons-httpclient:3.1' implementation project(':')
compile project(':')
} }
android { android {
compileSdkVersion 26 compileSdkVersion 26
buildToolsVersion "26.0.2"
sourceSets { sourceSets {
main { main {
@ -26,7 +24,7 @@ android {
} }
// Move the tests to tests/java, tests/res, etc... // Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests') androidTest.setRoot('tests')
// Move the build types to build-types/<type> // Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
@ -45,9 +43,4 @@ android {
packagingOptions { packagingOptions {
exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE.txt'
} }
android {
lintOptions {
abortOnError false
}
}
} }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

View File

@ -1,5 +1,5 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH. * Copyright (C) 2018 ownCloud GmbH.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -65,6 +65,7 @@ import com.owncloud.android.lib.resources.users.GetRemoteUserAvatarOperation;
* Activity to test OC framework * Activity to test OC framework
* @author masensio * @author masensio
* @author David A. Velasco * @author David A. Velasco
* @author David González Verdugo
*/ */
public class TestActivity extends Activity { public class TestActivity extends Activity {
@ -338,8 +339,8 @@ public class TestActivity extends Activity {
} }
public RemoteOperationResult getQuota() { public RemoteOperationResult getQuota(String remotePath) {
GetRemoteUserQuotaOperation getUserQuotaOperation = new GetRemoteUserQuotaOperation(); GetRemoteUserQuotaOperation getUserQuotaOperation = new GetRemoteUserQuotaOperation(remotePath);
return getUserQuotaOperation.execute(mClient); return getUserQuotaOperation.execute(mClient);
} }

View File

@ -28,7 +28,7 @@
android:versionCode="1" android:versionCode="1"
android:versionName="1.0" > android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" /> <uses-sdk android:minSdkVersion="14" />
<application> <application>
<uses-library android:name="android.test.runner" /> <uses-library android:name="android.test.runner" />
</application> </application>

View File

@ -1,13 +1,12 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
dependencies { dependencies {
compile fileTree(dir: 'libs', include: '*.jar') implementation fileTree(dir: 'libs', include: '*.jar')
compile project(':') implementation project(':')
} }
android { android {
compileSdkVersion 26 compileSdkVersion 26
buildToolsVersion "26.0.2"
sourceSets { sourceSets {
main { main {
@ -21,7 +20,7 @@ android {
} }
// Move the tests to tests/java, tests/res, etc... // Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests') androidTest.setRoot('tests')
// Move the build types to build-types/<type> // Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...

View File

@ -1,6 +1,6 @@
/* ownCloud Android Library is available under MIT license /* ownCloud Android Library is available under MIT license
* *
* Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2018 ownCloud Inc.
* Copyright (C) 2015 Bartosz Przybylski * Copyright (C) 2015 Bartosz Przybylski
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
@ -38,6 +38,7 @@ import com.owncloud.android.lib.test_project.TestActivity;
* *
* @author Bartosz Przybylski * @author Bartosz Przybylski
* @author David A. Velasco * @author David A. Velasco
* @author David González Verdugo
*/ */
public class GetUserQuotaTest extends RemoteTest { public class GetUserQuotaTest extends RemoteTest {
@ -45,6 +46,8 @@ public class GetUserQuotaTest extends RemoteTest {
private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName(); private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName();
private TestActivity mActivity; private TestActivity mActivity;
private String mFullPath2Root;
private String ROOT_PATH = "/";
@Override @Override
@ -52,13 +55,14 @@ public class GetUserQuotaTest extends RemoteTest {
super.setUp(); super.setUp();
setActivityInitialTouchMode(false); setActivityInitialTouchMode(false);
mActivity = getActivity(); mActivity = getActivity();
mFullPath2Root = mBaseFolderPath + ROOT_PATH;
} }
/** /**
* Test GetUserQuota * Test GetUserQuota
*/ */
public void testGetUserQuota() { public void testGetUserQuota() {
RemoteOperationResult result = mActivity.getQuota(); RemoteOperationResult result = mActivity.getQuota(mFullPath2Root);
assertTrue(result.isSuccess()); assertTrue(result.isSuccess());
Quota quota = (Quota)((ArrayList<Object>)result.getData()).get(0); Quota quota = (Quota)((ArrayList<Object>)result.getData()).get(0);
assertTrue(quota.getFree() >= 0); assertTrue(quota.getFree() >= 0);