Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[NEW] Add support for initial Rich Messaging #1557

Closed

Conversation

Shailesh351
Copy link
Contributor

@CLAassistant
Copy link

CLAassistant commented Jul 30, 2018

CLA assistant check
All committers have signed the CLA.

@Shailesh351 Shailesh351 changed the title Upstrem button action [NEW] Add support for initial Rich Messaging(ButtonAction as Attachment) Jul 30, 2018
@rafaelks
Copy link
Contributor

@Shailesh351 Could you please sign the CLA so we can review this PR?

@rafaelks
Copy link
Contributor

rafaelks commented Aug 7, 2018

@Shailesh351 Do you mind resolving the conflicts here please?

@rafaelks rafaelks added this to the 2.6.0 milestone Aug 7, 2018
Copy link
Contributor

@philipbrito philipbrito left a 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)
Copy link
Contributor

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.

Copy link
Contributor

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...

Copy link
Contributor

@philipbrito philipbrito Aug 8, 2018

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)
  }

?

Copy link
Contributor Author

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)

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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)
Copy link
Contributor

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>() {
Copy link
Contributor

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")
Copy link
Contributor

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)
Copy link
Contributor

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()
Copy link
Contributor

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

@Shailesh351
Copy link
Contributor Author

@luciofm @filipedelimabrito I have updated PR with requested changes. Please have a look.

Thank you

}

init {
with(itemView) {
Copy link
Contributor

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) {
Copy link
Contributor

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
@philipbrito philipbrito changed the title [NEW] Add support for initial Rich Messaging(ButtonAction as Attachment) [NEW] Add support for initial Rich Messaging Aug 23, 2018
Copy link
Contributor

@luciofm luciofm left a 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!!) {
Copy link
Contributor

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!!) {
Copy link
Contributor

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 {
Copy link
Contributor

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,
Copy link
Contributor

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(
Copy link
Contributor

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...

Copy link
Contributor

@luciofm luciofm left a 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

@Shailesh351
Copy link
Contributor Author

@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.

@luciofm
Copy link
Contributor

luciofm commented Aug 24, 2018

@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.

@Shailesh351
Copy link
Contributor Author

@luciofm I tried with Android Studio 3.2 RC 1 but develop branch is giving error while building.

Cannot access class 'Lkotlinx.coroutines.experimental.android.HandlerContext;'. Check your module classpath for missing or conflicting dependencies

@Shailesh351
Copy link
Contributor Author

@luciofm Done!!!. PR is ready.

@luciofm
Copy link
Contributor

luciofm commented Aug 28, 2018

Merged with #1620

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants