Skip to content

Commit

Permalink
Add a better demo app, add detekt, upgrade compose
Browse files Browse the repository at this point in the history
Resolves #6
  • Loading branch information
simonsickle committed Sep 25, 2021
1 parent adf4ad9 commit 5bfa0af
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 89 deletions.
29 changes: 28 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ dependencies {
implementation("androidx.compose.foundation:foundation-layout:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")

// Nav components
implementation("androidx.navigation:navigation-compose:2.4.0-alpha09")
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/simonsickle/composedbarcodes/BarcodeList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.simonsickle.composedbarcodes

import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.simonsickle.compose.barcodes.BarcodeType

@Composable
fun BarcodeList(navController: NavController) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
for (barcode in BarcodeType.values().sortedBy { it.name }) {
Spacer(modifier = Modifier.height(8.dp))
Button(onClick = {
navController.navigate(barcode.name)
}) {
Text(
text = barcode.name,
style = MaterialTheme.typography.button
)
}
Spacer(modifier = Modifier.height(8.dp))
}
}
}
53 changes: 5 additions & 48 deletions app/src/main/java/com/simonsickle/composedbarcodes/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,61 +1,18 @@
package com.simonsickle.composedbarcodes

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.simonsickle.compose.barcodes.Barcode
import com.simonsickle.compose.barcodes.BarcodeType
import com.simonsickle.composedbarcodes.ui.ComposedBarcodesTheme

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(ComposeView(this).apply {
setContent {
MainActivityContent()
}
})
}

@Preview
@Composable
private fun MainActivityContent() {
ComposedBarcodesTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Column(modifier = Modifier.fillMaxSize()) {

// Make sure the value is valid for the type of barcode selected
if (BarcodeType.QR_CODE.isValueValid(URL)) {

// Display the barcode to the user
Barcode(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.width(300.dp)
.height(300.dp),
type = BarcodeType.QR_CODE,
value = URL
)
}
}
setContent {
ComposedBarcodesTheme {
NavigationRegistry()
}
}
}

companion object {
private const val URL = "https://github.com/simonsickle"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.simonsickle.composedbarcodes

import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.simonsickle.compose.barcodes.BarcodeType
import com.simonsickle.composedbarcodes.examples.*

@Composable
fun NavigationRegistry() {
val title = remember { mutableStateOf("Barcode List") }
val navController = rememberNavController()
Scaffold(
topBar = {
TopAppBar(
navigationIcon = {
if (title.value != "Barcode List") {
IconButton(onClick = {
navController.popBackStack()
}) {
Icon(Icons.Filled.ArrowBack, "Back")
}
}
},
title = {
Text(
text = title.value,
style = MaterialTheme.typography.h5,
)
})
}
) {
NavHost(navController = navController, startDestination = "home") {
composable("home") {
title.value = "Barcode List"
BarcodeList(navController = navController)
}
composable(BarcodeType.AZTEC.name) {
title.value = "Aztec"
Aztec()
}
composable(BarcodeType.CODABAR.name) {
title.value = "Codabar"
Codabar()
}
composable(BarcodeType.CODE_128.name) {
title.value = "Code128"
Code128()
}
composable(BarcodeType.CODE_39.name) {
title.value = "Code39"
Code39()
}
composable(BarcodeType.CODE_93.name) {
title.value = "Code93"
Code93()
}
composable(BarcodeType.DATA_MATRIX.name) {
title.value = "DataMatrix"
DataMatrix()
}
composable(BarcodeType.EAN_13.name) {
title.value = "Ean13"
Ean13()
}
composable(BarcodeType.EAN_8.name) {
title.value = "Ean8"
Ean8()
}
composable(BarcodeType.ITF.name) {
title.value = "Itf"
Itf()
}
composable(BarcodeType.PDF_417.name) {
title.value = "Pdf 417"
Pdf417()
}
composable(BarcodeType.QR_CODE.name) {
title.value = "QR Code"
Qr()
}
composable(BarcodeType.UPC_A.name) {
title.value = "UPC A"
UpcA()
}
composable(BarcodeType.UPC_E.name) {
title.value = "UPC E"
UpcE()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "123456823232"

@Preview
@Composable
fun Aztec() {
GenericBarcodeExample(barcodeType = BarcodeType.AZTEC, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "31117013206375"

@Preview
@Composable
fun Codabar() {
GenericBarcodeExample(barcodeType = BarcodeType.CODABAR, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "123456823232"

@Preview
@Composable
fun Code128() {
GenericBarcodeExample(barcodeType = BarcodeType.CODE_128, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "CODE-39P"

@Preview
@Composable
fun Code39() {
GenericBarcodeExample(barcodeType = BarcodeType.CODE_39, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "CODE-39P"

@Preview
@Composable
fun Code93() {
GenericBarcodeExample(barcodeType = BarcodeType.CODE_93, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "123456823232"

@Preview
@Composable
fun DataMatrix() {
GenericBarcodeExample(barcodeType = BarcodeType.DATA_MATRIX, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "978020137962"

@Preview
@Composable
fun Ean13() {
GenericBarcodeExample(barcodeType = BarcodeType.EAN_13, value = BARCODE_VALUE)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.simonsickle.composedbarcodes.examples

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.simonsickle.compose.barcodes.BarcodeType

private const val BARCODE_VALUE = "23232426"

@Preview
@Composable
fun Ean8() {
GenericBarcodeExample(barcodeType = BarcodeType.EAN_8, value = BARCODE_VALUE)
}
Loading

0 comments on commit 5bfa0af

Please sign in to comment.