disable / enable all accounts
This commit is contained in:
parent
521c289db1
commit
960b7343d3
|
@ -26,21 +26,25 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
||||||
|
|
||||||
protected Account selectedAccount = null;
|
protected Account selectedAccount = null;
|
||||||
|
|
||||||
protected List<Account> accountList = new ArrayList<Account>();
|
protected final List<Account> accountList = new ArrayList<>();
|
||||||
protected ListView accountListView;
|
protected ListView accountListView;
|
||||||
protected AccountAdapter mAccountAdapter;
|
protected AccountAdapter mAccountAdapter;
|
||||||
@Override
|
|
||||||
public void onAccountUpdate() {
|
@Override
|
||||||
|
public void onAccountUpdate() {
|
||||||
|
synchronized (this.accountList) {
|
||||||
accountList.clear();
|
accountList.clear();
|
||||||
accountList.addAll(xmppConnectionService.getAccounts());
|
accountList.addAll(xmppConnectionService.getAccounts());
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mAccountAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
mAccountAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -91,6 +95,14 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.manageaccounts, menu);
|
getMenuInflater().inflate(R.menu.manageaccounts, menu);
|
||||||
|
MenuItem enableAll = menu.findItem(R.id.action_enable_all);
|
||||||
|
if (!accountsLeftToEnable()) {
|
||||||
|
enableAll.setVisible(false);
|
||||||
|
}
|
||||||
|
MenuItem disableAll = menu.findItem(R.id.action_disable_all);
|
||||||
|
if (!accountsLeftToDisable()) {
|
||||||
|
disableAll.setVisible(false);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +132,18 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_add_account:
|
case R.id.action_add_account:
|
||||||
startActivity(new Intent(getApplicationContext(),
|
startActivity(new Intent(getApplicationContext(),
|
||||||
EditAccountActivity.class));
|
EditAccountActivity.class));
|
||||||
break;
|
break;
|
||||||
default:
|
case R.id.action_disable_all:
|
||||||
break;
|
disableAllAccounts();
|
||||||
|
break;
|
||||||
|
case R.id.action_enable_all:
|
||||||
|
enableAllAccounts();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
@ -158,6 +176,56 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void disableAllAccounts() {
|
||||||
|
List<Account> list = new ArrayList<>();
|
||||||
|
synchronized (this.accountList) {
|
||||||
|
for (Account account : this.accountList) {
|
||||||
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
|
list.add(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Account account : list) {
|
||||||
|
disableAccount(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean accountsLeftToDisable() {
|
||||||
|
synchronized (this.accountList) {
|
||||||
|
for (Account account : this.accountList) {
|
||||||
|
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean accountsLeftToEnable() {
|
||||||
|
synchronized (this.accountList) {
|
||||||
|
for (Account account : this.accountList) {
|
||||||
|
if (account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableAllAccounts() {
|
||||||
|
List<Account> list = new ArrayList<>();
|
||||||
|
synchronized (this.accountList) {
|
||||||
|
for (Account account : this.accountList) {
|
||||||
|
if (account.isOptionSet(Account.OPTION_DISABLED)) {
|
||||||
|
list.add(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Account account : list) {
|
||||||
|
enableAccount(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void disableAccount(Account account) {
|
private void disableAccount(Account account) {
|
||||||
account.setOption(Account.OPTION_DISABLED, true);
|
account.setOption(Account.OPTION_DISABLED, true);
|
||||||
xmppConnectionService.updateAccount(account);
|
xmppConnectionService.updateAccount(account);
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_add_account"
|
android:id="@+id/action_add_account"
|
||||||
android:icon="@drawable/ic_action_add_person"
|
android:icon="@drawable/ic_action_add_person"
|
||||||
android:showAsAction="always"
|
android:showAsAction="always"
|
||||||
android:title="@string/action_add_account"/>
|
android:title="@string/action_add_account"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_settings"
|
android:id="@+id/action_enable_all"
|
||||||
android:orderInCategory="100"
|
android:title="@string/enable_all_accounts"/>
|
||||||
android:showAsAction="never"
|
<item
|
||||||
android:title="@string/action_settings"/>
|
android:id="@+id/action_disable_all"
|
||||||
|
android:title="@string/disable_all_accounts"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/action_settings"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
|
@ -403,4 +403,6 @@
|
||||||
<string name="current_password">Current password</string>
|
<string name="current_password">Current password</string>
|
||||||
<string name="new_password">New password</string>
|
<string name="new_password">New password</string>
|
||||||
<string name="password_should_not_be_empty">Password should not be empty</string>
|
<string name="password_should_not_be_empty">Password should not be empty</string>
|
||||||
|
<string name="enable_all_accounts">Enable all accounts</string>
|
||||||
|
<string name="disable_all_accounts">Disable all accounts</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue