mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 22:55:46 +03:00
allow account deleting from account picker
This commit is contained in:
parent
fdb9149e0e
commit
2c9b84a862
4 changed files with 87 additions and 27 deletions
6
res/menu/account_picker_long_click.xml
Normal file
6
res/menu/account_picker_long_click.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<item android:id="@+id/delete_account" android:title="Delete account"></item>
|
||||
|
||||
|
||||
</menu>
|
|
@ -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,
|
||||
|
|
|
@ -86,7 +86,7 @@ public class OCFile {
|
|||
* @return true if it is
|
||||
*/
|
||||
public boolean isDownloaded() {
|
||||
return localPath != null;
|
||||
return localPath != null || localPath.equals("");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,7 +36,10 @@ 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<Boolean> {
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -41,22 +53,7 @@ public class AccountSelectActivity extends SherlockListActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
|
||||
Account accounts[] = am.getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
|
||||
LinkedList< HashMap<String, String>> ll = new LinkedList<HashMap<String,String>>();
|
||||
for (Account a : accounts) {
|
||||
HashMap<String, String> h = new HashMap<String, String>();
|
||||
h.put("NAME", a.name);
|
||||
h.put("VER", "ownCloud version: " + am.getUserData(a, AccountAuthenticator.KEY_OC_VERSION));
|
||||
ll.add(h);
|
||||
}
|
||||
|
||||
setListAdapter(new AccountCheckedSimpleAdepter(this,
|
||||
ll,
|
||||
android.R.layout.simple_list_item_single_choice,
|
||||
new String[]{"NAME"},
|
||||
new int[]{android.R.id.text1}));
|
||||
populateAccountList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,6 +63,13 @@ public class AccountSelectActivity extends SherlockListActivity {
|
|||
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();
|
||||
|
@ -87,6 +91,51 @@ public class AccountSelectActivity extends SherlockListActivity {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(android.view.MenuItem item) {
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
||||
int index = info.position;
|
||||
HashMap<String, String> map = (HashMap<String, String>)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<String, String>> ll = new LinkedList<HashMap<String,String>>();
|
||||
for (Account a : accounts) {
|
||||
HashMap<String, String> h = new HashMap<String, String>();
|
||||
h.put("NAME", a.name);
|
||||
h.put("VER", "ownCloud version: " + am.getUserData(a, AccountAuthenticator.KEY_OC_VERSION));
|
||||
ll.add(h);
|
||||
}
|
||||
|
||||
setListAdapter(new AccountCheckedSimpleAdepter(this,
|
||||
ll,
|
||||
android.R.layout.simple_list_item_single_choice,
|
||||
new String[]{"NAME"},
|
||||
new int[]{android.R.id.text1}));
|
||||
registerForContextMenu(getListView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(AccountManagerFuture<Boolean> future) {
|
||||
if (future.isDone()) {
|
||||
AccountUtils.setCurrentOwnCloudAccount(this, AccountUtils.getCurrentOwnCloudAccount(this).name);
|
||||
populateAccountList();
|
||||
}
|
||||
}
|
||||
|
||||
private class AccountCheckedSimpleAdepter extends SimpleAdapter {
|
||||
private Account mCurrentAccount;
|
||||
private List<? extends Map<String, ?>> mPrivateData;
|
||||
|
@ -113,5 +162,6 @@ public class AccountSelectActivity extends SherlockListActivity {
|
|||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue