From 547f0e77f7243d63eaf89b164f4af3ab3d9a57cd Mon Sep 17 00:00:00 2001 From: Mark Hale Date: Sat, 10 Jul 2021 21:08:41 +0100 Subject: [PATCH] Don't require a log file in order to be able to connect. --- .../java/crazydude/com/telemetry/ui/MapsActivity.kt | 11 ++++++----- .../crazydude/com/telemetry/utils/NullOutputStream.kt | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/crazydude/com/telemetry/utils/NullOutputStream.kt diff --git a/app/src/main/java/crazydude/com/telemetry/ui/MapsActivity.kt b/app/src/main/java/crazydude/com/telemetry/ui/MapsActivity.kt index 99791bd2..dfe110bb 100644 --- a/app/src/main/java/crazydude/com/telemetry/ui/MapsActivity.kt +++ b/app/src/main/java/crazydude/com/telemetry/ui/MapsActivity.kt @@ -49,6 +49,7 @@ import crazydude.com.telemetry.service.DataService import crazydude.com.telemetry.ui.viewmodels.MapsViewModel import crazydude.com.telemetry.utils.DocumentLogFile import crazydude.com.telemetry.utils.LogFile +import crazydude.com.telemetry.utils.NullOutputStream import crazydude.com.telemetry.utils.StandardLogFile import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView import java.io.File @@ -888,7 +889,7 @@ class MapsActivity : AppCompatActivity() { private fun connectToBluetoothDevice(device: BluetoothDevice, isBLE: Boolean) { dataService?.let { - createLogFile()?.let { file -> + createLogFile().let { file -> it.connect(device, file, isBLE) } } @@ -899,7 +900,7 @@ class MapsActivity : AppCompatActivity() { connection: UsbDeviceConnection ) { dataService?.let { - createLogFile()?.let { file -> + createLogFile().let { file -> it.connect(port, connection, file) } } @@ -1144,9 +1145,9 @@ class MapsActivity : AppCompatActivity() { } } - private fun createLogFile(): OutputStream? { - var fileOutputStream: OutputStream? = null + private fun createLogFile(): OutputStream { if (preferenceManager.isLoggingEnabled()) { + var fileOutputStream: OutputStream val name = SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(Date()) if (!shouldUseStorageAPI()) { val dir = Environment.getExternalStoragePublicDirectory("TelemetryLogs") @@ -1167,7 +1168,7 @@ class MapsActivity : AppCompatActivity() { return fileOutputStream } - return null + return NullOutputStream() } private val batInfoReceiver: BroadcastReceiver = object : BroadcastReceiver() { diff --git a/app/src/main/java/crazydude/com/telemetry/utils/NullOutputStream.kt b/app/src/main/java/crazydude/com/telemetry/utils/NullOutputStream.kt new file mode 100644 index 00000000..70319641 --- /dev/null +++ b/app/src/main/java/crazydude/com/telemetry/utils/NullOutputStream.kt @@ -0,0 +1,9 @@ +package crazydude.com.telemetry.utils + +import java.io.OutputStream + +class NullOutputStream : OutputStream() { + override fun write(b: Int) { + // do nothing + } +} \ No newline at end of file