Fix PSE jsonIndex

Update About Page
This commit is contained in:
BuildTools
2024-05-23 21:07:11 +02:00
parent cfdf00e0a5
commit e64a010e1d
2 changed files with 61 additions and 48 deletions

View File

@@ -24,6 +24,7 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
@@ -70,14 +71,18 @@ fun AboutContent(activity: ComponentActivity){
.verticalScroll(rememberScrollState())
.fillMaxWidth())
{
Spacer(modifier = Modifier.height(16.dp))
Text(text = "This Product is published under the\nGNU General Public License\nVersion 3, 29 June 2007",
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(start = 16.dp, end = 16.dp))
Spacer(modifier = Modifier.height(32.dp))
Text(text = "Developed by:\n- Paul Posch\n- Matthias Meyer\n- Jakub Szarko\n- Emilian Bührer",
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(start = 16.dp, end = 16.dp))
AboutTextElement("This Product is published under the\nGNU General Public License\nVersion 3, 29 June 2007", 16.dp)
AboutTextElement("Developed by:\n- Paul Posch\n- Matthias Meyer\n- Jakub Szarko\n- Emilian Bührer", 32.dp)
AboutTextElement("Fun Facts:\nThis app consists of 2.873 lines of code\nThe repository is 413KB big\nThe development took about 3 month", 64.dp) //TODO: Update before launch
}
}
}
@Composable
fun AboutTextElement(text: String, space: Dp){
Spacer(modifier = Modifier.height(space))
Text(text = text,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onBackground,
modifier = Modifier.padding(start = 16.dp, end = 16.dp))
}

View File

@@ -1,6 +1,5 @@
package com.schoolapp.cleverclass
import android.content.Context
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
@@ -94,34 +93,38 @@ private val shells = listOf(
"K", "L", "M", "N", "O", "P", "Q"
)
private val elementNameList = 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"
)
private val elementButtonColors = 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, 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, 1,
2, 2, -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, 2, 2, 2, 2, 2,
3, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5,
6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6
)
// Content of PSE
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PSEMainContent(activity: ComponentActivity) {
val inputStream = activity.assets.open("elements_data.json")
val rootObj = JSONObject(InputStreamReader(inputStream).readText())
var showInfo by remember {
mutableStateOf(false)
}
var dialogChooser by remember {
mutableStateOf(-1)
}
val elementNameList = 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 elementButtonColors = 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, 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, 1,
2, 2, -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, 2, 2, 2, 2, 2,
3, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3,
4, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4,
5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5,
6, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6
)
Column {
TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
@@ -174,22 +177,9 @@ fun PSEMainContent(activity: ComponentActivity) {
for (element in 0..31) {
val index = row * 32 + element
if (elementNameList[index] != "") {
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(
color = colors[elementButtonColors[index]],
shape = RoundedCornerShape(5)
)
.clickable { dialogChooser = ++dialogCounter }
) {
Text(
modifier = Modifier.align(Alignment.Center),
text = elementNameList[index],
color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton,
style = MaterialTheme.typography.labelLarge
)
}
val elementJsonIndex = dialogCounter
++dialogCounter
ElementBox(arrayIndex = index, onClick = { dialogChooser = elementJsonIndex })
} else {
Box(
modifier = Modifier
@@ -214,7 +204,7 @@ fun PSEMainContent(activity: ComponentActivity) {
modifier = Modifier
.verticalScroll(rememberScrollState())
.horizontalScroll(rememberScrollState()),
text = readElementData(activity, dcValue),
text = readElementData(rootObj, dcValue),
color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.labelMedium
)
@@ -264,6 +254,26 @@ fun PSEMainContent(activity: ComponentActivity) {
}
@Composable
fun ElementBox(arrayIndex: Int, onClick: () -> Unit){
Box(modifier = Modifier
.padding(3.dp)
.size(60.dp)
.background(
color = colors[elementButtonColors[arrayIndex]],
shape = RoundedCornerShape(5)
)
.clickable { onClick() }
) {
Text(
modifier = Modifier.align(Alignment.Center),
text = elementNameList[arrayIndex],
color = com.schoolapp.cleverclass.ui.theme.TextOnColouredButton,
style = MaterialTheme.typography.labelLarge
)
}
}
@Composable
fun InformationBox(text: String, color: Color){
Box(modifier = Modifier
@@ -283,10 +293,8 @@ fun InformationBox(text: String, color: Color){
}
}
fun readElementData(context: Context, int: Int): String {
val inputStream = context.assets.open("elements_data.json")
val rootObj = JSONObject(InputStreamReader(inputStream).readText())
val elementData = rootObj.getJSONArray("elements").getJSONObject(int)
private fun readElementData(jsonObject: JSONObject, int: Int): String {
val elementData = jsonObject.getJSONArray("elements").getJSONObject(int)
return "Name:\n${elementData.get("Name")}\n\n" +
"Ordnungszahl:\n${elementData.get("Ordnungszahl")}\n\n" +
"Gruppe:\n${elementData.get("Gruppe")}\n\n" +