Skip to content

Commit b8ea2cb

Browse files
committed
Fixed an option when we trying to add a new account with existing keys. | #76.
1 parent 919c857 commit b8ea2cb

File tree

8 files changed

+177
-129
lines changed

8 files changed

+177
-129
lines changed

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/AddNewAccountActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.flowcrypt.email.database.dao.source.AccountDaoSource;
2525
import com.flowcrypt.email.model.KeyDetails;
2626
import com.flowcrypt.email.model.results.LoaderResult;
27+
import com.flowcrypt.email.security.SecurityUtils;
2728
import com.flowcrypt.email.ui.activity.base.BaseSignInActivity;
2829
import com.flowcrypt.email.ui.loader.LoadPrivateKeysFromMailAsyncTaskLoader;
2930
import com.flowcrypt.email.util.GeneralUtil;
@@ -128,6 +129,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
128129
case REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_GMAIL:
129130
switch (resultCode) {
130131
case Activity.RESULT_OK:
132+
case CheckKeysActivity.RESULT_NEUTRAL:
131133
returnResultOk();
132134
break;
133135

@@ -197,6 +199,8 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
197199
keyDetailsList,
198200
getString(R.string.found_backup_of_your_account_key),
199201
getString(R.string.continue_),
202+
SecurityUtils.isBackupKeysExist(this) ? getString(R.string
203+
.use_existing_keys) : null,
200204
getString(R.string.use_another_account), true),
201205
REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_GMAIL);
202206
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/AddNewAccountManuallyActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.flowcrypt.email.database.dao.source.AccountDaoSource;
3434
import com.flowcrypt.email.model.KeyDetails;
3535
import com.flowcrypt.email.model.results.LoaderResult;
36+
import com.flowcrypt.email.security.SecurityUtils;
3637
import com.flowcrypt.email.ui.activity.base.BaseActivity;
3738
import com.flowcrypt.email.ui.loader.CheckEmailSettingsAsyncTaskLoader;
3839
import com.flowcrypt.email.ui.loader.LoadPrivateKeysFromMailAsyncTaskLoader;
@@ -135,6 +136,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
135136
case REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_EMAIL:
136137
switch (resultCode) {
137138
case Activity.RESULT_OK:
139+
case CheckKeysActivity.RESULT_NEUTRAL:
138140
returnOkResult();
139141
break;
140142

@@ -289,6 +291,7 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
289291
keyDetailsList,
290292
getString(R.string.found_backup_of_your_account_key),
291293
getString(R.string.continue_),
294+
SecurityUtils.isBackupKeysExist(this) ? getString(R.string.use_existing_keys) : null,
292295
getString(R.string.use_another_account), true),
293296
REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_EMAIL);
294297
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/CheckKeysActivity.java

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ public class CheckKeysActivity extends BaseActivity implements View.OnClickListe
4545
LoaderManager.LoaderCallbacks<LoaderResult> {
4646

4747
public static final int RESULT_NEGATIVE = 10;
48+
public static final int RESULT_NEUTRAL = 11;
4849

4950
public static final String KEY_EXTRA_PRIVATE_KEYS = GeneralUtil.generateUniqueExtraKey(
5051
"KEY_EXTRA_PRIVATE_KEYS", CheckKeysActivity.class);
5152
public static final String KEY_EXTRA_BOTTOM_TITLE = GeneralUtil.generateUniqueExtraKey(
5253
"KEY_EXTRA_BOTTOM_TITLE", CheckKeysActivity.class);
53-
public static final String KEY_EXTRA_CHECK_BUTTON_TITLE = GeneralUtil.generateUniqueExtraKey(
54-
"KEY_EXTRA_CHECK_BUTTON_TITLE", CheckKeysActivity.class);
55-
public static final String KEY_EXTRA_NEGATIVE_ACTION_BUTTON_TITLE =
54+
public static final String KEY_EXTRA_POSITIVE_BUTTON_TITLE = GeneralUtil.generateUniqueExtraKey(
55+
"KEY_EXTRA_POSITIVE_BUTTON_TITLE", CheckKeysActivity.class);
56+
public static final String KEY_EXTRA_NEUTRAL_BUTTON_TITLE = GeneralUtil.generateUniqueExtraKey(
57+
"KEY_EXTRA_NEUTRAL_BUTTON_TITLE", CheckKeysActivity.class);
58+
public static final String KEY_EXTRA_NEGATIVE_BUTTON_TITLE =
5659
GeneralUtil.generateUniqueExtraKey(
57-
"KEY_EXTRA_NEGATIVE_ACTION_BUTTON_TITLE", CheckKeysActivity.class);
60+
"KEY_EXTRA_NEGATIVE_BUTTON_TITLE", CheckKeysActivity.class);
5861
public static final String KEY_EXTRA_IS_THROW_ERROR_IF_DUPLICATE_FOUND =
5962
GeneralUtil.generateUniqueExtraKey(
6063
"KEY_EXTRA_IS_THROW_ERROR_IF_DUPLICATE_FOUND", CheckKeysActivity.class);
@@ -63,19 +66,29 @@ public class CheckKeysActivity extends BaseActivity implements View.OnClickListe
6366
private EditText editTextKeyPassword;
6467
private View progressBar;
6568
private String bottomTitle;
66-
private String checkButtonTitle;
67-
private String anotherAccountButtonTitle;
69+
private String positiveButtonTitle;
70+
private String neutralButtonTitle;
71+
private String negativeButtonTitle;
6872
private boolean isThrowErrorIfDuplicateFound;
6973

7074
public static Intent newIntent(Context context, ArrayList<KeyDetails> privateKeys,
71-
String bottomTitle, String checkButtonTitle,
72-
String negativeActionButtonTitle,
75+
String bottomTitle, String positiveButtonTitle,
76+
String negativeButtonTitle,
77+
boolean isThrowErrorIfDuplicateFound) {
78+
return newIntent(context, privateKeys, bottomTitle, positiveButtonTitle, null, negativeButtonTitle,
79+
isThrowErrorIfDuplicateFound);
80+
}
81+
82+
public static Intent newIntent(Context context, ArrayList<KeyDetails> privateKeys,
83+
String bottomTitle, String positiveButtonTitle,
84+
String neutralButtonTitle, String negativeButtonTitle,
7385
boolean isThrowErrorIfDuplicateFound) {
7486
Intent intent = new Intent(context, CheckKeysActivity.class);
7587
intent.putExtra(KEY_EXTRA_PRIVATE_KEYS, privateKeys);
7688
intent.putExtra(KEY_EXTRA_BOTTOM_TITLE, bottomTitle);
77-
intent.putExtra(KEY_EXTRA_CHECK_BUTTON_TITLE, checkButtonTitle);
78-
intent.putExtra(KEY_EXTRA_NEGATIVE_ACTION_BUTTON_TITLE, negativeActionButtonTitle);
89+
intent.putExtra(KEY_EXTRA_POSITIVE_BUTTON_TITLE, positiveButtonTitle);
90+
intent.putExtra(KEY_EXTRA_NEUTRAL_BUTTON_TITLE, neutralButtonTitle);
91+
intent.putExtra(KEY_EXTRA_NEGATIVE_BUTTON_TITLE, negativeButtonTitle);
7992
intent.putExtra(KEY_EXTRA_IS_THROW_ERROR_IF_DUPLICATE_FOUND, isThrowErrorIfDuplicateFound);
8093
return intent;
8194
}
@@ -99,14 +112,13 @@ public View getRootView() {
99112
public void onCreate(@Nullable Bundle savedInstanceState) {
100113
super.onCreate(savedInstanceState);
101114
if (getIntent() != null) {
102-
this.privateKeyDetailsList = getIntent().getParcelableArrayListExtra
103-
(KEY_EXTRA_PRIVATE_KEYS);
115+
this.privateKeyDetailsList = getIntent().getParcelableArrayListExtra(KEY_EXTRA_PRIVATE_KEYS);
104116
this.bottomTitle = getIntent().getStringExtra(KEY_EXTRA_BOTTOM_TITLE);
105-
this.checkButtonTitle = getIntent().getStringExtra(KEY_EXTRA_CHECK_BUTTON_TITLE);
106-
this.anotherAccountButtonTitle = getIntent().getStringExtra
107-
(KEY_EXTRA_NEGATIVE_ACTION_BUTTON_TITLE);
108-
this.isThrowErrorIfDuplicateFound = getIntent().getBooleanExtra(
109-
KEY_EXTRA_IS_THROW_ERROR_IF_DUPLICATE_FOUND, false);
117+
this.positiveButtonTitle = getIntent().getStringExtra(KEY_EXTRA_POSITIVE_BUTTON_TITLE);
118+
this.neutralButtonTitle = getIntent().getStringExtra(KEY_EXTRA_NEUTRAL_BUTTON_TITLE);
119+
this.negativeButtonTitle = getIntent().getStringExtra(KEY_EXTRA_NEGATIVE_BUTTON_TITLE);
120+
this.isThrowErrorIfDuplicateFound = getIntent().getBooleanExtra
121+
(KEY_EXTRA_IS_THROW_ERROR_IF_DUPLICATE_FOUND, false);
110122
}
111123

112124
initViews();
@@ -115,12 +127,11 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
115127
@Override
116128
public void onClick(View v) {
117129
switch (v.getId()) {
118-
case R.id.buttonCheck:
130+
case R.id.buttonPositiveAction:
119131
UIUtil.hideSoftInput(this, editTextKeyPassword);
120132
if (privateKeyDetailsList != null && !privateKeyDetailsList.isEmpty()) {
121133
if (TextUtils.isEmpty(editTextKeyPassword.getText().toString())) {
122-
showInfoSnackbar(editTextKeyPassword,
123-
getString(R.string.passphrase_must_be_non_empty));
134+
showInfoSnackbar(editTextKeyPassword, getString(R.string.passphrase_must_be_non_empty));
124135
} else {
125136
if (getSnackBar() != null) {
126137
getSnackBar().dismiss();
@@ -132,6 +143,11 @@ public void onClick(View v) {
132143
}
133144
break;
134145

146+
case R.id.buttonNeutralAction:
147+
setResult(RESULT_NEUTRAL);
148+
finish();
149+
break;
150+
135151
case R.id.buttonNegativeAction:
136152
setResult(RESULT_NEGATIVE);
137153
finish();
@@ -183,33 +199,38 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
183199
setResult(Activity.RESULT_OK);
184200
finish();
185201
} else {
186-
showInfoSnackbar(getRootView(), getString(R.string
187-
.password_is_incorrect));
202+
showInfoSnackbar(getRootView(), getString(R.string.password_is_incorrect));
188203
}
189204
break;
190205
}
191206
}
192207

193208
private void initViews() {
194-
if (findViewById(R.id.buttonCheck) != null) {
195-
Button buttonCheck = (Button) findViewById(R.id.buttonCheck);
196-
buttonCheck.setText(checkButtonTitle);
197-
buttonCheck.setOnClickListener(this);
209+
if (findViewById(R.id.buttonPositiveAction) != null) {
210+
Button buttonPositiveAction = findViewById(R.id.buttonPositiveAction);
211+
buttonPositiveAction.setText(positiveButtonTitle);
212+
buttonPositiveAction.setOnClickListener(this);
213+
}
214+
215+
if (!TextUtils.isEmpty(neutralButtonTitle) && findViewById(R.id.buttonNeutralAction) != null) {
216+
Button buttonNeutralAction = findViewById(R.id.buttonNeutralAction);
217+
buttonNeutralAction.setVisibility(View.VISIBLE);
218+
buttonNeutralAction.setText(neutralButtonTitle);
219+
buttonNeutralAction.setOnClickListener(this);
198220
}
199221

200222
if (findViewById(R.id.buttonNegativeAction) != null) {
201-
Button buttonSelectAnotherAccount =
202-
(Button) findViewById(R.id.buttonNegativeAction);
203-
buttonSelectAnotherAccount.setText(anotherAccountButtonTitle);
204-
buttonSelectAnotherAccount.setOnClickListener(this);
223+
Button buttonNegativeAction = findViewById(R.id.buttonNegativeAction);
224+
buttonNegativeAction.setText(negativeButtonTitle);
225+
buttonNegativeAction.setOnClickListener(this);
205226
}
206227

207-
TextView textViewCheckKeysTitle = (TextView) findViewById(R.id.textViewCheckKeysTitle);
228+
TextView textViewCheckKeysTitle = findViewById(R.id.textViewCheckKeysTitle);
208229
if (textViewCheckKeysTitle != null) {
209230
textViewCheckKeysTitle.setText(bottomTitle);
210231
}
211232

212-
editTextKeyPassword = (EditText) findViewById(R.id.editTextKeyPassword);
233+
editTextKeyPassword = findViewById(R.id.editTextKeyPassword);
213234
progressBar = findViewById(R.id.progressBar);
214235
}
215236
}

FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/SplashActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
100100
case REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_GMAIL:
101101
switch (resultCode) {
102102
case Activity.RESULT_OK:
103-
AccountDao accountDao = addGmailAccount(currentGoogleSignInAccount);
103+
case CheckKeysActivity.RESULT_NEUTRAL:
104104
EmailSyncService.startEmailSyncService(this);
105-
EmailManagerActivity.runEmailManagerActivity(this, accountDao);
105+
EmailManagerActivity.runEmailManagerActivity(this, addGmailAccount(currentGoogleSignInAccount));
106106
finish();
107107
break;
108108

@@ -117,9 +117,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
117117
case REQUEST_CODE_CREATE_OR_IMPORT_KEY:
118118
switch (resultCode) {
119119
case Activity.RESULT_OK:
120-
AccountDao accountDao = addGmailAccount(currentGoogleSignInAccount);
121120
EmailSyncService.startEmailSyncService(this);
122-
EmailManagerActivity.runEmailManagerActivity(this, accountDao);
121+
EmailManagerActivity.runEmailManagerActivity(this, addGmailAccount(currentGoogleSignInAccount));
123122
finish();
124123
break;
125124

@@ -139,10 +138,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
139138
.KEY_EXTRA_AUTH_CREDENTIALS);
140139
AccountDaoSource accountDaoSource = new AccountDaoSource();
141140
accountDaoSource.addRow(this, authCredentials);
142-
AccountDao accountDao = accountDaoSource.getAccountInformation(this,
143-
authCredentials.getEmail());
144141
EmailSyncService.startEmailSyncService(this);
145-
EmailManagerActivity.runEmailManagerActivity(this, accountDao);
142+
EmailManagerActivity.runEmailManagerActivity(this,
143+
accountDaoSource.getAccountInformation(this, authCredentials.getEmail()));
146144

147145
finish();
148146
} catch (Exception e) {
@@ -222,7 +220,9 @@ public void onLoadFinished(Loader<LoaderResult> loader, LoaderResult loaderResul
222220
keyDetailsList,
223221
getString(R.string.found_backup_of_your_account_key),
224222
getString(R.string.continue_),
225-
getString(R.string.use_another_account), false),
223+
SecurityUtils.isBackupKeysExist(this) ? getString(R.string
224+
.use_existing_keys) : null,
225+
getString(R.string.use_another_account), true),
226226
REQUEST_CODE_CHECK_PRIVATE_KEYS_FROM_GMAIL);
227227
}
228228
} else if (loaderResult.getException() != null) {

0 commit comments

Comments
 (0)