Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PlatformContext to pass Android Activity Context to use cases #310

Merged
merged 8 commits into from
Apr 29, 2024

Conversation

cbeyls
Copy link
Contributor

@cbeyls cbeyls commented Apr 29, 2024

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 PlatformContext argument and use it to wrap the Android Context on Android.

  • Move PlatformContext from the ui module to the domain module so it can be referenced from use cases.
  • Define PlatformContext as an empty object on iOS and a class containing a Context reference on Android.
  • Replace LocalPlatformContext CompositionLocal with an expect getPlatformContext() composable function. There is no need to create a new CompositionLocal because Android already has LocalContext to carry the Context over to any composable function, and an expect function is safer because it guarantees that a non-null PlatformContext is provided for every platform at compile time.
  • Update UrlOpener, OpenMapUseCase, ApplyForAppClinicUseCase, OpenCocUseCase, OpenFaqUseCase, OpenLinkUseCase, OpenPartnerLinkUseCase, OpenXAccountUseCase, OpenXHashtagUseCase, OpenYoutubeUseCase, ShareSessionUseCase to accept a PlatformContext as first argument.
  • Update the Android implementation of ShareSessionUseCase to use ShareCompat.IntentBuilder from the androidx.core library.
  • Use safer Uri.Builder instead of custom String formatting to build map Uri.

cbeyls added 8 commits April 28, 2024 22:58
…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)
# Conflicts:
#	shared/ui/src/commonMain/kotlin/com/androidmakers/ui/agenda/SessionDetailLayout.kt
@martinbonnin
Copy link
Contributor

Replace LocalPlatformContext CompositionLocal with an expect getPlatformContext() composable function.

Much better 👍 . Also another use case for expect/actual classes.

@martinbonnin martinbonnin merged commit 1fab371 into paug:main Apr 29, 2024
1 check passed
@cbeyls cbeyls deleted the refactor/platformcontext_use_cases branch May 2, 2024 15:56
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.

2 participants