Skip to content

Commit 3abe536

Browse files
authored
MVI Lifecycle - Patch 1 (#60)
1 parent 3f57bc1 commit 3abe536

File tree

14 files changed

+56
-27
lines changed

14 files changed

+56
-27
lines changed

core/ui/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dependencies {
3030

3131
api androidx.composeUiGraphics
3232
api androidx.lifecycleViewModel
33+
api androidx.lifecycleCompose
3334
api google.accompanistSystemUiController
3435

3536
implementation reactive.rxjava

core/ui/src/main/java/com/shifthackz/aisdv1/core/ui/MviExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package com.shifthackz.aisdv1.core.ui
44

55
import androidx.compose.runtime.Composable
6-
import androidx.compose.runtime.collectAsState
76
import androidx.compose.ui.graphics.Color
7+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
88
import com.shifthackz.aisdv1.core.viewmodel.MviViewModel
99

1010
@Composable
@@ -29,7 +29,7 @@ fun <S : MviState, E : MviEffect> MviComposable(
2929

3030
@Composable
3131
override fun Content() {
32-
val state = viewModel.state.collectAsState().value
32+
val state = viewModel.state.collectAsStateWithLifecycle().value
3333
content(state)
3434
}
3535

gradle/dependencies.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ext {
44
composeUiToolingVersion = '1.4.3'
55
composeNavVersion = '2.5.3'
66
lifecycleViewModelVersion = '2.6.1'
7+
lifecycleComposeVersion = '2.6.0'
78
coreKtxVersion = '1.10.1'
89
appCompatVersion = '1.6.1'
910
activityVersion = '1.7.1'
@@ -48,6 +49,7 @@ ext {
4849
composeViewModel : "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycleViewModelVersion",
4950
composeNavigation : "androidx.navigation:navigation-compose:$composeNavVersion",
5051
lifecycleViewModel : "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleViewModelVersion",
52+
lifecycleCompose : "androidx.lifecycle:lifecycle-runtime-compose:$lifecycleComposeVersion",
5153
pagingRuntime : "androidx.paging:paging-runtime:$pagingVersion",
5254
pagingRx3 : "androidx.paging:paging-rxjava3:$pagingVersion",
5355
pagingCompose : "androidx.paging:paging-compose:$pagingComposeVersion",

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/gallery/detail/GalleryDetailScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import androidx.compose.material.icons.Icons
1111
import androidx.compose.material.icons.outlined.ArrowBack
1212
import androidx.compose.material3.*
1313
import androidx.compose.runtime.Composable
14-
import androidx.compose.runtime.collectAsState
1514
import androidx.compose.ui.Modifier
1615
import androidx.compose.ui.graphics.Color
1716
import androidx.compose.ui.graphics.ColorFilter
1817
import androidx.compose.ui.res.painterResource
1918
import androidx.compose.ui.res.stringResource
2019
import androidx.compose.ui.text.style.TextAlign
2120
import androidx.compose.ui.unit.dp
21+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2222
import com.shifthackz.aisdv1.core.model.UiText
2323
import com.shifthackz.aisdv1.core.model.asString
2424
import com.shifthackz.aisdv1.core.model.asUiText
@@ -48,7 +48,7 @@ class GalleryDetailScreen(
4848
override fun Content() {
4949
ScreenContent(
5050
modifier = Modifier.fillMaxSize(),
51-
state = viewModel.state.collectAsState().value,
51+
state = viewModel.state.collectAsStateWithLifecycle().value,
5252
adFeature = adFeature,
5353
onNavigateBack = onNavigateBack,
5454
onTabSelected = viewModel::selectTab,

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/gallery/list/GalleryScreen.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ package com.shifthackz.aisdv1.presentation.screen.gallery.list
55
import androidx.compose.foundation.ExperimentalFoundationApi
66
import androidx.compose.foundation.Image
77
import androidx.compose.foundation.clickable
8-
import androidx.compose.foundation.layout.*
8+
import androidx.compose.foundation.layout.Arrangement
9+
import androidx.compose.foundation.layout.Box
10+
import androidx.compose.foundation.layout.Column
11+
import androidx.compose.foundation.layout.PaddingValues
12+
import androidx.compose.foundation.layout.aspectRatio
13+
import androidx.compose.foundation.layout.fillMaxSize
14+
import androidx.compose.foundation.layout.fillMaxWidth
15+
import androidx.compose.foundation.layout.padding
16+
import androidx.compose.foundation.layout.size
917
import androidx.compose.foundation.lazy.grid.GridCells
1018
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
1119
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
1220
import androidx.compose.foundation.shape.RoundedCornerShape
13-
import androidx.compose.material3.*
21+
import androidx.compose.material3.CenterAlignedTopAppBar
22+
import androidx.compose.material3.ExperimentalMaterial3Api
23+
import androidx.compose.material3.IconButton
24+
import androidx.compose.material3.LocalContentColor
25+
import androidx.compose.material3.MaterialTheme
26+
import androidx.compose.material3.Scaffold
27+
import androidx.compose.material3.Text
1428
import androidx.compose.runtime.Composable
15-
import androidx.compose.runtime.collectAsState
1629
import androidx.compose.ui.Alignment
1730
import androidx.compose.ui.Modifier
1831
import androidx.compose.ui.draw.clip
@@ -24,6 +37,7 @@ import androidx.compose.ui.res.stringResource
2437
import androidx.compose.ui.text.style.TextAlign
2538
import androidx.compose.ui.unit.dp
2639
import androidx.compose.ui.unit.sp
40+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2741
import androidx.paging.LoadState
2842
import androidx.paging.PagingData
2943
import androidx.paging.compose.collectAsLazyPagingItems
@@ -48,7 +62,7 @@ class GalleryScreen(
4862
override fun Content() {
4963
ScreenContent(
5064
modifier = Modifier.fillMaxSize(),
51-
state = viewModel.state.collectAsState().value,
65+
state = viewModel.state.collectAsStateWithLifecycle().value,
5266
pagingFlow = viewModel.pagingFlow,
5367
onExportToolbarClick = viewModel::launchGalleryExportConfirmation,
5468
onExportConfirmClick = viewModel::launchGalleryExport,

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/img2img/ImageToImageScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import androidx.compose.material.icons.filled.Delete
1313
import androidx.compose.material.icons.filled.Edit
1414
import androidx.compose.material3.*
1515
import androidx.compose.runtime.Composable
16-
import androidx.compose.runtime.collectAsState
1716
import androidx.compose.ui.Alignment
1817
import androidx.compose.ui.Modifier
1918
import androidx.compose.ui.graphics.Color
@@ -23,6 +22,7 @@ import androidx.compose.ui.layout.ContentScale
2322
import androidx.compose.ui.res.stringResource
2423
import androidx.compose.ui.unit.dp
2524
import androidx.compose.ui.unit.sp
25+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2626
import com.shifthackz.aisdv1.core.common.math.roundTo
2727
import com.shifthackz.aisdv1.core.ui.MviScreen
2828
import com.shifthackz.aisdv1.domain.entity.AiGenerationResult
@@ -50,7 +50,7 @@ class ImageToImageScreen(
5050
override fun Content() {
5151
ScreenContent(
5252
modifier = Modifier.fillMaxSize(),
53-
state = viewModel.state.collectAsState().value,
53+
state = viewModel.state.collectAsStateWithLifecycle().value,
5454
onPickImage = { pickImage(viewModel::updateInputImage) },
5555
onTakePhoto = { takePhoto(viewModel::updateInputImage) },
5656
onClearPhoto = viewModel::clearInputImage,

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/loader/ConfigurationLoaderScreen.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package com.shifthackz.aisdv1.presentation.screen.loader
22

33
import androidx.compose.foundation.background
4-
import androidx.compose.foundation.layout.*
4+
import androidx.compose.foundation.layout.Arrangement
5+
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.Spacer
8+
import androidx.compose.foundation.layout.aspectRatio
9+
import androidx.compose.foundation.layout.fillMaxHeight
10+
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.foundation.layout.size
512
import androidx.compose.material3.CircularProgressIndicator
613
import androidx.compose.material3.MaterialTheme
714
import androidx.compose.material3.Text
815
import androidx.compose.runtime.Composable
9-
import androidx.compose.runtime.collectAsState
1016
import androidx.compose.ui.Alignment
1117
import androidx.compose.ui.Modifier
1218
import androidx.compose.ui.tooling.preview.Preview
1319
import androidx.compose.ui.unit.dp
20+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1421
import com.shifthackz.aisdv1.core.model.asString
1522
import com.shifthackz.aisdv1.core.model.asUiText
1623
import com.shifthackz.aisdv1.core.ui.MviScreen
@@ -22,7 +29,7 @@ class ConfigurationLoaderScreen(
2229

2330
@Composable
2431
override fun Content() {
25-
val state = viewModel.state.collectAsState().value
32+
val state = viewModel.state.collectAsStateWithLifecycle().value
2633
ScreenContent(
2734
modifier = Modifier.fillMaxSize(),
2835
state = state,

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/settings/SettingsScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.ui.res.stringResource
1414
import androidx.compose.ui.text.style.TextAlign
1515
import androidx.compose.ui.tooling.preview.Preview
1616
import androidx.compose.ui.unit.dp
17+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1718
import com.shifthackz.aisdv1.core.common.links.LinksProvider
1819
import com.shifthackz.aisdv1.core.model.UiText
1920
import com.shifthackz.aisdv1.core.model.asUiText
@@ -43,7 +44,7 @@ class SettingsScreen(
4344
override fun Content() {
4445
ScreenContent(
4546
modifier = Modifier.fillMaxSize(),
46-
state = viewModel.state.collectAsState().value,
47+
state = viewModel.state.collectAsStateWithLifecycle().value,
4748
onConfigurationItemClick = launchSetup,
4849
onSdModelItemClick = viewModel::launchSdModelSelectionDialog,
4950
onLaunchRewarded = launchRewarded,

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/setup/ServerSetupScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import androidx.compose.material.icons.filled.*
1111
import androidx.compose.material.icons.outlined.ArrowBack
1212
import androidx.compose.material3.*
1313
import androidx.compose.runtime.Composable
14-
import androidx.compose.runtime.collectAsState
1514
import androidx.compose.ui.Alignment
1615
import androidx.compose.ui.Modifier
1716
import androidx.compose.ui.res.stringResource
@@ -23,6 +22,7 @@ import androidx.compose.ui.text.style.TextAlign
2322
import androidx.compose.ui.tooling.preview.Preview
2423
import androidx.compose.ui.unit.dp
2524
import androidx.compose.ui.unit.sp
25+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2626
import com.shifthackz.aisdv1.core.common.links.LinksProvider
2727
import com.shifthackz.aisdv1.core.model.asString
2828
import com.shifthackz.aisdv1.core.model.asUiText
@@ -49,7 +49,7 @@ class ServerSetupScreen(
4949
override fun Content() {
5050
ScreenContent(
5151
modifier = Modifier.fillMaxSize(),
52-
state = viewModel.state.collectAsState().value,
52+
state = viewModel.state.collectAsStateWithLifecycle().value,
5353
demoModeUrl = linksProvider.demoModeUrl,
5454
onNavigateBack = onNavigateBack,
5555
onServerModeUpdated = viewModel::updateServerMode,

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/txt2img/TextToImageScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.RectangleShape
1515
import androidx.compose.ui.res.stringResource
1616
import androidx.compose.ui.tooling.preview.Preview
1717
import androidx.compose.ui.unit.dp
18+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1819
import com.shifthackz.aisdv1.core.ui.EmptyEffect
1920
import com.shifthackz.aisdv1.core.ui.MviScreen
2021
import com.shifthackz.aisdv1.domain.entity.AiGenerationResult
@@ -25,7 +26,6 @@ import com.shifthackz.aisdv1.presentation.widget.dialog.ErrorDialog
2526
import com.shifthackz.aisdv1.presentation.widget.dialog.GenerationImageResultDialog
2627
import com.shifthackz.aisdv1.presentation.widget.dialog.NoSdAiCoinsDialog
2728
import com.shifthackz.aisdv1.presentation.widget.dialog.ProgressDialog
28-
import com.shifthackz.aisdv1.presentation.widget.dialog.ProgressDialogStatus
2929
import com.shifthackz.aisdv1.presentation.widget.input.GenerationInputForm
3030
import org.koin.androidx.compose.koinViewModel
3131

@@ -36,7 +36,7 @@ class TextToImageScreen(
3636

3737
@Composable
3838
override fun Content() {
39-
val state = viewModel.state.collectAsState().value
39+
val state = viewModel.state.collectAsStateWithLifecycle().value
4040
ScreenContent(
4141
modifier = Modifier.fillMaxSize(),
4242
state = state,

0 commit comments

Comments
 (0)