Skip to content

Instantly share code, notes, and snippets.

@5AbhishekSaxena
Last active December 14, 2021 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5AbhishekSaxena/69565c177f79c59a872651f119d03132 to your computer and use it in GitHub Desktop.
Save 5AbhishekSaxena/69565c177f79c59a872651f119d03132 to your computer and use it in GitHub Desktop.
Factory method to get intent for each sharing type
class SharingIntentFactory {
fun prepareIntent(context: Context, sharingType: SharingType): Intent {
return when (sharingType) {
is SharingType.Default -> {
ShareCompat.IntentBuilder(context)
.setType("text/plain")
.setText(sharingType.text)
.intent
}
is SharingType.SmsType -> {
Intent().apply {
action = Intent.ACTION_VIEW
data = Uri.parse("sms: ${sharingType.sms.phoneNumber}")
putExtra("sms_body", sharingType.sms.body)
}
}
is SharingType.WebBrowserType -> {
Intent().apply {
action = Intent.ACTION_VIEW
data = sharingType.url.toUri()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment