Skip to content

Conversation

@joshuatam
Copy link
Contributor

@joshuatam joshuatam commented Jan 2, 2026

Moves the Timber log listener instantiation to the top of the class and removes it on service destruction for proper logging behavior.

Added missing off event at MainViewModel

Adds a prefix "Main:" or "UserLogin:" to Timber log messages to quickly identify the source of events.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed potential memory leaks by ensuring event subscriptions and listeners are properly removed during lifecycle cleanup
  • Chores

    • Centralized logger handling with explicit registration and removal for cleaner lifecycle management
    • Standardized log messages by adding explicit component tags across view models for improved traceability and debugging

✏️ Tip: You can customize this high-level summary in your review settings.

Moves the Timber log listener instantiation to the top of the class and removes it on service destruction for proper logging behavior.

Adds a prefix "Main:" or "UserLogin:" to Timber log messages to quickly identify the source of events.
@coderabbitai
Copy link

coderabbitai bot commented Jan 2, 2026

📝 Walkthrough

Walkthrough

Promoted a local logger to a class-level LogListener in SteamService with explicit add/remove lifecycle calls; standardized Timber logging to use explicit tags (e.g., "MainViewModel", "UserLoginViewModel") across two ViewModel classes and added one Steam event unsubscription in MainViewModel.onCleared.

Changes

Cohort / File(s) Summary
SteamService — logger lifecycle
app/src/main/java/app/gamenative/service/SteamService.kt
Added private val logger: LogListener at class level; replaced local logger usage with the field; call LogManager.addListener(logger) in onCreate() and LogManager.removeListener(logger) in clearValues() (companion object).
MainViewModel — tagged logging & cleanup
app/src/main/java/app/gamenative/ui/model/MainViewModel.kt
Replaced untagged Timber calls with Timber.tag("MainViewModel")..., added logging in additional branches, and unsubscribed SteamEvent.LogonStarted in onCleared().
UserLoginViewModel — tagged logging
app/src/main/java/app/gamenative/ui/model/UserLoginViewModel.kt
Replaced untagged Timber calls with Timber.tag("UserLoginViewModel")... across lifecycle and event handlers; no behavioral changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰
A tiny logger finds my den,
Tagged and tidy, hopping then,
From Steam to ViewModel, clear and bright,
I nibble bugs and keep logs light,
Hooray — clean trails in morning light!

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Remove duplicated log lines' does not accurately represent the main changes, which involve adding tags to logging statements, moving logger instantiation to class-level, and adding missing log events. Update the title to better reflect the actual changes, such as 'Add logging tags to ViewModels and refactor SteamService logger' or 'Add Timber tags for better log filtering and organization'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30520fe and c869ad2.

📒 Files selected for processing (2)
  • app/src/main/java/app/gamenative/ui/model/MainViewModel.kt
  • app/src/main/java/app/gamenative/ui/model/UserLoginViewModel.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
app/src/main/java/app/gamenative/ui/model/UserLoginViewModel.kt (1)

37-37: LGTM! Consistent Timber tagging improves log traceability.

The explicit Timber tags consistently identify the source ViewModel across all logging statements, making debugging and log filtering straightforward.

Also applies to: 52-52, 76-76, 99-99, 110-110, 117-117, 128-128, 184-184, 197-197, 211-211, 224-224, 279-279, 328-328

app/src/main/java/app/gamenative/ui/model/MainViewModel.kt (2)

79-79: LGTM! Consistent Timber tagging enhances observability.

All logging statements now use the explicit "MainViewModel" tag, making it easy to filter and trace events originating from this ViewModel.

Also applies to: 84-84, 89-89, 99-99, 106-106, 113-115, 367-367, 383-383


149-158: Excellent fix! Added missing event unsubscription.

The SteamEvent.LogonStarted event subscription (line 132) now has a corresponding unsubscription in onCleared, preventing a potential memory leak. This directly addresses the PR objective.


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 and usage tips.

@joshuatam joshuatam marked this pull request as ready for review January 2, 2026 06:19
Adds a Timber tag to logs within MainViewModel and UserLoginViewModel.
This improves log filtering and debugging by providing context.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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/ui/model/UserLoginViewModel.kt (1)

223-236: Critical: Missing event unsubscription causes memory leak.

The SteamEvent.RemotelyDisconnected event is subscribed at line 207 but never unsubscribed in onCleared. This prevents the onRemoteDisconnected handler from being garbage collected, causing a memory leak.

🔎 Proposed fix
     override fun onCleared() {
         Timber.tag("UserLoginViewModel").d("onCleared")
 
         PluviaApp.events.off<SteamEvent.Connected, Unit>(onSteamConnected)
         PluviaApp.events.off<SteamEvent.Disconnected, Unit>(onSteamDisconnected)
         PluviaApp.events.off<SteamEvent.LogonStarted, Unit>(onLogonStarted)
         PluviaApp.events.off<SteamEvent.LogonEnded, Unit>(onLogonEnded)
         PluviaApp.events.off<AndroidEvent.BackPressed, Unit>(onBackPressed)
         PluviaApp.events.off<SteamEvent.QrChallengeReceived, Unit>(onQrChallengeReceived)
         PluviaApp.events.off<SteamEvent.QrAuthEnded, Unit>(onQrAuthEnded)
         PluviaApp.events.off<SteamEvent.LoggedOut, Unit>(onLoggedOut)
+        PluviaApp.events.off<SteamEvent.RemotelyDisconnected, Unit>(onRemoteDisconnected)
 
         SteamService.stopLoginWithQr()
     }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30520fe and c869ad2.

📒 Files selected for processing (2)
  • app/src/main/java/app/gamenative/ui/model/MainViewModel.kt
  • app/src/main/java/app/gamenative/ui/model/UserLoginViewModel.kt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
app/src/main/java/app/gamenative/ui/model/UserLoginViewModel.kt (1)

37-37: LGTM! Consistent Timber tagging improves log traceability.

The explicit Timber tags consistently identify the source ViewModel across all logging statements, making debugging and log filtering straightforward.

Also applies to: 52-52, 76-76, 99-99, 110-110, 117-117, 128-128, 184-184, 197-197, 211-211, 224-224, 279-279, 328-328

app/src/main/java/app/gamenative/ui/model/MainViewModel.kt (2)

79-79: LGTM! Consistent Timber tagging enhances observability.

All logging statements now use the explicit "MainViewModel" tag, making it easy to filter and trace events originating from this ViewModel.

Also applies to: 84-84, 89-89, 99-99, 106-106, 113-115, 367-367, 383-383


149-158: Excellent fix! Added missing event unsubscription.

The SteamEvent.LogonStarted event subscription (line 132) now has a corresponding unsubscription in onCleared, preventing a potential memory leak. This directly addresses the PR objective.

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