From c6b11b60d22385aed498e7d3c48a31305e7a2c2e Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 22 Jan 2020 13:02:24 -0800 Subject: [PATCH] misc --- TODO.md | 2 ++ app/build.gradle | 14 +++++++--- .../com/geeksville/meshutil/MainActivity.kt | 27 ++++++++++++------- build.gradle | 1 + 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index bb7614f63..b7e94c655 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,7 @@ # Medium priority +* remove secret google settings json before open sourcing * require user auth to pair with the device (i.e. press button on device to allow a new phone to pair with it). Don't leave device discoverable. Don't let unpaired users do thing with device * add crash reporting @@ -12,4 +13,5 @@ Don't leave device discoverable. Don't let unpaired users do thing with device # Low priority +* possibly use finotes for analytics https://finotes.com/ * also add a receiver that fires after a new update was installed from the play stoe \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index a81c82c83..c6e3275d4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,7 @@ android { buildFeatures { // Enables Jetpack Compose for this module - compose true + compose false // FIXME, if true main app crashes } // Set both the Java and Kotlin compilers to target Java 8. @@ -50,9 +50,15 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' // You also need to include the following Compose toolkit dependencies. - implementation 'androidx.ui:ui-tooling:0.1.0-dev02' - implementation 'androidx.ui:ui-layout:0.1.0-dev02' - implementation 'androidx.ui:ui-material:0.1.0-dev02' + implementation("androidx.compose:compose-runtime:$compose_version") + implementation("androidx.ui:ui-framework:$compose_version") + implementation("androidx.ui:ui-layout:$compose_version") + implementation("androidx.ui:ui-material:$compose_version") + implementation("androidx.ui:ui-foundation:$compose_version") + implementation("androidx.ui:ui-animation:$compose_version") + implementation "androidx.ui:ui-tooling:$compose_version" + androidTestImplementation("androidx.ui:ui-platform:$compose_version") + androidTestImplementation("androidx.ui:ui-test:$compose_version") // add the Firebase SDK for Google Analytics diff --git a/app/src/main/java/com/geeksville/meshutil/MainActivity.kt b/app/src/main/java/com/geeksville/meshutil/MainActivity.kt index bcf00a66f..868217d3b 100644 --- a/app/src/main/java/com/geeksville/meshutil/MainActivity.kt +++ b/app/src/main/java/com/geeksville/meshutil/MainActivity.kt @@ -12,6 +12,7 @@ import com.google.android.material.snackbar.Snackbar import androidx.appcompat.app.AppCompatActivity import android.view.Menu import android.view.MenuItem +import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat @@ -26,9 +27,9 @@ class MainActivity : AppCompatActivity() { const val DID_REQUEST_PERM = 11 } - private val bluetoothAdapter: BluetoothAdapter by lazy(LazyThreadSafetyMode.NONE) { + private val bluetoothAdapter: BluetoothAdapter? by lazy(LazyThreadSafetyMode.NONE) { val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager - bluetoothManager.adapter!! + bluetoothManager.adapter } fun requestPermission() { @@ -59,7 +60,6 @@ class MainActivity : AppCompatActivity() { // result of the request. } else { // Permission has already been granted - SoftwareUpdateService.enqueueWork(this, SoftwareUpdateService.scanDevicesIntent) } } @@ -68,16 +68,25 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) setSupportActionBar(toolbar) - fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() + fab.setOnClickListener { _ -> + /* Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show() */ + + if(bluetoothAdapter != null) { + SoftwareUpdateService.enqueueWork(this, SoftwareUpdateService.scanDevicesIntent) + } } // Ensures Bluetooth is available on the device and it is enabled. If not, // displays a dialog requesting user permission to enable Bluetooth. - bluetoothAdapter.takeIf { !it.isEnabled }?.apply { - val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE) - startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT) + if(bluetoothAdapter != null) { + bluetoothAdapter!!.takeIf { !it.isEnabled }?.apply { + val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE) + startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT) + } + } + else { + Toast.makeText(this, "Error - this app requires bluetooth", Toast.LENGTH_LONG).show() } requestPermission() diff --git a/build.gradle b/build.gradle index 067ddf1f7..0dcbcd5de 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ buildscript { ext.kotlin_version = '1.3.61' + ext.compose_version = '0.1.0-dev03' repositories { google() jcenter()