53
53
import com .flowcrypt .email .database .dao .source .AccountDao ;
54
54
import com .flowcrypt .email .database .dao .source .AccountDaoSource ;
55
55
import com .flowcrypt .email .database .dao .source .ContactsDaoSource ;
56
+ import com .flowcrypt .email .database .dao .source .UserIdEmailsKeysDaoSource ;
56
57
import com .flowcrypt .email .js .Js ;
57
58
import com .flowcrypt .email .js .JsForUiManager ;
58
59
import com .flowcrypt .email .js .PgpContact ;
66
67
import com .flowcrypt .email .ui .activity .SelectContactsActivity ;
67
68
import com .flowcrypt .email .ui .activity .fragment .dialog .NoPgpFoundDialogFragment ;
68
69
import com .flowcrypt .email .ui .activity .listeners .OnChangeMessageEncryptedTypeListener ;
70
+ import com .flowcrypt .email .ui .adapter .FromAddressesAdapter ;
69
71
import com .flowcrypt .email .ui .adapter .PgpContactAdapter ;
70
72
import com .flowcrypt .email .ui .loader .LoadGmailAliasesLoader ;
71
73
import com .flowcrypt .email .ui .loader .UpdateInfoAboutPgpContactsAsyncTaskLoader ;
76
78
import com .flowcrypt .email .util .GeneralUtil ;
77
79
import com .flowcrypt .email .util .UIUtil ;
78
80
import com .flowcrypt .email .util .exception .FlowCryptException ;
81
+ import com .google .android .gms .common .util .CollectionUtils ;
79
82
import com .google .android .material .snackbar .Snackbar ;
80
83
import com .google .android .material .textfield .TextInputLayout ;
81
84
import com .hootsuite .nachos .NachoTextView ;
@@ -135,7 +138,7 @@ public class CreateMessageFragment extends BaseSyncFragment implements View.OnFo
135
138
private IncomingMessageInfo incomingMessageInfo ;
136
139
private ServiceInfo serviceInfo ;
137
140
private AccountDao accountDao ;
138
- private ArrayAdapter <String > fromAddressesArrayAdapter ;
141
+ private FromAddressesAdapter <String > fromAddressesArrayAdapter ;
139
142
private PgpContact pgpContactWithNoPublicKey ;
140
143
private ExtraActionInfo extraActionInfo ;
141
144
private MessageType messageType = MessageType .NEW ;
@@ -166,6 +169,7 @@ public class CreateMessageFragment extends BaseSyncFragment implements View.OnFo
166
169
private boolean isUpdateInfoAboutBccCompleted = true ;
167
170
private boolean isIncomingMessageInfoUsed ;
168
171
private boolean isMessageSentToQueue ;
172
+ private int originalColor ;
169
173
170
174
public CreateMessageFragment () {
171
175
pgpContactsTo = new ArrayList <>();
@@ -197,11 +201,15 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
197
201
initDraftCacheDirectory ();
198
202
199
203
accountDao = new AccountDaoSource ().getActiveAccountInformation (getContext ());
200
- fromAddressesArrayAdapter = new ArrayAdapter <>(getContext (),
204
+ fromAddressesArrayAdapter = new FromAddressesAdapter <>(getContext (),
201
205
android .R .layout .simple_list_item_1 , android .R .id .text1 , new ArrayList <String >());
202
206
fromAddressesArrayAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
207
+ fromAddressesArrayAdapter .setUseKeysInfo (onChangeMessageEncryptedTypeListener .getMessageEncryptionType ()
208
+ == MessageEncryptionType .ENCRYPTED );
203
209
if (accountDao != null ) {
204
210
fromAddressesArrayAdapter .add (accountDao .getEmail ());
211
+ fromAddressesArrayAdapter .updateKeyAvailable (accountDao .getEmail (), !CollectionUtils .isEmpty (
212
+ new UserIdEmailsKeysDaoSource ().getLongIdsByEmail (getContext (), accountDao .getEmail ())));
205
213
}
206
214
207
215
js = JsForUiManager .getInstance (getContext ()).getJs ();
@@ -553,6 +561,11 @@ public void handleSuccessLoaderResult(int loaderId, Object result) {
553
561
fromAddressesArrayAdapter .clear ();
554
562
fromAddressesArrayAdapter .addAll (aliases );
555
563
564
+ for (String email : aliases ) {
565
+ fromAddressesArrayAdapter .updateKeyAvailable (email , !CollectionUtils .isEmpty (
566
+ new UserIdEmailsKeysDaoSource ().getLongIdsByEmail (getContext (), email )));
567
+ }
568
+
556
569
prepareAliasForReplyIfNeed (aliases );
557
570
558
571
if (fromAddressesArrayAdapter .getCount () == 1 ) {
@@ -655,6 +668,13 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
655
668
switch (parent .getId ()) {
656
669
case R .id .spinnerFrom :
657
670
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
+ }
658
678
break ;
659
679
}
660
680
}
@@ -700,6 +720,12 @@ public void onMessageEncryptionTypeChange(MessageEncryptionType messageEncryptio
700
720
editTextRecipientsTo .getOnFocusChangeListener ().onFocusChange (editTextRecipientsTo , false );
701
721
editTextRecipientsCc .getOnFocusChangeListener ().onFocusChange (editTextRecipientsCc , false );
702
722
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
+
703
729
break ;
704
730
705
731
case STANDARD :
@@ -710,6 +736,8 @@ public void onMessageEncryptionTypeChange(MessageEncryptionType messageEncryptio
710
736
isUpdateInfoAboutToCompleted = true ;
711
737
isUpdateInfoAboutCcCompleted = true ;
712
738
isUpdateInfoAboutBccCompleted = true ;
739
+ fromAddressesArrayAdapter .setUseKeysInfo (false );
740
+ editTextFrom .setTextColor (originalColor );
713
741
break ;
714
742
}
715
743
}
@@ -1026,6 +1054,11 @@ private boolean isAllInformationCorrect() {
1026
1054
editTextRecipientsCc .chipifyAllUnterminatedTokens ();
1027
1055
editTextRecipientsBcc .chipifyAllUnterminatedTokens ();
1028
1056
1057
+ if (!fromAddressesArrayAdapter .isEnabled (spinnerFrom .getSelectedItemPosition ())) {
1058
+ showInfoSnackbar (editTextRecipientsTo , getString (R .string .no_key_available ));
1059
+ return false ;
1060
+ }
1061
+
1029
1062
if (TextUtils .isEmpty (editTextRecipientsTo .getText ().toString ())) {
1030
1063
showInfoSnackbar (editTextRecipientsTo , getString (R .string .text_must_not_be_empty ,
1031
1064
getString (R .string .prompt_recipients_to )));
@@ -1166,6 +1199,7 @@ private void initViews(View view) {
1166
1199
spinnerFrom .setAdapter (fromAddressesArrayAdapter );
1167
1200
1168
1201
editTextFrom = view .findViewById (R .id .editTextFrom );
1202
+ originalColor = editTextFrom .getCurrentTextColor ();
1169
1203
1170
1204
imageButtonAliases = view .findViewById (R .id .imageButtonAliases );
1171
1205
if (imageButtonAliases != null ) {
0 commit comments