Skip to content

Commit

Permalink
wip: send message from intent
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-espie committed Nov 18, 2024
1 parent cba4a23 commit 622320f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion app/src/main/java/com/geeksville/mesh/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.geeksville.mesh.concurrent.handledLaunch
import com.geeksville.mesh.databinding.ActivityMainBinding
import com.geeksville.mesh.model.BluetoothViewModel
import com.geeksville.mesh.model.DeviceVersion
import com.geeksville.mesh.model.IntentMessage
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.model.primaryChannel
import com.geeksville.mesh.model.shouldAddChannels
Expand All @@ -53,6 +54,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import java.text.DateFormat
import java.util.Date
import javax.inject.Inject
Expand Down Expand Up @@ -287,7 +290,17 @@ class MainActivity : AppCompatActivity(), Logging {
}

Intent.ACTION_SEND -> {

val text = intent.getStringExtra(Intent.EXTRA_TEXT)
if (text != null) {
val json = Json
try {
val intentMessage: IntentMessage = json.decodeFromString(text)
model.sendMessage(intentMessage.message, intentMessage.contactKey)
showMessages(intentMessage.contactKey, intentMessage.contactName)
} catch (e: SerializationException) {
errormsg("Failed to decode JSON: ${e.message}")
}
}
}

else -> {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/geeksville/mesh/model/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.MeshProtos.Routing
import com.geeksville.mesh.MessageStatus
import com.geeksville.mesh.R
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

val Routing.Error.stringRes: Int
get() = when (this) {
Expand Down Expand Up @@ -52,3 +54,14 @@ data class Message(
return title to text
}
}

@Serializable
data class IntentMessage (
val message: String,
@SerialName("contact_key")
val contactKey: String,
@SerialName("contact_name")
val contactName: String,
@SerialName("auto_send")
val autoSend: Boolean,
)

0 comments on commit 622320f

Please sign in to comment.