-
Notifications
You must be signed in to change notification settings - Fork 11
Update Tutorial to SDK 5.2.0 #65
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
Conversation
binding.typingHeaderView.setText(nobodyTyping); | ||
|
||
// Observe typing events and update typing header depending on its state. | ||
Flow<ChannelState> channelStateFlow = ChatClientExtensions.watchChannelAsState(ChatClient.instance(), cid, 30); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very clunky, but we currently don't expose any of our state classes (ChannelState
, GlobalState
, ...) as LiveData
.
It was either this or suggesting that Java users use Coroutines, which I feel is a bigger unknown in the Java world + the syntax would still be clunky since Flow
operators are written as extensions.
// Helper method that transforms typing updates into a string | ||
// containing typing member's names | ||
@NonNull | ||
private String joinTypingUpdatesToUserNames(@NonNull TypingEvent typingEvent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to do this manually because String.join()
is not compatible with Android API 21 without desugaring.
// Set view factory manager for Imgur attachments | ||
ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory(); | ||
|
||
List<ImgurAttachmentFactory> imgurAttachmentViewFactories = new ArrayList<ImgurAttachmentFactory>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, List.of()
not supported by API 21 without desugaring, making this feel clunky.
override fun createViewHolder( | ||
message: Message, | ||
listeners: MessageListListenerContainer?, | ||
parent: ViewGroup | ||
): InnerAttachmentViewHolder { | ||
val imgurAttachment = message.attachments.firstOrNull { it.isImgurAttachment() } | ||
?: return createViewHolder(message, listeners, parent) | ||
val imgurAttachment = message.attachments.first() { it.isImgurAttachment() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be safe because canHandle
has already made sure that this attachment exists.
Also previously this was a recursive call.
@@ -95,7 +96,10 @@ class ChannelActivity3 : AppCompatActivity() { | |||
|
|||
// Observe typing events and update typing header depending on its state. | |||
lifecycleScope.launchWhenStarted { | |||
ChatClient.instance().globalState.typingUpdates.collect { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GlobalState
should not be used here. It would provide typing updates not for a particular channel but for all active channels.
In order to get updates for a particular active channel we have to watch it first and collect the resulting ChannelState
.
…e imports for Stream resources because shortened imports confuse the IDE when copy pasting
@@ -47,12 +47,12 @@ class ImgurAttachmentFactory : AttachmentFactory { | |||
binding.ivMediaThumb.apply { | |||
shapeAppearanceModel = shapeAppearanceModel | |||
.toBuilder() | |||
.setAllCornerSizes(resources.getDimension(R.dimen.stream_ui_selected_attachment_corner_radius)) | |||
.setAllCornerSizes(resources.getDimension(io.getstream.chat.android.ui.R.dimen.stream_ui_selected_attachment_corner_radius)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using fully classified names seems to throw the IDE off when copy pasting from our tutorial or even another IDE where the import is working.
Classifying it fully fixes that and should result in the users a smoother experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 💯
Testing
You can use the following patch to make sure typing updates work in
ChannelActivity3
and "ChannelActivity4" in both Kotlin and Java apps.The following patch will change the user to
jc
, it shares the channelGlaring Bear
with usertutorialdroid
Code in a collapsible block