diff --git a/res/menu/account_picker_long_click.xml b/res/menu/account_picker_long_click.xml
new file mode 100644
index 0000000000..e7243981a9
--- /dev/null
+++ b/res/menu/account_picker_long_click.xml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
index 77575512f7..ee874d0af9 100644
--- a/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
+++ b/src/eu/alefzero/owncloud/datamodel/FileDataStorageManager.java
@@ -98,7 +98,11 @@ public class FileDataStorageManager implements DataStorageManager {
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
if (fileExists(file.getPath())) {
- file.setFileId(getFileByPath(file.getPath()).getFileId());
+ OCFile tmpfile = getFileByPath(file.getPath());
+ file.setStoragePath(tmpfile.getStoragePath());
+ cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+ file.setFileId(tmpfile.getFileId());
+
overriden = true;
if (getContentResolver() != null) {
getContentResolver().update(ProviderTableMeta.CONTENT_URI,
diff --git a/src/eu/alefzero/owncloud/datamodel/OCFile.java b/src/eu/alefzero/owncloud/datamodel/OCFile.java
index 9c40b947dc..b9be3addd0 100644
--- a/src/eu/alefzero/owncloud/datamodel/OCFile.java
+++ b/src/eu/alefzero/owncloud/datamodel/OCFile.java
@@ -86,7 +86,7 @@ public class OCFile {
* @return true if it is
*/
public boolean isDownloaded() {
- return localPath != null;
+ return localPath != null || localPath.equals("");
}
/**
diff --git a/src/eu/alefzero/owncloud/ui/activity/AccountSelectActivity.java b/src/eu/alefzero/owncloud/ui/activity/AccountSelectActivity.java
index f3dd4b3c2c..fc7ef2edee 100644
--- a/src/eu/alefzero/owncloud/ui/activity/AccountSelectActivity.java
+++ b/src/eu/alefzero/owncloud/ui/activity/AccountSelectActivity.java
@@ -7,11 +7,20 @@ import java.util.Map;
import android.accounts.Account;
import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.ContextMenu;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ContextMenu.ContextMenuInfo;
+import android.widget.AdapterView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
+import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.CheckedTextView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
@@ -27,8 +36,11 @@ import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
import eu.alefzero.owncloud.AccountUtils;
import eu.alefzero.owncloud.R;
-public class AccountSelectActivity extends SherlockListActivity {
+public class AccountSelectActivity extends SherlockListActivity
+ implements AccountManagerCallback {
+ private final Handler mHandler = new Handler();
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -41,7 +53,63 @@ public class AccountSelectActivity extends SherlockListActivity {
@Override
protected void onResume() {
super.onResume();
+ populateAccountList();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getSherlock().getMenuInflater();
+ inflater.inflate(eu.alefzero.owncloud.R.menu.account_picker, menu);
+ return true;
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenuInfo menuInfo) {
+ getMenuInflater().inflate(R.menu.account_picker_long_click, menu);
+ super.onCreateContextMenu(menu, v, menuInfo);
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ String accountName = ((TextView)v.findViewById(android.R.id.text1)).getText().toString();
+ AccountUtils.setCurrentOwnCloudAccount(this, accountName);
+ Intent i = new Intent(this, FileDisplayActivity.class);
+ startActivity(i);
+ finish();
+ }
+ @Override
+ public boolean onMenuItemSelected(int featureId, MenuItem item) {
+ if (item.getItemId() == R.id.createAccount) {
+ Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
+ intent.putExtra("authorities",
+ new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
+ startActivity(intent);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onContextItemSelected(android.view.MenuItem item) {
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+ int index = info.position;
+ HashMap map = (HashMap)getListAdapter().getItem(index);
+ String accountName = map.get("NAME");
+ AccountManager am = (AccountManager)getSystemService(ACCOUNT_SERVICE);
+ Account accounts[] = am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
+ for (Account a : accounts) {
+ if (a.name.equals(accountName)) {
+ am.removeAccount(a, this, mHandler);
+ }
+ }
+
+ return false;
+ }
+
+
+ private void populateAccountList() {
AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
Account accounts[] = am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
LinkedList< HashMap> ll = new LinkedList>();
@@ -57,34 +125,15 @@ public class AccountSelectActivity extends SherlockListActivity {
android.R.layout.simple_list_item_single_choice,
new String[]{"NAME"},
new int[]{android.R.id.text1}));
+ registerForContextMenu(getListView());
}
@Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getSherlock().getMenuInflater();
- inflater.inflate(eu.alefzero.owncloud.R.menu.account_picker, menu);
- return true;
- }
-
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- String accountName = ((TextView)v.findViewById(android.R.id.text1)).getText().toString();
- AccountUtils.setCurrentOwnCloudAccount(this, accountName);
- Intent i = new Intent(this, FileDisplayActivity.class);
- startActivity(i);
- finish();
- }
-
- @Override
- public boolean onMenuItemSelected(int featureId, MenuItem item) {
- if (item.getItemId() == R.id.createAccount) {
- Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
- intent.putExtra("authorities",
- new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
- startActivity(intent);
- return true;
+ public void run(AccountManagerFuture future) {
+ if (future.isDone()) {
+ AccountUtils.setCurrentOwnCloudAccount(this, AccountUtils.getCurrentOwnCloudAccount(this).name);
+ populateAccountList();
}
- return false;
}
private class AccountCheckedSimpleAdepter extends SimpleAdapter {
@@ -113,5 +162,6 @@ public class AccountSelectActivity extends SherlockListActivity {
}
+
}