Allow fixing no identities

pull/162/head
M66B 5 years ago
parent 4a0972f282
commit da265bcc86

@ -44,14 +44,6 @@ public interface DaoIdentity {
", identity.`primary` DESC, identity.display COLLATE NOCASE, identity.name COLLATE NOCASE, identity.email COLLATE NOCASE")
List<TupleIdentityEx> getComposableIdentities(Long account);
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
" JOIN account ON account.id = identity.account" +
" JOIN folder ON folder.account = identity.account AND folder.type = '" + EntityFolder.DRAFTS + "'" +
" WHERE (:account IS NULL OR identity.account = :account)" +
" AND identity.synchronize" +
" AND account.synchronize")
LiveData<List<TupleIdentityEx>> liveComposableIdentities(Long account);
@Query("SELECT * FROM identity" +
" WHERE account = :account" +
" ORDER BY name COLLATE NOCASE")

@ -172,9 +172,14 @@ public class FragmentAccounts extends FragmentBase {
if (cards && !Helper.isDarkTheme(getContext()))
view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.lightColorBackground_cards));
if (!settings)
if (settings) {
fab.show();
fabCompose.hide();
} else {
fab.hide();
fabCompose.hide();
fabCompose.show();
}
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
@ -215,19 +220,6 @@ public class FragmentAccounts extends FragmentBase {
animator.end();
}
});
if (!settings)
db.identity().liveComposableIdentities(null).observe(getViewLifecycleOwner(),
new Observer<List<TupleIdentityEx>>() {
@Override
public void onChanged(List<TupleIdentityEx> identities) {
if (identities == null || identities.size() == 0)
fabCompose.hide();
else
fabCompose.show();
}
});
}
@Override

@ -1786,6 +1786,8 @@ public class FragmentCompose extends FragmentBase {
private void onAction(int action) {
EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem();
if (identity == null)
throw new IllegalArgumentException(getString(R.string.title_from_missing));
// Workaround underlines left by Android
etBody.clearComposingText();
@ -1984,9 +1986,9 @@ public class FragmentCompose extends FragmentBase {
}
}
private SimpleTask<EntityMessage> draftLoader = new SimpleTask<EntityMessage>() {
private SimpleTask<DraftData> draftLoader = new SimpleTask<DraftData>() {
@Override
protected EntityMessage onExecute(Context context, Bundle args) throws Throwable {
protected DraftData onExecute(Context context, Bundle args) throws Throwable {
String action = args.getString("action");
long id = args.getLong("id", -1);
long reference = args.getLong("reference", -1);
@ -2354,21 +2356,41 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction();
}
return draft;
DraftData data = new DraftData();
data.draft = draft;
data.identities = db.identity().getComposableIdentities(null);
return data;
}
@Override
protected void onExecuted(Bundle args, final EntityMessage draft) {
working = draft.id;
protected void onExecuted(Bundle args, final DraftData data) {
if (data.identities == null || data.identities.size() == 0)
throw new IllegalStateException(getString(R.string.title_no_identities));
working = data.draft.id;
final String action = getArguments().getString("action");
Log.i("Loaded draft id=" + draft.id + " action=" + action);
Log.i("Loaded draft id=" + data.draft.id + " action=" + action);
etExtra.setText(draft.extra);
etTo.setText(MessageHelper.formatAddressesCompose(draft.to));
etCc.setText(MessageHelper.formatAddressesCompose(draft.cc));
etBcc.setText(MessageHelper.formatAddressesCompose(draft.bcc));
etSubject.setText(draft.subject);
// Show identities
IdentityAdapter iadapter = new IdentityAdapter(getContext(), data.identities);
spIdentity.setAdapter(iadapter);
// Select identity
if (data.draft.identity != null)
for (int pos = 0; pos < data.identities.size(); pos++) {
if (data.identities.get(pos).id.equals(data.draft.identity)) {
spIdentity.setSelection(pos);
break;
}
}
etExtra.setText(data.draft.extra);
etTo.setText(MessageHelper.formatAddressesCompose(data.draft.to));
etCc.setText(MessageHelper.formatAddressesCompose(data.draft.cc));
etBcc.setText(MessageHelper.formatAddressesCompose(data.draft.bcc));
etSubject.setText(data.draft.subject);
long reference = args.getLong("reference", -1);
etTo.setTag(reference < 0 ? "" : etTo.getText().toString());
@ -2378,54 +2400,21 @@ public class FragmentCompose extends FragmentBase {
grpAddresses.setVisibility("reply_all".equals(action) ? View.VISIBLE : View.GONE);
ibCcBcc.setVisibility(View.VISIBLE);
bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(draft.revision != null && draft.revision > 1);
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(draft.revision != null && !draft.revision.equals(draft.revisions));
bottom_navigation.getMenu().findItem(R.id.action_undo).setVisible(
data.draft.revision != null && data.draft.revision > 1);
bottom_navigation.getMenu().findItem(R.id.action_redo).setVisible(
data.draft.revision != null && !data.draft.revision.equals(data.draft.revisions));
plain_only = (draft.plain_only != null && draft.plain_only);
encrypt = (draft.encrypt != null && draft.encrypt);
plain_only = (data.draft.plain_only != null && data.draft.plain_only);
encrypt = (data.draft.encrypt != null && data.draft.encrypt);
getActivity().invalidateOptionsMenu();
if (args.getBoolean("incomplete"))
Snackbar.make(view, R.string.title_attachments_incomplete, Snackbar.LENGTH_LONG).show();
new SimpleTask<List<TupleIdentityEx>>() {
@Override
protected List<TupleIdentityEx> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
List<TupleIdentityEx> identities = db.identity().getComposableIdentities(null);
if (identities == null)
identities = new ArrayList<>();
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);
spIdentity.setAdapter(adapter);
// Select identity
if (draft.identity != null)
for (int pos = 0; pos < identities.size(); pos++) {
if (identities.get(pos).id.equals(draft.identity)) {
spIdentity.setSelection(pos);
break;
}
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getFragmentManager(), ex);
}
}.execute(FragmentCompose.this, new Bundle(), "compose:identities");
DB db = DB.getInstance(getContext());
db.attachment().liveAttachments(draft.id).observe(getViewLifecycleOwner(),
db.attachment().liveAttachments(data.draft.id).observe(getViewLifecycleOwner(),
new Observer<List<EntityAttachment>>() {
private int last_available = 0;
@ -2462,7 +2451,7 @@ public class FragmentCompose extends FragmentBase {
}
});
db.message().liveMessage(draft.id).observe(getViewLifecycleOwner(), new Observer<EntityMessage>() {
db.message().liveMessage(data.draft.id).observe(getViewLifecycleOwner(), new Observer<EntityMessage>() {
@Override
public void onChanged(EntityMessage draft) {
// Draft was deleted
@ -2491,7 +2480,17 @@ public class FragmentCompose extends FragmentBase {
handleFileShare();
else if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
else if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getContext(), ActivitySetup.class));
getActivity().finish();
}
});
snackbar.show();
} else
Helper.unexpectedError(getFragmentManager(), ex);
}
};
@ -3563,4 +3562,9 @@ public class FragmentCompose extends FragmentBase {
.create();
}
}
private class DraftData {
private EntityMessage draft;
private List<TupleIdentityEx> identities;
}
}

@ -256,19 +256,8 @@ public class FragmentFolders extends FragmentBase {
// Observe account
if (account < 0) {
setSubtitle(R.string.title_folders_unified);
fab.setImageResource(R.drawable.baseline_edit_24);
db.identity().liveComposableIdentities(null).observe(getViewLifecycleOwner(),
new Observer<List<TupleIdentityEx>>() {
@Override
public void onChanged(List<TupleIdentityEx> identities) {
if (identities == null || identities.size() == 0)
fab.hide();
else
fab.show();
}
});
fab.show();
} else
db.account().liveAccount(account).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
@Override

@ -895,11 +895,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
pbWait.setVisibility(View.VISIBLE);
fabReply.hide();
fabCompose.hide();
if (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER)
fabCompose.show();
else
fabCompose.hide();
if (viewType == AdapterMessage.ViewType.SEARCH && !server)
fabSearch.show();
else
fabSearch.hide();
fabMore.hide();
fabError.hide();
@ -2306,19 +2312,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
else
fabMore.hide();
if (viewType != AdapterMessage.ViewType.THREAD && viewType != AdapterMessage.ViewType.SEARCH) {
db.identity().liveComposableIdentities(account < 0 ? null : account).observe(getViewLifecycleOwner(),
new Observer<List<TupleIdentityEx>>() {
@Override
public void onChanged(List<TupleIdentityEx> identities) {
if (identities == null || identities.size() == 0)
fabCompose.hide();
else
fabCompose.show();
}
});
}
checkReporting();
}

Loading…
Cancel
Save