Use PlatformContext to pass Android Activity Context to use cases#310
Merged
martinbonnin merged 8 commits intopaug:mainfrom Apr 29, 2024
Merged
Conversation
…roid and be defined at the Domain level on all OSes - refactor ShareSessionUseCase to take a PlatformContext argument and use ShareCompat on Android (cherry picked from commit d0e0f49)
…as argument (cherry picked from commit b103c3f)
# Conflicts: # shared/ui/src/commonMain/kotlin/com/androidmakers/ui/agenda/SessionDetailLayout.kt
…ry after updating OpenFeedback SDK
Contributor
Much better 👍 . Also another use case for expect/actual classes. |
martinbonnin
pushed a commit
that referenced
this pull request
Mar 7, 2025
* - refactor PlatformContext to provide a non-null typed context on Android and be defined at the Domain level on all OSes - refactor ShareSessionUseCase to take a PlatformContext argument and use ShareCompat on Android (cherry picked from commit d0e0f49) * refactor UrlOpener and all related use cases to take PlatformContext as argument (cherry picked from commit b103c3f) * remove androidContextOrNull field from PlatformContext, now unnecessary after updating OpenFeedback SDK * fix missing PlatformContext argument for openMapUseCase() call * replace LocalPlatformContext with expect composable function getPlatformContext() * faster implementation of replace(" ", "") * use Uri Builder instead of custom String formatting to build Map Uri
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since many use cases should use an Activity Context rather than the Application Context on Android to work properly (mostly to launch Intents), refactor these use cases to take a
PlatformContextargument and use it to wrap the Android Context on Android.PlatformContextfrom the ui module to the domain module so it can be referenced from use cases.PlatformContextas an empty object on iOS and a class containing aContextreference on Android.LocalPlatformContextCompositionLocal with anexpect getPlatformContext()composable function. There is no need to create a new CompositionLocal because Android already hasLocalContextto carry the Context over to any composable function, and an expect function is safer because it guarantees that a non-nullPlatformContextis provided for every platform at compile time.UrlOpener,OpenMapUseCase,ApplyForAppClinicUseCase,OpenCocUseCase,OpenFaqUseCase,OpenLinkUseCase,OpenPartnerLinkUseCase,OpenXAccountUseCase,OpenXHashtagUseCase,OpenYoutubeUseCase,ShareSessionUseCaseto accept aPlatformContextas first argument.ShareSessionUseCaseto useShareCompat.IntentBuilderfrom the androidx.core library.Uri.Builderinstead of custom String formatting to build mapUri.