twilio / twilio-chat-demo-android

Chat API Demo Application for Android
MIT License
62 stars 51 forks source link

Download Media strategy. #61

Closed aalap03 closed 6 years ago

aalap03 commented 6 years ago

Right now in twilio we have media.download(byteoutputStream, statusListener, progressListener) method to download image.

So, Is there a way we can get the image link instead of bytearraystream with the REST call for already uploaded images in twilio? And we use download method when image upload is ongoing ???

I asked this because, It seems to get overwhelmed if I have too many images in a chat group and user enters first time and tries to download bytearrays while scrolling through the messages. With already uploaded links, glide can do the work, thus we handle only ongoing uploading images. My back-end colleague said they use image links for web client.

media?.download(byteOutputArray, object : StatusListener() {
                override fun onSuccess() {
                    mediaSid?.let { mapImageStatus.put(it, COMPLETED) }
                    info { "$mediaFileName Image: success " }
                    //set downloaded image file to imageview
                }

            }, object : ProgressListener() {

                override fun onStarted() {
                    toggleImageProgress(false, 0f)
                    info { "$mediaFileName Image: started: " }
                }

                override fun onProgress(progress: Long) {
                    mediaSid?.let { mapImageStatus.put(it, PROGRESS) }

                    val progressPer = ((progress.toDouble() / mediaSize!!.toDouble()) * 100).toFloat()
                    info { "$mediaFileName Image: progress.. $progressPer" }
                    mapImageProgress[mediaSid!!] = progressPer
                    toggleImageProgress(false, mapImageProgress[mediaSid]!!)
                }

                override fun onCompleted(mediaId: String?) {

                    info { "$mediaFileName Image: completed: hopefully binded......." }

                    //save image file and set downloaded image file to imageview

                    mapImagePaths[mediaSid!!] = imageFile
                }
            })
aalap03 commented 6 years ago

Hi, are there any ideas about this question or any feedback on this ?

berkus commented 6 years ago

You can get media URL through REST api, but it's not available to the SDK.

I'm still not quite getting what you're trying to do and what the problem is, can you give some simple examples?

aalap03 commented 6 years ago

So, I am trying to fill a MessagesActivity with Images and texts with pagination (15 msgs at a time), my issue is If I have lots of images and user scrolls too fast then some images gets distorted.

I use glide to populate downloaded Images, I save image file in local directory to avoid multiple downloads of image. It works in normal case but with too many images and fast scrolling It gets tedious to manage inside ViewHolder.

Also, as you mentioned if URL is available via REST call, Can developer make those calls from android client ??

berkus commented 6 years ago

Well, this is how you supposed to do - chat only manages uploading and downloading attached images; caching and fast drawing is your responsibility.

You could make REST calls from Android but this will be insecure - REST calls require your secret key auth.

You should probably rearchitect your approach to media downloading and caching, put more work upfront, preload images before scrolling in etc.

berkus commented 6 years ago

Closing as there is no followup.