Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Store UserSharePreferences in local storage#80

Merged
hamorillo merged 2 commits intotrunkfrom
adam/GRA-601
Jul 28, 2025
Merged

Store UserSharePreferences in local storage#80
hamorillo merged 2 commits intotrunkfrom
adam/GRA-601

Conversation

@AdamGrzybkowski
Copy link
Contributor

Description

This PR adds local storage for the UserSharePreferences.

Additionally (in the 2nd commit), I've remodeled a bit how the ShareUiState is built with the private contact info and added the private phone/email share prefs to the UserSharePreferences as well. The new PrivateContactInfo from :userComponent should be used in the next PRs to get/update those values.

Testing Steps

  1. Launch the app
  2. Change the share prefs on the share tab
  3. Kill the app
  4. Reopen the app and confirm the share prefs are restored

@AdamGrzybkowski AdamGrzybkowski added the enhancement New feature or request label Jul 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements local storage persistence for user sharing preferences and refactors the private contact information handling. The changes enable user preferences to persist across app sessions using Android DataStore.

  • Adds UserSharePreferencesStorage interface with DataStore implementation for persisting share preferences
  • Introduces new use cases for getting and updating user share preferences with Flow-based reactive updates
  • Refactors private contact info handling by separating data model (PrivateContactInfo) from UI state (PrivateContactState)

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
UpdateUserSharePreferencesUseCase.kt New use case for updating user share preferences with storage persistence
GetUserSharePreferencesUseCase.kt New use case for retrieving user share preferences as a Flow with distinct updates
UserSharePreferences.kt Enhanced data model with private email/phone fields and default values
PrivateContactInfo.kt New domain model for private contact information separate from UI state
UserComponentModule.kt Dependency injection setup for new use cases
DatastoreModule.kt DataStore configuration for UserSharePreferencesStorage
UserPrefsStorage.kt DataStore implementation with preference keys and serialization logic
ShareViewModel.kt Updated to use new use cases and handle preference persistence
ShareUiState.kt Refactored to separate domain models from UI state representation
Various test files Updated tests to use new models and default values

* Convenient interface to clear all user related data in one call.
*/
internal interface UserStorage : AuthTokenStorage, AvatarCacheBusterStorage {
internal interface UserStorage : AuthTokenStorage, AvatarCacheBusterStorage, UserSharePreferencesStorage {
Copy link

Copilot AI Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UserStorage interface is inheriting from UserSharePreferencesStorage, but the clear() method doesn't explicitly clear user share preferences. This could lead to inconsistent behavior where auth tokens and cache busters are cleared but share preferences persist.

Copilot uses AI. Check for mistakes.
@hamorillo hamorillo force-pushed the adam/GRA-577 branch 2 times, most recently from c58098a to f5c853f Compare July 28, 2025 13:17
Copy link

@hamorillo hamorillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀


private val tokenKey = stringPreferencesKey(AUTH_TOKEN_KEY)
private val avatarCacheBusterKey = stringPreferencesKey(AVATAR_CACHE_BUSTER_KEY)
private val userShareNameKey = booleanPreferencesKey(USER_SHARE_NAME_KEY)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 This is growing fast. Not for this PR, but we may consider splitting it up.

Copy link

@hamorillo hamorillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Base automatically changed from adam/GRA-577 to trunk July 28, 2025 21:10
# Conflicts:
#	homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/components/SharePrivateContactInfo.kt
@hamorillo hamorillo merged commit 850fc3b into trunk Jul 28, 2025
10 of 11 checks passed
@hamorillo hamorillo deleted the adam/GRA-601 branch July 28, 2025 21:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants