mirror of
https://github.com/status-im/syng-client.git
synced 2025-02-22 16:08:11 +00:00
Initialize first profile with only one address.
Small refactoring.
This commit is contained in:
parent
2ba0124dac
commit
70b9b77fef
@ -449,7 +449,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
|
||||
|
||||
@Override
|
||||
public void onProfileAdd() {
|
||||
GeneralUtil.showProfileCreateDialog(this);
|
||||
GeneralUtil.showProfileCreateDialog(this, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,67 +62,21 @@ public class LoginActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void createAndSetProfile() {
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(LoginActivity.this)
|
||||
.title("New profile")
|
||||
.positiveText(R.string.dialog_button_create)
|
||||
.negativeText(R.string.dialog_button_cancel)
|
||||
.customView(R.layout.profile_create_dialog, true)
|
||||
.autoDismiss(false)
|
||||
.cancelable(false)
|
||||
.callback(new MaterialDialog.ButtonCallback() {
|
||||
@Override
|
||||
public void onPositive(MaterialDialog dialog) {
|
||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||
EditText pass1 = (EditText) dialog.findViewById(R.id.et_profile_pass_1);
|
||||
EditText pass2 = (EditText) dialog.findViewById(R.id.et_profile_pass_2);
|
||||
GeneralUtil.showProfileCreateDialog(LoginActivity.this, false, new MaterialDialog.ButtonCallback() {
|
||||
@Override
|
||||
public void onPositive(MaterialDialog dialog) {
|
||||
if (GeneralUtil.processCreateDialog(LoginActivity.this, dialog)) {
|
||||
startNextActivity();
|
||||
}
|
||||
}
|
||||
|
||||
String nameString = name.getText().toString();
|
||||
String pass1String = pass1.getText().toString();
|
||||
String pass2String = pass2.getText().toString();
|
||||
@Override
|
||||
public void onNegative(MaterialDialog dialog) {
|
||||
LoginActivity.this.finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
Toast.makeText(LoginActivity.this, "Profile name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(pass1String) || TextUtils.isEmpty(pass2String)) {
|
||||
Toast.makeText(LoginActivity.this, "Password name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pass1.getText().toString().equals(pass2.getText().toString())) {
|
||||
Toast.makeText(LoginActivity.this, "Passwords should be the same!", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Profile profile = new Profile();
|
||||
profile.setName(name.getText().toString());
|
||||
profile.setPassword(pass1String);
|
||||
|
||||
List<String> addresses = new ArrayList<>();
|
||||
byte[] addr = HashUtil.sha3(profile.getName().getBytes());
|
||||
addresses.add(Hex.toHexString(addr));
|
||||
String secret = CONFIG.coinbaseSecret();
|
||||
byte[] cbAddr = HashUtil.sha3(secret.getBytes());
|
||||
addresses.add(Hex.toHexString(cbAddr));
|
||||
profile.setPrivateKeys(addresses);
|
||||
|
||||
ProfileManager.addProfile(profile);
|
||||
ProfileManager.setCurrentProfile(profile);
|
||||
GeneralUtil.hideKeyBoard(name, LoginActivity.this);
|
||||
GeneralUtil.hideKeyBoard(pass1, LoginActivity.this);
|
||||
GeneralUtil.hideKeyBoard(pass2, LoginActivity.this);
|
||||
startNextActivity();
|
||||
// dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative(MaterialDialog dialog) {
|
||||
LoginActivity.this.finish();
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
}).show();
|
||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||
GeneralUtil.showKeyBoard(name, LoginActivity.this);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,52 +87,67 @@ public final class GeneralUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void showProfileCreateDialog(final Context context) {
|
||||
public static boolean processCreateDialog(Context context, MaterialDialog dialog) {
|
||||
|
||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||
EditText pass1 = (EditText) dialog.findViewById(R.id.et_profile_pass_1);
|
||||
EditText pass2 = (EditText) dialog.findViewById(R.id.et_profile_pass_2);
|
||||
|
||||
String nameString = name.getText().toString();
|
||||
String pass1String = pass1.getText().toString();
|
||||
String pass2String = pass2.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
Toast.makeText(context, "Profile name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
if (TextUtils.isEmpty(pass1String) || TextUtils.isEmpty(pass2String)) {
|
||||
Toast.makeText(context, "Password name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pass1.getText().toString().equals(pass2.getText().toString())) {
|
||||
Toast.makeText(context, "Passwords should be the same!", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
} else {
|
||||
Profile profile = new Profile();
|
||||
profile.setName(name.getText().toString());
|
||||
profile.setPassword(pass1String);
|
||||
ProfileManager.addProfile(profile);
|
||||
ProfileManager.setCurrentProfile(profile);
|
||||
GeneralUtil.hideKeyBoard(name, context);
|
||||
GeneralUtil.hideKeyBoard(pass1, context);
|
||||
GeneralUtil.hideKeyBoard(pass2, context);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void showProfileCreateDialog(final Context context, boolean cancelable, MaterialDialog.ButtonCallback callback) {
|
||||
|
||||
if (callback == null) {
|
||||
callback = new MaterialDialog.ButtonCallback() {
|
||||
@Override
|
||||
public void onPositive(MaterialDialog dialog) {
|
||||
if (processCreateDialog(context, dialog)) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative(MaterialDialog dialog) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
};
|
||||
}
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(context)
|
||||
.title("New profile")
|
||||
.positiveText(R.string.dialog_button_create)
|
||||
.negativeText(R.string.dialog_button_cancel)
|
||||
.customView(R.layout.profile_create_dialog, true)
|
||||
.autoDismiss(false)
|
||||
.callback(new MaterialDialog.ButtonCallback() {
|
||||
@Override
|
||||
public void onPositive(MaterialDialog dialog) {
|
||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||
EditText pass1 = (EditText) dialog.findViewById(R.id.et_profile_pass_1);
|
||||
EditText pass2 = (EditText) dialog.findViewById(R.id.et_profile_pass_2);
|
||||
|
||||
String nameString = name.getText().toString();
|
||||
String pass1String = pass1.getText().toString();
|
||||
String pass2String = pass2.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
Toast.makeText(context, "Profile name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(pass1String) || TextUtils.isEmpty(pass2String)) {
|
||||
Toast.makeText(context, "Password name can't be empty", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pass1.getText().toString().equals(pass2.getText().toString())) {
|
||||
Toast.makeText(context, "Passwords should be the same!", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Profile profile = new Profile();
|
||||
profile.setName(name.getText().toString());
|
||||
profile.setPassword(pass1String);
|
||||
ProfileManager.addProfile(profile);
|
||||
GeneralUtil.hideKeyBoard(name, context);
|
||||
GeneralUtil.hideKeyBoard(pass1, context);
|
||||
GeneralUtil.hideKeyBoard(pass2, context);
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNegative(MaterialDialog dialog) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}).show();
|
||||
.cancelable(cancelable)
|
||||
.callback(callback)
|
||||
.show();
|
||||
EditText name = (EditText) dialog.findViewById(R.id.et_profile_name);
|
||||
GeneralUtil.showKeyBoard(name, context);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user