diff --git a/TODO.md b/TODO.md index c5ad4007..4b8e35dd 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,6 @@ -* make frontend using https://developer.android.com/jetpack/compose/tutorial +* use https://codelabs.developers.google.com/codelabs/jetpack-compose-basics/#4 to show service state *fix bluetooth # Medium priority @@ -23,3 +23,5 @@ Don't leave device discoverable. Don't let unpaired users do thing with device * assert() is apparently a noop - change to use my version of assert * DONE add crash reporting * DONE add analytics (make them optional) +* make frontend using https://developer.android.com/jetpack/compose/tutorial + diff --git a/app/build.gradle b/app/build.gradle index fa304c07..0ddb520f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,7 @@ android { buildFeatures { // Enables Jetpack Compose for this module - compose false // FIXME, if true main app crashes + compose true // NOTE, if true main app crashes if you use regular view layout functions } // Set both the Java and Kotlin compilers to target Java 8. diff --git a/app/src/main/java/com/geeksville/meshutil/MainActivity.kt b/app/src/main/java/com/geeksville/meshutil/MainActivity.kt index a7df116c..b9e7b650 100644 --- a/app/src/main/java/com/geeksville/meshutil/MainActivity.kt +++ b/app/src/main/java/com/geeksville/meshutil/MainActivity.kt @@ -13,12 +13,19 @@ import androidx.appcompat.app.AppCompatActivity import android.view.Menu import android.view.MenuItem import android.widget.Toast +import androidx.compose.Composable import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat +import androidx.ui.core.Text +import androidx.ui.core.dp +import androidx.ui.core.setContent +import androidx.ui.layout.Column +import androidx.ui.layout.Spacing +import androidx.ui.material.Button +import androidx.ui.material.MaterialTheme +import androidx.ui.tooling.preview.Preview import com.geeksville.android.Logging -import kotlinx.android.synthetic.main.activity_main.* -import java.util.* class MainActivity : AppCompatActivity(), Logging { @@ -66,22 +73,31 @@ class MainActivity : AppCompatActivity(), Logging { } } + @Composable + fun composeView() { + MaterialTheme { + Column { + Text(text = "MeshUtil Ugly UI", modifier = Spacing(16.dp)) + + Button(text = "Start scan", + onClick = { + if (bluetoothAdapter != null) { + SoftwareUpdateService.enqueueWork(this@MainActivity, SoftwareUpdateService.scanDevicesIntent) + } + }) + } + }} + + @Preview + @Composable + fun defaultPreview() { + composeView() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - setSupportActionBar(toolbar) - - fab.setOnClickListener { _ -> - /* Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() */ - - // test crash reporting - // logAssert(false) - // throw NotImplementedError("I like crap") - - if(bluetoothAdapter != null) { - SoftwareUpdateService.enqueueWork(this, SoftwareUpdateService.scanDevicesIntent) - } + setContent { + composeView() } // Ensures Bluetooth is available on the device and it is enabled. If not,