mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +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,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<Boolean> {
|
||||
|
||||
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<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>>();
|
||||
|
@ -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<Boolean> 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 {
|
|||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue