-
-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/copying stuff #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c5ee27
feat: support copying and duplicating macros, layouts, and buttons
stormpanda 417859b
feat(macropad): refactor copy operations and add profile/layout dupli…
stormpanda 8fbca4e
refactor(macropad): abstract and simplify dialog overlays and domain …
stormpanda af8ff94
refactor(macropad): move profile and layout delete options to context…
stormpanda 6d580e7
fix(macropad): address PR review comments for CopyDialogs localizatio…
stormpanda c8507af
fix(macropad): address additional review comments for magic numbers, …
stormpanda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
app/src/main/java/com/stormpanda/megingiard/macropad/CopyDialogs.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| 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 | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.