-
Notifications
You must be signed in to change notification settings - Fork 1
@LoadImage annotation
crypticminds edited this page Feb 7, 2020
·
3 revisions
@LoadImage annotation can be used over an ImageView or any of its variants (Eg. CircularImageView ) to load an image from a URL and set it into the view while caching it for future use.
- imageViewResourceId (Int) -> The resource id of the ImageView . This is a mandatory parameter that will be used to bind the view from the layout to the annotated variable.
- url (String) -> The Url from where the image will be downloaded. This is a mandatory parameter.
- placeHolder (Int)-> The resource id of the placeholder image that will be displayed until the image is downloaded and loaded into the ImageView. The id should be of a drawable resource. This is an optional parameter.
- enableLoadingAnimation (Boolean) -> A boolean value representing if a loading animation should be shown or not. The loading animation will only work if a placeholder image has been provided. The default animation will rotate the placeholder image. In upcoming releases, there will be option to provide custom animations such as fade-in, scale-up, etc.
-
Annotate the image view with @LoadImage. The variable needs to be public so that ColdStorae can access it and initialize it.
@LoadImage( R.id.image_1, "https://images.unsplash.com/photo-1549740425-5e9ed4d8cd34?ixlib=rb-1.2.1&w=1000&q=80", placeHolder = R.drawable.loading, enableLoadingAnimation = true ) lateinit var imageWithAnimation: ImageView -
Bind the class that contains the ImageView to the Cache. The cache binding is currently supported for Activity, Fragment and other Views (For example if you have created a custom view that contains ImageViews).
- For activities, the binding should be done after setContentView
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.load_image_example) Cache.bind(this) }
- For fragments, the binding should be done in onViewCreatedMethod
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) Cache.bind(this) }