Improve data flow - #58
Merged
Merged
Conversation
- 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 Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
- 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`.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.