Skip to content

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
feat/event-folder-db
Sep 28, 2025

Conversation

@vikas2-sharma
Copy link
Copy Markdown
Owner

No description provided.

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`.
@vikas2-sharma vikas2-sharma merged commit fad914b into main Sep 28, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant