Skip to content

MOBILE-114: Add public API unregisterInAppCallback#706

Open
enotniy wants to merge 2 commits intodevelopfrom
feature/MOBILE-114
Open

MOBILE-114: Add public API unregisterInAppCallback#706
enotniy wants to merge 2 commits intodevelopfrom
feature/MOBILE-114

Conversation

@enotniy
Copy link
Copy Markdown
Collaborator

@enotniy enotniy commented Apr 16, 2026

@enotniy enotniy requested a review from sergeysozinov April 16, 2026 15:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new public API to remove a previously registered InApp callback and revert to the SDK’s default InApp handling.

Changes:

  • Introduces unregisterInAppCallback() in the public Mindbox API with accompanying KDoc.
  • Plumbs the new API through InAppMessageManager / InAppMessageViewDisplayer and restores a stored default callback in the displayer implementation.
  • Adds unit tests verifying callback registration/unregistration behavior in InAppMessageViewDisplayerImpl.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt Adds public unregisterInAppCallback() and expands documentation for callback lifecycle.
sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageManager.kt Adds unregisterInAppCallback() to manager interface.
sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageManagerImpl.kt Implements unregisterInAppCallback() and switches wrappers to loggingRunCatching.
sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageViewDisplayer.kt Adds unregisterInAppCallback() to displayer interface.
sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageViewDisplayerImpl.kt Stores a defaultCallback and resets to it on unregister.
sdk/src/test/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageViewDisplayerImplTest.kt Adds tests covering default, register, unregister, and repeated register scenarios.

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

import cloud.mindbox.mobile_sdk.Mindbox.disposePushTokenSubscription
import cloud.mindbox.mobile_sdk.Mindbox.handleRemoteMessage
import cloud.mindbox.mobile_sdk.Mindbox.registerInAppCallback
import cloud.mindbox.mobile_sdk.Mindbox.unregisterInAppCallback
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

These two imports appear to be unused in code (only referenced in KDoc, and the KDoc links already resolve without importing members from the same object). With ktlint enabled in this repo (modulesCommon.gradle applies org.jlleitschuh.gradle.ktlint), unused imports will fail the lint task. Please remove these imports (or switch KDoc links to fully-qualified names if you intended to rely on imports for link resolution).

Suggested change
import cloud.mindbox.mobile_sdk.Mindbox.unregisterInAppCallback

Copilot uses AI. Check for mistakes.
Comment on lines +765 to +766
* of the next, so callbacks never overlap and the Activity reference is always cleared
* before the Activity can be garbage-collected.
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

The KDoc here claims that unregistering in onPause ensures the Activity reference is cleared before the Activity can be garbage-collected. In the current implementation, the callback is captured into InAppCallbackWrapper(callback: InAppCallback) when an in-app is shown (see InAppCallbackWrapper.kt), so any currently displayed/paused in-app can still hold the old callback (and its Activity reference) even after unregisterInAppCallback() is called. Please adjust the documentation to reflect that unregistering affects only future in-apps (or change the callback wiring so the wrapper delegates to the current callback rather than capturing a snapshot).

Suggested change
* of the next, so callbacks never overlap and the Activity reference is always cleared
* before the Activity can be garbage-collected.
* of the next, so callback registrations for future in-apps do not overlap.
* Note: `unregisterInAppCallback()` affects only future in-apps. An in-app that is
* already being shown may still hold the callback instance that was captured when it
* was displayed, so unregistering in `onPause` does not retroactively clear that
* reference.

Copilot uses AI. Check for mistakes.
Comment on lines +791 to +794
* **When to call:**
* Only needed for per-screen callbacks registered in `onResume`. Call in the corresponding
* `onPause` to release the Activity reference and restore default behavior while another
* screen is in the foreground.
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

This section says calling unregisterInAppCallback() in onPause will "release the Activity reference". Given the callback is copied into InAppCallbackWrapper at render time, an active/paused in-app may still retain the previous callback instance until it is dismissed/closed. Please either clarify this in the KDoc (e.g., recommend dismissing current in-app before unregistering if the callback captures an Activity) or update the implementation so active holders stop referencing the old callback after unregistration.

Copilot uses AI. Check for mistakes.
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.

3 participants