aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/ChangePasswordActivity.java
blob: 2e0637571f7a92a40a22f40fa0a4c47b7a8cf9a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package de.thedevstack.conversationsplus.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import de.thedevstack.conversationsplus.ConversationsPlusColors;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.utils.ui.TextViewUtil;

public class ChangePasswordActivity extends XmppActivity implements XmppConnectionService.OnAccountPasswordChanged {

	private Button mChangePasswordButton;
	private View.OnClickListener mOnChangePasswordButtonClicked = new View.OnClickListener() {
		@Override
		public void onClick(View view) {
			if (mAccount != null) {
				final String currentPassword = mCurrentPassword.getText().toString();
				final String newPassword = mNewPassword.getText().toString();
				final String newPasswordConfirm = mNewPasswordConfirm.getText().toString();
				if (!currentPassword.equals(mAccount.getPassword())) {
					mCurrentPassword.requestFocus();
					mCurrentPassword.setError(getString(R.string.account_status_unauthorized));
				} else if (!newPassword.equals(newPasswordConfirm)) {
                    mNewPasswordConfirm.requestFocus();
                    mNewPasswordConfirm.setError(getString(R.string.passwords_do_not_match));
                } else if (newPassword.isEmpty()) {
                    mNewPassword.requestFocus();
                    mNewPassword.setError(getString(R.string.password_should_not_be_empty));
				} else if (newPassword.trim().isEmpty()) {
					mNewPassword.requestFocus();
					mNewPassword.setError(getString(R.string.password_should_not_contain_only_spaces));
				} else {
					mCurrentPassword.setError(null);
					mNewPassword.setError(null);
					mNewPasswordConfirm.setError(null);
					xmppConnectionService.updateAccountPasswordOnServer(mAccount, newPassword, ChangePasswordActivity.this);
                    TextViewUtil.disable(mChangePasswordButton, ConversationsPlusColors.secondaryText(), R.string.updating);
				}
			}
		}
	};
	private EditText mCurrentPassword;
	private EditText mNewPassword;
	private EditText mNewPasswordConfirm;
	private Account mAccount;

	@Override
	void onBackendConnected() {
		this.mAccount = extractAccount(getIntent());

	}

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_change_password);
		Button mCancelButton = (Button) findViewById(R.id.left_button);
		mCancelButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				finish();
			}
		});
		this.mChangePasswordButton = (Button) findViewById(R.id.right_button);
		this.mChangePasswordButton.setOnClickListener(this.mOnChangePasswordButtonClicked);
		this.mCurrentPassword = (EditText) findViewById(R.id.current_password);
		this.mNewPassword = (EditText) findViewById(R.id.new_password);
		this.mNewPasswordConfirm = (EditText) findViewById(R.id.new_password_confirm);
	}

	@Override
	public void onPasswordChangeSucceeded() {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				Toast.makeText(ChangePasswordActivity.this,R.string.password_changed,Toast.LENGTH_LONG).show();
				finish();
			}
		});
	}

	@Override
	public void onPasswordChangeFailed() {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				mNewPassword.setError(getString(R.string.could_not_change_password));
                TextViewUtil.enable(mChangePasswordButton, ConversationsPlusColors.primaryText(), R.string.change_password);
			}
		});

	}

	public void refreshUiReal() {

	}
}