Skip to content

Instantly share code, notes, and snippets.

@clackbib
Last active July 11, 2017 12:18
Show Gist options
  • Save clackbib/26ae484f67b8f4c2fc8f3614ddfdd407 to your computer and use it in GitHub Desktop.
Save clackbib/26ae484f67b8f4c2fc8f3614ddfdd407 to your computer and use it in GitHub Desktop.
data class User(
val id: String,
val name: String,
val profilePicUrl: String,
val bio: String)
public class UserFragment : Fragment() {
private lateinit var vm: UserViewModel
private lateinit var bin: Disposable
private lateinit var tvTitle: TextView
private lateinit var tvDescription: TextView
private lateinit var ivPicture: ImageView
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bin = vm.user()
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ user ->
tvTitle.text = user.name
tvDescription.text = user.bio
Glide.with(context).load(user.profilePicUrl)
.into(ivPicture)
})
}
override fun onDestroyView() {
super.onDestroyView()
bin.dispose()
}
}
public class UserViewModel {
private lateinit var repo: Repository
fun user(): Observable<User> {
return repo.loadUser()
.subscribeOn(Schedulers.io())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment