@@ -40,26 +40,23 @@ import androidx.compose.material3.TopAppBarDefaults
4040import androidx.compose.runtime.Composable
4141import androidx.compose.runtime.CompositionLocalProvider
4242import androidx.compose.runtime.getValue
43- import androidx.compose.runtime.mutableStateOf
4443import androidx.compose.runtime.remember
4544import androidx.compose.runtime.rememberCoroutineScope
46- import androidx.compose.runtime.setValue
4745import androidx.compose.ui.Alignment
4846import androidx.compose.ui.Modifier
4947import androidx.compose.ui.draw.shadow
5048import androidx.compose.ui.graphics.Brush
5149import androidx.compose.ui.graphics.Color
50+ import androidx.compose.ui.tooling.preview.Preview
5251import androidx.compose.ui.unit.dp
5352import androidx.lifecycle.compose.collectAsStateWithLifecycle
54- import zed.rainxch.githubstore.core.presentation.res.*
5553import io.github.fletchmckee.liquid.LiquidState
5654import io.github.fletchmckee.liquid.liquefiable
5755import io.github.fletchmckee.liquid.liquid
5856import io.github.fletchmckee.liquid.rememberLiquidState
5957import kotlinx.coroutines.launch
6058import org.jetbrains.compose.resources.getString
6159import org.jetbrains.compose.resources.stringResource
62- import androidx.compose.ui.tooling.preview.Preview
6360import org.koin.compose.viewmodel.koinViewModel
6461import zed.rainxch.core.presentation.theme.GithubStoreTheme
6562import zed.rainxch.core.presentation.utils.ObserveAsEvents
@@ -72,7 +69,26 @@ import zed.rainxch.details.presentation.components.sections.logs
7269import zed.rainxch.details.presentation.components.sections.stats
7370import zed.rainxch.details.presentation.components.sections.whatsNew
7471import zed.rainxch.details.presentation.components.states.ErrorState
72+ import zed.rainxch.details.presentation.model.TranslationTarget
7573import zed.rainxch.details.presentation.utils.LocalTopbarLiquidState
74+ import zed.rainxch.githubstore.core.presentation.res.Res
75+ import zed.rainxch.githubstore.core.presentation.res.add_to_favourites
76+ import zed.rainxch.githubstore.core.presentation.res.cancel
77+ import zed.rainxch.githubstore.core.presentation.res.dismiss
78+ import zed.rainxch.githubstore.core.presentation.res.downgrade_requires_uninstall
79+ import zed.rainxch.githubstore.core.presentation.res.downgrade_warning_message
80+ import zed.rainxch.githubstore.core.presentation.res.install_permission_blocked_message
81+ import zed.rainxch.githubstore.core.presentation.res.install_permission_unavailable
82+ import zed.rainxch.githubstore.core.presentation.res.navigate_back
83+ import zed.rainxch.githubstore.core.presentation.res.open_repository
84+ import zed.rainxch.githubstore.core.presentation.res.open_with_external_installer
85+ import zed.rainxch.githubstore.core.presentation.res.remove_from_favourites
86+ import zed.rainxch.githubstore.core.presentation.res.repository_not_starred
87+ import zed.rainxch.githubstore.core.presentation.res.repository_starred
88+ import zed.rainxch.githubstore.core.presentation.res.share_repository
89+ import zed.rainxch.githubstore.core.presentation.res.star_from_github
90+ import zed.rainxch.githubstore.core.presentation.res.uninstall_first
91+ import zed.rainxch.githubstore.core.presentation.res.unstar_from_github
7692
7793@Composable
7894fun DetailsRoot (
@@ -84,37 +100,56 @@ fun DetailsRoot(
84100 val state by viewModel.state.collectAsStateWithLifecycle()
85101 val snackbarHostState = remember { SnackbarHostState () }
86102 val coroutineScope = rememberCoroutineScope()
87- var downgradeWarning by remember {
88- mutableStateOf<DetailsEvent .ShowDowngradeWarning ?>(null )
89- }
90103
91104 ObserveAsEvents (viewModel.events) { event ->
92105 when (event) {
93106 is DetailsEvent .OnOpenRepositoryInApp -> {
94107 onOpenRepositoryInApp(event.repositoryId)
95108 }
96109
97- is DetailsEvent .InstallTrackingFailed -> {
98-
99- }
100-
101110 is DetailsEvent .OnMessage -> {
102111 coroutineScope.launch {
103112 snackbarHostState.showSnackbar(event.message)
104113 }
105114 }
115+ }
116+ }
106117
107- is DetailsEvent .ShowDowngradeWarning -> {
108- downgradeWarning = event
118+ DetailsScreen (
119+ state = state,
120+ snackbarHostState = snackbarHostState,
121+ onAction = { action ->
122+ when (action) {
123+ DetailsAction .OnNavigateBackClick -> {
124+ onNavigateBack()
125+ }
126+
127+ is DetailsAction .OpenDeveloperProfile -> {
128+ onNavigateToDeveloperProfile(action.username)
129+ }
130+
131+ is DetailsAction .OnMessage -> {
132+ coroutineScope.launch {
133+ snackbarHostState.showSnackbar(getString(action.messageText))
134+ }
135+ }
136+
137+ else -> {
138+ viewModel.onAction(action)
139+ }
109140 }
110141 }
111- }
142+ )
112143
113- downgradeWarning?.let { warning ->
144+ state. downgradeWarning?.let { warning ->
114145 AlertDialog (
115- onDismissRequest = { downgradeWarning = null },
146+ onDismissRequest = {
147+ viewModel.onAction(DetailsAction .OnDismissDowngradeWarning )
148+ },
116149 title = {
117- Text (text = stringResource(Res .string.downgrade_requires_uninstall))
150+ Text (
151+ text = stringResource(Res .string.downgrade_requires_uninstall)
152+ )
118153 },
119154 text = {
120155 Text (
@@ -128,7 +163,7 @@ fun DetailsRoot(
128163 confirmButton = {
129164 TextButton (
130165 onClick = {
131- downgradeWarning = null
166+ viewModel.onAction( DetailsAction . OnDismissDowngradeWarning )
132167 viewModel.onAction(DetailsAction .UninstallApp )
133168 }
134169 ) {
@@ -139,8 +174,14 @@ fun DetailsRoot(
139174 }
140175 },
141176 dismissButton = {
142- TextButton (onClick = { downgradeWarning = null }) {
143- Text (text = stringResource(Res .string.cancel))
177+ TextButton (
178+ onClick = {
179+ viewModel.onAction(DetailsAction .OnDismissDowngradeWarning )
180+ }
181+ ) {
182+ Text (
183+ text = stringResource(Res .string.cancel)
184+ )
144185 }
145186 }
146187 )
@@ -177,32 +218,6 @@ fun DetailsRoot(
177218 }
178219 )
179220 }
180-
181- DetailsScreen (
182- state = state,
183- snackbarHostState = snackbarHostState,
184- onAction = { action ->
185- when (action) {
186- DetailsAction .OnNavigateBackClick -> {
187- onNavigateBack()
188- }
189-
190- is DetailsAction .OpenDeveloperProfile -> {
191- onNavigateToDeveloperProfile(action.username)
192- }
193-
194- is DetailsAction .OnMessage -> {
195- coroutineScope.launch {
196- snackbarHostState.showSnackbar(getString(action.messageText))
197- }
198- }
199-
200- else -> {
201- viewModel.onAction(action)
202- }
203- }
204- }
205- )
206221}
207222
208223@OptIn(ExperimentalMaterial3Api ::class , ExperimentalMaterial3ExpressiveApi ::class )
@@ -226,7 +241,9 @@ fun DetailsScreen(
226241 )
227242 },
228243 snackbarHost = {
229- SnackbarHost (snackbarHostState)
244+ SnackbarHost (
245+ hostState = snackbarHostState
246+ )
230247 },
231248 containerColor = MaterialTheme .colorScheme.background,
232249 modifier = Modifier .liquefiable(liquidTopbarState)
@@ -242,7 +259,12 @@ fun DetailsScreen(
242259 onLanguageSelected = { language ->
243260 when (state.languagePickerTarget) {
244261 TranslationTarget .About -> onAction(DetailsAction .TranslateAbout (language.code))
245- TranslationTarget .WhatsNew -> onAction(DetailsAction .TranslateWhatsNew (language.code))
262+ TranslationTarget .WhatsNew -> onAction(
263+ DetailsAction .TranslateWhatsNew (
264+ language.code
265+ )
266+ )
267+
246268 null -> {}
247269 }
248270 onAction(DetailsAction .DismissLanguagePicker )
@@ -524,16 +546,16 @@ private fun DetailsTopbar(
524546 )
525547 .then(
526548 if (isLiquidFrostAvailable()) {
527- Modifier .liquid(liquidTopbarState) {
528- this .shape = CutCornerShape (0 .dp)
529- if (isLiquidFrostAvailable()) {
530- this .frost = 5 .dp
549+ Modifier .liquid(liquidTopbarState) {
550+ this .shape = CutCornerShape (0 .dp)
551+ if (isLiquidFrostAvailable()) {
552+ this .frost = 5 .dp
553+ }
554+ this .curve = .25f
555+ this .refraction = .05f
556+ this .dispersion = .1f
531557 }
532- this .curve = .25f
533- this .refraction = .05f
534- this .dispersion = .1f
535- }
536- } else Modifier .background(MaterialTheme .colorScheme.surfaceContainerHighest))
558+ } else Modifier .background(MaterialTheme .colorScheme.surfaceContainerHighest))
537559 )
538560}
539561
0 commit comments