Add Options in settings
Add License and Readme Fixed color issues Update About page Fixed About button and package
This commit is contained in:
@@ -2,6 +2,7 @@ package com.schoolapp.cleverclass
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
@@ -27,6 +28,11 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
@@ -53,6 +59,7 @@ class MainActivity : ComponentActivity() {
|
||||
@Composable
|
||||
fun MainContent(){
|
||||
val context = LocalContext.current
|
||||
val sharedPreferences = context.getSharedPreferences("Settings", Context.MODE_PRIVATE)
|
||||
|
||||
Column{
|
||||
TopAppBar(
|
||||
@@ -75,11 +82,11 @@ fun MainContent(){
|
||||
)
|
||||
|
||||
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
|
||||
MainButton(onClick = { /*TODO: Stundenplan activity*/ }, color = Color(0xFFFF4081), text = "Stundenplan")
|
||||
MainButton(onClick = { /*TODO: Noten activity*/ }, color = Color(0xFFFFAB40), text = "Noten")
|
||||
MainButton(onClick = { switchToActivity(context, PSEActivity::class.java) }, color = Color(0xFF536DFE), text = "Periodensystem")
|
||||
MainButton(onClick = { /*TODO: Mebis activity*/ }, color = Color(0xFFE040FB), text = "Mebis")
|
||||
MainButton(onClick = { /*TODO: DSBmobile activity*/ }, color = Color(0xFFFF6E40), text = "DSBmobile")
|
||||
MainButton(onClick = { /*TODO: Stundenplan activity*/ }, color = Color(0xFFFF4081), text = "Stundenplan", sharedPreferences)
|
||||
MainButton(onClick = { /*TODO: Noten activity*/ }, color = Color(0xFFFFAB40), text = "Noten", sharedPreferences)
|
||||
MainButton(onClick = { switchToActivity(context, PSEActivity::class.java) }, color = Color(0xFF536DFE), text = "Periodensystem", sharedPreferences)
|
||||
MainButton(onClick = { /*TODO: Mebis activity*/ }, color = Color(0xFFE040FB), text = "Mebis", sharedPreferences)
|
||||
MainButton(onClick = { /*TODO: DSBmobile activity*/ }, color = Color(0xFFFF6E40), text = "DSBmobile", sharedPreferences)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,20 +94,47 @@ fun MainContent(){
|
||||
|
||||
// Main-menu Buttons
|
||||
@Composable
|
||||
fun MainButton(onClick: () -> Unit, color : Color, text : String) {
|
||||
fun MainButton(onClick: () -> Unit, color : Color, text : String, sharedPreferences: SharedPreferences) {
|
||||
var enabledState by remember(text) {
|
||||
mutableStateOf(getButtonEnabledState(sharedPreferences, text))
|
||||
}
|
||||
|
||||
Button(
|
||||
enabled = enabledState,
|
||||
onClick = onClick,
|
||||
shape = RoundedCornerShape(40),
|
||||
colors = ButtonDefaults.outlinedButtonColors(containerColor = color),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(128.dp)
|
||||
.height(if (enabledState) 128.dp else 0.dp)
|
||||
.padding(start = 16.dp, end = 16.dp, top = 16.dp)
|
||||
) {
|
||||
Text(text,
|
||||
color = MaterialTheme.colorScheme.background,
|
||||
style = MaterialTheme.typography.labelMedium)
|
||||
}
|
||||
|
||||
|
||||
// changes state when Shared Preference is updated
|
||||
val observer = remember {
|
||||
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||
if (key == text) {
|
||||
enabledState = getButtonEnabledState(sharedPreferences, text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// handles observer creation and disposal
|
||||
DisposableEffect(Unit) {
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(observer)
|
||||
onDispose {
|
||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(observer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getButtonEnabledState(sharedPreferences: SharedPreferences, key: String): Boolean {
|
||||
return sharedPreferences.getBoolean(key, true)
|
||||
}
|
||||
|
||||
fun switchToActivity(context : Context, activity : Class<*>){
|
||||
|
||||
Reference in New Issue
Block a user