diff --git a/res/drawable/ic_favorite.png b/res/drawable/ic_favorite.png
new file mode 100644
index 0000000000..27edbd4a8c
Binary files /dev/null and b/res/drawable/ic_favorite.png differ
diff --git a/res/layout/file_details_fragment.xml b/res/layout/file_details_fragment.xml
index 777f244611..9198e3f66e 100644
--- a/res/layout/file_details_fragment.xml
+++ b/res/layout/file_details_fragment.xml
@@ -155,25 +155,55 @@
android:id="@+id/fdPreviewAndDL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_below="@+id/fdDetailsContainer" >
+ android:layout_below="@+id/fdDetailsContainer"
+ android:gravity="center_horizontal" >
+
+
-
+ android:layout_below="@id/fdPreview"
+ android:gravity="center_horizontal" >
+
+
+
+
+
+
+
diff --git a/res/layout/list_layout.xml b/res/layout/list_layout.xml
index a8a101d2ce..bf6dade7e8 100644
--- a/res/layout/list_layout.xml
+++ b/res/layout/list_layout.xml
@@ -42,6 +42,15 @@
android:layout_gravity="center_vertical|center"
android:layout_margin="4dp"
android:src="@drawable/ic_menu_archive" />
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7c4734285b..e28d0581ad 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -112,4 +112,6 @@
Extensions available!
Looks like your ownCloud instance is supporting advanced extensions. Would you like to see extensions available for android ?
+ Keep file up to date
+ Share
diff --git a/src/eu/alefzero/owncloud/CrashlogSendActivity.java b/src/eu/alefzero/owncloud/CrashlogSendActivity.java
index fd0c58d718..9ff83f676f 100644
--- a/src/eu/alefzero/owncloud/CrashlogSendActivity.java
+++ b/src/eu/alefzero/owncloud/CrashlogSendActivity.java
@@ -43,7 +43,7 @@ import eu.alefzero.webdav.FileRequestEntity;
public class CrashlogSendActivity extends SherlockActivity implements OnClickListener, OnCancelListener {
private static final String TAG = "CrashlogSendActivity";
- private static final String CRASHLOG_SUBMIT_URL = "";
+ private static final String CRASHLOG_SUBMIT_URL = "http://alefzero.eu/a/crashlog/";
private static final int DIALOG_SUBMIT = 5;
private String mLogFilename;
diff --git a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
index 0ad0d1bbc1..1feb424bda 100644
--- a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
+++ b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
@@ -101,6 +101,7 @@ public class FileDataStorageManager implements DataStorageManager {
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDate());
+ cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
if (fileExists(file.getRemotePath())) {
OCFile tmpfile = getFileByPath(file.getRemotePath());
@@ -303,6 +304,8 @@ public class FileDataStorageManager implements DataStorageManager {
.getColumnIndex(ProviderTableMeta.FILE_MODIFIED)));
file.setLastSyncDate(c.getLong(c
.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
+ file.setKeepInSync(c.getInt(
+ c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false);
}
return file;
}
diff --git a/src/eu/alefzero/owncloud/datamodel/OCFile.java b/src/eu/alefzero/owncloud/datamodel/OCFile.java
index ca454d1576..ce9c03b5ea 100644
--- a/src/eu/alefzero/owncloud/datamodel/OCFile.java
+++ b/src/eu/alefzero/owncloud/datamodel/OCFile.java
@@ -50,6 +50,7 @@ public class OCFile implements Parcelable, Comparable {
private String mMimeType;
private boolean mNeedsUpdating;
private long mLastSyncDate;
+ private boolean mKeepInSync;
/**
* Create new {@link OCFile} with given path
@@ -87,8 +88,25 @@ public class OCFile implements Parcelable, Comparable {
mLocalPath = source.readString();
mMimeType = source.readString();
mNeedsUpdating = source.readInt() == 0;
+ mKeepInSync = source.readInt() == 1;
+ mLastSyncDate = source.readLong();
}
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeLong(mId);
+ dest.writeLong(mParentId);
+ dest.writeLong(mLength);
+ dest.writeLong(mCreationTimestamp);
+ dest.writeLong(mModifiedTimestamp);
+ dest.writeString(mRemotePath);
+ dest.writeString(mLocalPath);
+ dest.writeString(mMimeType);
+ dest.writeInt(mNeedsUpdating ? 1 : 0);
+ dest.writeInt(mKeepInSync ? 1 : 0);
+ dest.writeLong(mLastSyncDate);
+ }
+
/**
* Gets the ID of the file
*
@@ -248,6 +266,8 @@ public class OCFile implements Parcelable, Comparable {
mCreationTimestamp = 0;
mModifiedTimestamp = 0;
mLastSyncDate = 0;
+ mKeepInSync = false;
+ mNeedsUpdating = false;
}
/**
@@ -321,25 +341,19 @@ public class OCFile implements Parcelable, Comparable {
mLastSyncDate = lastSyncDate;
}
+ public void setKeepInSync(boolean keepInSync) {
+ mKeepInSync = keepInSync;
+ }
+
+ public boolean keepInSync() {
+ return mKeepInSync;
+ }
+
@Override
public int describeContents() {
return this.hashCode();
}
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeLong(mId);
- dest.writeLong(mParentId);
- dest.writeLong(mLength);
- dest.writeLong(mCreationTimestamp);
- dest.writeLong(mModifiedTimestamp);
- dest.writeString(mRemotePath);
- dest.writeString(mLocalPath);
- dest.writeString(mMimeType);
- dest.writeInt(mNeedsUpdating ? 1 : 0);
- dest.writeLong(mLastSyncDate);
- }
-
@Override
public int compareTo(OCFile another) {
if (isDirectory() && another.isDirectory()) {
diff --git a/src/eu/alefzero/owncloud/db/ProviderMeta.java b/src/eu/alefzero/owncloud/db/ProviderMeta.java
index 79f285ac02..62c0ace5f8 100644
--- a/src/eu/alefzero/owncloud/db/ProviderMeta.java
+++ b/src/eu/alefzero/owncloud/db/ProviderMeta.java
@@ -31,7 +31,7 @@ public class ProviderMeta {
public static final String AUTHORITY_FILES = "org.owncloud";
public static final String DB_FILE = "owncloud.db";
public static final String DB_NAME = "filelist";
- public static final int DB_VERSION = 1;
+ public static final int DB_VERSION = 2;
private ProviderMeta() {
}
@@ -58,6 +58,7 @@ public class ProviderMeta {
public static final String FILE_PATH = "path";
public static final String FILE_ACCOUNT_OWNER = "file_owner";
public static final String FILE_LAST_SYNC_DATE = "last_sync_date";
+ public static final String FILE_KEEP_IN_SYNC = "keep_in_sync";
public static final String DEFAULT_SORT_ORDER = FILE_NAME
+ " collate nocase asc";
diff --git a/src/eu/alefzero/owncloud/providers/FileContentProvider.java b/src/eu/alefzero/owncloud/providers/FileContentProvider.java
index b54aa21d80..160476ac7d 100644
--- a/src/eu/alefzero/owncloud/providers/FileContentProvider.java
+++ b/src/eu/alefzero/owncloud/providers/FileContentProvider.java
@@ -35,6 +35,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
+import android.util.Log;
/**
* The ContentProvider for the ownCloud App.
@@ -68,6 +69,8 @@ public class FileContentProvider extends ContentProvider {
ProviderTableMeta.FILE_STORAGE_PATH);
mProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE,
ProviderTableMeta.FILE_LAST_SYNC_DATE);
+ mProjectionMap.put(ProviderTableMeta.FILE_KEEP_IN_SYNC,
+ ProviderTableMeta.FILE_KEEP_IN_SYNC);
}
private static final int SINGLE_FILE = 1;
@@ -216,7 +219,11 @@ public class FileContentProvider extends ContentProvider {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-
+ if (oldVersion == 1 && newVersion >= 2) {
+ db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
+ " ADD COLUMN " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
+ " DEFAULT 0");
+ }
}
}
diff --git a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
index d3b6fc2bc4..73b74ed56f 100644
--- a/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
+++ b/src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java
@@ -19,6 +19,7 @@
package eu.alefzero.owncloud.syncadapter;
import java.io.IOException;
+import java.io.ObjectInputStream.GetField;
import java.util.Vector;
import org.apache.jackrabbit.webdav.DavException;
@@ -36,6 +37,7 @@ import android.os.Bundle;
import android.util.Log;
import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
import eu.alefzero.owncloud.datamodel.OCFile;
+import eu.alefzero.owncloud.files.services.FileDownloader;
import eu.alefzero.webdav.WebdavEntry;
/**
@@ -118,6 +120,17 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());
OCFile file = fillOCFile(we);
file.setParentId(parentId);
+ if (getStorageManager().getFileByPath(file.getRemotePath()) != null &&
+ getStorageManager().getFileByPath(file.getRemotePath()).keepInSync() &&
+ file.getModificationTimestamp() > getStorageManager().getFileByPath(file.getRemotePath())
+ .getModificationTimestamp()) {
+ Intent intent = new Intent(this.getContext(), FileDownloader.class);
+ intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
+ intent.putExtra(FileDownloader.EXTRA_FILE_PATH, file.getURLDecodedRemotePath());
+ intent.putExtra(FileDownloader.EXTRA_REMOTE_PATH, file.getRemotePath());
+ file.setKeepInSync(true);
+ getContext().startService(intent);
+ }
getStorageManager().saveFile(file);
if (parentId == 0)
parentId = file.getFileId();
diff --git a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
index e0eccf9196..146375992d 100644
--- a/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
+++ b/src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
@@ -111,7 +111,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setSupportProgressBarIndeterminateVisibility(false);
- Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
+// Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(getApplicationContext()));
if(savedInstanceState != null) {
mDirs = savedInstanceState.getStringArray(KEY_DIR_ARRAY);
diff --git a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java
index 6008d16689..646a1cab04 100644
--- a/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java
+++ b/src/eu/alefzero/owncloud/ui/adapter/FileListListAdapter.java
@@ -120,9 +120,17 @@ public class FileListListAdapter implements ListAdapter {
view.findViewById(R.id.last_mod).setVisibility(View.VISIBLE);
((TextView)view.findViewById(R.id.file_size)).setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
((TextView)view.findViewById(R.id.last_mod)).setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
+ // this if-else is needed even thoe fav icon is visible by default
+ // because android reuses views in listview
+ if (!file.keepInSync()) {
+ view.findViewById(R.id.imageView3).setVisibility(View.GONE);
+ } else {
+ view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
+ }
} else {
view.findViewById(R.id.file_size).setVisibility(View.GONE);
view.findViewById(R.id.last_mod).setVisibility(View.GONE);
+ view.findViewById(R.id.imageView3).setVisibility(View.GONE);
}
}
diff --git a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java
index 505ff6c74a..a8f0d812e6 100644
--- a/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java
+++ b/src/eu/alefzero/owncloud/ui/fragment/FileDetailFragment.java
@@ -17,6 +17,27 @@
*/
package eu.alefzero.owncloud.ui.fragment;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.HttpStatus;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.ActivityNotFoundException;
@@ -27,27 +48,36 @@ import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
+import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.PreferenceActivity.Header;
import android.util.Log;
+import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.MimeTypeMap;
import android.widget.Button;
+import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragment;
+import eu.alefzero.owncloud.AccountUtils;
import eu.alefzero.owncloud.DisplayUtils;
import eu.alefzero.owncloud.R;
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
+import eu.alefzero.owncloud.datamodel.FileDataStorageManager;
import eu.alefzero.owncloud.datamodel.OCFile;
import eu.alefzero.owncloud.files.services.FileDownloader;
+import eu.alefzero.owncloud.utils.OwnCloudVersion;
+import eu.alefzero.webdav.WebdavClient;
/**
* This Fragment is used to display the details about a file.
@@ -155,14 +185,27 @@ public class FileDetailFragment extends SherlockFragment implements
@Override
public void onClick(View v) {
- Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();
- Intent i = new Intent(getActivity(), FileDownloader.class);
- i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
- i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());
- i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath());
- i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());
- v.setEnabled(false);
- getActivity().startService(i);
+ if (v.getId() == R.id.fdDownloadBtn) {
+ Toast.makeText(getActivity(), "Downloading", Toast.LENGTH_LONG).show();
+ Intent i = new Intent(getActivity(), FileDownloader.class);
+ i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
+ i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());
+ i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath());
+ i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());
+ v.setEnabled(false);
+ getActivity().startService(i);
+ } else if (v.getId() == R.id.fdKeepInSync) {
+ CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
+ mFile.setKeepInSync(cb.isChecked());
+ FileDataStorageManager fdsm = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
+ fdsm.saveFile(mFile);
+ if (mFile.keepInSync() && !mFile.isDownloaded()) {
+ onClick(getView().findViewById(R.id.fdDownloadBtn));
+ }
+ }/* else if (v.getId() == R.id.fdShareBtn) {
+ Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));
+ t.start();
+ }*/
}
@@ -215,6 +258,11 @@ public class FileDetailFragment extends SherlockFragment implements
setTimeModified(mFile.getModificationTimestamp());
+ CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync);
+ cb.setChecked(mFile.keepInSync());
+ cb.setOnClickListener(this);
+ //getView().findViewById(R.id.fdShareBtn).setOnClickListener(this);
+
if (mFile.getStoragePath() != null) {
// Update preview
ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);
@@ -236,13 +284,29 @@ public class FileDetailFragment extends SherlockFragment implements
int width = options.outWidth;
int height = options.outHeight;
int scale = 1;
+ boolean recycle = false;
if (width >= 2048 || height >= 2048) {
scale = (int) (Math.ceil(Math.max(height, width)/2048.));
options.inSampleSize = scale;
- bmp.recycle();
-
- bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);
+ recycle = true;
}
+ Display display = getActivity().getWindowManager().getDefaultDisplay();
+ Point size = new Point();
+ display.getSize(size);
+ int screenwidth = size.x;
+
+ Log.e("ASD", "W " + width + " SW " + screenwidth);
+
+ if (width > screenwidth) {
+ scale = (int) (Math.ceil(Math.max(height, width)/screenwidth));
+ options.inSampleSize = scale;
+ recycle = true;
+ }
+
+
+ if (recycle) bmp.recycle();
+ bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);
+
}
if (bmp != null) {
preview.setImageBitmap(bmp);
@@ -406,4 +470,118 @@ public class FileDetailFragment extends SherlockFragment implements
}
+ // this is a temporary class for sharing purposes, it need to be replacead in transfer service
+ private class ShareRunnable implements Runnable {
+ private String mPath;
+
+ public ShareRunnable(String path) {
+ mPath = path;
+ }
+
+ public void run() {
+ AccountManager am = AccountManager.get(getActivity());
+ Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+ OwnCloudVersion ocv = new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
+ String url = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + AccountUtils.getWebdavPath(ocv);
+
+ Log.d("share", "sharing for version " + ocv.toString());
+
+ if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
+ String APPS_PATH = "/apps/files_sharing/";
+ String SHARE_PATH = "ajax/share.php";
+
+ String SHARED_PATH = "/apps/files_sharing/get.php?token=";
+
+ final String WEBDAV_SCRIPT = "webdav.php";
+ final String WEBDAV_FILES_LOCATION = "/files/";
+
+ WebdavClient wc = new WebdavClient();
+ HttpConnectionManagerParams params = new HttpConnectionManagerParams();
+ params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);
+
+ //wc.getParams().setParameter("http.protocol.single-cookie-header", true);
+ //wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
+
+ PostMethod post = new PostMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + APPS_PATH + SHARE_PATH);
+
+ post.addRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8" );
+ post.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
+ List formparams = new ArrayList();
+ Log.d("share", mPath+"");
+ formparams.add(new BasicNameValuePair("sources",mPath));
+ formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
+ formparams.add(new BasicNameValuePair("permissions", "0"));
+ post.setRequestEntity(new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));
+
+ int status;
+ try {
+ PropFindMethod find = new PropFindMethod(url+"/");
+ find.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
+ Log.d("sharer", ""+ url+"/");
+ wc.setCredentials(account.name.substring(0, account.name.lastIndexOf('@')), am.getPassword(account));
+
+ for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
+ Log.d("sharer-h", a.getName() + ":"+a.getValue());
+ }
+
+ int status2 = wc.executeMethod(find);
+
+ Log.d("sharer", "propstatus "+status2);
+
+ GetMethod get = new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
+ get.addRequestHeader("Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
+
+ status2 = wc.executeMethod(get);
+
+ Log.d("sharer", "getstatus "+status2);
+ Log.d("sharer", "" + get.getResponseBodyAsString());
+
+ for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
+ Log.d("sharer", a.getName() + ":"+a.getValue());
+ }
+
+ status = wc.executeMethod(post);
+ for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
+ Log.d("sharer-h", a.getName() + ":"+a.getValue());
+ }
+ for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
+ Log.d("sharer", a.getName() + ":"+a.getValue());
+ }
+ String resp = post.getResponseBodyAsString();
+ Log.d("share", ""+post.getURI().toString());
+ Log.d("share", "returned status " + status);
+ Log.d("share", " " +resp);
+
+ if(status != HttpStatus.SC_OK ||resp == null || resp.equals("") || resp.startsWith("false")) {
+ return;
+ }
+
+ JSONObject jsonObject = new JSONObject (resp);
+ String jsonStatus = jsonObject.getString("status");
+ if(!jsonStatus.equals("success")) throw new Exception("Error while sharing file status != success");
+
+ String token = jsonObject.getString("data");
+ String uri = am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
+ Log.d("Actions:shareFile ok", "url: " + uri);
+
+ } catch (HttpException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {
+
+ }
+ }
+ }
+
}
diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java
index fd1ec5049e..8d2934c121 100644
--- a/src/eu/alefzero/webdav/WebdavClient.java
+++ b/src/eu/alefzero/webdav/WebdavClient.java
@@ -21,10 +21,12 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.HashMap;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
@@ -33,6 +35,7 @@ import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.http.HttpStatus;
+import org.apache.http.params.CoreProtocolPNames;
import org.apache.jackrabbit.webdav.client.methods.DavMethod;
import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
@@ -54,7 +57,16 @@ public class WebdavClient extends HttpClient {
final private static String TAG = "WebdavClient";
private static final String USER_AGENT = "Android-ownCloud";
private OnDatatransferProgressListener mDataTransferListener;
- private static HashMap clients = new HashMap();
+ static private MultiThreadedHttpConnectionManager mConnManager = null;
+
+ static public MultiThreadedHttpConnectionManager getMultiThreadedConnManager() {
+ if (mConnManager == null) {
+ mConnManager = new MultiThreadedHttpConnectionManager();
+ mConnManager.setMaxConnectionsPerHost(5);
+ mConnManager.setMaxTotalConnections(5);
+ }
+ return mConnManager;
+ }
/**
* Creates a WebdavClient setup for the current account
@@ -62,7 +74,7 @@ public class WebdavClient extends HttpClient {
* @param context The application context
* @return
*/
- public WebdavClient (Account account, Context context){
+ public WebdavClient (Account account, Context context) {
OwnCloudVersion ownCloudVersion = new OwnCloudVersion(AccountManager.get(context).getUserData(account,
AccountAuthenticator.KEY_OC_VERSION));
String baseUrl = AccountManager.get(context).getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);
@@ -71,15 +83,20 @@ public class WebdavClient extends HttpClient {
String password = AccountManager.get(context).getPassword(account);
mUri = Uri.parse(baseUrl + webDavPath);
- getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
+
setCredentials(username, password);
- allowSelfsignedCertificates();
}
- public WebdavClient(){}
+ public WebdavClient() {
+ super(getMultiThreadedConnManager());
+
+ getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
+ getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+ allowSelfsignedCertificates();
+ }
public void setCredentials(String username, String password) {
- getParams().setAuthenticationPreemptive(true);
+ //getParams().setAuthenticationPreemptive(true);
getState().setCredentials(AuthScope.ANY,
getCredentials(username, password));
}