Comments (4)
In term of your approach I'd suggest smth like:
private fun addImageMessageToList(it: Message): com.frameshift.chat.model.Message {
val imageMessage = ImageMessage(imageUrl = STUB_IMAGE_URL).apply {
setSender(it.author)
setMessageId(it.media.sid)
setTimestamp(it.dateCreated.getTimeInMillis())
}
fetchMediaUrlAsync(it, imageMessage)
return imageMessage;
}
private fun fetchMediaUrlAsync(message: Message, model: com.frameshift.chat.model.Message) = viewModelScope.launch {
val imageUrl = io { fetchMediaUrlUseCase.perform(message.media) }
when (imageUrl) {
is Success -> model.imageUrl.postValue(imageUrl.body) // model.imageUrl is MutableLiveData<Uri>
else -> model.imageUrl.postValue(LOAD_ERROR_IMAGE_URL)
}
}
class ChannelListAdapter(
private val owner: LifecycleOwner // pass activity here
): RecyclerView.Adapter<...>() {
var messages: List<com.frameshift.chat.model.Message> by Delegates.observable(emptyList()) { _, old, new ->
new.forEachIndexed { index, message ->
message.imageUrl.observe(owner, Observer<Uri> {
notifyItemChanged(index)
})
}
}
override fun onBindViewHolder(holder: MessageViewHolder, position: Int) {
val message = messages[position]
GlideApp.with(this)
.load(message.imageUrl.value)
.into(holder.imageView).
}
}
In general if it's not too late I'd suggest to switch to the Recommended app architecture where most part of such questions solved out from the box. BTW we are going to publish new twilio demo apps later this year which will demonstrate how to build an app with twilio chat sdk using that architecture.
from twilio-chat-demo-android.
I'd suggest put a stub image into view and show it immediately, at the same time make async request which fetch imageUrl using sdk then download the image then update the view.
from twilio-chat-demo-android.
@rusmonster Even I thought the same. But I wanted the UI to be unaware of the Twilio. So how do you suggest I make an API call? Are you suggesting interface method from onBindViewHolder?
from twilio-chat-demo-android.
@rusmonster Is there any way I can fetch media Url from just message sid? Right now, my viewHolder has just message sid in model. I am thinking of maybe fetch urls in recyclerView oBindViewHolder using sid?
from twilio-chat-demo-android.
Related Issues (20)
- NullPointerException when calling channel.getMessages() HOT 8
- Upload listener not working HOT 6
- how to implement typing indicator in android chat app using twillo? HOT 2
- How to load message by message id? HOT 13
- Login error. Error 0:3 Request to EMS service has failed, unable to set FPA token HOT 1
- Build Failing on CI with twilio sdk HOT 8
- Socket Time Exception on Samsung devices when using 4G mobile data. HOT 3
- member.getAttributes() => attributes are always empty HOT 1
- Create Channel is missing the UniqueName value HOT 3
- Broadcast Functionality HOT 3
- Insecure TLS/SSL trust manager HOT 11
- SDK release section is outdated and not relevant in this repo HOT 9
- Make contribution to the project easier HOT 4
- Stop using this repo's tickets as gateway to the tickets for SDK HOT 3
- Channel synchronisation is taking more than 20 seconds with 143 live channels HOT 2
- JCenter is shutting down on May 1st, 2021 HOT 3
- Nested call back not getting result, want to get last message from each channel HOT 38
- APK size increases to 1.4 GB after integrating Programmable Chat HOT 5
- Sample JSON missing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twilio-chat-demo-android.