srctree

Robin Linden parent df5de688 af706dcd
Fix the offline-bootstrap code not always running

It failed to run after changing settings that would gracefully shut Toxdown as that sets the connection status to offline, meaning the that ourcheck for unique connection statuses would stop the bootstrap code fromrunning when creating a fresh Tox Service which initializes theconnection status to offline.

inlinesplit
atox/src/main/kotlin/ToxService.kt added: 5, removed: 5, total 0
@@ -29,7 +29,7 @@ class ToxService : LifecycleService() {
private val channelId = "ToxService"
private val notificationId = 1984
 
private var connectionStatus = ConnectionStatus.None
private var connectionStatus: ConnectionStatus? = null
 
private val notifier by lazy { getSystemService<NotificationManager>()!! }
private var bootstrapTimer = Timer()
@@ -57,13 +57,13 @@ class ToxService : LifecycleService() {
notifier.createNotificationChannels(listOf(friendRequestChannel))
}
 
private fun subTextFor(status: ConnectionStatus) = when (status) {
ConnectionStatus.None -> getText(R.string.atox_offline)
private fun subTextFor(status: ConnectionStatus?) = when (status) {
null, ConnectionStatus.None -> getText(R.string.atox_offline)
ConnectionStatus.TCP -> getText(R.string.atox_connected_with_tcp)
ConnectionStatus.UDP -> getText(R.string.atox_connected_with_udp)
}
 
private fun notificationFor(status: ConnectionStatus): Notification {
private fun notificationFor(status: ConnectionStatus?): Notification {
val pendingIntent: PendingIntent =
Intent(this, MainActivity::class.java).let { notificationIntent ->
PendingIntent.getActivity(this, 0, notificationIntent, 0)