Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TwitterViewComponent - simple
package com.bk.sample.android.component
[...]
import com.bk.sample.android.util.databinding.ObservableString
import com.twitter.sdk.android.core.Callback
import com.twitter.sdk.android.core.Result
import com.twitter.sdk.android.core.TwitterException
import com.twitter.sdk.android.core.models.Tweet
import com.twitter.sdk.android.tweetui.TweetUtils
import com.twitter.sdk.android.tweetui.TweetView
class TwitterViewComponent : RelativeLayout {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
/**
* Sets twitter id and builds tweet UI
*/
fun setTwitterId(tweetId: ObservableString) {
val componentInstance = this
TweetUtils.loadTweet(tweetId.get().toLong(), object: Callback<Tweet>() {
override fun success(result: Result<Tweet>?) {
val tweet = result!!.data
componentInstance.addView(TweetView(componentInstance.context, tweet))
invalidate()
}
override fun failure(exception: TwitterException?) {
Log.e(TwitterViewComponent::javaClass.name, "Could not load tweet: " + exception.toString())
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.