-
-
Save 5AbhishekSaxena/69565c177f79c59a872651f119d03132 to your computer and use it in GitHub Desktop.
Factory method to get intent for each sharing type
This file contains 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
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