new notification status stuff seems to work

This commit is contained in:
Kevin Hester 2020-02-28 20:09:00 -08:00
parent 42439c4b26
commit a0db3e0ccd
4 changed files with 29 additions and 13 deletions

View file

@ -268,8 +268,7 @@ class MeshService : Service(), Logging {
chan.lightColor = Color.BLUE
chan.importance = NotificationManager.IMPORTANCE_NONE
chan.lockscreenVisibility = Notification.VISIBILITY_PRIVATE
val service = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
service.createNotificationChannel(chan)
notificationManager.createNotificationChannel(chan)
return channelId
}
@ -278,7 +277,8 @@ class MeshService : Service(), Logging {
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
}
val channelId =
/// This must be lazy because we use Context
private val channelId: String by lazy() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
} else {
@ -286,10 +286,11 @@ class MeshService : Service(), Logging {
// https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#NotificationCompat.Builder(android.content.Context)
""
}
}
private val mainAppIntent = Intent(this, MainActivity::class.java)
private val openAppIntent = PendingIntent.getActivity(this, 0, mainAppIntent, 0)
private val notificationBuilder = NotificationCompat.Builder(this, channelId)
private val openAppIntent: PendingIntent by lazy() {
PendingIntent.getActivity(this, 0, Intent(this, MainActivity::class.java), 0)
}
/// A text message that has a arrived since the last notification update
private var recentReceivedText: TextMessage? = null
@ -298,7 +299,7 @@ class MeshService : Service(), Logging {
get() = if (!isConnected)
"No radio connected"
else
"Connected $numOnlineNodes / $numNodes online"
"Connected: $numOnlineNodes of $numNodes online"
override fun toString() = summaryString
@ -307,11 +308,13 @@ class MeshService : Service(), Logging {
*/
private fun createNotification(): Notification {
val notificationBuilder = NotificationCompat.Builder(this, channelId)
val builder = notificationBuilder.setOngoing(true)
.setPriority(PRIORITY_MIN)
.setCategory(if (recentReceivedText != null) Notification.CATEGORY_SERVICE else Notification.CATEGORY_MESSAGE)
.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
.setContentTitle("Meshtastic: $summaryString") // leave this off for now so our notification looks smaller
.setContentTitle(summaryString) // leave this off for now so our notification looks smaller
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentIntent(openAppIntent)
@ -643,7 +646,7 @@ class MeshService : Service(), Logging {
/// If we just changed our nodedb, we might want to do somethings
private fun onNodeDBChanged() {
updateNotification()
// we don't ask for GPS locations from android if our device has a built in GPS
if (!myNodeInfo!!.hasGPS) {
// If we have at least one other person in the mesh, send our GPS position otherwise stop listening to GPS

View file

@ -7,8 +7,10 @@ import android.os.ParcelUuid
import androidx.compose.*
import androidx.compose.frames.modelMapOf
import androidx.ui.core.ContextAmbient
import androidx.ui.core.LayoutModifier
import androidx.ui.core.Text
import androidx.ui.layout.Column
import androidx.ui.layout.LayoutGravity
import androidx.ui.material.CircularProgressIndicator
import androidx.ui.material.EmphasisLevels
import androidx.ui.material.ProvideEmphasis
@ -136,7 +138,7 @@ fun BTScanScreen() {
Text("An unexpected error was encountered. Please file a bug on our github: ${ScanUIState.errorText}")
} else {
if (ScanUIState.devices.isEmpty()) {
Text("Looking for Meshtastic devices... (zero found)")
Text(text = "Looking for Meshtastic devices... (zero found)", modifier = LayoutGravity.Center)
CircularProgressIndicator() // Show that we are searching still
} else {

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,5c-3.87,0 -7,3.13 -7,7h2c0,-2.76 2.24,-5 5,-5s5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM13,14.29c0.88,-0.39 1.5,-1.26 1.5,-2.29 0,-1.38 -1.12,-2.5 -2.5,-2.5S9.5,10.62 9.5,12c0,1.02 0.62,1.9 1.5,2.29v3.3L7.59,21 9,22.41l3,-3 3,3L16.41,21 13,17.59v-3.3zM12,1C5.93,1 1,5.93 1,12h2c0,-4.97 4.03,-9 9,-9s9,4.03 9,9h2c0,-6.07 -4.93,-11 -11,-11z"/>
</vector>