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
| private class EditModeViewDependency<out T>(val view: View, val initializer: () -> T) : ViewDependency<T> { | |
| override val value: T | |
| get() { | |
| ApplicationReference.application = EditModeApplication(view.context) | |
| return initializer.invoke() | |
| } | |
| } |
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
| private class EditModeApplication(context: Context) : ShazamApplication() { | |
| init { | |
| attachBaseContext(context) | |
| } | |
| } |
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
| private class EditModeViewDependency<out T>(val view: View, val initializer: () -> T) : ViewDependency<T> { | |
| override val value: T | |
| get() { | |
| ApplicationReference.application = view.context | |
| return initializer.invoke() | |
| } | |
| } |
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
| private class ImmediateViewDependency<out T>(initializer: () -> T) : ViewDependency<T> { | |
| override val value: T = initializer() | |
| } |
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
| interface ViewDependency<out T> : ReadOnlyProperty<View, T> { | |
| val value: T | |
| override fun getValue(thisRef: View, property: KProperty<*>): T = value | |
| } |
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
| public class SomeCustomView extends View { | |
| @Nullable | |
| private Picasso picasso; | |
| public SomeCustomView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | |
| super(context, attrs, defStyleAttr); | |
| if (!isInEditMode()) { | |
| picasso = picasso(); | |
| } |
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
| import static com.shazam.injector.picasso.PicassoInjector.picasso; | |
| public class SomeCustomView extends View { | |
| private final Picasso picasso = picasso(); | |
| ... | |
| } |
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
| public class PicassoInjector { | |
| public static Picasso picasso() { | |
| return Picasso.with(shazamApplicationContext()); | |
| } | |
| } |
NewerOlder