diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 4f257b6b53..bca447c61f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -811,6 +811,7 @@ public class FragmentCompose extends FragmentBase { args.putString("action", a.getString("action")); args.putLong("id", a.getLong("id", -1)); args.putLong("account", a.getLong("account", -1)); + args.putLong("identity", a.getLong("identity", -1)); args.putLong("reference", a.getLong("reference", -1)); args.putSerializable("ics", a.getSerializable("ics")); args.putString("status", a.getString("status")); @@ -827,9 +828,6 @@ public class FragmentCompose extends FragmentBase { Bundle args = new Bundle(); args.putString("action", "edit"); args.putLong("id", working); - args.putLong("account", -1); - args.putLong("reference", -1); - args.putLong("answer", -1); draftLoader.execute(this, args, "compose:edit"); } } else { @@ -840,9 +838,6 @@ public class FragmentCompose extends FragmentBase { Bundle args = new Bundle(); args.putString("action", working < 0 ? "new" : "edit"); args.putLong("id", working); - args.putLong("account", -1); - args.putLong("reference", -1); - args.putLong("answer", -1); draftLoader.execute(this, args, "compose:instance"); } } @@ -2297,16 +2292,25 @@ public class FragmentCompose extends FragmentBase { Address from = null; EntityIdentity selected = null; long aid = args.getLong("account", -1); + long iid = args.getLong("identity", -1); + + if (iid >= 0) + for (EntityIdentity identity : data.identities) + if (identity.id.equals(iid)) { + selected = identity; + break; + } if (data.draft.from != null && data.draft.from.length > 0) { - for (Address sender : data.draft.from) - for (EntityIdentity identity : data.identities) - if (identity.account.equals(aid) && - identity.sameAddress(sender)) { - from = sender; - selected = identity; - break; - } + if (selected == null) + for (Address sender : data.draft.from) + for (EntityIdentity identity : data.identities) + if (identity.account.equals(aid) && + identity.sameAddress(sender)) { + from = sender; + selected = identity; + break; + } if (selected == null) for (Address sender : data.draft.from) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 82fc9d5109..5a0de3b612 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -66,11 +66,13 @@ import android.view.animation.TranslateAnimation; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageButton; +import android.widget.ListView; import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; @@ -751,10 +753,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. fabCompose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - startActivity(new Intent(getContext(), ActivityCompose.class) - .putExtra("action", "new") - .putExtra("account", account) - ); + boolean identities_asked = prefs.getBoolean("identities_asked", false); + if (identities_asked) + startActivity(new Intent(getContext(), ActivityCompose.class) + .putExtra("action", "new") + .putExtra("account", account) + ); + else { + FragmentDialogIdentity fragment = new FragmentDialogIdentity(); + fragment.show(getFragmentManager(), "messages:identities"); + } } }); @@ -4580,8 +4588,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - prefs.edit().putBoolean("crash_reports", true).apply(); Log.setCrashReporting(true); } }) @@ -4629,6 +4635,93 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. } } + public static class FragmentDialogIdentity extends FragmentDialogBase { + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_identity, null); + ListView lvIdentity = dview.findViewById(R.id.lvIdentity); + CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain); + Button btnFix = dview.findViewById(R.id.btnFix); + Group grpIdentities = dview.findViewById(R.id.grpIdentities); + Group grpNoIdentities = dview.findViewById(R.id.grpNoIdentities); + ContentLoadingProgressBar pbWait = dview.findViewById(R.id.pbWait); + + lvIdentity.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + TupleIdentityEx identity = (TupleIdentityEx) lvIdentity.getAdapter().getItem(position); + + startActivity(new Intent(getContext(), ActivityCompose.class) + .putExtra("action", "new") + .putExtra("account", identity.account) + .putExtra("identity", identity.id) + ); + + dismiss(); + } + }); + + cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + prefs.edit().putBoolean("identities_asked", isChecked).apply(); + } + }); + + btnFix.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(getContext(), ActivitySetup.class)); + getActivity().finish(); + + dismiss(); + } + }); + + grpIdentities.setVisibility(View.GONE); + grpNoIdentities.setVisibility(View.GONE); + + new SimpleTask>() { + @Override + protected void onPreExecute(Bundle args) { + pbWait.setVisibility(View.VISIBLE); + } + + @Override + protected void onPostExecute(Bundle args) { + pbWait.setVisibility(View.GONE); + } + + @Override + protected List onExecute(Context context, Bundle args) { + DB db = DB.getInstance(getContext()); + return db.identity().getComposableIdentities(null); + } + + @Override + protected void onExecuted(Bundle args, List identities) { + AdapterIdentitySelect iadapter = new AdapterIdentitySelect(getContext(), identities); + lvIdentity.setAdapter(iadapter); + + grpIdentities.setVisibility(identities.size() > 0 ? View.VISIBLE : View.GONE); + grpNoIdentities.setVisibility(identities.size() > 0 ? View.GONE : View.VISIBLE); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getFragmentManager(), ex); + } + }.execute(this, new Bundle(), "identity:select"); + + return new AlertDialog.Builder(getContext()) + .setView(dview) + .setNegativeButton(android.R.string.cancel, null) + .create(); + } + } + public static class FragmentDialogError extends FragmentDialogBase { @NonNull @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index c78955c4bb..7111962750 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -70,7 +70,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc }; private final static String[] RESET_QUESTIONS = new String[]{ - "welcome", "show_html_confirmed", "print_html_confirmed", "delete_ref_confirmed", "edit_ref_confirmed", "crash_reports_asked" + "welcome", "crash_reports_asked", + "show_html_confirmed", "print_html_confirmed", + "identities_asked", "edit_ref_confirmed", "delete_ref_confirmed" }; @Override diff --git a/app/src/main/res/layout/dialog_identity.xml b/app/src/main/res/layout/dialog_identity.xml new file mode 100644 index 0000000000..8d6e2568b8 --- /dev/null +++ b/app/src/main/res/layout/dialog_identity.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + +