j
-.php
a
Copy code
fun ImageView.load(imageUrl: String, picasso: Picasa) {...}
and inject Picasa in your activity
j
You can also create your own component that will contain Picasa already
but that requires a bit more work
I see it a bit ugly to continuously send picasa, but there is no other way with a function extension
p
Use Picasso as a default parameter
fun ImageView.load(imageUrl: String, @VisibleForTesting picasso: Picasso = Picasso.get())
👍 1
j
true
mmm previously i was using Picasso.with(context).load(URL).into(imageView)
is the context not needed anymore?
p
Correct
j
ah ok, then that could be the reason why i didnt consider a default parameter
but now it works like a charm
p
Btw if you go fancy you could pass a function 😉
Copy code
fun ImageView.load(imageUrl: String, picasso: (Context) -> Picasso = { Picasso.with(it) }) {
  if (imageUrl.isNotEmpty()) {
    picasso(context).load(imageUrl).into(this)
  }
}
💪 2
j
nice
I will give this a try
a
@Paul Woitaschek is that a default value for the function? I'm not familiar with that syntax. Sorry if it's stupid, I'm still learning :p
p
Yes it is
picasso: (Context) -> Picasso
the parameter
picasso
is a function that takes a
Context
and returns an instance of
Picasso
.
= { Picasso.with(it) }
By default this function is a lambda and returns
Picasso.with(it)
when called (where
it
is a context)