-->\r
<manifest package="eu.alefzero.owncloud"\r
android:versionCode="1"\r
- android:versionName="0.1.131B" xmlns:android="http://schemas.android.com/apk/res/android">\r
+ android:versionName="0.1.132B" xmlns:android="http://schemas.android.com/apk/res/android">\r
\r
<uses-permission android:name="android.permission.GET_ACCOUNTS" />\r
<uses-permission android:name="android.permission.USE_CREDENTIALS" />\r
package eu.alefzero.owncloud;\r
\r
import java.io.File;\r
-import java.net.URLEncoder;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.LinkedList;\r
EditText mDirname;\r
\r
public a(String path, EditText dirname) {\r
- mPath = path;\r
+ mPath = path; \r
mDirname = dirname;\r
}\r
\r
}\r
\r
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\r
+ // click on folder in the list\r
Log.d(TAG, "on item click");\r
Vector<OCFile> tmpfiles = mStorageManager.getDirectoryContent(mFile);\r
if (tmpfiles == null) return;\r
}\r
\r
public void onClick(View v) {\r
+ // click on button\r
switch (v.getId()) {\r
case R.id.uploader_choose_folder:\r
- mUploadPath = "";\r
+ mUploadPath = "/";\r
for (String p : mParents)\r
- mUploadPath += URLEncoder.encode(p) + "/";\r
+ mUploadPath += p + "/";\r
+ mUploadPath = Uri.encode(mUploadPath, "/");\r
Log.d(TAG, "Uploading file to dir " + mUploadPath);\r
\r
uploadFiles();\r
final String display_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME)),\r
data = c.getString(c.getColumnIndex(Media.DATA));\r
local[i] = data;\r
- remote[i] = mUploadPath + display_name;\r
+ remote[i] = mUploadPath + Uri.encode(display_name);\r
} else if (uri.getScheme().equals("file")) {\r
final File file = new File(Uri.decode(uri.toString()).replace(uri.getScheme() + "://", ""));\r
local[i] = file.getAbsolutePath();\r
- remote[i] = mUploadPath + file.getName();\r
+ remote[i] = mUploadPath + Uri.encode(file.getName());\r
}\r
\r
}\r
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());
}
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;
* 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;
}
}
/**
+ * 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
*
* @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();
}
/**
@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) {
public static final String DOWNLOAD_FINISH_MESSAGE = "DOWNLOAD_FINISH";\r
public static final String EXTRA_ACCOUNT = "ACCOUNT";\r
public static final String EXTRA_FILE_PATH = "FILE_PATH";\r
+ public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";\r
public static final String EXTRA_FILE_SIZE = "FILE_SIZE";\r
private static final String TAG = "FileDownloader";\r
\r
private ServiceHandler mServiceHandler;\r
private Account mAccount;\r
private String mFilePath;\r
+ private String mRemotePath;\r
private int mLastPercent;\r
private long mTotalDownloadSize;\r
private long mCurrentDownlodSize;\r
}\r
mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);\r
mFilePath = intent.getStringExtra(EXTRA_FILE_PATH);\r
+ mRemotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);\r
Message msg = mServiceHandler.obtainMessage();\r
msg.arg1 = startId;\r
mServiceHandler.sendMessage(msg);\r
\r
Log.e(TAG, file.getAbsolutePath() + " " + oc_url.toString());\r
Log.e(TAG, mFilePath+"");\r
- if (wdc.downloadFile(mFilePath, file)) {\r
+ if (wdc.downloadFile(mRemotePath, file)) {\r
ContentValues cv = new ContentValues();\r
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getAbsolutePath());\r
getContentResolver().update(\r
package eu.alefzero.owncloud.files.services;
import java.io.File;
-import java.net.URLDecoder;
import eu.alefzero.owncloud.AccountUtils;
import eu.alefzero.owncloud.R;
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();
}
}
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);
}
package eu.alefzero.owncloud.syncadapter;\r
\r
import java.io.IOException;\r
-import java.net.URLDecoder;\r
import java.util.Vector;\r
\r
import org.apache.jackrabbit.webdav.DavException;\r
}\r
\r
private OCFile fillOCFile(WebdavEntry we) {\r
- OCFile file = new OCFile(URLDecoder.decode(we.path()));\r
+ OCFile file = new OCFile(we.path());\r
file.setCreationTimestamp(we.createTimestamp());\r
file.setFileLength(we.contentLength());\r
file.setMimetype(we.contentType());\r
import java.io.File;\r
import java.io.InputStreamReader;\r
import java.lang.Thread.UncaughtExceptionHandler;\r
-import java.net.URLEncoder;\r
import java.util.ArrayList;\r
\r
import android.accounts.Account;\r
AccountUtils.getCurrentOwnCloudAccount(this));\r
String remotepath = new String();\r
for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
- remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j));\r
+ remotepath += "/" + mDirectories.getItem(j);\r
}\r
if (!remotepath.endsWith("/"))\r
remotepath += "/";\r
- remotepath += URLEncoder.encode(new File(filepath).getName());\r
+ remotepath += new File(filepath).getName();\r
+ remotepath = Uri.encode(remotepath, "/");\r
\r
i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
\r
// Clear intent extra, so rotating the screen will not return us to this directory\r
getIntent().removeExtra(FileDetailFragment.EXTRA_FILE);\r
- } else {\r
- mCurrentDir = mStorageManager.getFileByPath("/");\r
}\r
+ \r
+ if (mCurrentDir == null)\r
+ mCurrentDir = mStorageManager.getFileByPath("/");\r
\r
// Drop-Down navigation and file list restore\r
mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
path = FileDisplayActivity.this.mCurrentDir.getRemotePath();\r
\r
// Create directory\r
- path += directoryName + "/";\r
+ path += Uri.encode(directoryName) + "/";\r
Thread thread = new Thread(new DirectoryCreator(path, a));\r
thread.start();\r
\r
.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);
*/\r
package eu.alefzero.owncloud.ui.adapter;\r
\r
-import java.net.URLDecoder;\r
import java.util.Vector;\r
\r
import eu.alefzero.owncloud.DisplayUtils;\r
Intent i = new Intent(getActivity(), FileDownloader.class);\r
i.putExtra(FileDownloader.EXTRA_ACCOUNT,\r
mIntent.getParcelableExtra(FileDownloader.EXTRA_ACCOUNT));\r
- i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getRemotePath());\r
+ i.putExtra(FileDownloader.EXTRA_REMOTE_PATH, mFile.getRemotePath());\r
+ i.putExtra(FileDownloader.EXTRA_FILE_PATH, mFile.getURLDecodedRemotePath());\r
i.putExtra(FileDownloader.EXTRA_FILE_SIZE, mFile.getFileLength());\r
getActivity().startService(i);\r
}\r
import java.io.File;\r
import java.io.FileOutputStream;\r
import java.io.IOException;\r
-import java.net.URLEncoder;\r
\r
import org.apache.commons.httpclient.Credentials;\r
import org.apache.commons.httpclient.HttpClient;\r
new EasySSLSocketFactory(), 443));\r
}\r
\r
- public boolean downloadFile(String filepath, File targetPath) {\r
+ public boolean downloadFile(String remoteFilepath, File targetPath) {\r
// HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ",\r
// "%20"));\r
- String[] splitted_filepath = filepath.split("/");\r
- filepath = "";\r
+ /* dvelasco - this is not necessary anymore; OCFile.mRemotePath (the origin of remoteFielPath) keeps valid URL strings\r
+ String[] splitted_filepath = remoteFilepath.split("/");\r
+ remoteFilepath = "";\r
for (String s : splitted_filepath) {\r
if (s.equals("")) continue;\r
- filepath += "/" + URLEncoder.encode(s);\r
+ remoteFilepath += "/" + URLEncoder.encode(s);\r
}\r
\r
- Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + "");\r
+ Log.e("ASD", mUri.toString() + remoteFilepath.replace(" ", "%20") + "");\r
GetMethod get = new GetMethod(mUri.toString()\r
- + filepath.replace(" ", "%20"));\r
+ + remoteFilepath.replace(" ", "%20"));\r
+ */\r
+ \r
+ GetMethod get = new GetMethod(mUri.toString() + remoteFilepath);\r
\r
// get.setHeader("Host", mUri.getHost());\r
// get.setHeader("User-Agent", "Android-ownCloud");\r
\r
public boolean createDirectory(String path) {\r
try {\r
- MkColMethod mkcol = new MkColMethod(mUri.toString() + "/" + path\r
- + "/");\r
+ MkColMethod mkcol = new MkColMethod(mUri.toString() + path);\r
int status = executeMethod(mkcol);\r
Log.d(TAG, "Status returned " + status);\r
Log.d(TAG, "uri: " + mkcol.getURI().toString());\r