Skip to content

[Oztechan/CCC#4839] Cancel previous interstitial timer before starting a new one - #4840

Open
mustafaozhan wants to merge 1 commit into
developfrom
4839-Cancel_previous_interstitial_timer
Open

[Oztechan/CCC#4839] Cancel previous interstitial timer before starting a new one#4840
mustafaozhan wants to merge 1 commit into
developfrom
4839-Cancel_previous_interstitial_timer

Conversation

@mustafaozhan

Copy link
Copy Markdown
Member

What

setupInterstitialAdTimer() now cancels the existing data.adJob before launching a new one.

Why

Two onAppForeground() calls without an intervening onAppBackground() (a lifecycle quirk) would stack multiple timer coroutines, firing interstitials too often. onAppBackground() already cancels the job on the normal path; this makes it robust regardless of lifecycle pairing.

Test

Added onAppForeground twice cancels the previous interstitial timer — asserts the first job is cancelled and only the new one is active after a second foreground (fails on the old code).

Closes #4839

Copilot AI lite review requested due to automatic review settings August 6, 2026 10:19
@mustafaozhan
mustafaozhan requested a review from a team as a code owner August 6, 2026 10:19
@mustafaozhan mustafaozhan self-assigned this Aug 6, 2026
@mustafaozhan mustafaozhan added this to the 2.13.0 milestone Aug 6, 2026

Copilot AI 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.

Pull request overview

This PR makes the interstitial ad timer in MainViewModel resilient to a lifecycle quirk where onAppForeground() can be invoked multiple times without an intervening onAppBackground(), preventing multiple timer coroutines from stacking and triggering interstitials too frequently.

Changes:

  • Cancel any existing data.adJob before starting a new interstitial timer in setupInterstitialAdTimer().
  • Add a regression test verifying that a second onAppForeground() cancels the previous timer job and leaves only the new one active.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
client/viewmodel/main/src/commonMain/kotlin/com/oztechan/ccc/client/viewmodel/main/MainViewModel.kt Cancels the previous interstitial timer job before launching a new one to prevent stacked timers.
client/viewmodel/main/src/commonTest/kotlin/com/oztechan/ccc/client/viewmodel/main/MainViewModelTest.kt Adds a regression test ensuring repeated foreground events cancel the prior timer job.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

Cancel previous interstitial timer before starting a new one

2 participants