feat: Integrate local DB for event folder management
This commit introduces significant changes to how event folders are managed within the application, shifting from direct Google Drive interaction to a local Room database approach.
**Key Changes:**
- **HomeViewmodel.kt:**
- Replaced DriveManager with EventFolderRepository to manage event folders.
- createNewEvent: Now creates event folders through eventFolderRepository.createNewEventFolder(eventItem).
- setRootFolder: Added a new function to ensure the creation or retrieval of a root project folder using eventFolderRepository.getOrCreateProjectFolder(). This is called when the HomeScreen is launched.
- eventFolderFlow: Added a new function to provide a Flow of EventFolder objects from the local database via eventFolderRepository.getAllEventFolder()#2
Merged
vikas2-sharma merged 7 commits intomainfrom Sep 28, 2025
Merged
feat: Integrate local DB for event folder management
This commit introduces significant changes to how event folders are managed within the application, shifting from direct Google Drive interaction to a local Room database approach.
**Key Changes:**
- **HomeViewmodel.kt:**
- Replaced DriveManager with EventFolderRepository to manage event folders.
- createNewEvent: Now creates event folders through eventFolderRepository.createNewEventFolder(eventItem).
- setRootFolder: Added a new function to ensure the creation or retrieval of a root project folder using eventFolderRepository.getOrCreateProjectFolder(). This is called when the HomeScreen is launched.
- eventFolderFlow: Added a new function to provide a Flow of EventFolder objects from the local database via eventFolderRepository.getAllEventFolder()#2vikas2-sharma merged 7 commits intomainfrom
HomeViewmodel.kt:**
- Replaced DriveManager with EventFolderRepository to manage event folders.
- createNewEvent: Now creates event folders through eventFolderRepository.createNewEventFolder(eventItem).
- setRootFolder: Added a new function to ensure the creation or retrieval of a root project folder using eventFolderRepository.getOrCreateProjectFolder(). This is called when the HomeScreen is launched.
- eventFolderFlow: Added a new function to provide a Flow of EventFolder objects from the local database via eventFolderRepository.getAllEventFolder()#2vikas2-sharma merged 7 commits intomainfrom
Conversation
This commit introduces the necessary Room database components to store and manage event folder information locally. **Key changes:** - **`EventFolder.kt`:** Added a new `@Entity` named `EventFolder` to represent event folders with `folderId`, `folderName`, and `folderDescription`. - **`EventFolderDao.kt`:** Created a new `Dao` interface with methods to insert, retrieve all, and retrieve a specific event folder by its ID. - **`UserDatabase.kt`:** Updated the `UserDatabase` to include `EventFolder` in its entities and provide an abstract method for `eventFolderDao()`. - **`EventFolderRepository.kt`:** Implemented a new repository to interact with `EventFolderDao`, providing methods to create a new folder and get all event folders. - **`Provider.kt`:** Added a Dagger provider for `EventFolderDao`. - **`RepositoryModule.kt`:** Added a Dagger provider for `EventFolderRepository`.
This commit introduces a new preference key, `ROOT_FOLDER_KEY`, to `DataStorePref` for storing the root folder identifier. Additionally, it: - Renames `getDataValue` to `getDataValueFlow` to better reflect its Flow return type. - Adds a new synchronous `getDataValue` function that returns a nullable String.
This commit introduces several improvements to the `EventFolderDao` to better manage locally stored event folder information. **Key changes:** - **Conflict Strategy Update:** The `insertEventFolder` function's conflict strategy is changed from `OnConflictStrategy.ABORT` to `OnConflictStrategy.IGNORE`. This allows the insertion to be skipped if an event folder with the same ID already exists, preventing crashes and simplifying data synchronization. - **Reactive Data Fetching:** The `getAllEventFolder` function is updated to return a `Flow<List<EventFolder>>` instead of a `List<EventFolder>?`. This enables reactive updates to the UI when the underlying event folder data changes. - **Delete All Functionality:** A new `deleteAllFolder` function is added to provide a way to clear all locally stored event folders. This can be useful for scenarios like user logout or data reset.
This commit introduces functionality to manage a root project folder ("PicCollab_root") in Google Drive and synchronize event folders between the local database and Drive.
**Key Changes:**
- **`EventFolderRepository.kt`:**
- `getOrCreateProjectFolder()`:
- Retrieves the root folder ID from DataStore.
- If not found, attempts to find the "PicCollab_root" folder in Drive.
- If still not found, creates "PicCollab_root" in Drive and stores its ID in DataStore.
- `createNewEventFolder()`: Now creates event folders under the obtained root project folder.
- `getAllEventFolder()`:
- Returns a `Flow` of local event folders.
- Launches a coroutine to:
- Fetch event folders from Google Drive under the root project folder.
- Insert these fetched folders into the local Room database.
- `removeAllFolderFromDB()`: Added to clear all folders from the local database.
- Constants `DEFAULT_PROJECT_FOLDER_NAME` and `DEFAULT_PROJECT_FOLDER_DESCRIPTION` are defined.
- **`DriveManager.kt`:**
- `createFolder()`: Modified to accept an optional `projectFolderId` to create folders within a specific parent. Handles potential exceptions during folder creation.
- `rootFolderId()`:
- Searches Google Drive for a folder named `DEFAULT_PROJECT_FOLDER_NAME`.
- Returns the ID of the found folder, or `null` if not found.
- `getEventFolderFromDrive()`:
- Fetches all folders from Google Drive that are children of the given `rootProjectId`.
- Maps these Drive files to `EventFolder` objects.
This enhancement ensures that event folders are organized under a dedicated project root in Google Drive and that the local database can be synchronized with the state of these folders on Drive.
This commit modifies the `ProfileViewmodel` to ensure that all event folders stored in the local Room database are deleted when a user logs out. The `logout` function in `ProfileViewmodel` now calls `eventFolderRepository.removeAllFolderFromDB()` to clear the event folder data, in addition to clearing user data and preferences.
feat: Clear event folders from DB on logout This commit modifies the `ProfileViewmodel` to ensure that all event folders stored in the local Room database are deleted when a user logs out. The `logout` function in `ProfileViewmodel` now calls `eventFolderRepository.removeAllFolderFromDB()` to clear the event folder data, in addition to clearing user data and preferences.
This commit introduces significant changes to how event folders are managed within the application, shifting from direct Google Drive interaction to a local Room database approach.
**Key Changes:**
- **`HomeViewmodel.kt`:**
- Replaced `DriveManager` with `EventFolderRepository` to manage event folders.
- `createNewEvent`: Now creates event folders through `eventFolderRepository.createNewEventFolder(eventItem)`.
- `setRootFolder`: Added a new function to ensure the creation or retrieval of a root project folder using `eventFolderRepository.getOrCreateProjectFolder()`. This is called when the `HomeScreen` is launched.
- `eventFolderFlow`: Added a new function to provide a `Flow` of `EventFolder` objects from the local database via `eventFolderRepository.getAllEventFolder()`.
- **`HomeScreen.kt`:**
- On `LaunchedEffect`, `viewmodel.setRootFolder()` is now called to initialize the root folder structure.
- The `LazyVerticalGrid` now collects and displays event folders from `viewmodel.eventFolderFlow()`, populating `EventFolderCard` with `eventItem.folderName`.
This change centralizes event folder data management within the local database, which will likely improve performance and offline capabilities. Google Drive interaction for folder creation will now be handled within the `EventFolderRepository`.
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.