Skip to content

Improve data flow - #58

Merged
nhoxbypass merged 13 commits into
developfrom
core/improve_data_flow
Apr 22, 2026
Merged

Improve data flow#58
nhoxbypass merged 13 commits into
developfrom
core/improve_data_flow

Conversation

@nhoxbypass

Copy link
Copy Markdown
Owner

No description provided.

- Update `FakeFirebaseStoreApiHelper` to load store data from JSON files in the `assets/stores_data` directory instead of using hardcoded helper methods.
- Introduce `loadStoresFromAssets` using `Gson` to parse store information for multiple brands (Circle K, MiniStop, FamilyMart, etc.).
- Update `RepositoryModule` to provide `@ApplicationContext` to `FakeFirebaseStoreApiHelper` to facilitate asset access.
- Refactor `insertOrUpdateComment` in the mock helper to use Kotlin's `getOrPut` for cleaner logic.
- Implement `refreshStores()` in `StoreRepository` and `AppStoreRepository` to handle remote data fetching, filtering, and local persistence.
- Move store data validation logic from `DataUtils` to `AppStoreRepository.filterInvalidData`.
- Refactor `StoreSyncHelper` to use the new `refreshStoresFromRemote` flow, simplifying remote data updates across `SyncDatabaseWorker`, `SettingViewModel`, and `SplashViewModel`.
- Update `StoreListViewModel` to fetch real data from `StoreRepository` instead of using mock data.
- Optimize `MainMapViewModel` to prevent redundant store loading when the map is initialized.
- Remove unused `findStoresBy` methods from `StoreRepository` and `AppStoreRepository`.
- Delete `FakeStoreDAO` and update `RepositoryModule` to provide the real `StoreDao` in mock builds.
- Add `AppStoreRepositoryFilterTest` and migrate related tests from `DataUtilsTest`.
- Move `Store` model from `data.remote.store.model` to `domain.model`.
- Refactor `Store` to use `Double` for `lat` and `lng` instead of `String`.
- Introduce `StoreDto` in the remote data layer to handle Firebase data mapping and conversion to the domain model.
- Add `StoreExt.kt` with a `toLatLng()` extension function to replace the internal `getPosition()` method.
- Update `StoreEntity` and database mappers to reflect the change from `String` to `Double` for coordinates.
- Update all UI components (Map, Search, Favorites, Detail), ViewModels, and Repositories to use the new domain model and coordinate types.
- Update mock data and unit tests in `DataUtils.kt` and `IntentUtilsTest.kt` to use numeric coordinate values.
- Simplify coordinate validation logic in `AppStoreRepository`.
- Introduce `Mutex` to synchronize access to `cachedStores` and prevent race conditions.
- Wrap `getAllStores`, `refreshStores`, `setStores`, and `deleteAllStores` logic within `cacheMutex.withLock`.
- Rename `persistStores` to `persistStoresLocked` to indicate it must be called within a locked context.
…on for Store components

- Update `RepositoryModule` in both `prod` and `mock` flavors to provide `StoreApiHelper` as a separate dependency.
- Refactor `provideStoreRepository` to inject `StoreApiHelper` instead of instantiating it internally.
- Introduce `provideDatabaseReference` in the `prod` flavor to provide the Firebase `DatabaseReference`.
- Remove `StoreSyncHelper` object and introduce `StoreRefreshService` class to handle store synchronization logic.
- Inject `StoreRefreshService` into `SyncDatabaseWorker`, `SettingViewModel`, and `SplashViewModel`, replacing manual dependencies on `ClientAuth` and `StoreRepository` for syncing.
- Move bot authentication credentials (email and password) from local method calls to constructor injection within `StoreRefreshService`.
- Configure `StoreRefreshService` provision in both `prod` and `mock` Hilt `RepositoryModule` files.
- Remove dependency on the global `App` context for store synchronization by utilizing injected credentials and repository instances.
- Update `StoreRefreshService` to perform Firebase authentication outside of the `try-finally` block, ensuring `signOut()` is only called if the sign-in attempt was initiated.
- Implement cancellation support in `FirebaseStoreApiHelper` by using `invokeOnCancellation` to remove `ValueEventListener` when coroutines are cancelled in `getAllStores` and `getComments`.
…cache clearing

- Update `saveToDatabase` to delete all local stores if the provided list is empty, ensuring the local database reflects the current server state.
- Refactor `clearCache` to be a `suspend` function and wrap cache clearing in a `cacheMutex.withLock` to ensure thread safety.
- Remove unused helper functions: `getFakeCircleKStoreList`, `getFakeSearchStoreItems`, `getFakeArPoints`, and `getFakeUserMultiStoreLists`.
- Simplify `getFakeStoreList` by removing redundant `.toDouble()` calls on numeric literals.
- Refactor loops and conditional logic to use idiomatic Kotlin features like `.forEach`, `when` expressions, and direct returns.
- Annotate unused direction-related test helpers with `@Suppress("unused")`.
- Clean up unused imports and remove the unused `VALID_PWD_REGEX` constant.
- Replace manual marker management with ClusterManager for better performance and automatic marker clustering
- Replace MutableStateFlow event stream with SharedFlow to fix event conflation on rapid successive emissions
- Fix startup flash by hiding map until first camera animation
- Fix resume re-centering by not resetting zoom-to-user flag on resume
- Fix configuration change causing blank map via savedInstanceState guard
- Add 4-second location timeout with fallback to persisted last-known location (or default), saved to SharedPreferences on every GPS update
- Fix NearByStoreAdapter dual-list bug and DiffUtil item identity
- Make NearByStore an immutable data class, cache LatLng in cluster items
- Remove dead code (onClearOldMapData, SetupMapEventHandlers, animateMarker)
- Replace `@drawable/logo_711_50` with `@drawable/logo_711_red` in `fragment_search.xml`.
- Comment out `TYPE_SHOP_N_GO` in `StoreType.kt`.
- Remove `TYPE_SHOP_N_GO` logo mapping in `UiUtils.kt` and corresponding unit tests in `UiUtilsTest.kt`.
- Remove sample "Shop & Go" store entries from `DataUtils.kt`.
- Remove `shopngo.json` mapping from `FakeFirebaseStoreApiHelper.kt`.
@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.50237% with 96 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.23%. Comparing base (7db5be0) to head (36b13ed).
⚠️ Report is 14 commits behind head on develop.

Files with missing lines Patch % Lines
...iet/fastfoodfinder/ui/main/map/MainMapViewModel.kt 57.69% 17 Missing and 5 partials ⚠️
...om/iceteaviet/fastfoodfinder/domain/model/Store.kt 31.03% 20 Missing ⚠️
...finder/data/remote/store/FirebaseStoreApiHelper.kt 0.00% 12 Missing ⚠️
...foodfinder/ui/main/map/cluster/StoreClusterItem.kt 0.00% 7 Missing ⚠️
...finder/ui/main/map/cluster/StoreClusterRenderer.kt 0.00% 7 Missing ⚠️
...t/fastfoodfinder/ui/main/map/NearByStoreAdapter.kt 0.00% 5 Missing ⚠️
...stfoodfinder/service/workers/SyncDatabaseWorker.kt 0.00% 4 Missing ⚠️
...a/com/iceteaviet/fastfoodfinder/utils/DataUtils.kt 84.61% 2 Missing and 2 partials ⚠️
...nder/data/domain/prefs/AppPreferencesRepository.kt 0.00% 3 Missing ⚠️
.../fastfoodfinder/ui/storelist/StoreListViewModel.kt 0.00% 3 Missing ⚠️
... and 6 more
Additional details and impacted files
@@              Coverage Diff              @@
##             develop      #58      +/-   ##
=============================================
+ Coverage      17.81%   25.23%   +7.41%     
- Complexity       195      285      +90     
=============================================
  Files             94       97       +3     
  Lines           2458     2814     +356     
  Branches         222      223       +1     
=============================================
+ Hits             438      710     +272     
- Misses          2002     2073      +71     
- Partials          18       31      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add unit tests for `AppStoreRepository` covering caching, database fallback, remote fetching, and data filtering.
- Add unit tests for `StoreRefreshService` to verify authentication-aware store synchronization logic.
- Add unit tests for `MainMapViewModel`, `SettingViewModel`, and `SplashViewModel` using `kotlinx-coroutines-test` and Mockito.
- Add mapping tests for `StoreEntity` and `StoreDto` to ensure correct domain model conversion.
- Expand `AppPreferencesHelperTest` with test cases for last known location persistence.
- Add `kotlinx-coroutines-test` dependency to `libs.versions.toml`.
@nhoxbypass
nhoxbypass merged commit 7fb264b into develop Apr 22, 2026
3 of 4 checks passed
@nhoxbypass
nhoxbypass deleted the core/improve_data_flow branch April 22, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant