Skip to content

Commit

Permalink
Merge pull request #562 from hannesa2/AddSuggestionsToBasicSample
Browse files Browse the repository at this point in the history
Add suggestions to basic sample
  • Loading branch information
hannesa2 authored Feb 16, 2024
2 parents 895abb9 + 31b66e9 commit 6460e69
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.google.android.material.snackbar.Snackbar
import info.mqtt.android.service.MqttAndroidClient
import info.mqtt.android.service.QoS
import info.mqtt.java.example.databinding.ActivityScrollingBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.eclipse.paho.client.mqttv3.*
import timber.log.Timber
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -77,11 +80,19 @@ class MQTTExampleActivity : AppCompatActivity() {
})
}

override fun onDestroy() {
Timber.d("onDestroy")
mqttAndroidClient.disconnect()
super.onDestroy()
}

private fun addToHistory(mainText: String) {
Timber.d(mainText)
@SuppressLint("SimpleDateFormat")
val timestamp = SimpleDateFormat("HH:mm.ss.SSS").format(Date(System.currentTimeMillis()))
adapter.add("$timestamp $mainText")
CoroutineScope(Dispatchers.Main).launch {
adapter.add("$timestamp $mainText")
}
Snackbar.make(findViewById(android.R.id.content), mainText, Snackbar.LENGTH_LONG).setAction("Action", null).show()
}

Expand Down

0 comments on commit 6460e69

Please sign in to comment.