Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Commit

Permalink
Add settings screen with logout button
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jan 21, 2022
1 parent ccd2c7f commit 51ee7a2
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/src/main/java/nl/kwyntes/roosterappie/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import nl.kwyntes.roosterappie.lib.AHScheduleService
import nl.kwyntes.roosterappie.lib.AuthData
import nl.kwyntes.roosterappie.ui.LoginScreen
import nl.kwyntes.roosterappie.ui.ScheduleScreen
import nl.kwyntes.roosterappie.ui.SettingsScreen
import nl.kwyntes.roosterappie.ui.theme.RoosterAppieTheme

val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "settings")
Expand Down Expand Up @@ -61,6 +62,7 @@ class MainActivity : ComponentActivity() {
) {
composable("login") { LoginScreen(navController, ahScheduleService) }
composable("schedule") { ScheduleScreen(navController, ahScheduleService) }
composable("settings") { SettingsScreen(navController, ahScheduleService) }
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/nl/kwyntes/roosterappie/ui/ScheduleScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import nl.kwyntes.roosterappie.lib.AHScheduleService
Expand All @@ -40,7 +40,12 @@ fun ScheduleScreen(navController: NavController, ahScheduleService: AHScheduleSe
topBar = {
TopAppBar(
backgroundColor = MaterialTheme.colors.primary,
title = { Text(monthYear.format()) }
title = { Text(monthYear.format()) },
actions = {
IconButton(onClick = { navController.navigate("settings") }) {
Icon(Icons.Filled.Settings, contentDescription = "Instellingen")
}
}
)
}
) { contentPadding ->
Expand Down
86 changes: 86 additions & 0 deletions app/src/main/java/nl/kwyntes/roosterappie/ui/SettingsScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package nl.kwyntes.roosterappie.ui

import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.datastore.preferences.core.edit
import androidx.navigation.NavController
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import nl.kwyntes.roosterappie.PREF_LOGIN_COOKIE
import nl.kwyntes.roosterappie.PREF_PASSWORD
import nl.kwyntes.roosterappie.PREF_PNL
import nl.kwyntes.roosterappie.dataStore
import nl.kwyntes.roosterappie.lib.AHScheduleService

@Composable
fun SettingsScreen(navController: NavController, ahScheduleService: AHScheduleService) {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()

Scaffold(
topBar = {
TopAppBar(
backgroundColor = MaterialTheme.colors.primary,
title = { Text("Instellingen") },
navigationIcon = {
IconButton(onClick = { navController.navigate("schedule") }) {
Icon(Icons.Filled.ArrowBack, contentDescription = "Terug")
}
}
)
}
) { contentPadding ->
Column(modifier = Modifier.padding(contentPadding)) {
Spacer(modifier = Modifier.height(20.dp))

Text(
"Uitloggen",

modifier = Modifier
.clickable {
coroutineScope.launch {
context.dataStore.edit {
it.remove(PREF_PNL)
it.remove(PREF_PASSWORD)
it.remove(PREF_LOGIN_COOKIE)
}
ahScheduleService.logout()

navController.navigate("login")
}
}
// Draw border only on top and bottom
.drawBehind {
val y = size.height - density / 2

drawLine(
Color.LightGray,
Offset(0f, 0f),
Offset(size.width, 0f),
density
)
drawLine(
Color.LightGray,
Offset(0f, y),
Offset(size.width, y),
density
)
}
.fillMaxWidth()
.padding(all = 20.dp)
)
}
}
}

0 comments on commit 51ee7a2

Please sign in to comment.