diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-17 21:46:33 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-17 21:46:33 +0200 |
commit | 245e32581b46acf11a2470441a296e9d520b6f71 (patch) | |
tree | 3b189d6e30c79503d39fb8fa1fc7cbe38087561e /src/main/java/de/pixart | |
parent | ea913ce9cd9b7f020425b62e19f4822f8e1dd1e4 (diff) |
add possibility to de-/activate accounts
fixes #195
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java | 8 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java | 24 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java index a47a128ab..bca4d3dbc 100644 --- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java @@ -227,6 +227,14 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda } } + public void onClickTglAccountState(Account account, boolean enable) { + if (enable) { + enableAccount(account); + } else { + disableAccount(account); + } + } + private void addAccountFromKey() { try { KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null); diff --git a/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java index 4ed6a5492..37d15f782 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/AccountAdapter.java @@ -6,6 +6,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.support.v7.widget.SwitchCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,6 +21,7 @@ import java.util.concurrent.RejectedExecutionException; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; +import de.pixart.messenger.ui.ManageAccountActivity; import de.pixart.messenger.ui.XmppActivity; import de.pixart.messenger.ui.util.Color; import de.pixart.messenger.utils.UIHelper; @@ -27,10 +29,18 @@ import de.pixart.messenger.utils.UIHelper; public class AccountAdapter extends ArrayAdapter<Account> { private XmppActivity activity; + private boolean showStateButton; + + public AccountAdapter(XmppActivity activity, List<Account> objects, boolean showStateButton) { + super(activity, 0, objects); + this.activity = activity; + this.showStateButton = showStateButton; + } public AccountAdapter(XmppActivity activity, List<Account> objects) { super(activity, 0, objects); this.activity = activity; + this.showStateButton = true; } @Override @@ -63,6 +73,20 @@ public class AccountAdapter extends ArrayAdapter<Account> { statusView.setTextColor(Color.get(activity, R.attr.TextColorError)); break; } + final SwitchCompat tglAccountState = view.findViewById(R.id.tgl_account_status); + final boolean isDisabled = (account.getStatus() == Account.State.DISABLED); + tglAccountState.setOnCheckedChangeListener(null); + tglAccountState.setChecked(!isDisabled); + if (this.showStateButton) { + tglAccountState.setVisibility(View.VISIBLE); + } else { + tglAccountState.setVisibility(View.GONE); + } + tglAccountState.setOnCheckedChangeListener((compoundButton, b) -> { + if (b == isDisabled && activity instanceof ManageAccountActivity) { + ((ManageAccountActivity) activity).onClickTglAccountState(account, b); + } + }); return view; } |