Skip to content

Commit 02329e1

Browse files
authored
Merge pull request #268 from rainxchzed/auth-improvement
2 parents 8f8888b + 1f1e2a1 commit 02329e1

38 files changed

Lines changed: 572 additions & 280 deletions

File tree

composeApp/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

composeApp/src/androidMain/res/drawable/ic_launcher_background.xml

Lines changed: 0 additions & 170 deletions
This file was deleted.

composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/Main.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import zed.rainxch.githubstore.app.deeplink.DeepLinkParser
1616
import zed.rainxch.githubstore.app.navigation.AppNavigation
1717
import zed.rainxch.githubstore.app.navigation.GithubStoreGraph
1818
import zed.rainxch.githubstore.app.components.RateLimitDialog
19+
import zed.rainxch.githubstore.app.components.SessionExpiredDialog
1920

2021
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
2122
@Composable
@@ -70,6 +71,18 @@ fun App(deepLinkUri: String? = null) {
7071
}
7172
}
7273

74+
if (state.showSessionExpiredDialog) {
75+
SessionExpiredDialog(
76+
onDismiss = {
77+
viewModel.onAction(MainAction.DismissSessionExpiredDialog)
78+
},
79+
onSignIn = {
80+
viewModel.onAction(MainAction.DismissSessionExpiredDialog)
81+
navBackStack.navigate(GithubStoreGraph.AuthenticationScreen)
82+
}
83+
)
84+
}
85+
7386
AppNavigation(
7487
navController = navBackStack
7588
)

composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/MainAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ package zed.rainxch.githubstore
22

33
sealed interface MainAction {
44
data object DismissRateLimitDialog : MainAction
5+
data object DismissSessionExpiredDialog : MainAction
56
}

composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/MainState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class MainState(
88
val isLoggedIn: Boolean = false,
99
val rateLimitInfo: RateLimitInfo? = null,
1010
val showRateLimitDialog: Boolean = false,
11+
val showSessionExpiredDialog: Boolean = false,
1112
val currentColorTheme: AppTheme = AppTheme.OCEAN,
1213
val isAmoledTheme: Boolean = false,
1314
val isDarkTheme: Boolean? = null,

composeApp/src/commonMain/kotlin/zed/rainxch/githubstore/MainViewModel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class MainViewModel(
8989
}
9090
}
9191

92+
viewModelScope.launch {
93+
authenticationState.sessionExpiredEvent.collect {
94+
_state.update { it.copy(showSessionExpiredDialog = true) }
95+
}
96+
}
97+
9298
viewModelScope.launch(Dispatchers.IO) {
9399
syncUseCase().onSuccess {
94100
installedAppsRepository.checkAllForUpdates()
@@ -101,6 +107,9 @@ class MainViewModel(
101107
MainAction.DismissRateLimitDialog -> {
102108
_state.update { it.copy(showRateLimitDialog = false) }
103109
}
110+
MainAction.DismissSessionExpiredDialog -> {
111+
_state.update { it.copy(showSessionExpiredDialog = false) }
112+
}
104113
}
105114
}
106115
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package zed.rainxch.githubstore.app.components
2+
3+
import androidx.compose.foundation.layout.Arrangement
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.material.icons.Icons
6+
import androidx.compose.material.icons.filled.LockOpen
7+
import androidx.compose.material3.AlertDialog
8+
import androidx.compose.material3.Button
9+
import androidx.compose.material3.Icon
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Text
12+
import androidx.compose.material3.TextButton
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.text.font.FontWeight
15+
import androidx.compose.ui.unit.dp
16+
import org.jetbrains.compose.resources.stringResource
17+
import zed.rainxch.githubstore.core.presentation.res.*
18+
19+
@Composable
20+
fun SessionExpiredDialog(
21+
onDismiss: () -> Unit,
22+
onSignIn: () -> Unit
23+
) {
24+
AlertDialog(
25+
onDismissRequest = onDismiss,
26+
icon = {
27+
Icon(
28+
imageVector = Icons.Default.LockOpen,
29+
contentDescription = null,
30+
tint = MaterialTheme.colorScheme.error
31+
)
32+
},
33+
title = {
34+
Text(
35+
text = stringResource(Res.string.session_expired_title),
36+
style = MaterialTheme.typography.headlineSmall,
37+
fontWeight = FontWeight.Black,
38+
color = MaterialTheme.colorScheme.onSurface
39+
)
40+
},
41+
text = {
42+
Column(
43+
verticalArrangement = Arrangement.spacedBy(8.dp)
44+
) {
45+
Text(
46+
text = stringResource(Res.string.session_expired_message),
47+
style = MaterialTheme.typography.bodyMedium,
48+
color = MaterialTheme.colorScheme.outline
49+
)
50+
51+
Text(
52+
text = stringResource(Res.string.session_expired_hint),
53+
style = MaterialTheme.typography.bodySmall,
54+
color = MaterialTheme.colorScheme.primary
55+
)
56+
}
57+
},
58+
confirmButton = {
59+
Button(onClick = onSignIn) {
60+
Text(
61+
text = stringResource(Res.string.sign_in_again),
62+
style = MaterialTheme.typography.bodySmall,
63+
color = MaterialTheme.colorScheme.onPrimary
64+
)
65+
}
66+
},
67+
dismissButton = {
68+
TextButton(onClick = onDismiss) {
69+
Text(
70+
text = stringResource(Res.string.continue_as_guest),
71+
style = MaterialTheme.typography.bodySmall,
72+
color = MaterialTheme.colorScheme.onSurface
73+
)
74+
}
75+
}
76+
)
77+
}

0 commit comments

Comments
 (0)