@@ -18,6 +18,7 @@ import androidx.compose.runtime.Composable
1818import androidx.compose.runtime.getValue
1919import androidx.compose.runtime.mutableStateOf
2020import androidx.compose.runtime.remember
21+ import androidx.compose.runtime.rememberCoroutineScope
2122import androidx.compose.runtime.setValue
2223import androidx.compose.ui.Alignment
2324import androidx.compose.ui.Modifier
@@ -29,11 +30,16 @@ import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium
2930import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleSmall
3031import app.k9mail.core.ui.compose.designsystem.atom.textfield.TextFieldOutlined
3132import app.k9mail.core.ui.compose.designsystem.molecule.input.CheckboxInput
33+ import app.k9mail.core.ui.compose.designsystem.organism.snackbar.SnackbarHost
34+ import app.k9mail.core.ui.compose.designsystem.organism.snackbar.SnackbarHostState
35+ import app.k9mail.core.ui.compose.designsystem.organism.snackbar.rememberSnackbarHostState
3236import app.k9mail.core.ui.compose.theme2.MainTheme
3337import kotlin.math.roundToInt
3438import kotlin.random.Random
3539import kotlin.time.Clock
3640import kotlin.time.ExperimentalTime
41+ import kotlinx.coroutines.CoroutineScope
42+ import kotlinx.coroutines.launch
3743import kotlinx.datetime.TimeZone
3844import kotlinx.datetime.toLocalDateTime
3945import net.thunderbird.core.ui.compose.designsystem.organism.message.ActiveMessageItem
@@ -141,21 +147,27 @@ private fun MessageItemConfiguration(
141147 label = " Sender" ,
142148 onValueChange = onSenderChange,
143149 isSingleLine = true ,
144- modifier = Modifier .fillMaxWidth().padding(horizontal = MainTheme .spacings.double),
150+ modifier = Modifier
151+ .fillMaxWidth()
152+ .padding(horizontal = MainTheme .spacings.double),
145153 )
146154 TextFieldOutlined (
147155 value = config.subject,
148156 label = " Subject" ,
149157 onValueChange = onSubjectChange,
150158 isSingleLine = true ,
151- modifier = Modifier .fillMaxWidth().padding(horizontal = MainTheme .spacings.double),
159+ modifier = Modifier
160+ .fillMaxWidth()
161+ .padding(horizontal = MainTheme .spacings.double),
152162 )
153163 TextFieldOutlined (
154164 value = config.preview,
155165 label = " Preview" ,
156166 onValueChange = onPreviewChange,
157167 isSingleLine = false ,
158- modifier = Modifier .fillMaxWidth().padding(horizontal = MainTheme .spacings.double),
168+ modifier = Modifier
169+ .fillMaxWidth()
170+ .padding(horizontal = MainTheme .spacings.double),
159171 )
160172 Column (modifier = Modifier .padding(horizontal = MainTheme .spacings.double)) {
161173 TextLabelSmall (text = " Preview lines: ${config.maxPreviewLines} " )
@@ -181,12 +193,17 @@ private fun CatalogMessageItems(config: MessageItemConfiguration, modifier: Modi
181193}
182194
183195@Composable
184- private fun ColumnScope.CatalogNewMessageItem (config : MessageItemConfiguration ) {
196+ private fun ColumnScope.CatalogNewMessageItem (
197+ config : MessageItemConfiguration ,
198+ ) {
185199 if (! config.hideSection) {
186200 Section (text = " New Message" , modifier = Modifier .padding(vertical = MainTheme .spacings.double))
187201 }
188202 var selected by remember { mutableStateOf(false ) }
189203 var favourite by remember { mutableStateOf(false ) }
204+ val snackbarHostState = rememberSnackbarHostState()
205+ val coroutineScope = rememberCoroutineScope()
206+
190207 NewMessageItem (
191208 sender = config.sender,
192209 subject = config.subject,
@@ -204,8 +221,13 @@ private fun ColumnScope.CatalogNewMessageItem(config: MessageItemConfiguration)
204221 }
205222 },
206223 onClick = {
207- if (selected) {
208- selected = false
224+ coroutineScope.launch {
225+ snackbarHostState.showSnackbar(" Clicked!" )
226+ }
227+ },
228+ onLongClick = {
229+ coroutineScope.launch {
230+ snackbarHostState.showSnackbar(" Long clicked!" )
209231 }
210232 },
211233 onFavouriteChange = { favourite = it },
@@ -217,15 +239,23 @@ private fun ColumnScope.CatalogNewMessageItem(config: MessageItemConfiguration)
217239 },
218240 maxPreviewLines = config.maxPreviewLines,
219241 )
242+
243+ SnackbarHost (snackbarHostState)
220244}
221245
222246@Composable
223- private fun ColumnScope.CatalogUnreadMessageItem (config : MessageItemConfiguration ) {
247+ private fun ColumnScope.CatalogUnreadMessageItem (
248+ config : MessageItemConfiguration ,
249+ ) {
224250 if (! config.hideSection) {
225251 Section (text = " Unread Message" , modifier = Modifier .padding(vertical = MainTheme .spacings.double))
226252 }
227253 var selected by remember { mutableStateOf(false ) }
228254 var favourite by remember { mutableStateOf(false ) }
255+
256+ val snackbarHostState = rememberSnackbarHostState()
257+ val coroutineScope = rememberCoroutineScope()
258+
229259 UnreadMessageItem (
230260 sender = config.sender,
231261 subject = config.subject,
@@ -243,8 +273,13 @@ private fun ColumnScope.CatalogUnreadMessageItem(config: MessageItemConfiguratio
243273 }
244274 },
245275 onClick = {
246- if (selected) {
247- selected = false
276+ coroutineScope.launch {
277+ snackbarHostState.showSnackbar(" Clicked!" )
278+ }
279+ },
280+ onLongClick = {
281+ coroutineScope.launch {
282+ snackbarHostState.showSnackbar(" Long clicked!" )
248283 }
249284 },
250285 onFavouriteChange = { favourite = it },
@@ -256,15 +291,23 @@ private fun ColumnScope.CatalogUnreadMessageItem(config: MessageItemConfiguratio
256291 },
257292 maxPreviewLines = config.maxPreviewLines,
258293 )
294+
295+ SnackbarHost (snackbarHostState)
259296}
260297
261298@Composable
262- private fun ColumnScope.CatalogReadMessageItem (config : MessageItemConfiguration ) {
299+ private fun ColumnScope.CatalogReadMessageItem (
300+ config : MessageItemConfiguration ,
301+ ) {
263302 if (! config.hideSection) {
264303 Section (text = " Read Message" , modifier = Modifier .padding(vertical = MainTheme .spacings.double))
265304 }
266305 var selected by remember { mutableStateOf(false ) }
267306 var favourite by remember { mutableStateOf(false ) }
307+
308+ val snackbarHostState = rememberSnackbarHostState()
309+ val coroutineScope = rememberCoroutineScope()
310+
268311 ReadMessageItem (
269312 sender = config.sender,
270313 subject = config.subject,
@@ -282,8 +325,13 @@ private fun ColumnScope.CatalogReadMessageItem(config: MessageItemConfiguration)
282325 }
283326 },
284327 onClick = {
285- if (selected) {
286- selected = false
328+ coroutineScope.launch {
329+ snackbarHostState.showSnackbar(" Clicked!" )
330+ }
331+ },
332+ onLongClick = {
333+ coroutineScope.launch {
334+ snackbarHostState.showSnackbar(" Long clicked!" )
287335 }
288336 },
289337 onFavouriteChange = { favourite = it },
@@ -295,15 +343,23 @@ private fun ColumnScope.CatalogReadMessageItem(config: MessageItemConfiguration)
295343 },
296344 maxPreviewLines = config.maxPreviewLines,
297345 )
346+
347+ SnackbarHost (snackbarHostState)
298348}
299349
300350@Composable
301- private fun ColumnScope.CatalogActiveMessageItem (config : MessageItemConfiguration ) {
351+ private fun ColumnScope.CatalogActiveMessageItem (
352+ config : MessageItemConfiguration ,
353+ ) {
302354 if (! config.hideSection) {
303355 Section (text = " Active Message" , modifier = Modifier .padding(vertical = MainTheme .spacings.double))
304356 }
305357 var selected by remember { mutableStateOf(false ) }
306358 var favourite by remember { mutableStateOf(false ) }
359+
360+ val snackbarHostState = rememberSnackbarHostState()
361+ val coroutineScope = rememberCoroutineScope()
362+
307363 ActiveMessageItem (
308364 sender = config.sender,
309365 subject = config.subject,
@@ -321,8 +377,13 @@ private fun ColumnScope.CatalogActiveMessageItem(config: MessageItemConfiguratio
321377 }
322378 },
323379 onClick = {
324- if (selected) {
325- selected = false
380+ coroutineScope.launch {
381+ snackbarHostState.showSnackbar(" Clicked!" )
382+ }
383+ },
384+ onLongClick = {
385+ coroutineScope.launch {
386+ snackbarHostState.showSnackbar(" Long clicked!" )
326387 }
327388 },
328389 onFavouriteChange = { favourite = it },
@@ -334,14 +395,22 @@ private fun ColumnScope.CatalogActiveMessageItem(config: MessageItemConfiguratio
334395 },
335396 maxPreviewLines = config.maxPreviewLines,
336397 )
398+
399+ SnackbarHost (snackbarHostState)
337400}
338401
339402@Composable
340- private fun ColumnScope.CatalogJunkMessageItem (config : MessageItemConfiguration ) {
403+ private fun ColumnScope.CatalogJunkMessageItem (
404+ config : MessageItemConfiguration ,
405+ ) {
341406 if (! config.hideSection) {
342407 Section (text = " Junk Message" , modifier = Modifier .padding(vertical = MainTheme .spacings.double))
343408 }
344409 var selected by remember { mutableStateOf(false ) }
410+
411+ val snackbarHostState = rememberSnackbarHostState()
412+ val coroutineScope = rememberCoroutineScope()
413+
345414 JunkMessageItem (
346415 sender = config.sender,
347416 subject = config.subject,
@@ -358,8 +427,13 @@ private fun ColumnScope.CatalogJunkMessageItem(config: MessageItemConfiguration)
358427 }
359428 },
360429 onClick = {
361- if (selected) {
362- selected = false
430+ coroutineScope.launch {
431+ snackbarHostState.showSnackbar(" Clicked!" )
432+ }
433+ },
434+ onLongClick = {
435+ coroutineScope.launch {
436+ snackbarHostState.showSnackbar(" Long clicked!" )
363437 }
364438 },
365439 modifier = Modifier .fillMaxWidth(),
@@ -370,6 +444,8 @@ private fun ColumnScope.CatalogJunkMessageItem(config: MessageItemConfiguration)
370444 },
371445 maxPreviewLines = config.maxPreviewLines,
372446 )
447+
448+ SnackbarHost (snackbarHostState)
373449}
374450
375451@Composable
0 commit comments