Added select default identity

pull/210/head
M66B 2 years ago
parent 7411776aeb
commit 7ff710f1b4

@ -333,10 +333,11 @@ public class FragmentCompose extends FragmentBase {
private static final int REQUEST_RECORD_AUDIO = 9;
private static final int REQUEST_OPENPGP = 10;
private static final int REQUEST_CONTACT_GROUP = 11;
private static final int REQUEST_LINK = 12;
private static final int REQUEST_DISCARD = 13;
private static final int REQUEST_SEND = 14;
private static final int REQUEST_REMOVE_ATTACHMENTS = 15;
private static final int REQUEST_SELECT_IDENTITY = 12;
private static final int REQUEST_LINK = 13;
private static final int REQUEST_DISCARD = 14;
private static final int REQUEST_SEND = 15;
private static final int REQUEST_REMOVE_ATTACHMENTS = 16;
private static final ExecutorService executor = Helper.getBackgroundExecutor(1, "compose");
@ -2155,6 +2156,9 @@ public class FragmentCompose extends FragmentBase {
} else if (itemId == R.id.menu_answer_create) {
onMenuAnswerCreate();
return true;
} else if (itemId == R.id.menu_select_identity) {
onMenuIdentitySelect();
return true;
} else if (itemId == R.id.title_search_in_text) {
startSearch();
return true;
@ -2525,6 +2529,13 @@ public class FragmentCompose extends FragmentBase {
fragmentTransaction.commit();
}
private void onMenuIdentitySelect() {
FragmentDialogSelectIdentity fragment = new FragmentDialogSelectIdentity();
fragment.setArguments(new Bundle());
fragment.setTargetFragment(this, REQUEST_SELECT_IDENTITY);
fragment.show(getParentFragmentManager(), "select:identity");
}
private void onTranslate(View anchor) {
final Context context = anchor.getContext();
@ -3047,6 +3058,10 @@ public class FragmentCompose extends FragmentBase {
if (resultCode == RESULT_OK && data != null)
onContactGroupSelected(data.getBundleExtra("args"));
break;
case REQUEST_SELECT_IDENTITY:
if (resultCode == RESULT_OK && data != null)
onSelectIdentity(data.getBundleExtra("args"));
break;
case REQUEST_LINK:
if (resultCode == RESULT_OK && data != null)
onLinkSelected(data.getBundleExtra("args"));
@ -4404,6 +4419,45 @@ public class FragmentCompose extends FragmentBase {
}.setExecutor(executor).execute(this, args, "compose:picked");
}
private void onSelectIdentity(Bundle args) {
new SimpleTask<EntityIdentity>() {
@Override
protected EntityIdentity onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
EntityIdentity identity;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
identity = db.identity().getIdentity(id);
if (identity != null) {
db.account().resetPrimary();
db.account().setAccountPrimary(identity.account, true);
db.identity().resetPrimary(identity.account);
db.identity().setIdentityPrimary(identity.id, true);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return identity;
}
@Override
protected void onExecuted(Bundle args, EntityIdentity identity) {
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "select:identity");
}
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
int start = args.getInt("start");

@ -106,6 +106,14 @@
<menu />
</item>
<item
android:id="@+id/menu_select_identity"
android:icon="@drawable/twotone_person_24"
android:title="@string/title_select_default_identity"
app:showAsAction="never">
<menu />
</item>
<item
android:id="@+id/title_search_in_text"
android:icon="@drawable/twotone_manage_search_24"

@ -1496,6 +1496,7 @@
<string name="title_insert_contact_group">Insert contact group</string>
<string name="title_insert_template">Insert template</string>
<string name="title_create_template">Create template</string>
<string name="title_select_default_identity">Select default identity</string>
<string name="title_translate">Translate</string>
<string name="title_translate_configure">Configure &#8230;</string>
<string name="title_translate_key">Enter key</string>

Loading…
Cancel
Save