mFile = mStorageManager.getFileByPath(full_path);\r
if (mFile != null) {\r
Vector<OCFile> files = mStorageManager.getDirectoryContent(mFile);\r
- if (files.size() > 0) {\r
- List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();\r
- for (OCFile f : files) {\r
- HashMap<String, Object> h = new HashMap<String, Object>();\r
- if (f.isDirectory()) {\r
- h.put("dirname", f.getFileName());\r
- data.add(h);\r
- }\r
+ List<HashMap<String, Object>> data = new LinkedList<HashMap<String,Object>>();\r
+ for (OCFile f : files) {\r
+ HashMap<String, Object> h = new HashMap<String, Object>();\r
+ if (f.isDirectory()) {\r
+ h.put("dirname", f.getFileName());\r
+ data.add(h);\r
}\r
- SimpleAdapter sa = new SimpleAdapter(this,\r
- data,\r
- R.layout.uploader_list_item_layout,\r
- new String[] {"dirname"},\r
- new int[] {R.id.textView1});\r
- setListAdapter(sa);\r
- Button btn = (Button) findViewById(R.id.uploader_choose_folder);\r
- btn.setOnClickListener(this);\r
- getListView().setOnItemClickListener(this);\r
}\r
- }\r
- /*\r
- mCursor = managedQuery(ProviderMeta.ProviderTableMeta.CONTENT_URI, null, ProviderTableMeta.FILE_NAME\r
- + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?", new String[] { "/", mAccount.name }, null);\r
-\r
- if (mCursor.moveToFirst()) {\r
- mCursor = managedQuery(\r
- ProviderMeta.ProviderTableMeta.CONTENT_URI,\r
- null,\r
- ProviderTableMeta.FILE_CONTENT_TYPE + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND "\r
- + ProviderTableMeta.FILE_PARENT + "=?",\r
- new String[] { "DIR", mAccount.name,\r
- mCursor.getString(mCursor.getColumnIndex(ProviderTableMeta._ID)) }, null);\r
-\r
- ListView lv = getListView();\r
- lv.setOnItemClickListener(this);\r
- SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.uploader_list_item_layout, mCursor,\r
- new String[] { ProviderTableMeta.FILE_NAME }, new int[] { R.id.textView1 });\r
- setListAdapter(sca);\r
+ SimpleAdapter sa = new SimpleAdapter(this,\r
+ data,\r
+ R.layout.uploader_list_item_layout,\r
+ new String[] {"dirname"},\r
+ new int[] {R.id.textView1});\r
+ setListAdapter(sa);\r
Button btn = (Button) findViewById(R.id.uploader_choose_folder);\r
btn.setOnClickListener(this);\r
- /*\r
- * disable this until new server interaction service wont be created\r
- * // insert create new directory for multiple items uploading if\r
- * (getIntent().getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {\r
- * Button createDirBtn = new Button(this);\r
- * createDirBtn.setId(android.R.id.button1);\r
- * createDirBtn.setText(R.string.uploader_btn_create_dir_text);\r
- * createDirBtn.setOnClickListener(this); ((LinearLayout)\r
- * findViewById(R.id.linearLayout1)).addView( createDirBtn,\r
- * LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); }\r
- *\r
- }*/\r
+ getListView().setOnItemClickListener(this);\r
+ }\r
}\r
\r
private boolean prepareStreamsToUpload() {\r
private ContentResolver mContentResolver;
private ContentProviderClient mContentProvider;
private Account mAccount;
-
+
private static String TAG = "FileDataStorageManager";
-
+
public FileDataStorageManager(Account account, ContentResolver cr) {
mContentProvider = null;
mContentResolver = cr;
file = createFileInstance(c);
}
c.close();
+ if (file == null && OCFile.PATH_SEPARATOR.equals(path)) {
+ return createRootDir(); // root should always exist
+ }
return file;
}
+
+ private OCFile createRootDir() {
+ OCFile file = new OCFile(OCFile.PATH_SEPARATOR);
+ file.setMimetype("DIR");
+ file.setParentId(DataStorageManager.ROOT_PARENT_ID);
+ saveFile(file);
+ return file;
+ }
+
@Override
public OCFile getFileById(long id) {
Cursor c = getCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
}
}
}
- if (removeDBData) {
- removeFile(dir, true);
- }
+ }
+ if (removeDBData) {
+ removeFile(dir, true);
}
}
}
* @param file A file that could be in the queue of downloads.\r
*/\r
public boolean isDownloading(Account account, OCFile file) {\r
+ if (account == null || file == null) return false;\r
String targetKey = buildRemoteName(account, file);\r
synchronized (mPendingDownloads) {\r
if (file.isDirectory()) {\r
* @param file A file that could be in the queue of pending uploads
*/
public boolean isUploading(Account account, OCFile file) {
+ if (account == null || file == null) return false;
String targetKey = buildRemoteName(account, file);
synchronized (mPendingUploads) {
if (file.isDirectory()) {
public class RemoteOperationResult implements Serializable {
/** Generated - should be refreshed every time the class changes!! */
- private static final long serialVersionUID = 5336333154035462033L;
+ private static final long serialVersionUID = -7805531062432602444L;
public enum ResultCode {
private int mHttpCode = -1;
private Exception mException = null;
private ResultCode mCode = ResultCode.UNKNOWN_ERROR;
- private Object mExtraData = null;
public RemoteOperationResult(ResultCode code) {
mCode = code;
return mCode == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED;
}
- public void setExtraData(Object data) {
- mExtraData = data;
- }
-
- public Object getExtraData() {
- return mExtraData;
- }
-
private CertificateCombinedException getCertificateCombinedException(Exception e) {
CertificateCombinedException result = null;
if (e instanceof CertificateCombinedException) {
break;
}
default:
- retval = onOptionsItemSelected(item);
+ retval = super.onOptionsItemSelected(item);
}
return retval;
}
protected Boolean doInBackground(Void... params) {
String[] checkedFilePaths = mFileListFragment.getCheckedFilePaths();
long total = 0;
- for (int i=0; i < checkedFilePaths.length ; i++) {
+ for (int i=0; checkedFilePaths != null && i < checkedFilePaths.length ; i++) {
String localPath = checkedFilePaths[i];
File localFile = new File(localPath);
total += localFile.length();
mAccount = ocAccount;\r
mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment \r
mLayout = R.layout.file_details_empty;\r
- \r
- if(fileToDetail != null && ocAccount != null) {\r
- mLayout = R.layout.file_details_fragment;\r
- }\r
}\r
\r
\r
mAccount = savedInstanceState.getParcelable(FileDetailFragment.EXTRA_ACCOUNT);\r
}\r
\r
+ if(mFile != null && mAccount != null) {\r
+ mLayout = R.layout.file_details_fragment;\r
+ }\r
+ \r
View view = null;\r
view = inflater.inflate(mLayout, container, false);\r
mView = view;\r
* @return True when the fragment was created with the empty layout.\r
*/\r
public boolean isEmpty() {\r
- return mLayout == R.layout.file_details_empty;\r
+ return (mLayout == R.layout.file_details_empty || mFile == null || mAccount == null);\r
}\r
\r
\r
if (mFile.getRemotePath().equals(uploadRemotePath) ||\r
renamedInUpload) {\r
if (uploadWasFine) {\r
- mFile = mStorageManager.getFileByPath(mFile.getRemotePath());\r
+ mFile = mStorageManager.getFileByPath(uploadRemotePath);\r
}\r
if (renamedInUpload) {\r
String newName = (new File(uploadRemotePath)).getName();\r
Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG);\r
msg.show();\r
- getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done\r
}\r
+ getSherlockActivity().removeStickyBroadcast(intent); // not the best place to do this; a small refactorization of BroadcastReceivers should be done\r
updateFileDetails(false); // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
}\r
}\r