Fix problem of old messages not being remembered

This commit is contained in:
geeksville 2020-07-01 17:47:53 -07:00
parent 800060a991
commit c0e58391a3
4 changed files with 13 additions and 9 deletions

View file

@ -423,7 +423,7 @@ class MainActivity : AppCompatActivity(), Logging,
private fun updateConnectionStatusImage(connected: MeshService.ConnectionState) {
if (actionBarMenu==null)
if (actionBarMenu == null)
return
val (image, tooltip) = when (connected) {
@ -736,7 +736,9 @@ class MainActivity : AppCompatActivity(), Logging,
registerMeshReceiver()
// Init our messages table with the service's record of past text messages
model.messagesState.messages.value = service.oldMessages
val msgs = service.oldMessages
debug("Service provided ${msgs.size} messages")
model.messagesState.messages.value = msgs
val connectionState =
MeshService.ConnectionState.valueOf(service.connectionState())

View file

@ -605,13 +605,13 @@ class MeshService : Service(), Logging {
}
/**
* discard entire node db & message state - used when changing radio channels
* discard entire node db & message state - used when downloading a new db from the device
*/
private fun discardNodeDB() {
myNodeInfo = null
nodeDBbyNodeNum.clear()
nodeDBbyID.clear()
recentDataPackets.clear()
// recentDataPackets.clear() We do NOT want to clear this, because it is the record of old messages the GUI still might want to show
haveNodeDB = false
}
@ -1024,6 +1024,9 @@ class MeshService : Service(), Logging {
/// Perform all the steps needed once we start waiting for device sleep to complete
fun startDeviceSleep() {
// Just in case the user uncleanly reboots the phone, save now (we normally save in onDestroy)
saveSettings()
// lost radio connection, therefore no need to keep listening to GPS
stopLocationRequests()

View file

@ -187,7 +187,8 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
layoutManager.stackFromEnd = true // We want the last rows to always be shown
messageListView.layoutManager = layoutManager
model.messagesState.messages.observe(viewLifecycleOwner, Observer { it ->
model.messagesState.messages.observe(viewLifecycleOwner, Observer {
debug("New messages received: ${it.size}")
messagesAdapter.onMessagesChanged(it)
})