Fixed identity selection changing, refactoring

pull/147/head
M66B 6 years ago
parent ad9c675fa4
commit 8306b0eb50

@ -30,18 +30,14 @@ import androidx.room.Update;
@Dao @Dao
public interface DaoIdentity { public interface DaoIdentity {
@Query("SELECT identity.*, account.name AS accountName FROM identity" + @Query("SELECT identity.*, account.name AS accountName FROM identity" +
" JOIN account ON account.id = identity.account")
LiveData<List<TupleIdentityEx>> liveIdentities();
@Query("SELECT identity.* FROM identity" +
" JOIN account ON account.id = identity.account" + " JOIN account ON account.id = identity.account" +
" WHERE (:account IS NULL OR account.id = :account)" + " WHERE NOT :synchronize OR account.synchronize")
" AND account.synchronize = :synchronize" + LiveData<List<TupleIdentityEx>> liveIdentities(boolean synchronize);
" AND identity.synchronize = :synchronize")
LiveData<List<EntityIdentity>> liveIdentities(Long account, boolean synchronize);
@Query("SELECT * FROM identity") @Query("SELECT identity.*, account.name AS accountName FROM identity" +
List<EntityIdentity> getIdentities(); " JOIN account ON account.id = identity.account" +
" WHERE NOT :synchronize OR account.synchronize")
List<TupleIdentityEx> getIdentities(boolean synchronize);
@Query("SELECT * FROM identity WHERE account = :account") @Query("SELECT * FROM identity WHERE account = :account")
List<EntityIdentity> getIdentities(long account); List<EntityIdentity> getIdentities(long account);

@ -1379,7 +1379,7 @@ public class FragmentCompose extends FragmentBase {
if ("edit".equals(action)) if ("edit".equals(action))
throw new IllegalStateException("Draft not found hide=" + (result.draft != null)); throw new IllegalStateException("Draft not found hide=" + (result.draft != null));
List<EntityIdentity> identities = db.identity().getIdentities(); List<TupleIdentityEx> identities = db.identity().getIdentities(true);
EntityMessage ref = db.message().getMessage(reference); EntityMessage ref = db.message().getMessage(reference);
if (ref == null) { if (ref == null) {
@ -1640,16 +1640,14 @@ public class FragmentCompose extends FragmentBase {
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
DB db = DB.getInstance(getContext()); new SimpleTask<List<TupleIdentityEx>>() {
db.identity().liveIdentities().observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() {
@Override @Override
public void onChanged(List<TupleIdentityEx> identities) { protected List<TupleIdentityEx> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
List<TupleIdentityEx> identities = db.identity().getIdentities(true);
if (identities == null) if (identities == null)
identities = new ArrayList<>(); identities = new ArrayList<>();
Log.i("Set identities=" + identities.size());
// Sort identities // Sort identities
Collections.sort(identities, new Comparator<TupleIdentityEx>() { Collections.sort(identities, new Comparator<TupleIdentityEx>() {
@Override @Override
@ -1664,6 +1662,13 @@ public class FragmentCompose extends FragmentBase {
} }
}); });
return identities;
}
@Override
protected void onExecuted(Bundle args, List<TupleIdentityEx> identities) {
Log.i("Set identities=" + identities.size());
// Show identities // Show identities
IdentityAdapter adapter = new IdentityAdapter(getContext(), identities); IdentityAdapter adapter = new IdentityAdapter(getContext(), identities);
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown); adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
@ -1677,9 +1682,15 @@ public class FragmentCompose extends FragmentBase {
break; break;
} }
} }
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
} }
}); }.execute(FragmentCompose.this, new Bundle(), "compose:identities");
DB db = DB.getInstance(getContext());
db.attachment().liveAttachments(result.draft.id).observe(getViewLifecycleOwner(), db.attachment().liveAttachments(result.draft.id).observe(getViewLifecycleOwner(),
new Observer<List<EntityAttachment>>() { new Observer<List<EntityAttachment>>() {

@ -104,7 +104,7 @@ public class FragmentIdentities extends FragmentBase {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
// Observe identities // Observe identities
DB.getInstance(getContext()).identity().liveIdentities().observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() { DB.getInstance(getContext()).identity().liveIdentities(false).observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() {
@Override @Override
public void onChanged(@Nullable List<TupleIdentityEx> identities) { public void onChanged(@Nullable List<TupleIdentityEx> identities) {
if (identities == null) if (identities == null)

@ -309,9 +309,9 @@ public class FragmentSetup extends FragmentBase {
} }
}); });
db.identity().liveIdentities(null, true).observe(getViewLifecycleOwner(), new Observer<List<EntityIdentity>>() { db.identity().liveIdentities(true).observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() {
@Override @Override
public void onChanged(@Nullable List<EntityIdentity> identities) { public void onChanged(@Nullable List<TupleIdentityEx> identities) {
boolean done = (identities != null && identities.size() > 0); boolean done = (identities != null && identities.size() > 0);
tvIdentityDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do); tvIdentityDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do);
tvIdentityDone.setTextColor(done ? textColorPrimary : colorWarning); tvIdentityDone.setTextColor(done ? textColorPrimary : colorWarning);

@ -21,4 +21,14 @@ package eu.faircode.email;
public class TupleIdentityEx extends EntityIdentity { public class TupleIdentityEx extends EntityIdentity {
public String accountName; public String accountName;
@Override
public boolean equals(Object obj) {
if (obj instanceof TupleIdentityEx) {
TupleIdentityEx other = (TupleIdentityEx) obj;
return (super.equals(obj) &&
(this.accountName == null ? other.accountName == null : accountName.equals(other.accountName)));
} else
return false;
}
} }

Loading…
Cancel
Save