316 lines
13 KiB
Kotlin
316 lines
13 KiB
Kotlin
package com.schoolapp.cleverclass
|
|
|
|
import android.content.Context
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.size
|
|
import androidx.compose.foundation.rememberScrollState
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.foundation.text.selection.TextSelectionColors
|
|
import androidx.compose.foundation.verticalScroll
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.ArrowBack
|
|
import androidx.compose.material.icons.outlined.Delete
|
|
import androidx.compose.material.icons.outlined.Info
|
|
import androidx.compose.material3.AlertDialog
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.IconButton
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.OutlinedTextField
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TextFieldDefaults
|
|
import androidx.compose.material3.TopAppBar
|
|
import androidx.compose.material3.TopAppBarDefaults
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.res.painterResource
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
|
import androidx.compose.ui.text.input.VisualTransformation
|
|
import androidx.compose.ui.unit.dp
|
|
import com.schoolapp.cleverclass.ui.theme.CleverClassTheme
|
|
import com.schoolapp.cleverclass.ui.theme.InputPrimaryColor
|
|
import com.schoolapp.cleverclass.ui.theme.InputSecondaryColor
|
|
|
|
private lateinit var activityType : String
|
|
|
|
class DSBLoginActivity : ComponentActivity() {
|
|
companion object{
|
|
const val TYPE_KEY = "type_key"
|
|
}
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
activityType = intent.getStringExtra(TYPE_KEY).toString()
|
|
|
|
setContent {
|
|
CleverClassTheme {
|
|
Surface(
|
|
modifier = Modifier.fillMaxSize(),
|
|
color = MaterialTheme.colorScheme.background
|
|
) {
|
|
DSBLoginContent(activity = this)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Content of DSBLogin
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
@Composable
|
|
fun DSBLoginContent(activity: ComponentActivity){
|
|
val inputFieldColors = TextFieldDefaults.outlinedTextFieldColors(
|
|
textColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
containerColor = MaterialTheme.colorScheme.secondaryContainer,
|
|
cursorColor = InputPrimaryColor,
|
|
selectionColors = TextSelectionColors(
|
|
handleColor = InputPrimaryColor,
|
|
backgroundColor = InputSecondaryColor
|
|
),
|
|
focusedBorderColor = InputSecondaryColor,
|
|
unfocusedBorderColor = Color.Transparent
|
|
)
|
|
|
|
val sharedPreferences = activity.getSharedPreferences("DSBmobile", Context.MODE_PRIVATE)
|
|
val editor = sharedPreferences.edit()
|
|
|
|
var username by remember {
|
|
mutableStateOf(sharedPreferences.getString("username", "").toString())
|
|
}
|
|
var password by remember {
|
|
mutableStateOf(sharedPreferences.getString("password", "").toString())
|
|
}
|
|
var showPassword by remember {
|
|
mutableStateOf(false)
|
|
}
|
|
|
|
var showInfo by remember {
|
|
mutableStateOf(false)
|
|
}
|
|
var showDeleteConfirmation by remember {
|
|
mutableStateOf(false)
|
|
}
|
|
|
|
Column {
|
|
TopAppBar(
|
|
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(MaterialTheme.colorScheme.primaryContainer),
|
|
title = { Text(text = "") },
|
|
navigationIcon = {
|
|
IconButton(onClick = { activity.finish() }) {
|
|
Icon(
|
|
imageVector = Icons.Filled.ArrowBack,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(28.dp),
|
|
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
}
|
|
},
|
|
modifier = Modifier.fillMaxWidth()
|
|
)
|
|
|
|
Column(
|
|
verticalArrangement = Arrangement.Center,
|
|
modifier = Modifier
|
|
.fillMaxHeight()
|
|
.verticalScroll(rememberScrollState())
|
|
) {
|
|
Surface(
|
|
color = MaterialTheme.colorScheme.primaryContainer,
|
|
shape = RoundedCornerShape(20),
|
|
modifier = Modifier.padding(16.dp)
|
|
) {
|
|
Column(horizontalAlignment = Alignment.CenterHorizontally,
|
|
modifier = Modifier.padding(16.dp)
|
|
) {
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
Text(
|
|
text = "DSBmobile Login Daten",
|
|
style = MaterialTheme.typography.labelMedium,
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
modifier = Modifier.padding(10.dp)
|
|
)
|
|
|
|
Spacer(modifier = Modifier.weight(1f))
|
|
|
|
if (activityType == "Settings")
|
|
IconButton(onClick = { showDeleteConfirmation = !showDeleteConfirmation }) {
|
|
Icon(
|
|
imageVector = Icons.Outlined.Delete,
|
|
contentDescription = null,
|
|
modifier = Modifier.size(28.dp),
|
|
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
}
|
|
else if (activityType == "FirstTime")
|
|
IconButton(onClick = { showInfo = !showInfo }) {
|
|
Icon(
|
|
imageVector = Icons.Outlined.Info,
|
|
contentDescription = null,
|
|
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
}
|
|
}
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
OutlinedTextField(
|
|
value = username,
|
|
onValueChange = { username = it },
|
|
placeholder = {
|
|
Text(
|
|
text = "Benutzername",
|
|
style = MaterialTheme.typography.labelMedium,
|
|
color = MaterialTheme.colorScheme.primaryContainer
|
|
)
|
|
},
|
|
modifier = Modifier.fillMaxWidth(),
|
|
singleLine = true,
|
|
shape = RoundedCornerShape(20),
|
|
textStyle = MaterialTheme.typography.labelMedium,
|
|
colors = inputFieldColors
|
|
)
|
|
|
|
Spacer(modifier = Modifier.height(16.dp))
|
|
|
|
OutlinedTextField(
|
|
value = password,
|
|
onValueChange = { password = it },
|
|
placeholder = {
|
|
Text(
|
|
text = "Passwort",
|
|
style = MaterialTheme.typography.labelMedium,
|
|
color = MaterialTheme.colorScheme.primaryContainer
|
|
)
|
|
},
|
|
modifier = Modifier.fillMaxWidth(),
|
|
singleLine = true,
|
|
shape = RoundedCornerShape(20),
|
|
textStyle = MaterialTheme.typography.labelMedium,
|
|
colors = inputFieldColors,
|
|
visualTransformation = if(showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
|
|
trailingIcon = {
|
|
IconButton(onClick = { showPassword = !showPassword })
|
|
{
|
|
Image(
|
|
painter = painterResource(
|
|
id = if(showPassword)
|
|
R.drawable.baseline_visibility_24
|
|
else
|
|
R.drawable.baseline_visibility_off_24
|
|
),
|
|
contentDescription = null,
|
|
)
|
|
}
|
|
}
|
|
)
|
|
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
|
|
Box(
|
|
contentAlignment = Alignment.Center,
|
|
modifier = Modifier.clickable {
|
|
editor.putString("username", username)
|
|
editor.putString("password", password)
|
|
editor.apply()
|
|
activity.finish()
|
|
}
|
|
) {
|
|
Text(
|
|
text = "Speichern",
|
|
color = MaterialTheme.colorScheme.secondary,
|
|
style = MaterialTheme.typography.labelMedium,
|
|
modifier = Modifier.padding(10.dp)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (showInfo) {
|
|
AlertDialog(
|
|
onDismissRequest = { showInfo = false },
|
|
text = {
|
|
Text(
|
|
text = "Der Benutzername und das Passwort können später in den Einstellungen geändert werden",
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
style = MaterialTheme.typography.labelMedium)
|
|
},
|
|
confirmButton = {
|
|
Text(
|
|
text = "Schließen",
|
|
color = MaterialTheme.colorScheme.secondary,
|
|
style = MaterialTheme.typography.labelMedium,
|
|
modifier = Modifier.clickable { showInfo = false }
|
|
)
|
|
},
|
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
modifier = Modifier
|
|
.padding(5.dp)
|
|
)
|
|
}
|
|
|
|
if (showDeleteConfirmation) {
|
|
AlertDialog(
|
|
onDismissRequest = { showDeleteConfirmation = false },
|
|
text = {
|
|
Text(
|
|
text = "Möchten Sie wirklich die Anmeldedaten löschen?",
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
style = MaterialTheme.typography.labelMedium
|
|
)
|
|
},
|
|
confirmButton = {
|
|
Row(modifier = Modifier.fillMaxWidth()){
|
|
Text(
|
|
text = "Bestätigen",
|
|
color = MaterialTheme.colorScheme.secondary,
|
|
style = MaterialTheme.typography.labelMedium,
|
|
modifier = Modifier.clickable {
|
|
editor.putString("username", "")
|
|
editor.putString("password", "")
|
|
editor.apply()
|
|
showDeleteConfirmation = false
|
|
activity.finish()
|
|
}
|
|
)
|
|
|
|
Spacer(modifier = Modifier.weight(1f))
|
|
|
|
Text(
|
|
text = "Abbrechen",
|
|
color = MaterialTheme.colorScheme.secondary,
|
|
style = MaterialTheme.typography.labelMedium,
|
|
modifier = Modifier.clickable { showDeleteConfirmation = false }
|
|
)
|
|
}
|
|
},
|
|
containerColor = MaterialTheme.colorScheme.primaryContainer
|
|
)
|
|
}
|
|
} |