-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a better demo app, add detekt, upgrade compose
Resolves #6
- Loading branch information
1 parent
adf4ad9
commit 5bfa0af
Showing
23 changed files
with
422 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/simonsickle/composedbarcodes/BarcodeList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
app/src/main/java/com/simonsickle/composedbarcodes/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
app/src/main/java/com/simonsickle/composedbarcodes/NavigationRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Aztec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Codabar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Code128.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Code39.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Code93.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/DataMatrix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Ean13.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/simonsickle/composedbarcodes/examples/Ean8.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.