diff --git a/app/build.gradle b/app/build.gradle index 589fa3613..61cc9403a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ android { applicationId "com.geeksville.mesh" minSdkVersion 21 // The oldest emulator image I have tried is 22 (though 21 probably works) targetSdkVersion 29 - versionCode 20142 // format is Mmmss (where M is 1+the numeric major number - versionName "1.1.42" + versionCode 20143 // format is Mmmss (where M is 1+the numeric major number + versionName "1.1.43" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" // per https://developer.android.com/studio/write/vector-asset-studio diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 9a22cbde6..2a761eab1 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -805,8 +805,9 @@ class MainActivity : AppCompatActivity(), Logging, registerMeshReceiver() // Init our messages table with the service's record of past text messages (ignore all other message types) + val allMsgs = service.oldMessages val msgs = - service.oldMessages.filter { p -> p.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE } + allMsgs.filter { p -> p.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE } debug("Service provided ${msgs.size} messages and myNodeNum ${service.myNodeInfo?.myNodeNum}") model.myNodeInfo.value = service.myNodeInfo model.messagesState.setMessages(msgs) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index b8a4ff2f4..19d1f18e9 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -596,17 +596,21 @@ class MeshService : Service(), Logging { } private fun rememberDataPacket(dataPacket: DataPacket) { - // discard old messages if needed then add the new one - while (recentDataPackets.size > 50) - recentDataPackets.removeAt(0) + // Now that we use data packets for more things, we need to be choosier about what we keep. Since (currently - in the future less so) + // we only care about old text messages, we just store those... + if(dataPacket.dataType == Portnums.PortNum.TEXT_MESSAGE_APP_VALUE) { + // discard old messages if needed then add the new one + while (recentDataPackets.size > 50) + recentDataPackets.removeAt(0) - // FIXME - possible kotlin bug in 1.3.72 - it seems that if we start with the (globally shared) emptyList, - // then adding items are affecting that shared list rather than a copy. This was causing aliasing of - // recentDataPackets with messages.value in the GUI. So if the current list is empty we are careful to make a new list - if (recentDataPackets.isEmpty()) - recentDataPackets = mutableListOf(dataPacket) - else - recentDataPackets.add(dataPacket) + // FIXME - possible kotlin bug in 1.3.72 - it seems that if we start with the (globally shared) emptyList, + // then adding items are affecting that shared list rather than a copy. This was causing aliasing of + // recentDataPackets with messages.value in the GUI. So if the current list is empty we are careful to make a new list + if (recentDataPackets.isEmpty()) + recentDataPackets = mutableListOf(dataPacket) + else + recentDataPackets.add(dataPacket) + } } /// Update our model and resend as needed for a MeshPacket we just received from the radio diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt index 1217c4699..67b4903aa 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt @@ -7,7 +7,6 @@ import android.app.PendingIntent import android.content.Context import android.content.Intent import android.graphics.Bitmap -import android.graphics.BitmapFactory import android.graphics.Canvas import android.graphics.Color import android.os.Build @@ -25,8 +24,7 @@ import java.io.Closeable class MeshServiceNotifications( private val context: Context -) : Closeable -{ +) : Closeable { private val notificationManager: NotificationManager get() = context.notificationManager val notifyId = 101 private var largeIcon: Bitmap? = null @@ -101,20 +99,31 @@ class MeshServiceNotifications( summaryString: String, senderName: String ): Notification { - // We delay making this bitmap until we know we need it - if(largeIcon == null) - largeIcon = getBitmapFromVectorDrawable(R.mipmap.ic_launcher2) - - val category = if (recentReceivedText != null) Notification.CATEGORY_SERVICE else Notification.CATEGORY_MESSAGE + val category = + if (recentReceivedText != null) Notification.CATEGORY_SERVICE else Notification.CATEGORY_MESSAGE val builder = NotificationCompat.Builder(context, channelId).setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setCategory(category) - .setSmallIcon(if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) R.drawable.app_icon_novect else R.drawable.app_icon) // vector form icons don't work reliably on older androids - .setLargeIcon(largeIcon) // we must include a large icon because of a bug in cyanogenmod https://github.com/open-keychain/open-keychain/issues/1356#issue-89493995 .setContentTitle(summaryString) // leave this off for now so our notification looks smaller .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentIntent(openAppIntent) + // Set the notification icon + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { + // If running on really old versions of android (<= 5.1.1) (possibly only cyanogen) we might encounter a bug with setting application specific icons + // so punt and stay with just the bluetooth icon - see https://meshtastic.discourse.group/t/android-1-1-42-ready-for-alpha-testing/2399/3?u=geeksville + builder.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth) + } else { + // Newer androids also support a 'large' icon + + // We delay making this bitmap until we know we need it + if (largeIcon == null) + largeIcon = getBitmapFromVectorDrawable(R.mipmap.ic_launcher2) + + builder.setSmallIcon(if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) R.drawable.app_icon_novect else R.drawable.app_icon) // vector form icons don't work reliably on older androids + .setLargeIcon(largeIcon) + } + // FIXME, show information about the nearest node // if(shortContent != null) builder.setContentText(shortContent) diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index 004340bd0..decfa6fed 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -574,6 +574,10 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { /// Setup the ui widgets unrelated to BLE scanning private fun initCommonUI() { + // We want to leave these visible in the IDE, but make sure they default to not visible until we have valid data + binding.positionBroadcastPeriodView.visibility = View.GONE + binding.lsSleepView.visibility = View.GONE + model.ownerName.observe(viewLifecycleOwner, { name -> binding.usernameEditText.setText(name) }) @@ -587,8 +591,10 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { model.isConnected.observe(viewLifecycleOwner, Observer { connectionState -> val connected = connectionState == MeshService.ConnectionState.CONNECTED binding.usernameView.isEnabled = connected - binding.positionBroadcastPeriodView.isEnabled = connected - binding.lsSleepView.isEnabled = connected + + // Don't even show advanced fields until after we have a connection + binding.positionBroadcastPeriodView.visibility = if (connected) View.VISIBLE else View.GONE + binding.lsSleepView.visibility = if (connected) View.VISIBLE else View.GONE if (connectionState == MeshService.ConnectionState.DISCONNECTED) model.ownerName.value = "" diff --git a/app/src/main/proto b/app/src/main/proto index dfe7bc121..106f4bfde 160000 --- a/app/src/main/proto +++ b/app/src/main/proto @@ -1 +1 @@ -Subproject commit dfe7bc1217a00c23eecb9dfcf1d56fe95ebddc3b +Subproject commit 106f4bfdebe277ab0b86d2b8c950ab78a35b0654 diff --git a/app/src/main/res/layout/settings_fragment.xml b/app/src/main/res/layout/settings_fragment.xml index 97a82dd09..7f6e135f2 100644 --- a/app/src/main/res/layout/settings_fragment.xml +++ b/app/src/main/res/layout/settings_fragment.xml @@ -91,6 +91,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:background="@color/cardview_light_background" android:checked="true" @@ -103,13 +104,15 @@