hard-coded elementsymbol into Array "elementButtonCurrent"

This commit is contained in:
matthias
2024-04-23 15:38:52 +02:00
parent 70408661a8
commit afc4f7e30a

View File

@@ -67,6 +67,15 @@ fun PSEContent(activity: ComponentActivity){
mutableStateOf(-1)
}
val elementConstructorList = listOf(
"H", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "He",
"Li", "Be", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "B", "C", "N", "O", "F", "Ne",
"Na", "Mg", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Al", "Si", "P", "S", "Cl", "Ar",
"K", "Ca", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr",
"Rb", "Sr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe",
"Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn",
"Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts", "Og"
)
val elementButtonCurrent = listOf(
0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1,
2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9,
10, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12, 13, 14, 15, 16, 17,
@@ -89,7 +98,7 @@ fun PSEContent(activity: ComponentActivity){
IconButton(onClick = { activity.finish() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = null,
contentDescription = "",
modifier = Modifier.size(60.dp),
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
@@ -101,7 +110,7 @@ fun PSEContent(activity: ComponentActivity){
}) {
Icon(
imageVector = Icons.Outlined.Info,
contentDescription = null,
contentDescription = "",
modifier = Modifier.size(28.dp),
tint = MaterialTheme.colorScheme.onPrimaryContainer
)
@@ -118,14 +127,14 @@ fun PSEContent(activity: ComponentActivity){
) {
Row {
for (i in 0 .. 31) {
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFBCA76D))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
} else {
Box(
@@ -138,14 +147,14 @@ fun PSEContent(activity: ComponentActivity){
}
Row {
for (i in 32 .. 63)
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFC65253))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
} else {
Box(
@@ -157,14 +166,14 @@ fun PSEContent(activity: ComponentActivity){
}
Row {
for (i in 64 .. 95)
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFF337733))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
} else {
Box(
@@ -176,15 +185,15 @@ fun PSEContent(activity: ComponentActivity){
}
Row {
for (i in 96 .. 127)
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
if (i in 112..121) {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFF337733))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
else {
@@ -192,9 +201,9 @@ fun PSEContent(activity: ComponentActivity){
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFDC2222))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
} else {
@@ -207,15 +216,15 @@ fun PSEContent(activity: ComponentActivity){
}
Row {
for (i in 128..159)
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
if (i in 144..153) {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFDC2222))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
else {
@@ -223,9 +232,9 @@ fun PSEContent(activity: ComponentActivity){
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFF129DC3))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
} else {
@@ -238,16 +247,16 @@ fun PSEContent(activity: ComponentActivity){
}
Row {
for (i in 160..191)
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
when (i) {
in 162..175 -> {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFDC2222))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
in 176..185 -> {
@@ -255,9 +264,9 @@ fun PSEContent(activity: ComponentActivity){
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFF129DC3))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
else -> {
@@ -265,9 +274,9 @@ fun PSEContent(activity: ComponentActivity){
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFDDCC69))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
}
@@ -281,16 +290,16 @@ fun PSEContent(activity: ComponentActivity){
}
Row {
for (i in 192 .. 223)
if (elementConstructorList[i] != -1) {
if (elementConstructorList[i] != "") {
when (i) {
in 194..207 -> {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFF129DC3))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
in 208..217 -> {
@@ -298,9 +307,9 @@ fun PSEContent(activity: ComponentActivity){
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFFDDCC69))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
else -> {
@@ -308,9 +317,9 @@ fun PSEContent(activity: ComponentActivity){
.padding(3.dp)
.size(60.dp)
.background(color = Color(0xFF7044DD))
.clickable { dialogChooser = elementConstructorList[i] }
.clickable { dialogChooser = elementButtonCurrent[i] }
) {
Text(modifier = Modifier.align(Alignment.Center), text = readElementSymbol(activity, elementConstructorList[i]), color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
Text(modifier = Modifier.align(Alignment.Center), text = elementConstructorList[i], color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton)
}
}
}
@@ -385,7 +394,6 @@ fun readElementData(context: Context, int: Int): String {
val elementDataArray = rootObj.getJSONArray("elements")
val elementData = elementDataArray.getJSONObject(int)
return "Name\n >>> ${elementData.get("Name")}\n\n" +
"Elementsymbol\n >>> ${elementData.get("Elementsymbol")}\n\n" +
"Molare Masse\n >>> ${elementData.get("Molare Masse")}\n\n" +
"Dichte\n >>> ${elementData.get("Dichte")}\n\n" +
"Elektronegativität\n >>> ${elementData.get("Elektronegativität")}\n\n" +
@@ -396,13 +404,4 @@ fun readElementData(context: Context, int: Int): String {
"Strahlungsart\n >>> ${elementData.get("Strahlungsart")}\n\n" +
"künstlich\n >>> ${elementData.get("künstlich")}\n\n" +
"langlebigstes Isotop\n >>> ${elementData.get("langlebigstes Isotop")}"
}
fun readElementSymbol(context: Context, int: Int): String {
val file = "elements_data.json"
val assetManager = context.assets
val inputStream = assetManager.open(file)
val rootObj = JSONObject(InputStreamReader(inputStream).readText())
val elementDataArray = rootObj.getJSONArray("elements")
val elementData = elementDataArray.getJSONObject(int)
return "${elementData.get("Elementsymbol")}"
}