Skip to content

Optim/general optimizations#1028

Merged
theovilardo merged 5 commits intomasterfrom
optim/general-optimizations
Feb 10, 2026
Merged

Optim/general optimizations#1028
theovilardo merged 5 commits intomasterfrom
optim/general-optimizations

Conversation

@theovilardo
Copy link
Copy Markdown
Owner

General optimizations with paging 3 and media store

…e selection

- Prevent potential null pointer exceptions by using safe calls on `sessionManager` when ending a current session or retrieving session data.
- **Library & Paging**:
    - Migrates `LibrarySongsTab` to use `LazyPagingItems<Song>` for efficient memory usage and smoother scrolling in large libraries.
    - Introduces `LibraryViewModel` and `LibraryStateHolder` to manage the Paging flow and handle library loading states.
    - Implements Room-backed pagination in `MusicDao` and `MediaStoreSongRepository` with support for multiple sort orders (A-Z, Artist, Album, Date Added, Duration).
    - Synchronizes selection mode and playback queue logic with Paging snapshots.

- **Data Layer Improvements**:
    - Updates `MusicRepository` and `SongRepository` interfaces to support paginated song fetching with sort options.
    - Refactors `getSongsForAlbum`, `getArtistsForSong`, and `getSongsForArtist` to fetch data directly from `MusicDao` on `Dispatchers.IO` for better performance.
    - Adjusts `MediaStoreSongRepository` to include a minimum duration filter (10s) and handles directory exclusion filtering directly via Room.

- **UI Refinements**:
    - Reorganizes `LibrarySongsTab` code for better maintainability and integrates it into `LibraryScreen`.
    - Updates `LibraryScreen` to use the new `LibraryViewModel` for data fetching.
    - Enhances `EnhancedSongListItem` usage within the paginated list to support loading placeholders and selection states.

- **Dependency Injection**:
    - Updates `AppModule` to reflect changes in `SongRepository` and `LyricsRepositoryImpl` dependencies.
- Remove `allSongs`, `albums`, `artists`, and `songCount` from `PlayerUiState` to reduce UI state size and unnecessary updates.
- Expose `albumsFlow` and `artistsFlow` directly from `PlayerViewModel` using `LibraryStateHolder` flows.
- Update `LibraryScreen` and `GenreDetailScreen` to collect library data from these standalone flows instead of the monolithic UI state.
- Optimize `LibraryScreen` by removing redundant state transformations and `remember` blocks for library categories.
- Update shuffle logic in `PlayerViewModel` to access library data via `LibraryStateHolder`.
- **LibrarySongsTab**: Added `sortOption` parameter and a `LaunchedEffect` to reset scroll position to the top when the sorting criteria changes.
- **LibraryAlbumsTab**: Implemented `LaunchedEffect` to scroll both list and grid views to the top upon changing the album sort option.
- **LibraryArtistsTab**: Added logic to reset scroll position to the top when the artist sort option is updated.
- **LibraryScreen**: Updated `LibrarySongsTab` call site to provide `currentSongSortOption` from `playerUiState`.
- **Refactoring**: Move complex folder hierarchy building logic from `MusicRepositoryImpl` to a dedicated `FolderTreeBuilder` class to improve maintainability and testability.
- **Optimization**: Clean up path normalization and parent-path resolution by using string manipulation instead of repeated `File` object instantiation.
- **Dependency Injection**:
    - Provide `FolderTreeBuilder` as a `@Singleton` in `AppModule`.
    - Update `MusicRepositoryImpl` to receive `FolderTreeBuilder` via constructor injection.
- **Data & Logic**:
    - Update `FolderTreeBuilder` to handle directory rule resolution and song filtering.
    - Maintain existing logic for internal and SD card storage root detection.
    - Ensure songs are sorted by track number and title within the generated tree.
@theovilardo theovilardo merged commit 577a179 into master Feb 10, 2026
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