1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-13 10:56:23 +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-sdk
android:minSdkVersion="8"
android:minSdkVersion="14"
android:targetSdkVersion="26" />
</manifest>

View File

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

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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

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

View File

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

View File

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

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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

@ -22,101 +22,152 @@
THE SOFTWARE.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="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
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_height="wrap_content"
android:layout_below="@+id/button_refresh"
android:layout_above="@+id/button_upload"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
>
</ListView>
android:layout_below="@id/server_address"
android:layout_marginTop="10dp"
android:onClick="onClickHandler"
android:text="@string/refresh"/>
<Button
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_height="@dimen/frame_height"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_above="@+id/button_download"
>
</FrameLayout>
android:layout_below="@id/button_refresh"
android:layout_marginTop="10dp"
android:onClick="onClickHandler"
android:text="@string/upload"/>
<Button
android:id="@id/button_download"
style="@style/ButtonStyle"
android:layout_alignParentBottom="true"
android:id="@+id/button_download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/download"
android:onClick="onClickHandler"
/>
<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%"
/>
android:layout_below="@id/button_upload"
android:layout_marginTop="10dp"
android:onClick="onClickHandler"
android:text="@string/download"/>
<Button
android:id="@id/button_delete_local"
style="@style/ButtonStyle"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/delete_local_file"
android:onClick="onClickHandler"
/>
android:id="@+id/button_delete_remote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/button_download"
android:layout_marginTop="10dp"
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>

View File

@ -26,6 +26,7 @@
<resources>
<string name="app_name">ownCloud Sample Client</string>
<string name="refresh">Refresh</string>
<string name="check_server">Check server</string>
<string name="upload">Upload</string>
<string name="delete_remote_file">Delete remote file</string>
<string name="download">Download</string>
@ -41,7 +42,7 @@
<string name="upload_folder_path">to_upload</string>
<string name="download_folder_path">downloaded</string>
<string name="error_copying_sample_file">Sample file could not be saved in temporal folder; upload will not work</string>
<string name="sample_file_name">oc_sample.png</string>
<string name="sample_file_name">oc_sample.png</string>
<string name="sample_file_mimetype">image/png</string>
<string name="error_deleting_local_file">Downloaded file could not be deleted</string>
</resources>

View File

@ -1,5 +1,7 @@
/* 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
* of this software and associated documentation files (the "Software"), to deal
@ -24,6 +26,35 @@
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.FileOutputStream;
import java.io.IOException;
@ -32,35 +63,30 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.resources.files.RemoteFile;
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.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;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Credentials;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
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;
@ -69,6 +95,10 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private FilesArrayAdapter mFilesAdapter;
private View mFrame;
private OkHttpClient mOkHttpClient;
private String mCredentials;
/** Called when the activity is first created. */
@Override
@ -88,7 +118,7 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
);
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
AssetManager assets = getAssets();
@ -110,8 +140,14 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
Toast.makeText(this, R.string.error_copying_sample_file, Toast.LENGTH_SHORT).show();
Log.e(LOG_TAG, getString(R.string.error_copying_sample_file), e);
}
((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);
// mFrame = findViewById(R.id.frame);
}
@ -127,63 +163,264 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
public void onClickHandler(View button) {
switch (button.getId()) {
case R.id.button_check_server:
startCheck();
break;
case R.id.button_refresh:
startRefresh();
break;
case R.id.button_upload:
startUpload();
break;
case R.id.button_download:
startDownload();
break;
case R.id.button_delete_remote:
startRemoteDeletion();
break;
case R.id.button_download:
startDownload();
break;
case R.id.button_delete_local:
startLocalDeletion();
break;
// case R.id.button_delete_local:
// startLocalDeletion();
// break;
default:
Toast.makeText(this, R.string.youre_doing_it_wrong, Toast.LENGTH_SHORT).show();
}
}
private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
refreshOperation.execute(mClient, this, mHandler);
}
private void startCheck() {
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() {
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 mimeType = getString(R.string.sample_file_mimetype);
MediaType mediaType = MediaType.parse(mimeType);
// Get the last modification date of the file from the file system
Long timeStampLong = fileToUpload.lastModified()/1000;
String timeStamp = timeStampLong.toString();
UploadRemoteFileOperation uploadOperation = new UploadRemoteFileOperation(fileToUpload.getAbsolutePath(), remotePath, mimeType, timeStamp);
uploadOperation.addDatatransferProgressListener(this);
uploadOperation.execute(mClient, this, mHandler);
// Let's first use OKHttp with the new endpoint without depending on our library operations
// 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 downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
downFolder.mkdir();
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
final File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
// Let's first use OKHttp with the new endpoint without depending on our library operations
// 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 fileToUpload = upFolder.listFiles()[0];
final File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
removeOperation.execute(mClient, this, mHandler);
}
private void startDownload() {
File downFolder = new File(getCacheDir(), getString(R.string.download_folder_path));
downFolder.mkdir();
File upFolder = new File(getCacheDir(), getString(R.string.upload_folder_path));
File fileToUpload = upFolder.listFiles()[0];
String remotePath = FileUtils.PATH_SEPARATOR + fileToUpload.getName();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remotePath, downFolder.getAbsolutePath());
downloadOperation.addDatatransferProgressListener(this);
downloadOperation.execute(mClient, this, mHandler);
// Let's first use OKHttp with the new endpoint without depending on our library operations
// 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")
@ -193,8 +430,8 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
if (!downloadedFile.delete() && downloadedFile.exists()) {
Toast.makeText(this, R.string.error_deleting_local_file, Toast.LENGTH_SHORT).show();
} else {
((TextView) findViewById(R.id.download_progress)).setText("0%");
findViewById(R.id.frame).setBackgroundDrawable(null);
// ((TextView) findViewById(R.id.download_progress)).setText("0%");
// findViewById(R.id.frame).setBackgroundDrawable(null);
}
}
@ -243,10 +480,10 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private void onSuccessfulRemoteDeletion(RemoveRemoteFileOperation operation, RemoteOperationResult result) {
startRefresh();
TextView progressView = (TextView) findViewById(R.id.upload_progress);
if (progressView != null) {
progressView.setText("0%");
}
// TextView progressView = (TextView) findViewById(R.id.upload_progress);
// if (progressView != null) {
// progressView.setText("0%");
// }
}
@SuppressWarnings("deprecation")
@ -266,11 +503,11 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
@Override
public void run() {
TextView progressView = null;
if (upload) {
progressView = (TextView) findViewById(R.id.upload_progress);
} else {
progressView = (TextView) findViewById(R.id.download_progress);
}
// if (upload) {
// progressView = (TextView) findViewById(R.id.upload_progress);
// } else {
// progressView = (TextView) findViewById(R.id.download_progress);
// }
if (progressView != null) {
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
* Copyright (C) 2016 ownCloud GmbH.
/** ownCloud Android Library is available under MIT license
*
* @author Christian Schabesberger
* Copyright (C) 2018 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
@ -164,7 +166,7 @@ public class WebdavEntry {
prop = propSet.get(
EXTENDED_PROPERTY_NAME_PERMISSIONS, Namespace.getNamespace(NAMESPACE_OC)
);
if (prop != null) {
if (prop != null && prop.getValue() != null) {
mPermissions = prop.getValue().toString();
}

View File

@ -140,6 +140,17 @@ public class WebdavUtils {
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

View File

@ -1,5 +1,5 @@
/* 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
* 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.
* <p/>
*
* Provides a common classification of remote operation results for all the
* application.
*
* @author David A. Velasco
* @author David González Verdugo
*/
public class RemoteOperationResult implements Serializable {
@ -378,8 +379,8 @@ public class RemoteOperationResult implements Serializable {
}
}
public void setData(ArrayList<Object> files) {
mData = files;
public void setData(ArrayList<Object> items) {
mData = items;
}
public ArrayList<Object> getData() {

View File

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

View File

@ -1,6 +1,7 @@
/* ownCloud Android Library is available under MIT license
* @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
* of this software and associated documentation files (the "Software"), to deal
@ -245,8 +246,10 @@ public class GetRemoteCapabilitiesOperation extends RemoteOperation {
capability.setFilesUndelete(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_UNDELETE)));
}
capability.setFilesVersioning(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_VERSIONING)));
if (respFiles.has(PROPERTY_VERSIONING)) {
capability.setFilesVersioning(CapabilityBooleanType.fromBooleanValue(
respFiles.getBoolean(PROPERTY_VERSIONING)));
}
Log_OC.d(TAG, "*** Added " + NODE_FILES);
}
}

View File

@ -1,6 +1,6 @@
/* 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) 2014 Marcello Steiner
*
@ -28,24 +28,38 @@
package com.owncloud.android.lib.resources.users;
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.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.json.JSONObject;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
/**
* @author marcello
* @author David González Verdugo
*/
public class GetRemoteUserQuotaOperation extends RemoteOperation {
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;
double mRelative;
@ -64,72 +78,66 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
private static final String TAG = GetRemoteUserQuotaOperation.class.getSimpleName();
private static final String NODE_OCS = "ocs";
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";
private String mRemotePath;
// 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
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result = null;
int status;
GetMethod get = null;
PropFindMethod query = null;
//Get the user
try {
OwnCloudCredentials credentials = client.getCredentials();
String url = client.getBaseUri() + OCS_ROUTE + credentials.getUsername();
// remote request
query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
WebdavUtils.getQuotaPropSet(),
DavConstants.DEPTH_0);
get = new GetMethod(url);
get.setQueryString(new NameValuePair[]{new NameValuePair("format","json")});
get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
status = client.executeMethod(get);
int status = client.executeMethod(query);
if(isSuccess(status)) {
String response = get.getResponseBodyAsString();
if (isSuccess(status)) {
// get data from remote folder
MultiStatus dataInServer = query.getResponseBodyAsMultiStatus();
Quota quota = readData(dataInServer, client);
// Parse the response
JSONObject respJSON = new JSONObject(response);
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);
// Result of the operation
result = new RemoteOperationResult(true, query);
ArrayList<Object> data = new ArrayList<>();
data.add(quota);
// Result
result = new RemoteOperationResult(true, get);
//Quota data in data collection
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);
// Add data to the result
if (result.isSuccess()) {
result.setData(data);
}
} else {
// synchronization failed
result = new RemoteOperationResult(false, query);
}
} catch (Exception e) {
result = new RemoteOperationResult(e);
Log_OC.e(TAG, "Exception while getting OC user information", e);
} finally {
if (get != null) {
get.releaseConnection();
if (query != null)
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) {
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-sdk
android:minSdkVersion="8"
android:minSdkVersion="14"
android:targetSdkVersion="26" />
<application

View File

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

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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
* Copyright (C) 2016 ownCloud GmbH.
* Copyright (C) 2018 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
@ -65,6 +65,7 @@ import com.owncloud.android.lib.resources.users.GetRemoteUserAvatarOperation;
* Activity to test OC framework
* @author masensio
* @author David A. Velasco
* @author David González Verdugo
*/
public class TestActivity extends Activity {
@ -338,8 +339,8 @@ public class TestActivity extends Activity {
}
public RemoteOperationResult getQuota() {
GetRemoteUserQuotaOperation getUserQuotaOperation = new GetRemoteUserQuotaOperation();
public RemoteOperationResult getQuota(String remotePath) {
GetRemoteUserQuotaOperation getUserQuotaOperation = new GetRemoteUserQuotaOperation(remotePath);
return getUserQuotaOperation.execute(mClient);
}

View File

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

View File

@ -1,13 +1,12 @@
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':')
implementation fileTree(dir: 'libs', include: '*.jar')
implementation project(':')
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
sourceSets {
main {
@ -21,7 +20,7 @@ android {
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
androidTest.setRoot('tests')
// Move the build types to build-types/<type>
// 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
*
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2018 ownCloud Inc.
* Copyright (C) 2015 Bartosz Przybylski
*
* 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 David A. Velasco
* @author David González Verdugo
*/
public class GetUserQuotaTest extends RemoteTest {
@ -45,6 +46,8 @@ public class GetUserQuotaTest extends RemoteTest {
private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName();
private TestActivity mActivity;
private String mFullPath2Root;
private String ROOT_PATH = "/";
@Override
@ -52,13 +55,14 @@ public class GetUserQuotaTest extends RemoteTest {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2Root = mBaseFolderPath + ROOT_PATH;
}
/**
* Test GetUserQuota
*/
public void testGetUserQuota() {
RemoteOperationResult result = mActivity.getQuota();
RemoteOperationResult result = mActivity.getQuota(mFullPath2Root);
assertTrue(result.isSuccess());
Quota quota = (Quota)((ArrayList<Object>)result.getData()).get(0);
assertTrue(quota.getFree() >= 0);