-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#159][Part1] [Compose] Support datastore replacing shared preference #389
[#159][Part1] [Compose] Support datastore replacing shared preference #389
Conversation
Kover report for template-xml:🧛 Template - XML Unit Tests Code Coverage:
|
File | Coverage |
---|---|
BaseViewModel.kt |
0.00% |
HomeViewModel.kt |
0.00% |
UseCase.kt |
100.00% |
Modified Files Not Found In Coverage Report:
AndroidManifest.xml
AppPreferencesRepository.kt
AppPreferencesRepositoryImpl.kt
HomeScreen.kt
IsFirstTimeLaunchPreferencesUseCase.kt
IsFirstTimeLaunchPreferencesUseCaseTest.kt
PreferencesModule.kt
StorageModule.kt
UpdateFirstTimeLaunchPreferencesUseCase.kt
UpdateFirstTimeLaunchPreferencesUseCaseTest.kt
UseCaseTest.kt
Versions.kt
build.gradle.kts
build.gradle.kts
Codebase cunningly covered by count Shroud 🧛
Kover report for template-compose:
🧛 Template - Compose Unit Tests Code Coverage: 24.28%
Coverage of Modified Files:
File | Coverage |
---|---|
BaseViewModel.kt |
97.62% |
HomeScreen.kt |
0.00% |
HomeViewModel.kt |
100.00% |
UseCase.kt |
100.00% |
Modified Files Not Found In Coverage Report:
AndroidManifest.xml
AppPreferencesRepository.kt
AppPreferencesRepositoryImpl.kt
IsFirstTimeLaunchPreferencesUseCase.kt
IsFirstTimeLaunchPreferencesUseCaseTest.kt
PreferencesModule.kt
StorageModule.kt
UpdateFirstTimeLaunchPreferencesUseCase.kt
UpdateFirstTimeLaunchPreferencesUseCaseTest.kt
UseCaseTest.kt
Versions.kt
build.gradle.kts
build.gradle.kts
Codebase cunningly covered by count Shroud 🧛
Generated by 🚫 Danger
33274a5
to
cc91780
Compare
@lydiasama Will your issue be split up like this? 🙏
Also, please rebase 🚀 |
48d57de
to
2a7f79d
Compare
@Tuubz Updated. 🚀 |
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt
Outdated
Show resolved
Hide resolved
...ata/src/main/java/co/nimblehq/sample/compose/data/repository/AppPreferencesRepositoryImpl.kt
Outdated
Show resolved
Hide resolved
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeViewModel.kt
Outdated
Show resolved
Hide resolved
...omain/src/main/java/co/nimblehq/sample/compose/domain/repository/AppPreferencesRepository.kt
Outdated
Show resolved
Hide resolved
...ata/src/main/java/co/nimblehq/sample/compose/data/repository/AppPreferencesRepositoryImpl.kt
Outdated
Show resolved
Hide resolved
...mpose/app/src/main/java/co/nimblehq/sample/compose/di/modules/PreferencesRepositofyModule.kt
Outdated
Show resolved
Hide resolved
...ata/src/main/java/co/nimblehq/sample/compose/data/repository/AppPreferencesRepositoryImpl.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
...ata/src/main/java/co/nimblehq/sample/compose/data/repository/AppPreferencesRepositoryImpl.kt
Show resolved
Hide resolved
4fe2a05
to
6dbe671
Compare
@luongvo @thiennguyen0196 Resolved all. Plus, unit tests are added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest lgtm, 1 last issue 👋
sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/home/HomeScreen.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment 🚀
...omain/src/main/java/co/nimblehq/sample/compose/domain/repository/AppPreferencesRepository.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏🏼 👏🏼
...ata/src/main/java/co/nimblehq/sample/compose/data/repository/AppPreferencesRepositoryImpl.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@lydiasama Conflict 🦀 |
…cing-shared-preference
@kaungkhantsoe Thanks ❤️ Resolved! |
#159
What happened 👀
Part 1: Integrate for sample-compose
Part 2: Integrate for sample-xml
Part 3: Integrate for both template-xml & template-compose
Insight 📝
Sample-Compose
project.GetFirstTimeLaunchPreferencesUseCase
andUpdateFirstTimeLaunchPreferencesUseCase
.But it has never come to do the
hideLoading()
function. It seems it never ends thecollect()
function. So I changed the approach to be:And what's interesting is, when I tried the
.onCompletion
, it will do theonCompletion
block when gets error, but not execute it when it succeeds. So in success case, it will not hide loading if we do the following code:After discussing with @Wadeewee, we can wrap the
appPreferencesDataStore.data
withflow
, so that we can use.first()
to get only the first emit from the DataStore preferences and it can finish thecollect()
function.💡 Here is the solution:
_uiModels
,_firstTimeLaunch
, andshowLoading
flow inHomeViewState
. So we can get rid of their public variables. Moreover, we can just observe onlyin
HomeScreen
. BTW, I'm not sure if we could reduce the recomposition by doing this because when the HomeViewState's properties are changed, it might trigger to recompose anyway. So I'll keep the codebase as the same.AndroidManifest
because when I test uninstall and reinstall the app, sometimes the preferences does not remove entirely. But instead, it keep some caches. So it's better to not allow caching.Ref: https://stackoverflow.com/a/33176898
Proof Of Work 📹
Success case:
device-2023-01-11-181454.mp4
Error case:
device-2023-01-12-172134.mp4
How does it look like in the device's storage: