-
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.
Merge remote-tracking branch 'origin/main' into github-actions-only
- Loading branch information
Showing
14 changed files
with
138 additions
and
109 deletions.
There are no files selected for viewing
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
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
12 changes: 11 additions & 1 deletion
12
data/user/src/main/kotlin/nl/q42/template/data/user/local/UserLocalDataSource.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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
package nl.q42.template.data.user.local | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.update | ||
import nl.q42.template.data.user.local.model.UserEntity | ||
import javax.inject.Inject | ||
|
||
internal class UserLocalDataSource @Inject constructor() { | ||
|
||
private val userFlow = MutableStateFlow<UserEntity?>(null) // this is dummy code, replace it with your own local storage implementation. | ||
|
||
fun setUser(userEntity: UserEntity) { | ||
// store in DB or preferences here: use preferences for simple key-values, for more complex objects, use a Room DB. | ||
|
||
// usually you store in DataStore or DB here... | ||
|
||
userFlow.update { userEntity } // this is dummy code, replace it with your own local storage implementation. | ||
} | ||
|
||
fun getUserFlow(): Flow<UserEntity?> = userFlow | ||
} |
3 changes: 2 additions & 1 deletion
3
data/user/src/main/kotlin/nl/q42/template/data/user/local/model/UserEntity.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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package nl.q42.template.data.user.local.model | ||
|
||
import nl.q42.template.domain.user.model.EmailAddress | ||
import nl.q42.template.domain.user.model.User | ||
|
||
internal data class UserEntity(val email: String) | ||
|
||
internal fun UserEntity.mapToUser() = User(email = email) | ||
internal fun UserEntity.mapToUser() = User(email = EmailAddress(email)) |
5 changes: 4 additions & 1 deletion
5
domain/user/src/main/kotlin/nl/q42/template/domain/user/model/User.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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
package nl.q42.template.domain.user.model | ||
|
||
data class User(val email: String) | ||
@JvmInline | ||
value class EmailAddress(val value: String) | ||
|
||
data class User(val email: EmailAddress) |
7 changes: 5 additions & 2 deletions
7
domain/user/src/main/kotlin/nl/q42/template/domain/user/repo/UserRepository.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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package nl.q42.template.domain.user.repo | ||
|
||
import nl.q42.template.domain.user.model.User | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import nl.q42.template.actionresult.domain.ActionResult | ||
import nl.q42.template.domain.user.model.User | ||
|
||
interface UserRepository { | ||
suspend fun getUser(): ActionResult<User> | ||
suspend fun fetchUser(): ActionResult<Unit> | ||
fun getUserFlow(): Flow<User?> | ||
} |
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
16 changes: 16 additions & 0 deletions
16
domain/user/src/main/kotlin/nl/q42/template/domain/user/usecase/GetUserFlowUseCase.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,16 @@ | ||
package nl.q42.template.domain.user.usecase | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import nl.q42.template.domain.user.model.User | ||
import nl.q42.template.domain.user.repo.UserRepository | ||
import javax.inject.Inject | ||
|
||
class GetUserFlowUseCase @Inject constructor(private val userRepository: UserRepository) { | ||
|
||
operator fun invoke(): Flow<User?> = | ||
userRepository | ||
.getUserFlow() | ||
.flowOn(Dispatchers.Default) | ||
} |
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
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 |
---|---|---|
|
@@ -2,15 +2,13 @@ package nl.q42.template.ui.home | |
|
||
import androidx.compose.foundation.layout.Arrangement.Center | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment.Companion.CenterHorizontally | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import nl.q42.template.presentation.home.HomeViewState | ||
import nl.q42.template.ui.compose.get | ||
import nl.q42.template.ui.presentation.toViewStateString | ||
|
@@ -35,15 +33,10 @@ internal fun HomeContent( | |
/** | ||
* This is dummy. Use the strings file IRL. | ||
*/ | ||
when (viewState) { | ||
is HomeViewState.Data -> viewState.userEmailTitle?.let { userEmailTitle -> | ||
Text(text = userEmailTitle.get()) | ||
} | ||
viewState.userEmailTitle?.get()?.let { Text(text = it) } | ||
|
||
HomeViewState.Empty -> {} | ||
HomeViewState.Error -> Text(text = "Error") | ||
HomeViewState.Loading -> Text(text = "Loading") | ||
} | ||
if (viewState.isLoading) CircularProgressIndicator() | ||
if (viewState.showError) Text(text = "Error") | ||
|
||
Button(onClick = onLoadClicked) { | ||
Text("Refresh") | ||
|
@@ -55,41 +48,29 @@ internal fun HomeContent( | |
Button(onClick = onOpenOnboardingClicked) { | ||
Text("Open onboarding") | ||
} | ||
|
||
Spacer(modifier = Modifier.height(32.dp)) | ||
|
||
Text(text = "NOTE: when cloning this template, set up your own Firebase project and replace google-services.json") | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun HomeContentErrorPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState.Error, {}, {}, {}) | ||
HomeContent(HomeViewState(showError = true), {}, {}, {}) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun HomeContentLoadingPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState.Loading, {}, {}, {}) | ||
HomeContent(HomeViewState(isLoading = true), {}, {}, {}) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun HomeContentEmptyPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState.Empty, {}, {}, {}) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun HomeContentDataPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState.Data("[email protected]".toViewStateString()), {}, {}, {}) | ||
HomeContent(HomeViewState(userEmailTitle = "[email protected]".toViewStateString()), {}, {}, {}) | ||
} | ||
} |
Oops, something went wrong.