Created
August 30, 2018 07:45
-
-
Save kosiara/83528fce18c9ab01f21d64dfaad0c2c1 to your computer and use it in GitHub Desktop.
TwitterViewComponent - simple
This file contains hidden or 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
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