@@ -33,7 +33,7 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
33
33
private var _externalsManager : NewMessageExternalsManager ? = null
34
34
private inline val externalsManager: NewMessageExternalsManager get() = _externalsManager !!
35
35
36
- private var lastFieldToTakeFocus: FocusableElement ? = FocusableElement . TO
36
+ private var lastFieldToTakeFocus: FieldType ? = TO
37
37
38
38
fun initValues (
39
39
newMessageViewModel : NewMessageViewModel ,
@@ -58,7 +58,7 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
58
58
onContactAddedCallback = { newMessageViewModel.addRecipientToField(recipient = it, type = TO ) },
59
59
onContactRemovedCallback = { recipient -> recipient.removeInViewModelAndUpdateBannerVisibility(TO ) },
60
60
onCopyContactAddressCallback = { fragment.copyRecipientEmailToClipboard(it, snackbarManager) },
61
- gotFocusCallback = { elementGotFocus( FocusableElement . TO ) },
61
+ gotFocusCallback = { fieldGotFocus( TO ) },
62
62
onToggleEverythingCallback = ::openAdvancedFields,
63
63
)
64
64
@@ -68,7 +68,7 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
68
68
onContactAddedCallback = { newMessageViewModel.addRecipientToField(recipient = it, type = CC ) },
69
69
onContactRemovedCallback = { recipient -> recipient.removeInViewModelAndUpdateBannerVisibility(CC ) },
70
70
onCopyContactAddressCallback = { fragment.copyRecipientEmailToClipboard(it, snackbarManager) },
71
- gotFocusCallback = { elementGotFocus( FocusableElement . CC ) },
71
+ gotFocusCallback = { fieldGotFocus( CC ) },
72
72
)
73
73
74
74
bccField.initRecipientField(
@@ -77,7 +77,7 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
77
77
onContactAddedCallback = { newMessageViewModel.addRecipientToField(recipient = it, type = BCC ) },
78
78
onContactRemovedCallback = { recipient -> recipient.removeInViewModelAndUpdateBannerVisibility(BCC ) },
79
79
onCopyContactAddressCallback = { fragment.copyRecipientEmailToClipboard(it, snackbarManager) },
80
- gotFocusCallback = { elementGotFocus( FocusableElement . BCC ) },
80
+ gotFocusCallback = { fieldGotFocus( BCC ) },
81
81
)
82
82
}
83
83
@@ -96,24 +96,18 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
96
96
externalsManager.updateBannerVisibility()
97
97
}
98
98
99
- private fun elementGotFocus (element : FocusableElement ? ) {
100
- newMessageViewModel.focusedElementLiveData.value = element
101
- }
102
-
103
- fun observeFocusedElement () = with (binding) {
104
- newMessageViewModel.focusedElementLiveData.observe(viewLifecycleOwner) { field ->
105
- if (lastFieldToTakeFocus == field) return @observe
106
-
107
- if (field == null && newMessageViewModel.otherRecipientsFieldsAreEmpty.value == true ) {
108
- toField.collapseEverything()
109
- } else {
110
- if (field != FocusableElement .TO ) toField.collapse()
111
- if (field != FocusableElement .CC ) ccField.collapse()
112
- if (field != FocusableElement .BCC ) bccField.collapse()
113
- }
99
+ private fun fieldGotFocus (field : FieldType ? ) = with (binding) {
100
+ if (lastFieldToTakeFocus == field) return
114
101
115
- lastFieldToTakeFocus = field
102
+ if (field == null && newMessageViewModel.otherRecipientsFieldsAreEmpty.value == true ) {
103
+ toField.collapseEverything()
104
+ } else {
105
+ if (field != TO ) toField.collapse()
106
+ if (field != CC ) ccField.collapse()
107
+ if (field != BCC ) bccField.collapse()
116
108
}
109
+
110
+ lastFieldToTakeFocus = field
117
111
}
118
112
119
113
private fun openAdvancedFields (isCollapsed : Boolean ) = with (binding) {
@@ -126,9 +120,11 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
126
120
initializeFieldsAsOpen.observe(viewLifecycleOwner) { openAdvancedFields(isCollapsed = ! it) }
127
121
}
128
122
129
- fun setOnFocusChangedListeners () = with (binding) {
130
- subjectTextField.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) elementGotFocus(FocusableElement .OTHER ) }
131
- editorWebView.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) elementGotFocus(FocusableElement .BODY ) }
123
+ fun setOnFocusChangedListeners () = with (newMessageViewModel) {
124
+ binding.subjectTextField.setOnFocusChangeListener { _, hasFocus -> if (hasFocus) fieldGotFocus(null ) }
125
+ binding.editorWebView.setOnFocusChangeListener { _, hasFocus -> isEditorWebViewFocusedLiveData.value = hasFocus }
126
+
127
+ isEditorWebViewFocusedLiveData.observe(viewLifecycleOwner) { hasFocus -> if (hasFocus) fieldGotFocus(null ) }
132
128
}
133
129
134
130
fun focusBodyField () {
@@ -159,12 +155,4 @@ class NewMessageRecipientFieldsManager @Inject constructor(private val snackbarM
159
155
CC ,
160
156
BCC ,
161
157
}
162
-
163
- enum class FocusableElement {
164
- TO ,
165
- CC ,
166
- BCC ,
167
- BODY ,
168
- OTHER ,
169
- }
170
158
}
0 commit comments