[components] Close https://github.com/mozilla-mobile/android-components/issues/8040: Move ImageLoader to support-base

The `ImageLoader` API is public and we should have it in a better place.
This commit is contained in:
Jonathan Almeida
2020-10-05 20:21:33 -04:00
committed by mergify[bot]
parent 9afa3a75f7
commit ac73bae091
18 changed files with 27 additions and 22 deletions

View File

@@ -27,6 +27,7 @@ android {
dependencies {
implementation Dependencies.kotlin_stdlib
implementation Dependencies.kotlin_coroutines
implementation Dependencies.androidx_annotation
testImplementation Dependencies.androidx_test_junit
testImplementation Dependencies.testing_robolectric

View File

@@ -0,0 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.concept.base.images
import android.graphics.drawable.Drawable
import android.widget.ImageView
import androidx.annotation.MainThread
/**
* A loader that can load an image from an ID directly into an [ImageView].
*/
interface ImageLoader {
/**
* Loads an image asynchronously and then displays it in the [ImageView].
* If the view is detached from the window before loading is completed, then loading is cancelled.
*
* @param view [ImageView] to load the image into.
* @param request [ImageLoadRequest] Load image for this given request.
* @param placeholder [Drawable] to display while image is loading.
* @param error [Drawable] to display if loading fails.
*/
@MainThread
fun loadIntoView(
view: ImageView,
request: ImageLoadRequest,
placeholder: Drawable? = null,
error: Drawable? = null
)
}

View File

@@ -0,0 +1,23 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package mozilla.components.concept.base.images
import androidx.annotation.Px
/**
* A request to save an image. This is an alias for the id of the image.
*/
typealias ImageSaveRequest = String
/**
* A request to load an image.
*
* @property id The id of the image to retrieve.
* @property size The preferred size of the image that should be loaded in pixels.
*/
data class ImageLoadRequest(
val id: String,
@Px val size: Int
)