-
-
Notifications
You must be signed in to change notification settings - Fork 341
Variable for %GPS in quick chat. Feature request #2653 #3535
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
8e1b191
d28de35
a775e0e
9edd293
a7bb96d
e32eee6
2d29fab
31e4af6
e6cb702
603e745
28f269b
6ae5878
62e1831
976e170
0e43566
7c27419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "Bash(dir)", | ||
| "Bash(git clone https://github.com/meshtastic/Meshtastic-Android.git .)", | ||
| "Bash(git submodule update --init --recursive)", | ||
| "Bash(where sdkmanager)", | ||
| "Bash(echo $ANDROID_HOME)", | ||
| "Bash(./gradlew --version)", | ||
| "Bash(./gradlew assembleDebug)", | ||
| "Bash(where java)", | ||
| "Bash(\"C:\\Program Files\\Android\\Android Studio\\jbr\\bin\\java.exe\" -version)", | ||
| "Bash($env:JAVA_HOME=\"C:\\Program Files\\Android\\Android Studio\\jbr\")", | ||
| "Bash(export JAVA_HOME=\"C:/Program Files/Android/Android Studio/jbr\")", | ||
| "Read(//c/Users/**)", | ||
| "Bash(./gradlew :feature:messaging:assembleDebug)", | ||
| "Bash(./gradlew assembleFdroidDebug)", | ||
| "Bash(./gradlew assembleGoogleDebug)", | ||
| "Bash(./gradlew clean)", | ||
| "Bash(./gradlew :app:assembleFdroidDebug)", | ||
| "Bash(./gradlew clean assembleFdroidDebug)", | ||
| "Bash(./gradlew :app:assembleFdroidDebug --rerun-tasks)", | ||
| "Bash(./gradlew :app:assembleGoogleDebug)" | ||
| ], | ||
| "deny": [], | ||
| "ask": [] | ||
| } | ||
| } | ||
DaneEvans marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,6 +303,8 @@ fun MessageScreen( | |
| handleQuickChatAction( | ||
| action = action, | ||
| messageInputState = messageInputState, | ||
| userLatitude = ourNode?.takeIf { it.validPosition != null }?.latitude, | ||
| userLongitude = ourNode?.takeIf { it.validPosition != null }?.longitude, | ||
|
||
| onSendMessage = { text -> onEvent(MessageScreenEvent.SendMessage(text)) }, | ||
| ) | ||
| }, | ||
|
|
@@ -422,25 +424,37 @@ private fun String.ellipsize(maxLength: Int): String = if (length > maxLength) " | |
| * | ||
| * @param action The [QuickChatAction] to handle. | ||
| * @param messageInputState The [TextFieldState] of the message input field. | ||
| * @param userLatitude Current user latitude, if available. | ||
| * @param userLongitude Current user longitude, if available. | ||
| * @param onSendMessage Lambda to call when a message needs to be sent. | ||
| */ | ||
| private fun handleQuickChatAction( | ||
| action: QuickChatAction, | ||
| messageInputState: TextFieldState, | ||
| userLatitude: Double?, | ||
| userLongitude: Double?, | ||
| onSendMessage: (String) -> Unit, | ||
| ) { | ||
| val processedMessage = | ||
| if (userLatitude != null && userLongitude != null) { | ||
|
||
| val gpsString = "%.7f,%.7f".format(userLatitude, userLongitude) | ||
| action.message.replace("%GPS", gpsString, ignoreCase = true) | ||
| } else { | ||
| action.message | ||
| } | ||
|
|
||
| when (action.mode) { | ||
| QuickChatAction.Mode.Append -> { | ||
| val originalText = messageInputState.text.toString() | ||
| // Avoid appending if the exact message is already present (simple check) | ||
| if (!originalText.contains(action.message)) { | ||
| if (!originalText.contains(processedMessage)) { | ||
| val newText = | ||
| buildString { | ||
| append(originalText) | ||
| if (originalText.isNotEmpty() && !originalText.endsWith(' ')) { | ||
| append(' ') | ||
| } | ||
| append(action.message) | ||
| append(processedMessage) | ||
| } | ||
| .limitBytes(MESSAGE_CHARACTER_LIMIT_BYTES) | ||
| messageInputState.setTextAndPlaceCursorAtEnd(newText) | ||
|
|
@@ -449,7 +463,7 @@ private fun handleQuickChatAction( | |
|
|
||
| QuickChatAction.Mode.Instant -> { | ||
| // Byte limit for 'Send' mode messages is handled by the backend/transport layer. | ||
| onSendMessage(action.message) | ||
| onSendMessage(processedMessage) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -707,7 +721,7 @@ private fun QuickChatRow( | |
| val allActions = remember(alertAction, actions) { listOf(alertAction) + actions } | ||
|
|
||
| LazyRow(modifier = modifier.padding(vertical = 4.dp), horizontalArrangement = Arrangement.spacedBy(4.dp)) { | ||
| items(allActions, key = { it.uuid }) { action -> | ||
| items(allActions, key = { it.position }) { action -> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we changing this key?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key was changed from uuid to position to fix a crash: Key "0" was already used. Both the alert bell action and the default location pin action are created with uuid=0L (the default The position field is guaranteed unique: Bell action: position = -1 |
||
| Button(onClick = { onClick(action) }, enabled = enabled) { Text(text = action.name) } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ class MessageViewModel | |
| constructor( | ||
| private val nodeRepository: NodeRepository, | ||
| radioConfigRepository: RadioConfigRepository, | ||
| quickChatActionRepository: QuickChatActionRepository, | ||
| private val quickChatActionRepository: QuickChatActionRepository, | ||
| private val serviceRepository: ServiceRepository, | ||
| private val packetRepository: PacketRepository, | ||
| private val uiPrefs: UiPrefs, | ||
|
|
@@ -77,6 +77,26 @@ constructor( | |
|
|
||
| val quickChatActions = quickChatActionRepository.getAllActions().stateInWhileSubscribed(initialValue = emptyList()) | ||
|
|
||
| init { | ||
| viewModelScope.launch(Dispatchers.IO) { | ||
| val actions = quickChatActionRepository.getAllActions() | ||
| var isEmpty = true | ||
| actions.collect { list -> | ||
| if (isEmpty && list.isEmpty()) { | ||
| quickChatActionRepository.upsert( | ||
| org.meshtastic.core.database.entity.QuickChatAction( | ||
| name = "📍", | ||
| message = "https://maps.google.com/?q=%GPS", | ||
|
||
| mode = org.meshtastic.core.database.entity.QuickChatAction.Mode.Append, | ||
| position = 0, | ||
| ), | ||
| ) | ||
| } | ||
| isEmpty = false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private val contactKeyForMessages: MutableStateFlow<String?> = MutableStateFlow(null) | ||
| private val messagesForContactKey: StateFlow<List<Message>> = | ||
| contactKeyForMessages | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.