Building a Prediction and followup widget


Minimum SDK Version


This is a guide on building a custom Prediction and followup Widget. For an overview of the Custom Widget UI system see Custom Widget UI.

Prediction Widget Model

The Prediction Widget Model is responsible for providing prediction specific data and remote apis for vote and results;

Prediction Data(object of LiveLikeWidget class)
The Prediction Data provides data about the Prediction Widget such as the title text and the options.

The model also provides metadata about the widget such as the Date that it was created or the timeout duration set by the Producer.

Note: Use options in livelikeWidget class for the Prediction.

predictionWidgetModel?.widgetData?.let { liveLikeWidget ->
            liveLikeWidget.options?.let {
                if (it.size > 2) {
                    rcyl_poll_list.layoutManager = GridLayoutManager(context, 2)
                val adapter =
                    PredictionListAdapter(context, isImage, ArrayList( { item -> item!! }))
                rcyl_poll_list.adapter = adapter
                adapter.pollListener = object : PollListAdapter.PollListener {
                    override fun onSelectOption(id: String) {
                button2.visibility = View.GONE

For submitting or changing the vote on the option for the poll which needed optionId to send to the backend for changing/submitting the vote for the poll.


The VoteResults gives you events for updates on the Prediction Widget. The event contains the vote count changes for each option on the server.

predictionWidgetModel?.voteResults?.subscribe(this) { result ->
                    result?.choices?.let { options ->
                        options.forEach { op ->
                            adapter.optionIdCount[] = op.vote_count ?: 0

Interaction History
To load the interaction history, you can call the loadInteractionHistory method

predictionWidgetViewModel?.loadInteractionHistory( object : LiveLikeCallback<List<PredictionWidgetUserInteraction>>(){
            override fun onResponse(result: List<PredictionWidgetUserInteraction>?, error: String?) {


FollowUp Widget Model

The follow-up model has the same functions as the above one except lockInVote.

This method on the model allows you to the retrieve predictionVoteId that user voted on prediction associated with this follow up

val voteId = followUpWidgetViewModel?.getPredictionVoteId()
optionsAdapter.selectedIndex = optionList.indexOfFirst { option-> option?.id == followUpWidgetViewModel?.getPredictionVoteId() }

claims the rewards on the prediction follow up using a user’s vote
returns nothing but notifies leaderboard clients