Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.DragHandle
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand All @@ -44,11 +50,14 @@ internal fun ButtonListItem(
enableTouch: Boolean,
isDragging: Boolean,
onEdit: () -> Unit,
onDuplicate: () -> Unit,
onCopyToLayout: () -> Unit,
onDelete: () -> Unit,
dragHandleModifier: Modifier,
modifier: Modifier = Modifier,
) {
val colors = LocalAppColors.current
var menuExpanded by remember { mutableStateOf(false) }

val isTrackpoint = btn.action is PadAction.TrackpointMove
val isDeviceDisabled = when (btn.action) {
Expand Down Expand Up @@ -146,8 +155,32 @@ internal fun ButtonListItem(
}
}

IconButton(onClick = { onDelete() }) {
Icon(Icons.Rounded.Delete, contentDescription = stringResource(R.string.macropad_editor_delete_button), tint = colors.onSurfaceSecondary)
Box {
IconButton(onClick = { menuExpanded = true }) {
Icon(Icons.Rounded.MoreVert, contentDescription = stringResource(R.string.cd_more_options), tint = colors.onSurfaceSecondary)
}
DropdownMenu(
expanded = menuExpanded,
onDismissRequest = { menuExpanded = false },
modifier = Modifier.background(colors.surface),
) {
DropdownMenuItem(
text = { Text(stringResource(R.string.settings_macropad_edit), color = colors.onSurface, style = MaterialTheme.typography.bodyMedium) },
onClick = { menuExpanded = false; onEdit() }
)
DropdownMenuItem(
text = { Text(stringResource(R.string.macropad_editor_copy_button_duplicate), color = colors.onSurface, style = MaterialTheme.typography.bodyMedium) },
onClick = { menuExpanded = false; onDuplicate() }
)
DropdownMenuItem(
text = { Text(stringResource(R.string.macropad_editor_copy_to_layout), color = colors.onSurface, style = MaterialTheme.typography.bodyMedium) },
onClick = { menuExpanded = false; onCopyToLayout() }
)
DropdownMenuItem(
text = { Text(stringResource(R.string.macropad_editor_delete_button), color = colors.error, style = MaterialTheme.typography.bodyMedium) },
onClick = { menuExpanded = false; onDelete() }
)
}
}
Icon(
imageVector = Icons.Rounded.DragHandle,
Expand Down
135 changes: 135 additions & 0 deletions app/src/main/java/com/stormpanda/megingiard/macropad/CopyDialogs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.stormpanda.megingiard.macropad

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.stormpanda.megingiard.R
import com.stormpanda.megingiard.ui.LocalAppColors

Comment thread
Copilot marked this conversation as resolved.
private const val TAG = "CopyDialogs"

@Composable
internal fun InlineProfileSelectionOverlay(
title: String,
profiles: List<PadProfile>,
excludeProfileId: String?,
onSelect: (String) -> Unit,
onDismiss: () -> Unit,
) {
val colors = LocalAppColors.current
val filteredProfiles = profiles.filter { it.id != excludeProfileId }

InlineDialogOverlay(
title = title,
onDismiss = onDismiss,
) {
if (filteredProfiles.isEmpty()) {
Text(
text = stringResource(R.string.macropad_copy_no_profiles_available),
color = colors.onSurfaceSecondary,
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.padding(vertical = 16.dp)
)
Comment on lines +39 to +45
} else {
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = 240.dp)
) {
items(filteredProfiles) { profile ->
Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onSelect(profile.id) }
.padding(vertical = 12.dp, horizontal = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = profile.name,
color = colors.onSurface,
style = MaterialTheme.typography.bodyLarge
)
}
}
}
}
}
}

@Composable
internal fun InlineLayoutSelectionOverlay(
title: String,
profiles: List<PadProfile>,
excludeLayoutId: String?,
onSelect: (targetProfileId: String, targetLayoutId: String) -> Unit,
onDismiss: () -> Unit,
) {
val colors = LocalAppColors.current
val hasSelectableLayouts = profiles.any { profile ->
profile.layouts.any { it.id != excludeLayoutId }
}

InlineDialogOverlay(
title = title,
onDismiss = onDismiss,
) {
if (!hasSelectableLayouts) {
Text(
text = stringResource(R.string.macropad_copy_no_layouts_available),
color = colors.onSurfaceSecondary,
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.padding(vertical = 16.dp)
)
} else {
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.heightIn(max = 300.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
profiles.forEach { profile ->
val layouts = profile.layouts.filter { it.id != excludeLayoutId }
if (layouts.isNotEmpty()) {
item(key = "header_${profile.id}") {
Text(
text = profile.name,
color = colors.accent,
style = MaterialTheme.typography.labelMedium,
fontWeight = FontWeight.SemiBold,
modifier = Modifier.padding(top = 8.dp, bottom = 4.dp, start = 8.dp)
)
}
items(layouts) { layout ->
Row(
modifier = Modifier
.fillMaxWidth()
.clickable { onSelect(profile.id, layout.id) }
.padding(vertical = 10.dp, horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = layout.name,
color = colors.onSurface,
style = MaterialTheme.typography.bodyLarge
)
}
}
}
}
}
}
}
}
Loading