@@ -20,6 +20,7 @@ package com.infomaniak.mail.ui.newMessage
20
20
import android.content.res.ColorStateList
21
21
import androidx.core.view.isGone
22
22
import androidx.core.view.isVisible
23
+ import androidx.lifecycle.lifecycleScope
23
24
import com.google.android.material.button.MaterialButton
24
25
import com.infomaniak.mail.MatomoMail
25
26
import com.infomaniak.mail.MatomoMail.trackEvent
@@ -28,11 +29,12 @@ import com.infomaniak.mail.databinding.FragmentNewMessageBinding
28
29
import com.infomaniak.mail.utils.extensions.getAttributeColor
29
30
import com.infomaniak.mail.utils.extensions.notYetImplemented
30
31
import dagger.hilt.android.scopes.FragmentScoped
32
+ import kotlinx.coroutines.launch
31
33
import javax.inject.Inject
32
34
import com.google.android.material.R as RMaterial
33
35
34
36
@FragmentScoped
35
- class NewMessageEditorManager @Inject constructor() : NewMessageManager() {
37
+ class NewMessageEditorManager @Inject constructor(private val insertLinkDialog : InsertLinkDialog ) : NewMessageManager() {
36
38
37
39
private var _aiManager : NewMessageAiManager ? = null
38
40
private inline val aiManager: NewMessageAiManager get() = _aiManager !!
@@ -57,19 +59,30 @@ class NewMessageEditorManager @Inject constructor() : NewMessageManager() {
57
59
_openFilePicker = openFilePicker
58
60
}
59
61
60
- fun observeEditorActions ( ) {
62
+ fun observeEditorFormatActions () = with (binding ) {
61
63
newMessageViewModel.editorAction.observe(viewLifecycleOwner) { (editorAction, _) ->
62
64
when (editorAction) {
63
65
EditorAction .ATTACHMENT -> _openFilePicker ?.invoke()
64
66
EditorAction .CAMERA -> fragment.notYetImplemented()
65
- EditorAction .LINK -> fragment.notYetImplemented()
67
+ EditorAction .LINK -> if (buttonLink.isActivated) {
68
+ editorWebView.unlink()
69
+ } else {
70
+ insertLinkDialog.show { displayText, url ->
71
+ editorWebView.createLink(displayText, url)
72
+ }
73
+ }
66
74
EditorAction .CLOCK -> fragment.notYetImplemented()
67
75
EditorAction .AI -> aiManager.openAiPrompt()
76
+ EditorAction .BOLD -> editorWebView.toggleBold()
77
+ EditorAction .ITALIC -> editorWebView.toggleItalic()
78
+ EditorAction .UNDERLINE -> editorWebView.toggleUnderline()
79
+ EditorAction .STRIKE_THROUGH -> editorWebView.toggleStrikeThrough()
80
+ EditorAction .UNORDERED_LIST -> editorWebView.toggleUnorderedList()
68
81
}
69
82
}
70
83
}
71
84
72
- fun setupEditorActions () = with (binding) {
85
+ fun setupEditorFormatActions () = with (binding) {
73
86
fun linkEditor (view : MaterialButton , action : EditorAction ) {
74
87
view.setOnClickListener {
75
88
context.trackEvent(" editorActions" , action.matomoValue)
@@ -79,34 +92,55 @@ class NewMessageEditorManager @Inject constructor() : NewMessageManager() {
79
92
80
93
linkEditor(editorAttachment, EditorAction .ATTACHMENT )
81
94
linkEditor(editorCamera, EditorAction .CAMERA )
82
- linkEditor(editorLink, EditorAction .LINK )
83
95
linkEditor(editorClock, EditorAction .CLOCK )
84
96
linkEditor(editorAi, EditorAction .AI )
97
+
98
+ linkEditor(buttonBold, EditorAction .BOLD )
99
+ linkEditor(buttonItalic, EditorAction .ITALIC )
100
+ linkEditor(buttonUnderline, EditorAction .UNDERLINE )
101
+ linkEditor(buttonStrikeThrough, EditorAction .STRIKE_THROUGH )
102
+ linkEditor(buttonList, EditorAction .UNORDERED_LIST )
103
+ linkEditor(buttonLink, EditorAction .LINK )
85
104
}
86
105
87
106
fun setupEditorFormatActionsToggle () = with (binding) {
88
107
editorTextOptions.setOnClickListener {
89
108
newMessageViewModel.isEditorExpanded = ! newMessageViewModel.isEditorExpanded
90
- updateEditorVisibility (newMessageViewModel.isEditorExpanded)
109
+ updateEditorFormatActionsVisibility (newMessageViewModel.isEditorExpanded)
91
110
}
92
111
}
93
112
94
- private fun updateEditorVisibility (isEditorExpanded : Boolean ) = with (binding) {
113
+ private fun updateEditorFormatActionsVisibility (isExpanded : Boolean ) = with (binding) {
114
+ if (isExpanded) editorWebView.requestFocus()
95
115
96
- val color = if (isEditorExpanded ) {
116
+ val color = if (isExpanded ) {
97
117
context.getAttributeColor(RMaterial .attr.colorPrimary)
98
118
} else {
99
119
context.getColor(R .color.iconColor)
100
120
}
101
- val resId = if (isEditorExpanded ) R .string.buttonTextOptionsClose else R .string.buttonTextOptionsOpen
121
+ val resId = if (isExpanded ) R .string.buttonTextOptionsClose else R .string.buttonTextOptionsOpen
102
122
103
123
editorTextOptions.apply {
104
124
iconTint = ColorStateList .valueOf(color)
105
125
contentDescription = context.getString(resId)
106
126
}
107
127
108
- editorActions.isGone = isEditorExpanded
109
- textEditing.isVisible = isEditorExpanded
128
+ editorActions.isGone = isExpanded
129
+ sendButton.isGone = isExpanded
130
+ formatOptionsScrollView.isVisible = isExpanded
131
+ }
132
+
133
+ fun observeEditorStatus (): Unit = with (binding) {
134
+ viewLifecycleOwner.lifecycleScope.launch {
135
+ editorWebView.editorStatusesFlow.collect {
136
+ buttonBold.isActivated = it.isBold
137
+ buttonItalic.isActivated = it.isItalic
138
+ buttonUnderline.isActivated = it.isUnderlined
139
+ buttonStrikeThrough.isActivated = it.isStrikeThrough
140
+ buttonList.isActivated = it.isUnorderedListSelected
141
+ buttonLink.isActivated = it.isLinkSelected
142
+ }
143
+ }
110
144
}
111
145
112
146
enum class EditorAction (val matomoValue : String ) {
@@ -115,10 +149,10 @@ class NewMessageEditorManager @Inject constructor() : NewMessageManager() {
115
149
LINK (" addLink" ),
116
150
CLOCK (MatomoMail .ACTION_POSTPONE_NAME ),
117
151
AI (" aiWriter" ),
118
- // BOLD("bold"),
119
- // ITALIC("italic"),
120
- // UNDERLINE("underline"),
121
- // STRIKE_THROUGH("strikeThrough"),
122
- // UNORDERED_LIST("unorderedList"),
152
+ BOLD (" bold" ),
153
+ ITALIC (" italic" ),
154
+ UNDERLINE (" underline" ),
155
+ STRIKE_THROUGH (" strikeThrough" ),
156
+ UNORDERED_LIST (" unorderedList" ),
123
157
}
124
158
}
0 commit comments