fixed disable account when sliding and not clicking the toggle

This commit is contained in:
iNPUTmice 2015-04-13 18:19:40 +02:00
parent 62faa163f0
commit 2f24b09309
2 changed files with 9 additions and 8 deletions

View File

@ -168,8 +168,8 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
} }
} }
public void onClickTglAccountState(Account account) { public void onClickTglAccountState(Account account, boolean enable) {
if (account.isOptionSet(Account.OPTION_DISABLED)) { if (enable) {
enableAccount(account); enableAccount(account);
} else { } else {
disableAccount(account); disableAccount(account);

View File

@ -11,6 +11,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Switch; import android.widget.Switch;
@ -51,14 +52,14 @@ public class AccountAdapter extends ArrayAdapter<Account> {
break; break;
} }
final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status); final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status);
boolean isDisabled = (account.getStatus() == Account.State.DISABLED) ? true : false; final boolean isDisabled = (account.getStatus() == Account.State.DISABLED) ? true : false;
tglAccountState.setOnCheckedChangeListener(null);
tglAccountState.setChecked(!isDisabled); tglAccountState.setChecked(!isDisabled);
tglAccountState.setOnClickListener(new View.OnClickListener() { tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onClick(View v) { public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (activity instanceof ManageAccountActivity) { if (b == isDisabled && activity instanceof ManageAccountActivity) {
((ManageAccountActivity) activity).onClickTglAccountState(account); ((ManageAccountActivity) activity).onClickTglAccountState(account,b);
tglAccountState.toggle();
} }
} }
}); });