Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 2.62 KB

save_cellular_traffic.md

File metadata and controls

87 lines (63 loc) · 2.62 KB

Save cellular data

Translations: 简体中文

Important

  1. Required import sketch-extensions-core module
  2. Temporarily unavailable for non-Android platforms

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.

Configure

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(R.drawable.ic_error) {
        saveCellularTrafficError(R.drawable.ic_signal_cellular)
    }
}

// Compose
ComposableImageRequest(context, "https://example.com/image.jpg") {
    saveCellularTraffic(true)

    composableError(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

Click to force load

Important

  1. Only supports Android View
  2. This feature requires the use of SketchImageView

Enable clicking ImageView to ignore cellular data and redisplay the image

sketchImageView.setClickIgnoreSaveCellularTrafficEnabled(true)