@@ -566,7 +566,11 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
566
566
new UserIdEmailsKeysDaoSource ().getLongIdsByEmail (getContext (), email )));
567
567
}
568
568
569
- prepareAliasForReplyIfNeed (aliases );
569
+ if (incomingMessageInfo != null ) {
570
+ prepareAliasForReplyIfNeed (aliases );
571
+ } else if (onChangeMessageEncryptedTypeListener .getMessageEncryptionType () == MessageEncryptionType .ENCRYPTED ) {
572
+ showFirstMatchedAliasWithPrvKey (aliases );
573
+ }
570
574
571
575
if (fromAddressesArrayAdapter .getCount () == 1 ) {
572
576
if (imageButtonAliases .getVisibility () == View .VISIBLE ) {
@@ -885,39 +889,62 @@ private List<PgpContact> runUpdatePgpContactsAction(List<PgpContact> pgpContacts
885
889
* @param aliases A list of Gmail aliases.
886
890
*/
887
891
private void prepareAliasForReplyIfNeed (List <String > aliases ) {
888
- if (incomingMessageInfo != null ) {
889
- ArrayList <String > toAddresses ;
890
- if (folderType == FoldersManager .FolderType .SENT ) {
891
- toAddresses = incomingMessageInfo .getFrom ();
892
- } else {
893
- toAddresses = incomingMessageInfo .getTo ();
894
- }
892
+ MessageEncryptionType messageEncryptionType = onChangeMessageEncryptedTypeListener .getMessageEncryptionType ();
895
893
896
- if (toAddresses != null ) {
897
- String firstFoundedAlias = null ;
898
- for (String toAddress : toAddresses ) {
899
- if (firstFoundedAlias == null ) {
900
- for (String alias : aliases ) {
901
- if (alias .equalsIgnoreCase (toAddress )) {
894
+ ArrayList <String > toAddresses ;
895
+ if (folderType == FoldersManager .FolderType .SENT ) {
896
+ toAddresses = incomingMessageInfo .getFrom ();
897
+ } else {
898
+ toAddresses = incomingMessageInfo .getTo ();
899
+ }
900
+
901
+ if (toAddresses != null ) {
902
+ String firstFoundedAlias = null ;
903
+ for (String toAddress : toAddresses ) {
904
+ if (firstFoundedAlias == null ) {
905
+ for (String alias : aliases ) {
906
+ if (alias .equalsIgnoreCase (toAddress )) {
907
+ if (messageEncryptionType == MessageEncryptionType .ENCRYPTED ) {
908
+ if (fromAddressesArrayAdapter .hasPrvKey (alias )) {
909
+ firstFoundedAlias = alias ;
910
+ }
911
+ } else {
902
912
firstFoundedAlias = alias ;
903
- break ;
904
913
}
914
+ break ;
905
915
}
906
- } else {
907
- break ;
908
916
}
917
+ } else {
918
+ break ;
909
919
}
920
+ }
910
921
911
- if (firstFoundedAlias != null ) {
912
- int position = fromAddressesArrayAdapter .getPosition (firstFoundedAlias );
913
- if (position != -1 ) {
914
- spinnerFrom .setSelection (position );
915
- }
922
+ if (firstFoundedAlias != null ) {
923
+ int position = fromAddressesArrayAdapter .getPosition (firstFoundedAlias );
924
+ if (position != -1 ) {
925
+ spinnerFrom .setSelection (position );
916
926
}
917
927
}
918
928
}
919
929
}
920
930
931
+ private void showFirstMatchedAliasWithPrvKey (List <String > aliases ) {
932
+ String firstFoundedAliasWithPrvKey = null ;
933
+ for (String alias : aliases ) {
934
+ if (fromAddressesArrayAdapter .hasPrvKey (alias )) {
935
+ firstFoundedAliasWithPrvKey = alias ;
936
+ break ;
937
+ }
938
+ }
939
+
940
+ if (firstFoundedAliasWithPrvKey != null ) {
941
+ int position = fromAddressesArrayAdapter .getPosition (firstFoundedAliasWithPrvKey );
942
+ if (position != -1 ) {
943
+ spinnerFrom .setSelection (position );
944
+ }
945
+ }
946
+ }
947
+
921
948
/**
922
949
* Remove not valid emails from the recipients list.
923
950
*
0 commit comments