Linked edit account name dialog.

This commit is contained in:
Adrian Tiberius 2015-08-12 18:05:53 +02:00
parent 7ef640213d
commit 317d509b24
3 changed files with 35 additions and 35 deletions

View File

@ -225,14 +225,18 @@ public abstract class BaseActivity extends AppCompatActivity implements
protected void changeProfile(Profile profile) {
TextView textView = (TextView) findViewById(R.id.tv_name);
if (textView != null) {
textView.setText(profile.getName());
}
updateCurrentProfileName(profile.getName());
SyngApplication.changeProfile(profile);
initDApps();
}
protected void updateCurrentProfileName(String name) {
TextView textView = (TextView) findViewById(R.id.tv_name);
if (textView != null) {
textView.setText(name);
}
}
protected void requestChangeProfile(Profile profile) {
requestProfile = profile;
@ -273,34 +277,6 @@ public abstract class BaseActivity extends AppCompatActivity implements
.show();
}
public void initSpinner() {
List<Profile> profilesList = PrefsUtil.getProfiles();
spinnerAdapter = new SpinnerAdapter(this, android.R.layout.simple_dropdown_item_1line, profilesList);
// mAccountSpinner.setAdapter(spinnerAdapter);
// mAccountSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// //String item = (String) adapterView.getItemAtPosition(i);
// if (adapterView != null && adapterView.getChildAt(0) != null) {
// ((TextView) adapterView.getChildAt(0)).setTextColor(Color.parseColor("#ffffff"));
// }
// Profile profile = spinnerAdapter.getItem(i);
// if (profile.getPasswordProtectedProfile()) {
// requestChangeProfile(profile);
// } else {
// changeProfile(profile);
// }
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> adapterView) {
// ((TextView) adapterView.getChildAt(0)).setTextColor(Color.parseColor("#ffffff"));
// }
//
// });
}
private void initSearch() {
mSearchTextView.addTextChangedListener(new TextWatcher() {
@ -599,7 +575,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
}
@Override
public void onProfilePress(Profile profile) {
public void onProfilePress(final Profile profile) {
MaterialDialog dialog = new MaterialDialog.Builder(this)
.title("Edit account")
.content("Put your name to create new account")
@ -607,7 +583,19 @@ public abstract class BaseActivity extends AppCompatActivity implements
.input("Name", "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog dialog, CharSequence input) {
Toast.makeText(BaseActivity.this, "Just do nothing", Toast.LENGTH_SHORT).show();
profile.setName(input.toString());
PrefsUtil.updateProfile(profile);
for (Profile item: mProfiles) {
if (item.getId().equals(profile.getId())) {
int index = mProfiles.indexOf(item);
mProfiles.set(index, profile);
break;
}
}
mAccountDrawerAdapter.notifyDataSetChanged();
if (SyngApplication.currentProfile.getId().equals(profile.getId())) {
updateCurrentProfileName(profile.getName());
}
}
}).show();
dialog.getInputEditText().setText(profile.getName());

View File

@ -19,6 +19,8 @@ public class Profile implements Serializable {
protected String name;
protected String id = createPrivateKey();
protected List<String> privateKeys = new ArrayList<>();
/* "password protect profile" (encrypt the private keys) */
@ -143,6 +145,16 @@ public class Profile implements Serializable {
this.name = name;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
protected void setPassword(String password) {
this.passwordHash = Hex.toHexString(HashUtil.sha3(password.getBytes()));

View File

@ -70,7 +70,7 @@ public final class PrefsUtil {
ArrayList<Profile> profiles = getProfiles();
for (Profile item: profiles) {
if (item.getName().equals(profile.getName())) {
if (item.getId().equals(profile.getId())) {
int index = profiles.indexOf(item);
profiles.set(index, profile);
saveProfiles(profiles);