Translations: 简体中文
Important
Only available on Android platform
The cellular traffic saving function can set the depth parameter of ImageRequest to Depth.LOCAL when detecting that current cellular traffic is present, so that images will no longer be downloaded from the network.
${LAST_VERSION}
: (Not included 'v')
implementation("io.github.panpf.sketch4:sketch-extensions-core:${LAST_VERSION}")
First register the SaveCellularTrafficRequestInterceptor request interceptor, as follows:
// Register for all ImageRequests when customizing Sketch
Sketch.Builder(context).apply {
components {
addRequestInterceptor(SaveCellularTrafficRequestInterceptor())
}
}.build()
// Register for a single ImageRequest when loading an image
ImageRequest(context, "https://example.com/image.jpg") {
components {
addRequestInterceptor(SaveCellularTrafficRequestInterceptor())
}
}
Then enable the cellular data saving function for a single request, as follows:
ImageRequest(context, "https://example.com/image.jpg") {
saveCellularTraffic(true)
}
Finally, configure the error status picture dedicated to the cellular traffic saving function, as follows:
// View
ImageRequest(context, "https://example.com/image.jpg") {
saveCellularTraffic(true)
error(
ConditionStateImage(defaultImage = R.drawable.ic_error) {
saveCellularTrafficError(R.drawable.ic_signal_cellular)
}
)
}
// Compose
ComposableImageRequest(context, "https://example.com/image.jpg") {
saveCellularTraffic(true)
error(
ComposableConditionStateImage(defaultImage = Res.drawable.ic_error) {
saveCellularTrafficError(Res.drawable.ic_signal_cellular)
}
)
}
Tip
saveCellularTrafficError(Res.drawable.ic_signal_cellular)
needs to import the
sketch-extensions-compose-resources
module
Important
- Only supports Android View
- This feature requires the use of SketchImageView
Enable clicking ImageView to ignore cellular data and redisplay the image
sketchImageView.setClickIgnoreSaveCellularTrafficEnabled(true)