Add "Use folder cover images" setting - #123
Conversation
|
| Filename | Overview |
|---|---|
| app/src/main/java/com/lostf1sh/pixelplayeross/PixelPlayerApplication.kt | Adds application-lifetime preference and permission reconciliation so cache state follows startup, restore, and foreground transitions. |
| app/src/main/java/com/lostf1sh/pixelplayeross/utils/AlbumArtUtils.kt | Adds permission-aware folder-cover resolution, bounded external-image reads, and effective-state comparison logic. |
| app/src/main/java/com/lostf1sh/pixelplayeross/presentation/viewmodel/SettingsViewModel.kt | Persists folder-art changes, clears artwork caches, records effective state, and requests a full sync. |
| app/src/main/java/com/lostf1sh/pixelplayeross/presentation/screens/SettingsCategoryScreen.kt | Adds the permission-gated folder-art toggle and accurately reflects unavailable image access. |
| app/src/main/java/com/lostf1sh/pixelplayeross/data/preferences/UserPreferencesRepository.kt | Adds the user preference and device-local cache-state marker while excluding the marker from backups. |
| app/src/test/java/com/lostf1sh/pixelplayeross/utils/FolderAlbumArtUpdateTest.kt | Covers initial, unchanged, and changed effective cache-state decisions. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Folder-art preference] --> B{Image permission available?}
B -->|No| C[Use embedded artwork]
B -->|Yes| D[Search trusted song folder]
D -->|Cover found and within limit| E[Copy bounded cover into per-song cache]
D -->|No usable cover| C
F[Preference or permission transition] --> G[Reconcile effective state]
G --> H[Clear album-art and Coil caches]
H --> I[Trigger library rescan]
Reviews (3): Last reviewed commit: "Record and reconcile the effective cover..." | Re-trigger Greptile
|
Could you please extend this option to include artist images located inside the folder? You could use filenames like artist.jpg, band.jpg (and .png). Unfortunately, many third-party artist images are incorrect or of low quality; this option would fix that issue! |
I think this behavior isn't as common as having the |
I didn't express myself very well; I meant in the Artist folder. I suggested this idea because many people have huge libraries, and doing it automatically would be more practical... but anyway, thanks :) |
What
Adds an opt-in "Use folder cover images" setting (Settings → Library → Sync & Scanning). When enabled, a cover image sitting next to the audio file -
cover.jpg,folder.jpg,albumart.png,front.jpgand the other names already listed inAlbumArtUtils.commonArtworkFileNames- is used as album art.Why
Album art currently shows only when it is embedded in the audio file's tags. Users who keep one
cover.jpgper album folder - the storage-efficient layout, and the same convention the app already follows for sibling.lrclyrics files - get no artwork at all.Folder scanning used to happen automatically and was removed on purpose, because it picked up unrelated images (Gallery, DCIM, Downloads) for music stored in mixed directories.
findExternalAlbumArtFileandshouldTrustDirectoryArtworksurvived that removal, documented as being "for explicit, controlled callers only". This PR adds that explicit caller - a setting that is off by default, so nothing changes for existing users and the original problem cannot come back unasked.How it works
readExternalAlbumArtBytesinAlbumArtUtilsis wired intoensureAlbumArtCachedFileandhasLocalAlbumArt. Every local artwork consumer - lists, full player, media notification, Android Auto, widgets, palette extraction - resolves through those two, so no changes were needed inSyncWorker, the Room entities, or any UI component.cover.jpgis usually the full-resolution original, while embedded art is often a downscaled copy.Music/,Download/,DCIM/,Pictures/and friends are still ignored even when the setting is on. Only dedicated album folders qualify.boundArtworkForCache(1536 px / JPEG q90) and stays underAlbumArtCacheManager's LRU accounting. Covers larger than 20 MB are skipped rather than read into memory.filesDirand outlive the process, and a permission granted back in system settings changes what should be cached without the preference ever changing.ImageCacheManager.clearAllCoverArtCaches()is new for this; the existing per-URI invalidation can only guess at Coil's size-suffixed keys, which is not good enough for a library-wide change.Permission
Reading a non-audio file next to a track needs
READ_MEDIA_IMAGESon API 33+ -READ_MEDIA_AUDIOdoes not cover image files, so without itcover.jpgis simply invisible and the feature would silently do nothing on every modern device. The permission is now declared and requested only when the user turns the setting on. Below API 33 nothing extra is requested, sinceREAD_EXTERNAL_STORAGEis already granted during setup.A partial "Select photos" grant on Android 14+ is deliberately treated as not granted: it gives no access to arbitrary music folders. In that case the setting stays off and an explanatory toast is shown. This is what the new
SelectedPhotoAccesslint warning refers to - see the note below.Settings search
Registered in
SettingsRegistryasNAVIGABLE_CARDrather thanSWITCH. ASWITCHspec flips the preference straight from the search results, which would bypass the permission prompt and persist the setting with no image access - silently doing nothing. As a navigable card, search jumps to the Library screen and highlights the real, permission-gated toggle.Translations
Four new strings, added to
values/and all 11 locale folders (ar,de,es,fr,in,it,ko,nb,ru,tr,zh-rCN), so this adds no newMissingTranslationfindings.Local checks
Run with JDK 21 (
JAVA_HOME=/opt/homebrew/opt/openjdk@21, OpenJDK 21.0.12.1) after./gradlew clean::app:compileDebugKotlin:app:testDebugUnitTest:app:lintDebuglintDebugalready fails on the base commitdb8cd3b, which I linted separately for comparison:db8cd3bThe error count is identical - those are
MissingTranslationacross the existing string catalogue plus media3UnsafeOptInUsageError, and none of them are in files this PR touches. The one added warning is theSelectedPhotoAccessentry described below.Eight new unit tests. Four in
AlbumArtUtilsTestcover the new seam: bytes returned when enabled,nullwhen disabled (the opt-in gate),nullwhen the cover exceeds the size limit, andnullin an excluded directory even when enabled. Four more inFolderAlbumArtUpdateTestcover the cache-state reconciler: first record, unchanged state, a preference change, and a permission re-grant with no preference change. The four existingfindExternalAlbumArtFiletests are unchanged.Notes for reviewers
AndroidManifest.xml:17:Your app is currently not handling Selected Photos Access introduced in Android 14+ [SelectedPhotoAccess]. This is expected - handling partial photo access would mean accepting a grant that cannot read arbitrary music folders, which is exactly the case this feature must reject. Happy to add a baseline entry or an explicit suppression if you'd prefer the warning silenced.