Browse Source

Fill forms only once

- This is simpler than using SimpleTask for a one shot get
- Account, identity and folder are update on state change / error
main
M66B 6 years ago
parent
commit
9819b658bb
3 changed files with 39 additions and 21 deletions
  1. +13
    -7
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  2. +8
    -2
      app/src/main/java/eu/faircode/email/FragmentFolder.java
  3. +18
    -12
      app/src/main/java/eu/faircode/email/FragmentIdentity.java

+ 13
- 7
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -596,6 +596,8 @@ public class FragmentAccount extends FragmentEx {
// Observe
DB.getInstance(getContext()).account().liveAccount(id).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
boolean once = false;
@Override
public void onChanged(@Nullable EntityAccount account) {
// Get providers
@ -607,13 +609,17 @@ public class FragmentAccount extends FragmentEx {
spProvider.setAdapter(padapter);
if (savedInstanceState == null) {
etName.setText(account == null ? null : account.name);
etHost.setText(account == null ? null : account.host);
etPort.setText(account == null ? null : Long.toString(account.port));
etUser.setText(account == null ? null : account.user);
tilPassword.getEditText().setText(account == null ? null : account.password);
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? true : account.primary);
if (!once) {
once = true;
etName.setText(account == null ? null : account.name);
etHost.setText(account == null ? null : account.host);
etPort.setText(account == null ? null : Long.toString(account.port));
etUser.setText(account == null ? null : account.user);
tilPassword.getEditText().setText(account == null ? null : account.password);
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? true : account.primary);
}
} else {
int provider = savedInstanceState.getInt("provider");
spProvider.setTag(provider);


+ 8
- 2
app/src/main/java/eu/faircode/email/FragmentFolder.java View File

@ -148,6 +148,8 @@ public class FragmentFolder extends FragmentEx {
// Observe
DB.getInstance(getContext()).folder().liveFolder(id).observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
boolean once = false;
@Override
public void onChanged(@Nullable EntityFolder folder) {
if (folder == null) {
@ -156,8 +158,12 @@ public class FragmentFolder extends FragmentEx {
}
if (savedInstanceState == null) {
cbSynchronize.setChecked(folder.synchronize);
etAfter.setText(Integer.toString(folder.after));
if (!once) {
once = true;
cbSynchronize.setChecked(folder.synchronize);
etAfter.setText(Integer.toString(folder.after));
}
}
pbWait.setVisibility(View.GONE);


+ 18
- 12
app/src/main/java/eu/faircode/email/FragmentIdentity.java View File

@ -393,21 +393,27 @@ public class FragmentIdentity extends FragmentEx {
// Observe identity
db.identity().liveIdentity(id).observe(getViewLifecycleOwner(), new Observer<EntityIdentity>() {
boolean once = false;
@Override
public void onChanged(@Nullable final EntityIdentity identity) {
if (savedInstanceState == null) {
etName.setText(identity == null ? null : identity.name);
etEmail.setText(identity == null ? null : identity.email);
etReplyTo.setText(identity == null ? null : identity.replyto);
etHost.setText(identity == null ? null : identity.host);
cbStartTls.setChecked(identity == null ? false : identity.starttls);
etPort.setText(identity == null ? null : Long.toString(identity.port));
etUser.setText(identity == null ? null : identity.user);
tilPassword.getEditText().setText(identity == null ? null : identity.password);
cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
cbPrimary.setChecked(identity == null ? true : identity.primary);
etName.requestFocus();
if (!once) {
once = true;
etName.setText(identity == null ? null : identity.name);
etEmail.setText(identity == null ? null : identity.email);
etReplyTo.setText(identity == null ? null : identity.replyto);
etHost.setText(identity == null ? null : identity.host);
cbStartTls.setChecked(identity == null ? false : identity.starttls);
etPort.setText(identity == null ? null : Long.toString(identity.port));
etUser.setText(identity == null ? null : identity.user);
tilPassword.getEditText().setText(identity == null ? null : identity.password);
cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
cbPrimary.setChecked(identity == null ? true : identity.primary);
etName.requestFocus();
}
} else
tilPassword.getEditText().setText(savedInstanceState.getString("password"));


Loading…
Cancel
Save