5353import com .flowcrypt .email .database .dao .source .AccountDao ;
5454import com .flowcrypt .email .database .dao .source .AccountDaoSource ;
5555import com .flowcrypt .email .database .dao .source .ContactsDaoSource ;
56+ import com .flowcrypt .email .database .dao .source .UserIdEmailsKeysDaoSource ;
5657import com .flowcrypt .email .js .Js ;
5758import com .flowcrypt .email .js .JsForUiManager ;
5859import com .flowcrypt .email .js .PgpContact ;
6667import com .flowcrypt .email .ui .activity .SelectContactsActivity ;
6768import com .flowcrypt .email .ui .activity .fragment .dialog .NoPgpFoundDialogFragment ;
6869import com .flowcrypt .email .ui .activity .listeners .OnChangeMessageEncryptedTypeListener ;
70+ import com .flowcrypt .email .ui .adapter .FromAddressesAdapter ;
6971import com .flowcrypt .email .ui .adapter .PgpContactAdapter ;
7072import com .flowcrypt .email .ui .loader .LoadGmailAliasesLoader ;
7173import com .flowcrypt .email .ui .loader .UpdateInfoAboutPgpContactsAsyncTaskLoader ;
7678import com .flowcrypt .email .util .GeneralUtil ;
7779import com .flowcrypt .email .util .UIUtil ;
7880import com .flowcrypt .email .util .exception .FlowCryptException ;
81+ import com .google .android .gms .common .util .CollectionUtils ;
7982import com .google .android .material .snackbar .Snackbar ;
8083import com .google .android .material .textfield .TextInputLayout ;
8184import com .hootsuite .nachos .NachoTextView ;
@@ -135,7 +138,7 @@ public class CreateMessageFragment extends BaseSyncFragment implements View.OnFo
135138 private IncomingMessageInfo incomingMessageInfo ;
136139 private ServiceInfo serviceInfo ;
137140 private AccountDao accountDao ;
138- private ArrayAdapter <String > fromAddressesArrayAdapter ;
141+ private FromAddressesAdapter <String > fromAddressesArrayAdapter ;
139142 private PgpContact pgpContactWithNoPublicKey ;
140143 private ExtraActionInfo extraActionInfo ;
141144 private MessageType messageType = MessageType .NEW ;
@@ -166,6 +169,7 @@ public class CreateMessageFragment extends BaseSyncFragment implements View.OnFo
166169 private boolean isUpdateInfoAboutBccCompleted = true ;
167170 private boolean isIncomingMessageInfoUsed ;
168171 private boolean isMessageSentToQueue ;
172+ private int originalColor ;
169173
170174 public CreateMessageFragment () {
171175 pgpContactsTo = new ArrayList <>();
@@ -197,11 +201,15 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
197201 initDraftCacheDirectory ();
198202
199203 accountDao = new AccountDaoSource ().getActiveAccountInformation (getContext ());
200- fromAddressesArrayAdapter = new ArrayAdapter <>(getContext (),
204+ fromAddressesArrayAdapter = new FromAddressesAdapter <>(getContext (),
201205 android .R .layout .simple_list_item_1 , android .R .id .text1 , new ArrayList <String >());
202206 fromAddressesArrayAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
207+ fromAddressesArrayAdapter .setUseKeysInfo (onChangeMessageEncryptedTypeListener .getMessageEncryptionType ()
208+ == MessageEncryptionType .ENCRYPTED );
203209 if (accountDao != null ) {
204210 fromAddressesArrayAdapter .add (accountDao .getEmail ());
211+ fromAddressesArrayAdapter .updateKeyAvailable (accountDao .getEmail (), !CollectionUtils .isEmpty (
212+ new UserIdEmailsKeysDaoSource ().getLongIdsByEmail (getContext (), accountDao .getEmail ())));
205213 }
206214
207215 js = JsForUiManager .getInstance (getContext ()).getJs ();
@@ -553,6 +561,11 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
553561 fromAddressesArrayAdapter .clear ();
554562 fromAddressesArrayAdapter .addAll (aliases );
555563
564+ for (String email : aliases ) {
565+ fromAddressesArrayAdapter .updateKeyAvailable (email , !CollectionUtils .isEmpty (
566+ new UserIdEmailsKeysDaoSource ().getLongIdsByEmail (getContext (), email )));
567+ }
568+
556569 prepareAliasForReplyIfNeed (aliases );
557570
558571 if (fromAddressesArrayAdapter .getCount () == 1 ) {
@@ -655,6 +668,13 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
655668 switch (parent .getId ()) {
656669 case R .id .spinnerFrom :
657670 editTextFrom .setText ((CharSequence ) parent .getAdapter ().getItem (position ));
671+ if (onChangeMessageEncryptedTypeListener .getMessageEncryptionType () == MessageEncryptionType .ENCRYPTED ) {
672+ ArrayAdapter adapter = (ArrayAdapter ) parent .getAdapter ();
673+ int colorGray = UIUtil .getColor (getContext (), R .color .gray );
674+ editTextFrom .setTextColor (adapter .isEnabled (position ) ? originalColor : colorGray );
675+ } else {
676+ editTextFrom .setTextColor (originalColor );
677+ }
658678 break ;
659679 }
660680 }
@@ -700,6 +720,12 @@ public void onMessageEncryptionTypeChange(MessageEncryptionType messageEncryptio
700720 editTextRecipientsTo .getOnFocusChangeListener ().onFocusChange (editTextRecipientsTo , false );
701721 editTextRecipientsCc .getOnFocusChangeListener ().onFocusChange (editTextRecipientsCc , false );
702722 editTextRecipientsBcc .getOnFocusChangeListener ().onFocusChange (editTextRecipientsBcc , false );
723+ fromAddressesArrayAdapter .setUseKeysInfo (true );
724+
725+ int colorGray = UIUtil .getColor (getContext (), R .color .gray );
726+ boolean isItemEnabled = fromAddressesArrayAdapter .isEnabled (spinnerFrom .getSelectedItemPosition ());
727+ editTextFrom .setTextColor (isItemEnabled ? originalColor : colorGray );
728+
703729 break ;
704730
705731 case STANDARD :
@@ -710,6 +736,8 @@ public void onMessageEncryptionTypeChange(MessageEncryptionType messageEncryptio
710736 isUpdateInfoAboutToCompleted = true ;
711737 isUpdateInfoAboutCcCompleted = true ;
712738 isUpdateInfoAboutBccCompleted = true ;
739+ fromAddressesArrayAdapter .setUseKeysInfo (false );
740+ editTextFrom .setTextColor (originalColor );
713741 break ;
714742 }
715743 }
@@ -1026,6 +1054,11 @@ private boolean isAllInformationCorrect() {
10261054 editTextRecipientsCc .chipifyAllUnterminatedTokens ();
10271055 editTextRecipientsBcc .chipifyAllUnterminatedTokens ();
10281056
1057+ if (!fromAddressesArrayAdapter .isEnabled (spinnerFrom .getSelectedItemPosition ())) {
1058+ showInfoSnackbar (editTextRecipientsTo , getString (R .string .no_key_available ));
1059+ return false ;
1060+ }
1061+
10291062 if (TextUtils .isEmpty (editTextRecipientsTo .getText ().toString ())) {
10301063 showInfoSnackbar (editTextRecipientsTo , getString (R .string .text_must_not_be_empty ,
10311064 getString (R .string .prompt_recipients_to )));
@@ -1166,6 +1199,7 @@ private void initViews(View view) {
11661199 spinnerFrom .setAdapter (fromAddressesArrayAdapter );
11671200
11681201 editTextFrom = view .findViewById (R .id .editTextFrom );
1202+ originalColor = editTextFrom .getCurrentTextColor ();
11691203
11701204 imageButtonAliases = view .findViewById (R .id .imageButtonAliases );
11711205 if (imageButtonAliases != null ) {
0 commit comments