Files
CleverClass/app/src/main/java/com/schoolapp/cleverclass/SettingsActivity.kt
BuildTools 1c6c814736 Add Options in settings
Add License and Readme
Fixed color issues
Update About page
Fixed About button and package
2024-03-21 19:22:49 +01:00

144 lines
5.1 KiB
Kotlin

package com.schoolapp.cleverclass
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.SharedPreferences.Editor
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
class SettingsActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CleverClassTheme {
Surface(modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background) {
SettingsContent(activity = this)
}
}
}
}
}
// Content of Settings
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsContent(activity: ComponentActivity) {
val sharedPreferences = activity.getSharedPreferences("Settings", Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
Column(modifier = Modifier.fillMaxSize()) {
// Top AppBar
TopAppBar(
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
title = {
Text(
text = "Einstellungen",
style = MaterialTheme.typography.headlineSmall
)
},
navigationIcon = {
IconButton(onClick = { activity.finish() }) {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = null,
modifier = Modifier.size(28.dp)
)
}
},
modifier = Modifier.fillMaxWidth()
)
// Settings
Column(
modifier = Modifier
.weight(1f)
.verticalScroll(rememberScrollState())
.fillMaxWidth()
) {
Setting(text = "Stundenplan", sharedPreferences, editor)
Setting(text = "Noten", sharedPreferences, editor)
Setting(text = "Periodensystem", sharedPreferences, editor)
Setting(text = "Mebis", sharedPreferences, editor)
Setting(text = "DSBmobile", sharedPreferences, editor)
}
// About Button
Column(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Divider()
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "About",
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.clickable {
val intent = Intent(activity, AboutActivity::class.java)
activity.startActivity(intent)
}
)
Spacer(modifier = Modifier.height(16.dp))
}
}
}
@Composable
fun Setting(text : String, sharedPreferences: SharedPreferences, editor: Editor){
val checkedState = remember { mutableStateOf(sharedPreferences.getBoolean(text, true)) }
Spacer(modifier = Modifier.height(16.dp))
Row(verticalAlignment = Alignment.CenterVertically) {
Spacer(modifier = Modifier.width(16.dp))
Switch(
checked = checkedState.value,
onCheckedChange = { isChecked ->
checkedState.value = isChecked
editor.putBoolean(text, isChecked)
editor.apply()
}
)
Spacer(modifier = Modifier.width(16.dp))
Text(text = text,
color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.labelMedium)
}
}