return new_file;
}
+ public static OCFile createNewFile(ContentResolver contentResolver, Account a,
+ String path, int length, int creation_timestamp, int modified_timestamp,
+ String mimetype, long parent_id) {
+ OCFile new_file = new OCFile(contentResolver, a);
+ Cursor c = new_file.cr_.query(ProviderTableMeta.CONTENT_URI_FILE, null,
+ ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND "
+ + ProviderTableMeta.FILE_PATH + "=?", new String[]{new_file.account_.name,
+ path}, null);
+ if (c.moveToFirst())
+ new_file.setFileData(c);
+ c.close();
+
+ new_file.path_ = path;
+ new_file.length_ = length;
+ new_file.creation_timestamp_ = creation_timestamp;
+ new_file.modified_timestamp_ = modified_timestamp;
+ new_file.mimetype_ = mimetype;
+ new_file.parent_id_ = parent_id;
+
+ return new_file;
+ }
+
public OCFile(ContentResolver cr, Account account, long id) {
cr_ = cr;
account_ = account;
cp_ = cp;
resetData();
}
+
+ private OCFile(ContentResolver cr, Account account) {
+ account_ = account;
+ cr_ = cr;
+ resetData();
+ }
private void resetData() {
id_ = -1;
import android.accounts.AccountManager;\r
import android.app.AlertDialog;\r
import android.app.Dialog;\r
+import android.app.AlertDialog.Builder;\r
import android.content.DialogInterface;\r
import android.content.DialogInterface.OnCancelListener;\r
+import android.content.DialogInterface.OnClickListener;\r
import android.content.Intent;\r
+import android.net.Uri;\r
import android.os.Bundle;\r
import android.support.v4.app.ActionBar;\r
import android.support.v4.app.ActionBar.OnNavigationListener;\r
import android.support.v4.view.MenuItem;\r
import android.view.MenuInflater;\r
import android.widget.ArrayAdapter;\r
+import android.widget.EditText;\r
import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.R.id;\r
import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+import eu.alefzero.owncloud.datamodel.OCFile;\r
import eu.alefzero.owncloud.ui.fragment.FileList;\r
+import eu.alefzero.webdav.WebdavClient;\r
\r
/**\r
* Displays, what files the user has available in his ownCloud.\r
}\r
\r
@Override\r
+ protected Dialog onCreateDialog(int id, Bundle args) {\r
+ final AlertDialog.Builder builder = new Builder(this);\r
+ final EditText dirName = new EditText(getBaseContext());\r
+ builder.setView(dirName);\r
+ builder.setTitle(R.string.uploader_info_dirname);\r
+ \r
+ builder.setPositiveButton(R.string.common_ok, new OnClickListener() {\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ String s = dirName.getText().toString();\r
+ if (s.trim().isEmpty()) {\r
+ dialog.cancel();\r
+ return;\r
+ }\r
+ AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+ // following account choosing is incorrect and needs to be replaced\r
+ // with some sort of session mechanism\r
+ Account a = am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE)[0];\r
+\r
+ String path = "";\r
+ for (int i = mDirectories.getCount()-2; i >= 0; --i) {\r
+ path += "/" + mDirectories.getItem(i);\r
+ }\r
+ OCFile parent = new OCFile(getContentResolver(), a, path+"/");\r
+ path += "/" + s + "/";\r
+ Thread thread = new Thread(new DirectoryCreator(path, a, am));\r
+ thread.start();\r
+ OCFile.createNewFile(getContentResolver(), a, path, 0, 0, 0, "DIR", parent.getFileId()).save();\r
+ \r
+ dialog.dismiss();\r
+ }\r
+ });\r
+ builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ dialog.cancel();\r
+ }\r
+ });\r
+ return builder.create();\r
+ }\r
+ \r
+ @Override\r
public void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
mDirectories = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item);\r
public boolean onOptionsItemSelected(MenuItem item) {\r
switch (item.getItemId()) {\r
case R.id.settingsItem :\r
+ {\r
Intent i = new Intent(this, Preferences.class);\r
startActivity(i);\r
break;\r
+ }\r
+ case R.id.createDirectoryItem:\r
+ {\r
+ showDialog(0);\r
+ break;\r
+ }\r
}\r
return true;\r
}\r
}\r
((FileList)getSupportFragmentManager().findFragmentById(R.id.fileList)).onBackPressed();\r
}\r
+ \r
+ private class DirectoryCreator implements Runnable {\r
+ private String mTargetPath;\r
+ private Account mAccount;\r
+ private AccountManager mAm;\r
+ \r
+ public DirectoryCreator(String targetPath, Account account, AccountManager am) {\r
+ mTargetPath = targetPath;\r
+ mAccount = account;\r
+ mAm = am;\r
+ }\r
+ \r
+ @Override\r
+ public void run() {\r
+ WebdavClient wdc = new WebdavClient(Uri.parse(mAm.getUserData(mAccount,\r
+ AccountAuthenticator.KEY_OC_URL)));\r
+ \r
+ String username = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
+ String password = mAm.getPassword(mAccount);\r
+ \r
+ wdc.setCredentials(username, password);\r
+ wdc.allowUnsignedCertificates();\r
+ wdc.createDirectory(mTargetPath);\r
+ }\r
+ \r
+ }\r
}
\ No newline at end of file