Skip to content

feat(): achievement sound on unlock#1671

Open
phobos665 wants to merge 3 commits into
utkarshdalal:masterfrom
phobos665:feat/achievement-sound
Open

feat(): achievement sound on unlock#1671
phobos665 wants to merge 3 commits into
utkarshdalal:masterfrom
phobos665:feat/achievement-sound

Conversation

@phobos665

@phobos665 phobos665 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Description

Highly requested feature:

Adds an achievement unlock sound on unlock of achievement.

Adds the media player and the play of the tune within the AchievementWatcher which is the best place for this. Pretty simple change and we already have the required permissions in Android to do this.

Only question is whether we'd like to change the sound to something else.

Recording

Type of Change

  • Bug fix
  • Performance / stability improvement
  • Compatibility improvements
  • Other (requires prior approval)

Checklist

  • If I have access to #code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.
  • This change aligns with the current project scope (core functionality, stability, or performance). If not, it has been explicitly approved beforehand.
  • I have attached a recording of the change.
  • I have read and agree to the contribution guidelines in CONTRIBUTING.md.

Summary by cubic

Adds a short sound when an achievement unlocks and a settings toggle to control it. Uses a single, thread-safe MediaPlayer in AchievementWatcher with achievement_pop.mp3.

  • New Features
    • Plays the sound on unlock when the new "Play Achievement Sound" setting is on (default on); independent of the notification setting.
    • Adds a Settings switch and PrefManager.achievementPlaySound, with translations.
    • Uses a single app-context MediaPlayer in AchievementWatcher (synchronized, restarts if already playing, released on stop); XServerScreen passes context to initialize it.

Written for commit fdd2c9b. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added a new Settings toggle to enable/disable playing an achievement unlock sound when a new achievement is detected.
  • Bug Fixes

    • Improved achievement sound playback so it restarts properly and failures are handled gracefully.
    • Improved cleanup by releasing the achievement sound resource when monitoring stops.
  • Localization / Documentation

    • Added the new “Play Achievement Sound” setting text across supported languages.

@phobos665 phobos665 requested a review from utkarshdalal as a code owner July 5, 2026 12:25
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

AchievementWatcher now plays an unlock sound from a raw resource when new achievements are detected, gated by a new preference. The settings UI adds a toggle for that preference, and localized strings were added for the new label. XServerScreen now passes context into the watcher constructor.

Changes

Achievement sound playback

Layer / File(s) Summary
MediaPlayer playback flow
app/src/main/java/app/gamenative/service/AchievementWatcher.kt
AchievementWatcher now accepts Context, creates a MediaPlayer for R.raw.achievement_pop, conditionally plays it on new unlocks, and releases it in stop().
Preference and settings toggle
app/src/main/java/app/gamenative/PrefManager.kt, app/src/main/java/app/gamenative/ui/screen/settings/SettingsGroupInterface.kt
Adds achievementPlaySound to preferences and wires a new settings switch to read and update it.
Steam watcher wiring and strings
app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt, app/src/main/res/values*/strings.xml
Passes context into AchievementWatcher and adds the new localized settings_achievement_play_sound label across supported locales.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SettingsGroupInterface
  participant PrefManager
  participant AchievementWatcher
  participant MediaPlayer

  SettingsGroupInterface->>PrefManager: achievementPlaySound = toggle state
  AchievementWatcher->>PrefManager: read achievementPlaySound
  AchievementWatcher->>MediaPlayer: MediaPlayer.create(context, R.raw.achievement_pop)
  AchievementWatcher->>AchievementWatcher: checkForNewUnlocks() finds new unlock
  AchievementWatcher->>MediaPlayer: start()/seekTo(0) when enabled
Loading

Possibly related PRs

  • utkarshdalal/GameNative#831: Also changes AchievementWatcher behavior around earned achievement handling and notification flow.
  • utkarshdalal/GameNative#975: Modifies the same unlock-handling path in AchievementWatcher, with adjacent logic around achievement events.
  • utkarshdalal/GameNative#1251: Updates achievement notification gating in AchievementWatcher, which is the same control path extended here with sound playback.

Suggested reviewers: utkarshdalal

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding achievement unlock sound playback.
Description check ✅ Passed The description mostly follows the template with sections for description, type of change, and checklist, but the Recording section is empty.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/main/java/app/gamenative/service/AchievementWatcher.kt (1)

20-35: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Avoid storing the screen Context in AchievementWatcher.
PluviaApp.achievementWatcher is a companion-object reference, and XServerScreen passes LocalContext.current into setupXEnvironment and then into AchievementWatcher. Keeping that Context as a field can retain the Activity for the whole session; use context.applicationContext for MediaPlayer.create(...) and drop the stored property.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/app/gamenative/service/AchievementWatcher.kt` around lines
20 - 35, Avoid keeping the passed screen Context as a field in
AchievementWatcher, since PluviaApp.achievementWatcher can outlive the Activity
and leak it. In AchievementWatcher, use context.applicationContext directly
where needed, especially for MediaPlayer.create(...), and remove the stored
Context property from the constructor/state so the class only holds the
application-scoped context behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/app/gamenative/service/AchievementWatcher.kt`:
- Line 34: The MediaPlayer instance in AchievementWatcher is accessed from
multiple threads, so its lifecycle and playback calls need serialization. Update
achievementSoundPlayer usage so create/playback/stop/release all happen on one
thread or are protected by synchronization, including the FileObserver.onEvent
path and the stop() cleanup. Make sure the isPlaying, seekTo, start(), and
release() operations cannot race with each other by guarding the shared
MediaPlayer state consistently.

---

Outside diff comments:
In `@app/src/main/java/app/gamenative/service/AchievementWatcher.kt`:
- Around line 20-35: Avoid keeping the passed screen Context as a field in
AchievementWatcher, since PluviaApp.achievementWatcher can outlive the Activity
and leak it. In AchievementWatcher, use context.applicationContext directly
where needed, especially for MediaPlayer.create(...), and remove the stored
Context property from the constructor/state so the class only holds the
application-scoped context behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e3d11e5-9fb9-42b5-b2ee-4413a0ea6abf

📥 Commits

Reviewing files that changed from the base of the PR and between 7aaa095 and 01a7534.

⛔ Files ignored due to path filters (1)
  • app/src/main/res/raw/achievement_pop.mp3 is excluded by !**/*.mp3
📒 Files selected for processing (2)
  • app/src/main/java/app/gamenative/service/AchievementWatcher.kt
  • app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt

Comment thread app/src/main/java/app/gamenative/service/AchievementWatcher.kt Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/src/main/java/app/gamenative/service/AchievementWatcher.kt Outdated
Comment thread app/src/main/java/app/gamenative/ui/screen/xserver/XServerScreen.kt
@phobos665 phobos665 marked this pull request as draft July 6, 2026 09:46
@phobos665 phobos665 marked this pull request as ready for review July 6, 2026 09:57

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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