Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] How to use asFile() request Builder #173

Closed
Shabinder opened this issue Dec 30, 2020 · 1 comment
Closed

[Help] How to use asFile() request Builder #173

Shabinder opened this issue Dec 30, 2020 · 1 comment

Comments

@Shabinder
Copy link

Shabinder commented Dec 30, 2020

I am trying to Accomplish Something Like this:

Load Image from a URL asFile then copy that file for later Use and and also load same Image.

If I do following using Drawable the image obtaines as File is of Low Res than original.

Glide
            .with(imgView)
            .asFile()
            .load(imgUri)
            .placeholder(R.drawable.ic_song_placeholder)
            .error(R.drawable.ic_musicplaceholder)
            .listener(object:RequestListener<File>{
                override fun onLoadFailed(
                    e: GlideException?,
                    model: Any?,
                    target: Target<File>?,
                    isFirstResource: Boolean
                ): Boolean {
                    log("Glide","LoadFailed")
                    return false
                }

                override fun onResourceReady(
                    resource: File?,
                    model: Any?,
                    target: Target<File>?,
                    dataSource: DataSource?,
                    isFirstResource: Boolean
                ): Boolean {
                    CoroutineScope(Dispatchers.Main).launch {
                            try {
                                val file = File(/*File Path*/)
                                resource?.copyTo(file)
                                Glide.with(imgView)
                                    .load(file)
                                    .placeholder(R.drawable.ic_song_placeholder)
                                    .into(imgView)
                            } catch (e: IOException) {
                                e.printStackTrace()
                            }
                    }
                     return false
                }
            }).submit()
        }
@chrisbanes
Copy link
Contributor

Duplicate of #172

@chrisbanes chrisbanes marked this as a duplicate of #172 Dec 30, 2020
@google google locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants