-
Notifications
You must be signed in to change notification settings - Fork 553
[NEW] Add support for initial Rich Messaging #1557
Conversation
@Shailesh351 Could you please sign the CLA so we can review this PR? |
@Shailesh351 Do you mind resolving the conflicts here please? |
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.
Avoid using !!
in the code. It is a true source of bugs.
|
||
init { | ||
with(itemView) { | ||
setupActionMenu(actions_attachment_container) |
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.
with
is useless here since there is only one block being used. Could be itemView.setupActionMenu(actions_attachment_container)
instead.
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.
I don't see any issue using with
even if it is just for one statement...
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.
You can use it anywhere, anytime, but again: When there is only one block being used it is useless. What about spread with
with only one block being used on our entire codebase? It will never been an issue
but for sure it will be useless, helping only to increase the code lines.
Btw, do you see any advantage declaring:
init {
with(itemView) {
setupActionMenu(actions_attachment_container)
}
}
instead of:
init {
itemView.setupActionMenu(actions_attachment_container)
}
?
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.
@filipedelimabrito Unable to access setupActionMenu method without with(itemView)
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.
itemView.setupActionMenu(actions_attachment_container)
works.
|
||
//TODO | ||
if (action.imageUrl != null) { | ||
button.visibility = View.GONE |
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.
Replace with button.isVisible = false
//TODO | ||
if (action.imageUrl != null) { | ||
button.visibility = View.GONE | ||
image.visibility = View.VISIBLE |
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.
Replace with image.isVisible = true
image.controller = controller | ||
|
||
} else if (action.text != null) { | ||
button.visibility = View.VISIBLE |
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.
Replace with button.isVisible = true
|
||
} else if (action.text != null) { | ||
button.visibility = View.VISIBLE | ||
image.visibility = View.GONE |
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.
Replace with image.isVisible = false
if (temp.url != null && temp.isWebView != null) { | ||
if (temp.isWebView!!) { | ||
//Open in a configurable sizable webview | ||
Toast.makeText(context, "Open in a configurable sizable webview", Toast.LENGTH_SHORT).show() |
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.
Hard coded string. Please, remove and use the string from the string.xml
files.
} | ||
} else { | ||
//Send to bot but not in chat window | ||
Toast.makeText(context, "Send to bot but not in chat window", Toast.LENGTH_SHORT).show() |
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.
Hard coded string. Please, remove and use the string from the string.xml
files.
|
||
init { | ||
with(itemView) { | ||
setupActionMenu(actions_attachment_container) |
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.
I don't see any issue using with
even if it is just for one statement...
fun onActionClicked(action: Action) | ||
} | ||
|
||
class ActionsListAdapter(actions: List<Action>, var actionAttachmentOnClickListener: ActionAttachmentOnClickListener) : RecyclerView.Adapter<ActionsListAdapter.ViewHolder>() { |
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.
I think I'd prefer using a new package and multiple files instead of multiple classes and inner classes on the same file
} | ||
|
||
fun bindAction(action: Action) { | ||
TimberLogger.debug("action : $action") |
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.
Don't use 'TimberLogger' directly, use Timber.d()
or other Timber
variants.
inner class ViewHolder(var layout: View) : RecyclerView.ViewHolder(layout) { | ||
lateinit var action: ButtonAction | ||
|
||
var button: MaterialButton = layout.findViewById(R.id.action_button) |
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.
No need for findView, can use synthetic
accessors from kotlin extensions
} else { | ||
//Open in chrome custom tab | ||
with(this) { | ||
val customTabsBuilder = CustomTabsIntent.Builder() |
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 a View.openTabbedUrl()
extension function on chat.rocket.android.util.extensions.View.kt
@luciofm @filipedelimabrito I have updated PR with requested changes. Please have a look. Thank you |
} | ||
|
||
init { | ||
with(itemView) { |
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 a good usage of with
with more than one block code being used. Less than that is useless.
👍
with(itemView) { | ||
title.text = data.title ?: "" | ||
actions_list.layoutManager = LinearLayoutManager(itemView.context, | ||
when (alignment) { |
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.
You can resume the condition in this way:
if (alignment == "horizontal") {
LinearLayoutManager.HORIZONTAL
} else {
LinearLayoutManager.VERTICAL
}
or, if you prefer to use when
:
when (alignment) {
"horizontal" -> LinearLayoutManager.HORIZONTAL
else -> LinearLayoutManager.VERTICAL
}
Not needed to repeat LinearLayoutManager.VERTICAL
two times.
Merge branch 'temp-button-action' into upstrem-button-action
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.
@Shailesh351 the PR is not compiling... And please sync with develop
override fun onActionClicked(view: View, action: Action) { | ||
val temp = action as ButtonAction | ||
if (temp.url != null && temp.isWebView != null) { | ||
if (temp.isWebView!!) { |
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.
if you use temp.isWebView == true
you don't need to override nullability (!!
)
view.openTabbedUrl(Uri.parse(temp.url)) | ||
} | ||
} else if (temp.message != null && temp.isMessageInChatWindow != null) { | ||
if (temp.isMessageInChatWindow!!) { |
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.
same here
} else if (temp.message != null && temp.isMessageInChatWindow != null) { | ||
if (temp.isMessageInChatWindow!!) { | ||
//Send to chat window | ||
temp.message.run { |
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.
use temp.message?.let { message ->
that way you don't need to override nullability on temp.message
, just use message
import chat.rocket.core.model.attachment.actions.ActionsAttachment | ||
|
||
data class ActionsAttachmentUiModel( | ||
override val attachmentUrl: String, |
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.
use 4 spaces indentation here, please.
@@ -339,6 +339,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR | |||
} | |||
|
|||
if (recycler_view.adapter == null) { | |||
adapter = ChatRoomAdapter( |
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.
The adapter is already initialized on onCreate
don't create it twice. Also, this is not compiling...
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.
Oops, was meant to request changes...
the PR is not compiling... And please sync with develop
@luciofm Made requested changes and I'm able to successfully compile the PR now. Still latest develop branch is not building successfully so haven't merged it yet. |
@Shailesh351 you need to use Android Studio 3.3.0-alpha5 or 3.2.0-beta5, don't use 3.3.0-alpha6 because it has issues. |
@luciofm I tried with Android Studio 3.2 RC 1 but develop branch is giving error while building.
|
@luciofm Done!!!. PR is ready. |
Merged with #1620 |
@RocketChat/android
This PR adds support for initail Rich Messaging (ButtonActions as Attachment)
Test it with SDK : RocketChat/Rocket.Chat.Kotlin.SDK#203
And follow this to test it: https://github.com/WideChat/Rocket.Chat.Android/wiki/(WIP)--Rich-Messaging-Acceptance-Test
Spec: https://github.com/WideChat/Rocket.Chat.Android/wiki/Buttons-Inside-Attachment-Object-Spec
Demo : https://photos.app.goo.gl/okir1oP776cAcZ279