Merge branch 'master' of gitorious.org:owncloud/android-devel

This commit is contained in:
Bartek Przybylski 2012-06-25 19:46:31 +02:00
commit b22ad95e2f
12 changed files with 65 additions and 42 deletions

View file

@ -18,7 +18,7 @@
-->
<manifest package="eu.alefzero.owncloud"
android:versionCode="1"
android:versionName="0.1.131B" xmlns:android="http://schemas.android.com/apk/res/android">
android:versionName="0.1.132B" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

View file

@ -18,7 +18,6 @@
package eu.alefzero.owncloud;
import java.io.File;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@ -215,7 +214,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
EditText mDirname;
public a(String path, EditText dirname) {
mPath = path;
mPath = path;
mDirname = dirname;
}
@ -239,6 +238,7 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
}
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// click on folder in the list
Log.d(TAG, "on item click");
Vector<OCFile> tmpfiles = mStorageManager.getDirectoryContent(mFile);
if (tmpfiles == null) return;
@ -255,11 +255,13 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
}
public void onClick(View v) {
// click on button
switch (v.getId()) {
case R.id.uploader_choose_folder:
mUploadPath = "";
mUploadPath = "/";
for (String p : mParents)
mUploadPath += URLEncoder.encode(p) + "/";
mUploadPath += p + "/";
mUploadPath = Uri.encode(mUploadPath, "/");
Log.d(TAG, "Uploading file to dir " + mUploadPath);
uploadFiles();
@ -408,11 +410,11 @@ public class Uploader extends ListActivity implements OnItemClickListener, andro
final String display_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME)),
data = c.getString(c.getColumnIndex(Media.DATA));
local[i] = data;
remote[i] = mUploadPath + display_name;
remote[i] = mUploadPath + Uri.encode(display_name);
} else if (uri.getScheme().equals("file")) {
final File file = new File(Uri.decode(uri.toString()).replace(uri.getScheme() + "://", ""));
local[i] = file.getAbsolutePath();
remote[i] = mUploadPath + file.getName();
remote[i] = mUploadPath + Uri.encode(file.getName());
}
}

View file

@ -288,9 +288,9 @@ public class FileDataStorageManager implements DataStorageManager {
file.setStoragePath(c.getString(c
.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
if (file.getStoragePath() == null) {
// try to find exisiting file and bind it with current account
// try to find existing file and bind it with current account
File sdCard = Environment.getExternalStorageDirectory();
File f = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + file.getRemotePath());
File f = new File(sdCard.getAbsolutePath() + "/owncloud/" + mAccount.name + file.getURLDecodedRemotePath());
if (f.exists())
file.setStoragePath(f.getAbsolutePath());
}

View file

@ -19,7 +19,10 @@
package eu.alefzero.owncloud.datamodel;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
@ -52,10 +55,19 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
* Create new {@link OCFile} with given path
*
* @param path The remote path of the file
* @throws MalformedURLException
*/
public OCFile(String path) {
resetData();
mNeedsUpdating = false;
// dvelasco: let's make mandatory that mRemotePath is a valid URL always; this will make our life easier with the URL-encoding/decoding
if (path != null && path.length() > 0) {
try {
new URL("http://silly.test.com:8888" + path);
} catch (MalformedURLException e) {
throw new RuntimeException("Trying to create a OCFile with a non valid remote path: " + path , e);
}
} else throw new RuntimeException("Trying to create a OCFile with a non valid remote path: " + path);
mRemotePath = path;
}
@ -94,6 +106,15 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
return mRemotePath;
}
/**
* Returns the remote path of the file on ownCloud
*
* @return The remote path to the file
*/
public String getURLDecodedRemotePath() {
return Uri.decode(mRemotePath);
}
/**
* Can be used to check, whether or not this file exists in the database
* already
@ -182,11 +203,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
* @return The name of the file
*/
public String getFileName() {
if (mRemotePath != null) {
File f = new File(mRemotePath);
return f.getName().equals("") ? "/" : f.getName();
}
return null;
File f = new File(getURLDecodedRemotePath());
return f.getName().length() == 0 ? "/" : f.getName();
}
/**
@ -324,13 +342,13 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
@Override
public int compareTo(OCFile another) {
if (isDirectory() && another.isDirectory()) {
return getFileName().toLowerCase().compareTo(another.getFileName().toLowerCase());
return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
} else if (isDirectory()) {
return -1;
} else if (another.isDirectory()) {
return 1;
}
return getFileName().toLowerCase().compareTo(another.getFileName().toLowerCase());
return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
}
public boolean equals(Object o) {

View file

@ -35,6 +35,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_FILE_PATH = "FILE_PATH";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_FILE_SIZE = "FILE_SIZE";
private static final String TAG = "FileDownloader";
@ -43,6 +44,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
private ServiceHandler mServiceHandler;
private Account mAccount;
private String mFilePath;
private String mRemotePath;
private int mLastPercent;
private long mTotalDownloadSize;
private long mCurrentDownlodSize;
@ -85,6 +87,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
}
mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
mFilePath = intent.getStringExtra(EXTRA_FILE_PATH);
mRemotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
mServiceHandler.sendMessage(msg);
@ -141,7 +144,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString());
Log.e(TAG, mFilePath+"");
if (wdc.downloadFile(mFilePath, file)) {
if (wdc.downloadFile(mRemotePath, file)) {
ContentValues cv = new ContentValues();
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath());
getContentResolver().update(

View file

@ -1,7 +1,6 @@
package eu.alefzero.owncloud.files.services;
import java.io.File;
import java.net.URLDecoder;
import eu.alefzero.owncloud.AccountUtils;
import eu.alefzero.owncloud.R;
@ -124,7 +123,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
Toast.makeText(this, "Upload successfull", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(this, "No i kupa", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Upload could not be completed", Toast.LENGTH_SHORT).show();
}
}
@ -176,14 +175,13 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
mCurrentIndexUpload = i;
if (wc.putFile(mLocalPaths[i], mRemotePaths[i], mimeType)) {
mResult |= true;
String decRemotePath = URLDecoder.decode(mRemotePaths[i]);
OCFile new_file = new OCFile(decRemotePath); // FyleSyncAdapter and this MUST use the same encoding when creating a new OCFile
OCFile new_file = new OCFile(mRemotePaths[i]);
new_file.setMimetype(mimeType);
new_file.setFileLength(new File(mLocalPaths[i]).length());
new_file.setModificationTimestamp(System.currentTimeMillis());
new_file.setLastSyncDate(0);
new_file.setStoragePath(mLocalPaths[i]);
File f = new File(URLDecoder.decode(mRemotePaths[i]));
File f = new File(mRemotePaths[i]);
new_file.setParentId(storageManager.getFileByPath(f.getParent().endsWith("/")?f.getParent():f.getParent()+"/").getFileId());
storageManager.saveFile(new_file);
}

View file

@ -19,7 +19,6 @@
package eu.alefzero.owncloud.syncadapter;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.Vector;
import org.apache.jackrabbit.webdav.DavException;
@ -140,7 +139,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
}
private OCFile fillOCFile(WebdavEntry we) {
OCFile file = new OCFile(URLDecoder.decode(we.path()));
OCFile file = new OCFile(we.path());
file.setCreationTimestamp(we.createTimestamp());
file.setFileLength(we.contentLength());
file.setMimetype(we.contentType());

View file

@ -22,7 +22,6 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.lang.Thread.UncaughtExceptionHandler;
import java.net.URLEncoder;
import java.util.ArrayList;
import android.accounts.Account;
@ -223,11 +222,12 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
AccountUtils.getCurrentOwnCloudAccount(this));
String remotepath = new String();
for (int j = mDirectories.getCount() - 2; j >= 0; --j) {
remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j));
remotepath += "/" + mDirectories.getItem(j);
}
if (!remotepath.endsWith("/"))
remotepath += "/";
remotepath += URLEncoder.encode(new File(filepath).getName());
remotepath += new File(filepath).getName();
remotepath = Uri.encode(remotepath, "/");
i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);
i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);
@ -309,9 +309,10 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
// Clear intent extra, so rotating the screen will not return us to this directory
getIntent().removeExtra(FileDetailFragment.EXTRA_FILE);
} else {
mCurrentDir = mStorageManager.getFileByPath("/");
}
if (mCurrentDir == null)
mCurrentDir = mStorageManager.getFileByPath("/");
// Drop-Down navigation and file list restore
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);
@ -428,7 +429,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
path = FileDisplayActivity.this.mCurrentDir.getRemotePath();
// Create directory
path += directoryName + "/";
path += Uri.encode(directoryName) + "/";
Thread thread = new Thread(new DirectoryCreator(path, a));
thread.start();

View file

@ -84,7 +84,7 @@ public class FileListActionListAdapter implements ListAdapter {
.getSystemService(Context.ACCOUNT_SERVICE);
String ocurl = accm.getUserData(mAccount,
AccountAuthenticator.KEY_OC_URL);
ocurl += mFilePath + mFilename;
ocurl += mFilePath + Uri.encode(mFilename);
intent.setData(Uri.parse(ocurl));
} else {
intent.putExtra("toDownload", false);

View file

@ -17,7 +17,6 @@
*/
package eu.alefzero.owncloud.ui.adapter;
import java.net.URLDecoder;
import java.util.Vector;
import eu.alefzero.owncloud.DisplayUtils;

View file

@ -144,7 +144,8 @@ public class FileDetailFragment extends SherlockFragment implements
Intent i = new Intent(getActivity(), FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_ACCOUNT,
mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT));
i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());
i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());
i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath());
i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());
getActivity().startService(i);
}

View file

@ -21,7 +21,6 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
@ -71,19 +70,23 @@ public class WebdavClient extends HttpClient {
new EasySSLSocketFactory(), 443));
}
public boolean downloadFile(String filepath, File targetPath) {
public boolean downloadFile(String remoteFilepath, File targetPath) {
// HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ",
// "%20"));
String[] splitted_filepath = filepath.split("/");
filepath = "";
/* dvelasco - this is not necessary anymore; OCFile.mRemotePath (the origin of remoteFielPath) keeps valid URL strings
String[] splitted_filepath = remoteFilepath.split("/");
remoteFilepath = "";
for (String s : splitted_filepath) {
if (s.equals("")) continue;
filepath += "/" + URLEncoder.encode(s);
remoteFilepath += "/" + URLEncoder.encode(s);
}
Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + "");
Log.e("ASD", mUri.toString() + remoteFilepath.replace(" ", "%20") + "");
GetMethod get = new GetMethod(mUri.toString()
+ filepath.replace(" ", "%20"));
+ remoteFilepath.replace(" ", "%20"));
*/
GetMethod get = new GetMethod(mUri.toString() + remoteFilepath);
// get.setHeader("Host", mUri.getHost());
// get.setHeader("User-Agent", "Android-ownCloud");
@ -155,8 +158,7 @@ public class WebdavClient extends HttpClient {
public boolean createDirectory(String path) {
try {
MkColMethod mkcol = new MkColMethod(mUri.toString() + "/" + path
+ "/");
MkColMethod mkcol = new MkColMethod(mUri.toString() + path);
int status = executeMethod(mkcol);
Log.d(TAG, "Status returned " + status);
Log.d(TAG, "uri: " + mkcol.getURI().toString());