Sharing Clips

The following section deals only with presenting the ClipShare functionality once you have performed a successful snap with the SnapOdds SDK.

Implementation

  1. Ensure your class conforms to ClipShareFragmentResultListener

  2. Instantiate ClipShareFragment with the required arguments

  3. Handle the result in your listener implementation

Sharing Clips

The following code illustrates how to present the ClipShareFragment. The recommended way is to present this right after you get the callback from the SnapOdds SDK about a snapped sport event, which is also reflected in this code sample.

override fun snapActivityDidSnapSportEvent(
        activity: SnapActivity,
        fragment: SnapFragment,
        sportEvent: SportEventSnapResultEntry
    ) {
        activity.finish()

        val tvChannelId = sportEvent.tvChannel?.id ?: return
        val snapTimestamp = sportEvent.timestamp ?: return
        val authorizationHeader = Snapscreen.instance?.authorizationHeader ?: return

        val epgUnitNameFallback = sportEvent.sportEvent?.league ?: sportEvent.sportEvent?.tournament ?: sportEvent.sportEvent?.sport

        parentFragmentManager.beginTransaction()
            .replace(
                R.id.fragment_container,
                ClipShareFragment.newInstance(
                    tvChannelId = tvChannelId,
                    tvChannelLogoUrl = sportEvent.tvChannel?.logoURL,
                    tvChannelName = sportEvent.tvChannel?.name,
                    epgUnitNameFallback = epgUnitNameFallback,
                    snapTimestamp = snapTimestamp,
                    snapscreenAuthorizationHeader = authorizationHeader,
                    listener = this
                )
            )
            .addToBackStack(ClipShareFragment::class.java.canonicalName)
            .commit()
    }

When the user successfully trims a desired clip, the following method is called in your ClipShareFragmentResultListener:

override fun clipShareFragmentDidCreateClip(fragment: ClipShareFragment, clip: Clip) {
  // add desired behaviour here
}

When the clip could not be created for any reason, the following method is called in your ClipShareFragmentResultListener:

override fun clipShareFragmentDidFailCreatingClip(fragment: ClipShareFragment) {
  // add desired behaviour here
}

When no clip information for the provided Snap Result could be loaded, the following method is called in your ClipShareFragmentResultListener:

override fun clipShareFragmentDidFailLoadingClip(fragment: ClipShareFragment) {
  // add desired behaviour here
}

Additionally it is (very rarely) possible that the loaded clip is not long enough to support trimming. In that case the following method is called in your ClipShareFragmentResultListener:

override fun clipShareFragmentDidFailWithTooShortClip(fragment: ClipShareFragment) {
  // add desired behaviour here
}

Last updated