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
public interface DaoIdentity {
@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" +
" WHERE (:account IS NULL OR account.id = :account)" +
" AND account.synchronize = :synchronize" +
" AND identity.synchronize = :synchronize")
LiveData<List<EntityIdentity>> liveIdentities(Long account, boolean synchronize);
" WHERE NOT :synchronize OR account.synchronize")
LiveData<List<TupleIdentityEx>> liveIdentities(boolean synchronize);
@Query("SELECT * FROM identity")
List<EntityIdentity> getIdentities();
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
" 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")
List<EntityIdentity> getIdentities(long account);

@ -1379,7 +1379,7 @@ public class FragmentCompose extends FragmentBase {
if ("edit".equals(action))
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);
if (ref == null) {
@ -1640,16 +1640,14 @@ public class FragmentCompose extends FragmentBase {
getActivity().invalidateOptionsMenu();
DB db = DB.getInstance(getContext());
db.identity().liveIdentities().observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() {
new SimpleTask<List<TupleIdentityEx>>() {
@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)
identities = new ArrayList<>();
Log.i("Set identities=" + identities.size());
// Sort identities
Collections.sort(identities, new Comparator<TupleIdentityEx>() {
@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
IdentityAdapter adapter = new IdentityAdapter(getContext(), identities);
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
@ -1677,9 +1682,15 @@ public class FragmentCompose extends FragmentBase {
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(),
new Observer<List<EntityAttachment>>() {

@ -104,7 +104,7 @@ public class FragmentIdentities extends FragmentBase {
super.onActivityCreated(savedInstanceState);
// 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
public void onChanged(@Nullable List<TupleIdentityEx> identities) {
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
public void onChanged(@Nullable List<EntityIdentity> identities) {
public void onChanged(@Nullable List<TupleIdentityEx> identities) {
boolean done = (identities != null && identities.size() > 0);
tvIdentityDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do);
tvIdentityDone.setTextColor(done ? textColorPrimary : colorWarning);

@ -21,4 +21,14 @@ package eu.faircode.email;
public class TupleIdentityEx extends EntityIdentity {
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