Skip to content

refactor(FormatEntity): centralize format display helpers and fix container naming#814

Closed
adam-adrian wants to merge 5 commits into
ArchiveTuneApp:devfrom
adam-adrian:refactor/codec-display-helpers
Closed

refactor(FormatEntity): centralize format display helpers and fix container naming#814
adam-adrian wants to merge 5 commits into
ArchiveTuneApp:devfrom
adam-adrian:refactor/codec-display-helpers

Conversation

@adam-adrian

@adam-adrian adam-adrian commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Extracts 5 reusable extension functions (containerLabel, codecLabel, formattedBitrate, formattedSampleRate, formattedFileSize) into FormatEntity.kt, replacing ~70 lines of duplicated inline formatting/parsing logic scattered across 6 queue composables in QueueComponents.kt and a private duplicate in PlayerComponents.kt.

The inline parsing was naming its variable codec while actually extracting the container from mimeType — variables are now honestly named container.

No user-facing display changes; the player still shows the same WEBM • 141 kbps • 3 MB row.

Linked Work

  • Closes: -
  • Related: -

Change Type

  • Feature
  • Bug fix
  • UI / UX
  • Performance / memory
  • Playback / Media3
  • Lyrics / provider integration
  • Search / YouTube / network data
  • Local library / Room database
  • Widgets / notification / shortcuts
  • Settings / preferences / DataStore
  • Discord / Last.fm / ListenBrainz / external integration
  • Localization / strings / fastlane metadata
  • Build / Gradle / CI / release packaging
  • Dependency update
  • Documentation only

Affected Surfaces

  • :app
  • :innertube
  • :betterlyrics
  • :kugou
  • :lrclib
  • :lastfm
  • :simpmusic
  • :paxsenix
  • :unison
  • :canvas
  • :shazamkit
  • :spotifycore
  • server
  • fastlane
  • .github
  • Other:

Screenshots / Recordings

No visual changes. Display output is identical before and after.

Before After
WEBM • 141 kbps • 3 MB WEBM • 141 kbps • 3 MB

Behavior Notes

  • Display unchanged: all 9 player styles (V1–V9) show the exact same text as before. The refactor only changes how the strings are produced, not what they contain.
  • Variable naming fix: inline val codec = mimeType.substringAfter("/") was extracting the container, not the codec. Now val container = currentFormat.containerLabel().
  • Local file bitrate edge case: formattedBitrate() returns "Unknown" when bitrate == 0 (local files from LocalSongScanner), instead of the previous "0 kbps".
  • V2 sample rate & file size: behavior preserved — formattedSampleRate() returns null and formattedFileSize() returns "" when data is absent, matching the old listOfNotNull join logic.
  • V3/V5 fileSize: intentionally kept as "" to preserve the minimal display style.

Architecture Checklist

  • The change preserves UDF flow: UI -> ViewModel -> UseCase/domain -> Repository/data.
  • Screen state is represented structurally with Loading, Success, Empty, and Error where this PR introduces or changes screen state.
  • Composables receive immutable, UI-specific domain models instead of raw Room, network, or service entities. (Extension functions on FormatEntity are pure and side-effect-free.)
  • Business work is not triggered directly from composition.
  • Exceptions are surfaced through explicit state or result types instead of being swallowed.
  • No runBlocking is introduced in app execution paths.

Compose / Material Checklist

  • UI state is hoisted out of composable layout code.
  • Reactive state is collected with collectAsStateWithLifecycle().
  • New UI models are annotated with @Immutable or @Stable. (N/A — no new UI models.)
  • Lazy layouts use stable key values and explicit contentType.
  • Non-primitive constants, structural lambdas, and allocation-heavy objects in hot paths are remembered. (Extension functions are lightweight string operations, no allocation concerns.)
  • Rapidly changing inputs such as scroll, gesture, animation, or playback progress use derivedStateOf where appropriate.
  • UI strings come from stringResource() and duplicated visible strings on the same screen are avoided. (No new user-facing strings.)
  • Interactive elements keep a minimum 48dp touch target.
  • Material 3 / Material 3 Expressive tokens are used for color, typography, shape, and motion instead of hardcoded UI values.
  • Edge-to-edge layouts handle and consume WindowInsets correctly when this PR changes screen layout.

Concurrency / Performance Checklist

  • Business coroutines are scoped to viewModelScope or an existing lifecycle-owned application/service scope.
  • Disk, database, network, parsing, and heavy mapping work is dispatched to Dispatchers.IO or Dispatchers.Default.
  • Cancellation is handled explicitly where long-running work, playback, downloads, sync, lyrics fetching, or recognition is involved.
  • The change avoids blocking the main thread.
  • The change avoids unnecessary allocations in recomposition loops, playback loops, polling loops, and provider parsing paths.
  • Large lists, images, lyrics payloads, and network responses are bounded, streamed, cached, paged, or mapped off the main thread as appropriate.

Data / Persistence Checklist

  • Room entity, DAO, or database changes include a schema update under app/schemas. (N/A — no schema changes, only extension functions added to existing entity file.)
  • Database migrations preserve existing user data and fail clearly when migration is impossible.
  • DataStore or preference-key changes are backward compatible.
  • Network DTOs remain isolated from UI models.
  • Provider responses handle missing, malformed, regional, or rate-limited data without crashing the app.

Playback / Integration Checklist

  • Media3 playback, queue, cache, and service behavior remains stable across foreground, background, notification, and process recreation paths.
  • Audio focus, notification controls, widgets, shortcuts, and media session actions are considered when playback behavior changes.
  • External integrations handle absent credentials, revoked auth, network failure, and API changes.
  • Native, AAR, or ABI-sensitive changes account for mobile/tv and universal, arm64, armeabi, x86, and x86_64 variants.

Localization / Assets Checklist

  • User-facing strings are added to the base resources and translated resources are updated or intentionally left for translation follow-up. (No new strings.)
  • Unused string resources, drawables, and metadata are removed when replaced.
  • Image assets have explicit display dimensions and are decoded at the displayed size.
  • Fastlane metadata, screenshots, icons, or release text are updated when user-facing store behavior changes.

Privacy / Security Checklist

  • No secrets, keys, tokens, keystores, signing files, private certificates, or local machine paths are committed.
  • Logs do not expose access tokens, cookies, auth headers, user identifiers, listening history, or local file paths.
  • New network calls are justified by the feature and use existing client, proxy, timeout, and error-handling patterns.
  • User data remains local unless the PR explicitly documents the integration and consent path.

Verification

  • Android Studio sync: (Not performed in this environment — patch verified via git apply --check on clean dev tree.)
  • Manual device/emulator verification: Tested and reviewed manually on Poco X7 Pro
  • UI screenshot/recording attached: (N/A — no visual changes.)
  • Accessibility or touch-target review: (N/A — no layout changes.)
  • Regression areas checked: All 6 queue composables (V1–V9), V8QualityChip, codecLabel() import resolution.
  • CI expectation: Build successfully

Reviewer Focus

  • FormatEntity.kt: Confirm codecLabel() logic matches the original private version exactly (it was moved verbatim).
  • QueueComponents.kt V2 (QueueCollapsedContentV2): The codec/container/codecLabel branching logic is preserved — only the formatting calls were extracted to helpers.
  • QueueComponents.kt V3/V5: Confirm fileSize = "" is intentionally kept (not an oversight).
  • PlayerComponents.kt: Confirm the removed private fun FormatEntity.codecLabel() is the only call site that now resolves via import — V8QualityChip at line ~2576.

Release Notes

Internal refactor: no user-facing changes. Player codec/format display is unchanged.

… labeling

Move codecLabel(), containerLabel(), formattedBitrate(), formattedSampleRate(),
and formattedFileSize() into FormatEntity.kt as public extensions,
replacing ~70 lines of duplicated inline parsing scattered across 6 queue composables
and the private codecLabel() in PlayerComponents.kt.

The inline parsing in QueueComponents named its variable 'codec' while actually
extracting the container from mimeType (e.g. 'WEBM' instead of 'opus').
Variable is now honestly named 'container'. User-facing display is unchanged.

Bonus: bitrate formatting now returns 'Unknown' instead of '0 kbps' for local
files where bitrate is not available.
@sang765 sang765 added the BUG Something isn't working label Jun 17, 2026
Extract the duplicated title/artist tap behavior into a single
rememberPlayerTitleActions() helper, and add a reusable ClickableArtists
primitive that makes each artist name individually tappable. Classic, V7,
V8 and V9 now share this behavior instead of each hand-rolling its own
lambdas, removing prior feature drift (per-artist navigation previously
existed only in the classic style).

Visual rendering stays per-style: adding a new player style no longer
requires touching shared title/artist code.
Tapping the song title navigated to the album but used snapTo to move the
sheet, which jumps without animation and — crucially — does not update the
sheet's internal anchor. The anchor could then go stale (e.g. still
EXPANDED), so on the next recomposition the sheet snapped back open,
making "tap title to collapse" appear broken on the home screen while it
worked elsewhere.

Use collapseSoft() instead, which animates and updates the anchor,
matching the artist-tap behavior.
- Remove unused PlayerTitleActions.onFirstArtistClick (dead code)
- ClickableArtists: use detectTapGestures instead of a standing
  awaitPointerEventScope loop; memoize the AnnotatedString; restore
  per-artist annotation tags; document the marquee hit-test caveat
- Drop the now-unused clipboardManager/context params threaded through
  PlayerTitleSection / PlayerControlsContent (and remove dead imports)
@adam-adrian adam-adrian deleted the refactor/codec-display-helpers branch June 17, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BUG Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants