This repository has been archived by the owner on Feb 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add settings screen with logout button
- Loading branch information
BuildTools
committed
Jan 21, 2022
1 parent
ccd2c7f
commit 51ee7a2
Showing
4 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/src/main/java/nl/kwyntes/roosterappie/ui/SettingsScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} | ||
} |