Skip to content

Commit

Permalink
merge list function to one icon
Browse files Browse the repository at this point in the history
  • Loading branch information
eylulnc committed Dec 22, 2024
1 parent b35e481 commit b7c485a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.FormatListBulleted
import androidx.compose.material.icons.automirrored.filled.List
import androidx.compose.material.icons.automirrored.filled.Send
import androidx.compose.material.icons.filled.Cancel
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.FormatListNumbered
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
Expand Down Expand Up @@ -316,6 +319,9 @@ private fun FormattingOptions(
currentTextFieldValue: TextFieldValue,
onTextChanged: (TextFieldValue) -> Unit
) {

var isDropdownExpanded by remember { mutableStateOf(false) }

Row(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -406,33 +412,56 @@ private fun FormattingOptions(
)
}

// OrderedList Button
IconButton(onClick = {
applyMarkdownStyle(
style = MarkdownStyle.OrderedList,
currentTextFieldValue = currentTextFieldValue,
onTextChanged = onTextChanged
)

}) {
Icon(
imageVector = Icons.Default.FormatListNumbered,
contentDescription = "Ordered List"
)
}
Box(modifier = Modifier.align(Alignment.Top)) {
IconButton(
onClick = { isDropdownExpanded = true }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.List,
contentDescription = null
)
}

// UnorderedList Button
IconButton(onClick = {
applyMarkdownStyle(
style = MarkdownStyle.UnorderedList,
currentTextFieldValue = currentTextFieldValue,
onTextChanged = onTextChanged
)
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.FormatListBulleted,
contentDescription = "Unordered List"
)
DropdownMenu(
expanded = isDropdownExpanded,
onDismissRequest = { isDropdownExpanded = false }
) {
// Unordered List item
DropdownMenuItem(
leadingIcon = {
Icon(
imageVector = Icons.AutoMirrored.Filled.FormatListBulleted,
contentDescription = null
)
},
text = { Text(text = stringResource(R.string.reply_format_unordered)) },
onClick = {
isDropdownExpanded = false
applyMarkdownStyle(
style = MarkdownStyle.UnorderedList,
currentTextFieldValue = currentTextFieldValue,
onTextChanged = onTextChanged
)
}
)
// Ordered List item
DropdownMenuItem(
leadingIcon = {
Icon(
imageVector = Icons.Default.FormatListNumbered,
contentDescription = null
)
},
text = { Text(stringResource(R.string.reply_format_ordered)) },
onClick = {
isDropdownExpanded = false
applyMarkdownStyle(
style = MarkdownStyle.OrderedList,
currentTextFieldValue = currentTextFieldValue,
onTextChanged = onTextChanged
)
}
)
}
}
}
}
Expand Down Expand Up @@ -464,7 +493,10 @@ private fun applyMarkdownStyle(
)
} else {
// Other styles
val newText = text.substring(0, selection.start) + startTag + endTag + text.substring(selection.end)
val newText = text.substring(
0,
selection.start
) + startTag + endTag + text.substring(selection.end)
val newCursorPosition = selection.start + startTag.length
onTextChanged(
TextFieldValue(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="reply_format_unordered">Unordered List</string>
<string name="reply_format_ordered">Ordered List</string>
</resources>

0 comments on commit b7c485a

Please sign in to comment.