mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-01 05:02:21 -05:00
added callback to change account password to notify UI on success / failure
This commit is contained in:
parent
e4d9dca2fe
commit
0c22a8d1c6
@ -144,7 +144,7 @@ public class IqGenerator extends AbstractGenerator {
|
|||||||
packet.setTo(account.getServer());
|
packet.setTo(account.getServer());
|
||||||
final Element query = packet.addChild("query", Xmlns.REGISTER);
|
final Element query = packet.addChild("query", Xmlns.REGISTER);
|
||||||
final Jid jid = account.getJid();
|
final Jid jid = account.getJid();
|
||||||
query.addChild("username").setContent(jid.isDomainJid() ? jid.toString() : jid.getLocalpart());
|
query.addChild("username").setContent(jid.getLocalpart());
|
||||||
query.addChild("password").setContent(newPassword);
|
query.addChild("password").setContent(newPassword);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -1100,19 +1100,25 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
|
|||||||
getNotificationService().updateErrorNotification();
|
getNotificationService().updateErrorNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAccountPasswordOnServer(final Account account, final String newPassword) {
|
public void updateAccountPasswordOnServer(final Account account, final String newPassword, final OnAccountPasswordChanged callback) {
|
||||||
if (account.isOnlineAndConnected()) {
|
|
||||||
final IqPacket iq = getIqGenerator().generateSetPassword(account, newPassword);
|
final IqPacket iq = getIqGenerator().generateSetPassword(account, newPassword);
|
||||||
sendIqPacket(account, iq, new OnIqPacketReceived() {
|
sendIqPacket(account, iq, new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
public void onIqPacketReceived(final Account account, final IqPacket packet) {
|
||||||
if (packet.getType() == IqPacket.TYPE_RESULT) {
|
if (packet.getType() == IqPacket.TYPE_RESULT) {
|
||||||
account.setPassword(newPassword);
|
account.setPassword(newPassword);
|
||||||
updateAccount(account);
|
databaseBackend.updateAccount(account);
|
||||||
|
callback.onPasswordChangeSucceeded();
|
||||||
|
} else {
|
||||||
|
callback.onPasswordChangeFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnAccountPasswordChanged {
|
||||||
|
public void onPasswordChangeSucceeded();
|
||||||
|
public void onPasswordChangeFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteAccount(final Account account) {
|
public void deleteAccount(final Account account) {
|
||||||
|
@ -25,6 +25,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
|
||||||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||||
import eu.siacs.conversations.utils.CryptoHelper;
|
import eu.siacs.conversations.utils.CryptoHelper;
|
||||||
@ -34,7 +35,7 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
|||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||||
|
|
||||||
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate {
|
public class EditAccountActivity extends XmppActivity implements OnAccountUpdate, XmppConnectionService.OnAccountPasswordChanged {
|
||||||
|
|
||||||
private AutoCompleteTextView mAccountJid;
|
private AutoCompleteTextView mAccountJid;
|
||||||
private EditText mPassword;
|
private EditText mPassword;
|
||||||
@ -63,13 +64,13 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
|
|
||||||
private boolean mFetchingAvatar = false;
|
private boolean mFetchingAvatar = false;
|
||||||
|
private boolean mChangingPassword = false;
|
||||||
|
|
||||||
private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
|
private final OnClickListener mSaveButtonClickListener = new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
if (mAccount != null
|
if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED) {
|
||||||
&& mAccount.getStatus() == Account.State.DISABLED) {
|
|
||||||
mAccount.setOption(Account.OPTION_DISABLED, false);
|
mAccount.setOption(Account.OPTION_DISABLED, false);
|
||||||
xmppConnectionService.updateAccount(mAccount);
|
xmppConnectionService.updateAccount(mAccount);
|
||||||
return;
|
return;
|
||||||
@ -107,10 +108,13 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||||||
}
|
}
|
||||||
if (changePassword) {
|
if (changePassword) {
|
||||||
if (mAccount.isOnlineAndConnected()) {
|
if (mAccount.isOnlineAndConnected()) {
|
||||||
xmppConnectionService.updateAccountPasswordOnServer(mAccount, mPassword.getText().toString());
|
xmppConnectionService.updateAccountPasswordOnServer(mAccount, mPassword.getText().toString(),EditAccountActivity.this);
|
||||||
|
mChangingPassword = true;
|
||||||
|
updateSaveButton();
|
||||||
} else {
|
} else {
|
||||||
mPassword.setError(getResources().getString(R.string.account_status_no_internet));
|
Toast.makeText(EditAccountActivity.this,R.string.not_connected_try_again,Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
mAccount.setPassword(password);
|
mAccount.setPassword(password);
|
||||||
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
|
||||||
@ -119,8 +123,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) {
|
if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) {
|
||||||
mAccountJid
|
mAccountJid.setError(getString(R.string.account_already_exists));
|
||||||
.setError(getString(R.string.account_already_exists));
|
|
||||||
mAccountJid.requestFocus();
|
mAccountJid.requestFocus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -253,13 +256,15 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updateSaveButton() {
|
protected void updateSaveButton() {
|
||||||
if (mAccount != null
|
if (mChangingPassword) {
|
||||||
&& mAccount.getStatus() == Account.State.CONNECTING) {
|
this.mSaveButton.setEnabled(false);
|
||||||
|
this.mSaveButton.setTextColor(getSecondaryTextColor());
|
||||||
|
this.mSaveButton.setText(R.string.updating);
|
||||||
|
} else if (mAccount != null && mAccount.getStatus() == Account.State.CONNECTING) {
|
||||||
this.mSaveButton.setEnabled(false);
|
this.mSaveButton.setEnabled(false);
|
||||||
this.mSaveButton.setTextColor(getSecondaryTextColor());
|
this.mSaveButton.setTextColor(getSecondaryTextColor());
|
||||||
this.mSaveButton.setText(R.string.account_status_connecting);
|
this.mSaveButton.setText(R.string.account_status_connecting);
|
||||||
} else if (mAccount != null
|
} else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED) {
|
||||||
&& mAccount.getStatus() == Account.State.DISABLED) {
|
|
||||||
this.mSaveButton.setEnabled(true);
|
this.mSaveButton.setEnabled(true);
|
||||||
this.mSaveButton.setTextColor(getPrimaryTextColor());
|
this.mSaveButton.setTextColor(getPrimaryTextColor());
|
||||||
this.mSaveButton.setText(R.string.enable);
|
this.mSaveButton.setText(R.string.enable);
|
||||||
@ -446,8 +451,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||||||
if (this.mAccount.getStatus() == Account.State.ONLINE
|
if (this.mAccount.getStatus() == Account.State.ONLINE
|
||||||
&& !this.mFetchingAvatar) {
|
&& !this.mFetchingAvatar) {
|
||||||
this.mStats.setVisibility(View.VISIBLE);
|
this.mStats.setVisibility(View.VISIBLE);
|
||||||
this.mSessionEst.setText(UIHelper.readableTimeDifference(
|
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
|
||||||
getApplicationContext(), this.mAccount.getXmppConnection()
|
|
||||||
.getLastSessionEstablished()));
|
.getLastSessionEstablished()));
|
||||||
Features features = this.mAccount.getXmppConnection().getFeatures();
|
Features features = this.mAccount.getXmppConnection().getFeatures();
|
||||||
if (features.rosterVersioning()) {
|
if (features.rosterVersioning()) {
|
||||||
@ -517,4 +521,30 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
|
|||||||
this.mStats.setVisibility(View.GONE);
|
this.mStats.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasswordChangeSucceeded() {
|
||||||
|
this.mChangingPassword = false;
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(EditAccountActivity.this,R.string.password_changed,Toast.LENGTH_SHORT).show();
|
||||||
|
updateSaveButton();
|
||||||
|
updateAccountInformation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasswordChangeFailed() {
|
||||||
|
this.mChangingPassword = false;
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mPassword.requestFocus();
|
||||||
|
mPassword.setError(getString(R.string.could_not_change_password));
|
||||||
|
updateSaveButton();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,4 +389,7 @@
|
|||||||
<string name="copy_otr_clipboard_description">Copy OTR fingerprint to clipboard</string>
|
<string name="copy_otr_clipboard_description">Copy OTR fingerprint to clipboard</string>
|
||||||
<string name="fetching_history_from_server">Fetching history from server</string>
|
<string name="fetching_history_from_server">Fetching history from server</string>
|
||||||
<string name="no_more_history_on_server">No more history on server</string>
|
<string name="no_more_history_on_server">No more history on server</string>
|
||||||
|
<string name="updating">Updating…</string>
|
||||||
|
<string name="password_changed">Password changed!</string>
|
||||||
|
<string name="could_not_change_password">Could not change password</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user