Skip to content

Commit

Permalink
revert: share message from json parser
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-espie committed Nov 25, 2024
1 parent 4c626b9 commit dc8a865
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
28 changes: 1 addition & 27 deletions app/src/main/java/com/geeksville/mesh/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ 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.toChannelSet
import com.geeksville.mesh.service.MeshService
Expand Down Expand Up @@ -77,8 +76,6 @@ 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 @@ -335,23 +332,7 @@ 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)
if (intentMessage.autoSend) {
model.sendMessage(intentMessage.message, intentMessage.contactKey)
showMessages(intentMessage.contactKey, intentMessage.contactName)
} else {
showMessagesPreInit(
intentMessage.contactKey,
intentMessage.contactName,
intentMessage.message
)
}
} catch (e: SerializationException) {
debug("Failed to decode JSON: ${e.message}; falling back to default message")
shareMessages(text)
}
shareMessages(text)
}
}

Expand Down Expand Up @@ -625,13 +606,6 @@ class MainActivity : AppCompatActivity(), Logging {
}
}

private fun showMessagesPreInit(contactKey: String?, contactName: String?, message: String?) {
model.setCurrentTab(0)
if (contactKey != null && contactName != null && message != null) {
supportFragmentManager.navigateToPreInitMessages(contactKey, contactName, message)
}
}

private fun shareMessages(message: String?) {
model.setCurrentTab(0)
if (message != null) {
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/geeksville/mesh/model/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ 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 @@ -54,14 +52,3 @@ 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 dc8a865

Please sign in to comment.