Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
611b0086
Commit
611b0086
authored
Aug 23, 2018
by
Shailesh Baldaniya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Add horizontal and vertical buttons
parent
40004009
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
94 deletions
+100
-94
ActionsAttachmentViewHolder.kt
...t/android/chatroom/adapter/ActionsAttachmentViewHolder.kt
+10
-71
ActionsListAdapter.kt
...hat/rocket/android/chatroom/adapter/ActionsListAdapter.kt
+73
-0
ChatRoomAdapter.kt
...a/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
+7
-18
ActionsAttachmentUiModel.kt
...cket/android/chatroom/uimodel/ActionsAttachmentUiModel.kt
+1
-0
UiModelMapper.kt
...ava/chat/rocket/android/chatroom/uimodel/UiModelMapper.kt
+1
-1
item_action_button.xml
app/src/main/res/layout/item_action_button.xml
+8
-4
No files found.
app/src/main/java/chat/rocket/android/chatroom/adapter/ActionsAttachmentViewHolder.kt
View file @
611b0086
package
chat.rocket.android.chatroom.adapter
package
chat.rocket.android.chatroom.adapter
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.chatroom.uimodel.ActionsAttachmentUiModel
import
chat.rocket.android.chatroom.uimodel.ActionsAttachmentUiModel
import
chat.rocket.android.emoji.EmojiReactionListener
import
chat.rocket.android.emoji.EmojiReactionListener
import
chat.rocket.core.model.attachment.actions.Action
import
chat.rocket.core.model.attachment.actions.Action
import
chat.rocket.core.model.attachment.actions.ButtonAction
import
chat.rocket.core.model.attachment.actions.ButtonAction
import
kotlinx.android.synthetic.main.item_actions_attachment.view.*
import
kotlinx.android.synthetic.main.item_actions_attachment.view.*
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.LinearLayoutManager
import
chat.rocket.android.R
import
timber.log.Timber
import
chat.rocket.android.util.TimberLogger
import
com.facebook.drawee.backends.pipeline.Fresco
import
com.facebook.drawee.view.SimpleDraweeView
import
com.google.android.material.button.MaterialButton
class
ActionsAttachmentViewHolder
(
class
ActionsAttachmentViewHolder
(
itemView
:
View
,
itemView
:
View
,
...
@@ -31,75 +24,21 @@ class ActionsAttachmentViewHolder(
...
@@ -31,75 +24,21 @@ class ActionsAttachmentViewHolder(
override
fun
bindViews
(
data
:
ActionsAttachmentUiModel
)
{
override
fun
bindViews
(
data
:
ActionsAttachmentUiModel
)
{
val
actions
=
data
.
actions
val
actions
=
data
.
actions
TimberLogger
.
debug
(
"no of actions : ${actions.size} : $actions"
)
val
alignment
=
data
.
buttonAlignment
Timber
.
d
(
"no of actions : ${actions.size} : $actions"
)
with
(
itemView
)
{
with
(
itemView
)
{
title
.
text
=
data
.
title
?:
""
title
.
text
=
data
.
title
?:
""
actions_list
.
layoutManager
=
LinearLayoutManager
(
itemView
.
context
)
actions_list
.
layoutManager
=
LinearLayoutManager
(
itemView
.
context
,
when
(
alignment
)
{
"vertical"
->
LinearLayoutManager
.
VERTICAL
"horizontal"
->
LinearLayoutManager
.
HORIZONTAL
else
->
LinearLayoutManager
.
VERTICAL
//Default
},
false
)
actions_list
.
adapter
=
ActionsListAdapter
(
actions
,
actionAttachmentOnClickListener
)
actions_list
.
adapter
=
ActionsListAdapter
(
actions
,
actionAttachmentOnClickListener
)
}
}
}
}
}
}
interface
ActionAttachmentOnClickListener
{
interface
ActionAttachmentOnClickListener
{
fun
onActionClicked
(
action
:
Action
)
fun
onActionClicked
(
view
:
View
,
action
:
Action
)
}
class
ActionsListAdapter
(
actions
:
List
<
Action
>,
var
actionAttachmentOnClickListener
:
ActionAttachmentOnClickListener
)
:
RecyclerView
.
Adapter
<
ActionsListAdapter
.
ViewHolder
>()
{
var
actions
:
List
<
Action
>
=
actions
inner
class
ViewHolder
(
var
layout
:
View
)
:
RecyclerView
.
ViewHolder
(
layout
)
{
lateinit
var
action
:
ButtonAction
var
button
:
MaterialButton
=
layout
.
findViewById
(
R
.
id
.
action_button
)
val
image
:
SimpleDraweeView
=
layout
.
findViewById
(
R
.
id
.
action_image_button
)
private
val
onClickListener
=
View
.
OnClickListener
{
actionAttachmentOnClickListener
.
onActionClicked
(
action
)
}
init
{
button
.
setOnClickListener
(
onClickListener
)
image
.
setOnClickListener
(
onClickListener
)
}
fun
bindAction
(
action
:
Action
)
{
TimberLogger
.
debug
(
"action : $action"
)
this
.
action
=
action
as
ButtonAction
//TODO
if
(
action
.
imageUrl
!=
null
)
{
button
.
visibility
=
View
.
GONE
image
.
visibility
=
View
.
VISIBLE
//Image button
val
controller
=
Fresco
.
newDraweeControllerBuilder
().
apply
{
setUri
(
action
.
imageUrl
)
autoPlayAnimations
=
true
oldController
=
image
.
controller
}.
build
()
image
.
controller
=
controller
}
else
if
(
action
.
text
!=
null
)
{
button
.
visibility
=
View
.
VISIBLE
image
.
visibility
=
View
.
GONE
this
.
button
.
setText
(
action
.
text
)
}
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
item_action_button
,
parent
,
false
)
return
ViewHolder
(
view
)
}
override
fun
getItemCount
():
Int
{
return
actions
.
size
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
action
=
actions
[
position
]
holder
.
bindAction
(
action
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/ActionsListAdapter.kt
0 → 100644
View file @
611b0086
package
chat.rocket.android.chatroom.adapter
import
android.view.View
import
android.view.ViewGroup
import
androidx.core.view.isVisible
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.R
import
chat.rocket.android.util.extensions.inflate
import
chat.rocket.core.model.attachment.actions.Action
import
chat.rocket.core.model.attachment.actions.ButtonAction
import
com.facebook.drawee.backends.pipeline.Fresco
import
kotlinx.android.synthetic.main.item_action_button.view.*
import
timber.log.Timber
class
ActionsListAdapter
(
actions
:
List
<
Action
>,
var
actionAttachmentOnClickListener
:
ActionAttachmentOnClickListener
)
:
RecyclerView
.
Adapter
<
ActionsListAdapter
.
ViewHolder
>()
{
var
actions
:
List
<
Action
>
=
actions
inner
class
ViewHolder
(
var
layout
:
View
)
:
RecyclerView
.
ViewHolder
(
layout
)
{
lateinit
var
action
:
ButtonAction
private
val
onClickListener
=
View
.
OnClickListener
{
actionAttachmentOnClickListener
.
onActionClicked
(
it
,
action
)
}
init
{
with
(
itemView
)
{
action_button
.
setOnClickListener
(
onClickListener
)
action_image_button
.
setOnClickListener
(
onClickListener
)
}
}
fun
bindAction
(
action
:
Action
)
{
with
(
itemView
)
{
Timber
.
d
(
"action : $action"
)
this
@ViewHolder
.
action
=
action
as
ButtonAction
if
(
action
.
imageUrl
!=
null
)
{
action_button
.
isVisible
=
false
action_image_button
.
isVisible
=
true
//Image button
val
controller
=
Fresco
.
newDraweeControllerBuilder
().
apply
{
setUri
(
action
.
imageUrl
)
autoPlayAnimations
=
true
oldController
=
action_image_button
.
controller
}.
build
()
action_image_button
.
controller
=
controller
}
else
if
(
action
.
text
!=
null
)
{
action_button
.
isVisible
=
true
action_image_button
.
isVisible
=
false
this
.
action_button
.
setText
(
action
.
text
)
}
}
}
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_action_button
)
return
ViewHolder
(
view
)
}
override
fun
getItemCount
():
Int
{
return
actions
.
size
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
action
=
actions
[
position
]
holder
.
bindAction
(
action
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
View file @
611b0086
...
@@ -5,10 +5,8 @@ import android.content.Context
...
@@ -5,10 +5,8 @@ import android.content.Context
import
android.net.Uri
import
android.net.Uri
import
androidx.recyclerview.widget.RecyclerView
import
androidx.recyclerview.widget.RecyclerView
import
android.view.MenuItem
import
android.view.MenuItem
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.Toast
import
androidx.browser.customtabs.CustomTabsIntent
import
androidx.core.content.res.ResourcesCompat
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.uimodel.*
import
chat.rocket.android.chatroom.uimodel.*
...
@@ -219,24 +217,15 @@ class ChatRoomAdapter(
...
@@ -219,24 +217,15 @@ class ChatRoomAdapter(
}
}
private
val
actionAttachmentOnClickListener
=
object
:
ActionAttachmentOnClickListener
{
private
val
actionAttachmentOnClickListener
=
object
:
ActionAttachmentOnClickListener
{
override
fun
onActionClicked
(
action
:
Action
)
{
override
fun
onActionClicked
(
view
:
View
,
action
:
Action
)
{
val
temp
=
action
as
ButtonAction
val
temp
=
action
as
ButtonAction
if
(
temp
.
url
!=
null
&&
temp
.
isWebView
!=
null
)
{
if
(
temp
.
url
!=
null
&&
temp
.
isWebView
!=
null
)
{
if
(
temp
.
isWebView
!!
)
{
if
(
temp
.
isWebView
!!
)
{
//Open in a configurable sizable webview
//
TODO:
Open in a configurable sizable webview
T
oast
.
makeText
(
context
,
"Open in a configurable sizable webview"
,
Toast
.
LENGTH_SHORT
).
show
(
)
T
imber
.
d
(
"Open in a configurable sizable webview"
)
}
else
{
}
else
{
//Open in chrome custom tab
//Open in chrome custom tab
with
(
this
)
{
view
.
openTabbedUrl
(
Uri
.
parse
(
temp
.
url
))
val
customTabsBuilder
=
CustomTabsIntent
.
Builder
()
customTabsBuilder
.
setToolbarColor
(
ResourcesCompat
.
getColor
(
context
!!
.
resources
,
R
.
color
.
colorPrimary
,
context
.
theme
))
val
customTabsIntent
=
customTabsBuilder
.
build
()
try
{
customTabsIntent
.
launchUrl
(
context
,
Uri
.
parse
(
temp
.
url
!!
))
}
catch
(
ex
:
Exception
)
{
Timber
.
d
(
ex
,
"Unable to launch URL"
)
}
}
}
}
}
else
if
(
temp
.
message
!=
null
&&
temp
.
isMessageInChatWindow
!=
null
)
{
}
else
if
(
temp
.
message
!=
null
&&
temp
.
isMessageInChatWindow
!=
null
)
{
if
(
temp
.
isMessageInChatWindow
!!
)
{
if
(
temp
.
isMessageInChatWindow
!!
)
{
...
@@ -247,8 +236,8 @@ class ChatRoomAdapter(
...
@@ -247,8 +236,8 @@ class ChatRoomAdapter(
}
}
}
}
}
else
{
}
else
{
//Send to bot but not in chat window
//
TODO:
Send to bot but not in chat window
T
oast
.
makeText
(
context
,
"Send to bot but not in chat window"
,
Toast
.
LENGTH_SHORT
).
show
(
)
T
imber
.
d
(
"Send to bot but not in chat window"
)
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/uimodel/ActionsAttachmentUiModel.kt
View file @
611b0086
...
@@ -9,6 +9,7 @@ data class ActionsAttachmentUiModel(
...
@@ -9,6 +9,7 @@ data class ActionsAttachmentUiModel(
override
val
attachmentUrl
:
String
,
override
val
attachmentUrl
:
String
,
val
title
:
String
?,
val
title
:
String
?,
val
actions
:
List
<
Action
>,
val
actions
:
List
<
Action
>,
val
buttonAlignment
:
String
,
override
val
message
:
Message
,
override
val
message
:
Message
,
override
val
rawData
:
ActionsAttachment
,
override
val
rawData
:
ActionsAttachment
,
override
val
messageId
:
String
,
override
val
messageId
:
String
,
...
...
app/src/main/java/chat/rocket/android/chatroom/uimodel/UiModelMapper.kt
View file @
611b0086
...
@@ -319,7 +319,7 @@ class UiModelMapper @Inject constructor(
...
@@ -319,7 +319,7 @@ class UiModelMapper @Inject constructor(
val
dayMarkerText
=
DateTimeHelper
.
getFormattedDateForMessages
(
localDateTime
,
context
)
val
dayMarkerText
=
DateTimeHelper
.
getFormattedDateForMessages
(
localDateTime
,
context
)
ActionsAttachmentUiModel
(
attachmentUrl
=
url
,
title
=
title
,
ActionsAttachmentUiModel
(
attachmentUrl
=
url
,
title
=
title
,
actions
=
actions
,
message
=
message
,
rawData
=
attachment
,
actions
=
actions
,
buttonAlignment
=
buttonAlignment
,
message
=
message
,
rawData
=
attachment
,
messageId
=
message
.
id
,
reactions
=
getReactions
(
message
),
messageId
=
message
.
id
,
reactions
=
getReactions
(
message
),
preview
=
message
.
copy
(
message
=
content
.
message
),
unread
=
message
.
unread
,
preview
=
message
.
copy
(
message
=
content
.
message
),
unread
=
message
.
unread
,
showDayMarker
=
false
,
currentDayMarkerText
=
dayMarkerText
)
showDayMarker
=
false
,
currentDayMarkerText
=
dayMarkerText
)
...
...
app/src/main/res/layout/item_action_button.xml
View file @
611b0086
...
@@ -6,18 +6,22 @@
...
@@ -6,18 +6,22 @@
android:orientation=
"horizontal"
>
android:orientation=
"horizontal"
>
<com.google.android.material.button.MaterialButton
<com.google.android.material.button.MaterialButton
style=
"@style/Widget.MaterialComponents.Button"
android:id=
"@+id/action_button"
android:id=
"@+id/action_button"
android:textSize=
"12sp"
style=
"@style/Widget.MaterialComponents.Button"
android:textAppearance=
"@style/TextAppearance.AppCompat.Body2"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"2dp"
android:layout_marginStart=
"2dp"
android:textAppearance=
"@style/TextAppearance.AppCompat.Body2"
android:textSize=
"12sp"
/>
<com.facebook.drawee.view.SimpleDraweeView
<com.facebook.drawee.view.SimpleDraweeView
android:id=
"@+id/action_image_button"
android:id=
"@+id/action_image_button"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"75dp"
android:layout_height=
"75dp"
android:layout_marginBottom=
"10dp"
android:layout_marginBottom=
"10dp"
android:layout_marginEnd=
"2dp"
android:layout_marginStart=
"2dp"
android:visibility=
"gone"
android:visibility=
"gone"
fresco:actualImageScaleType=
"fitStart"
fresco:actualImageScaleType=
"fitStart"
fresco:placeholderImage=
"@drawable/image_dummy"
/>
fresco:placeholderImage=
"@drawable/image_dummy"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment