Post sharing functionality is currently not available from the system. However, UIKit provides a ready made "share" button with an interface for users to specify their own post sharing behaviours.
Post sharing settings
These settings allow you to control the "share" button visibility. The button appearance is based on the post origin and the destination that it can be shared to.
The are five possible targets that a post can be shared to
My feed - The post can be shared to my feed. This option will enable "Share to my timeline" menu when user clicks share button.
Public community - The post can be shared to any public community. This option will enable "Share to group" menu when user clicks share button.
Privatecommunity - The post can be shared to any private community. This option will enable "Share to group" menu when user clicks share button.
External - The post can be shared externally. This option will enable "More options" menu when user clicks share button.
Origin - The post can be shared within the community feed that it was created. If the post was created in either public or private community, this option will enable "Share to group" menu when user clicks share button.
There are four possible origins
My feed post - Posts that were created on my feed. By default, possible sharing targets are My feed, Public community, and Private community.
User feed post - Posts that were created on any other users' feed. By default, possible sharing targets are My feed, Public community, and Private community.
Public community feed post - Posts that were created on any public community. By default, possible sharing targets are My feed, Public community, and Private community.
Private community feed post - Posts that were created on any private community. By default, possible sharing target is Origin.
Usage
You can select a set of targets for each post origin.
// In your Application class
val mySharingSettings = AmityPostSharingSettings()
// Allow post created by logged-in user to be shared anywhere
mySharingSettings.myFeedPostSharingTarget
= listOf(AmityPostSharingSettings.values())
// Allow post created by any other user to be shared anywhere
mySharingSettings.userFeedPostSharingTarget
= listOf(AmityPostSharingSettings.values())
// Allow post created by any other user to be shared anywhere
mySharingSettings.publicCommunityPostSharingTarget
= listOf(AmityPostSharingSettings.values())
// Ensure post created in private community cannot be shared elsewhere
mySharingSettings.privateCommunityPostSharingTarget
= listOf(AmityPostSharingSettings.originFeed)
AmityUIKitClient.socialUISettings.postSharingSettings = mySharingSettings
Post sharing events
Based on Post sharing settings, there are up to three post sharing events that can be emitted by UIKit.
Share to my timeline - an event emitted when a user clicks on "Share to my timeline" button.
Share to group - an event emitted when a user clicks on "Share to group" button.
Share externally - an event emitted when a user clicks "More options" button.
Usage
You can choose to intercept one or all of the events and apply your custom behaviors.
// In your Application class
// Ex. launch a share intent with post data
AmityUIKitClient.socialUISettings.feedEventHandler
= object : AmityPostShareClickListener {
override fun shareToExternal(context: Context, post: EkoPost) {
// generate a link
val sharingPost = "https://www.upstra.co/post?id=" + post.getPostId()
// lauch an intent with the generated link
val share = Intent.createChooser(Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, sharingPost)
}, null)
startActivity(share)
}
}
Post Rendering
Custom Post Rendering
UIKit provides default renderers for the core data types, text, image, and file. For custom post rendering, a map of data type and renderer can be registered and UIKit will refer to this map while rendering post component.
Usage
// To provide a custom renderer, implement an AmityPostRenderer
val customViewHolder = object : AmityPostRenderer {
// Specify the dataType to be rendered by this renderer
override fun getDataType(): String = "myapp.customtype"
// Provide a layout of your viewHolder
override fun getLayoutId(): Int = R.layout.custom_post
// Provide a viewHolder that is subclassed from AmityPostContentViewHolder
override fun createViewHolder(
view: View
): AmityPostContentViewHolder {
return MyCustomViewHolder(view)
}
// Choose whether to have a post header
override fun enableHeader(): Boolean {
return true
}
// Choose whether to have a post footer
override fun enableFooter(): Boolean {
return false
}
}
// Register the custom renderer
AmityUIKitClient.socialUISettings.registerPostRenderers(listOf(customViewHolder))