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
db35dc16
Commit
db35dc16
authored
Oct 31, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reactions to a message (on UI) using View#post; update
flexboxlayout dependency
parent
b4a9a468
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
30 deletions
+39
-30
BaseViewHolder.kt
...va/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
+13
-9
MessageReactionsAdapter.kt
...ocket/android/chatroom/adapter/MessageReactionsAdapter.kt
+11
-9
LocalComponent.kt
...rc/main/java/chat/rocket/android/dagger/LocalComponent.kt
+1
-1
MessageDao.kt
app/src/main/java/chat/rocket/android/db/MessageDao.kt
+1
-1
item_reaction.xml
app/src/main/res/layout/item_reaction.xml
+8
-7
layout_reactions.xml
app/src/main/res/layout/layout_reactions.xml
+1
-1
colors.xml
app/src/main/res/values/colors.xml
+2
-0
build.gradle
build.gradle
+1
-1
dependencies.gradle
dependencies.gradle
+1
-1
No files found.
app/src/main/java/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
View file @
db35dc16
...
...
@@ -18,7 +18,9 @@ import chat.rocket.android.util.extensions.toList
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.isSystemMessage
import
com.google.android.flexbox.FlexDirection
import
com.google.android.flexbox.FlexWrap
import
com.google.android.flexbox.FlexboxLayoutManager
import
com.google.android.flexbox.JustifyContent
abstract
class
BaseViewHolder
<
T
:
BaseUiModel
<*>>(
itemView
:
View
,
...
...
@@ -41,13 +43,12 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
private
fun
bindReactions
()
{
data
?.
let
{
val
recyclerView
=
itemView
.
findViewById
(
R
.
id
.
recycler_view_reactions
)
as
RecyclerView
val
adapter
:
MessageReactionsAdapter
if
(
recyclerView
.
adapter
==
null
)
{
adapter
=
MessageReactionsAdapter
()
val
adapter
:
MessageReactionsAdapter
=
if
(
recyclerView
.
adapter
==
null
)
{
MessageReactionsAdapter
()
}
else
{
adapter
=
recyclerView
.
adapter
as
MessageReactionsAdapter
adapter
.
clear
()
recyclerView
.
adapter
as
MessageReactionsAdapter
}
adapter
.
clear
()
if
(
it
.
nextDownStreamMessage
==
null
)
{
adapter
.
listener
=
object
:
EmojiReactionListener
{
...
...
@@ -61,13 +62,16 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
}
}
}
val
context
=
itemView
.
context
val
manager
=
FlexboxLayoutManager
(
context
,
FlexDirection
.
ROW
)
manager
.
justifyContent
=
JustifyContent
.
FLEX_START
recyclerView
.
layoutManager
=
manager
recyclerView
.
adapter
=
adapter
adapter
.
addReactions
(
it
.
reactions
.
filterNot
{
reactionUiModel
->
reactionUiModel
.
unicode
.
startsWith
(
":"
)
&&
reactionUiModel
.
url
.
isNullOrEmpty
()
})
if
(
it
.
reactions
.
isNotEmpty
())
{
itemView
.
post
{
adapter
.
addReactions
(
it
.
reactions
)
}
}
}
}
}
...
...
@@ -129,4 +133,4 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
}
return
true
}
}
\ No newline at end of file
}
app/src/main/java/chat/rocket/android/chatroom/adapter/MessageReactionsAdapter.kt
View file @
db35dc16
...
...
@@ -4,7 +4,6 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.core.content.ContextCompat
import
androidx.recyclerview.widget.RecyclerView
import
chat.rocket.android.R
...
...
@@ -35,17 +34,17 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
}
else
->
{
view
=
inflater
.
inflate
(
R
.
layout
.
item_reaction
,
parent
,
false
)
Single
ReactionViewHolder
(
view
,
listener
)
ReactionViewHolder
(
view
,
listener
)
}
}
}
override
fun
onBindViewHolder
(
holder
:
RecyclerView
.
ViewHolder
,
position
:
Int
)
{
if
(
holder
is
Single
ReactionViewHolder
)
{
if
(
holder
is
ReactionViewHolder
)
{
holder
.
bind
(
reactions
[
position
])
}
else
{
holder
as
AddReactionViewHolder
holder
.
bind
(
reactions
[
0
]
.
messageId
)
holder
.
bind
(
reactions
.
first
()
.
messageId
)
}
}
...
...
@@ -73,7 +72,7 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
fun
contains
(
reactionShortname
:
String
)
=
reactions
.
firstOrNull
{
it
.
shortname
==
reactionShortname
}
!=
null
class
Single
ReactionViewHolder
(
class
ReactionViewHolder
(
view
:
View
,
private
val
listener
:
EmojiReactionListener
?
)
:
RecyclerView
.
ViewHolder
(
view
),
View
.
OnClickListener
{
...
...
@@ -97,9 +96,11 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
this
.
reaction
=
reaction
with
(
itemView
)
{
if
(
reaction
.
url
.
isNullOrEmpty
())
{
text_emoji
.
text
=
reaction
.
unicode
// The view at index 0 corresponds to the one to display unicode text emoji.
view_flipper_reaction
.
displayedChild
=
0
text_emoji
.
text
=
reaction
.
unicode
}
else
{
// The view at index 1 corresponds to the one to display custom emojis which are images.
view_flipper_reaction
.
displayedChild
=
1
val
glideRequest
=
if
(
reaction
.
url
!!
.
endsWith
(
"gif"
,
true
))
{
GlideApp
.
with
(
context
).
asGif
()
...
...
@@ -110,15 +111,16 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
glideRequest
.
load
(
reaction
.
url
).
into
(
image_emoji
)
}
text_count
.
text
=
reaction
.
count
.
toString
()
val
myself
=
localRepository
.
get
(
LocalRepository
.
CURRENT_USERNAME_KEY
)
if
(
reaction
.
usernames
.
contains
(
myself
))
{
val
context
=
itemView
.
context
text_count
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorAccent
))
}
view_flipper_reaction
.
setOnClickListener
(
this
@SingleReactionViewHolder
)
text_count
.
setOnClickListener
(
this
@SingleReactionViewHolder
)
text_count
.
text
=
reaction
.
count
.
toString
()
view_flipper_reaction
.
setOnClickListener
(
this
@ReactionViewHolder
)
text_count
.
setOnClickListener
(
this
@ReactionViewHolder
)
}
}
...
...
app/src/main/java/chat/rocket/android/dagger/LocalComponent.kt
View file @
db35dc16
...
...
@@ -19,7 +19,7 @@ interface LocalComponent {
fun
build
():
LocalComponent
}
fun
inject
(
adapter
:
MessageReactionsAdapter
.
Single
ReactionViewHolder
)
fun
inject
(
adapter
:
MessageReactionsAdapter
.
ReactionViewHolder
)
fun
inject
(
adapter
:
MessageReactionsAdapter
.
AddReactionViewHolder
)
/*@Component.Builder
...
...
app/src/main/java/chat/rocket/android/db/MessageDao.kt
View file @
db35dc16
...
...
@@ -40,7 +40,7 @@ abstract class MessageDao {
@Insert
(
onConflict
=
OnConflictStrategy
.
REPLACE
)
abstract
fun
insert
(
field
:
AttachmentFieldEntity
)
@Insert
(
onConflict
=
OnConflictStrategy
.
IGNOR
E
)
@Insert
(
onConflict
=
OnConflictStrategy
.
REPLAC
E
)
abstract
fun
insert
(
reaction
:
ReactionEntity
)
@Insert
(
onConflict
=
OnConflictStrategy
.
REPLACE
)
...
...
app/src/main/res/layout/item_reaction.xml
View file @
db35dc16
<?xml version="1.0" encoding="utf-8"?>
<
androidx.constraintlayout.widget.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Linear
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:orientation=
"horizontal"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"2dp"
...
...
@@ -10,7 +11,7 @@
<ViewFlipper
android:id=
"@+id/view_flipper_reaction"
android:layout_width=
"wrap_content"
android:layout_height=
"
wrap_cont
ent"
android:layout_height=
"
match_par
ent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/text_count"
app:layout_constraintStart_toStartOf=
"parent"
...
...
@@ -19,12 +20,13 @@
<TextView
android:id=
"@+id/text_emoji"
android:layout_width=
"wrap_content"
android:layout_height=
"
wrap_cont
ent"
android:layout_height=
"
match_par
ent"
android:ellipsize=
"end"
android:gravity=
"center"
android:maxLines=
"1"
android:paddingStart=
"4dp"
android:paddingLeft=
"4dp"
android:textColor=
"
#868585
"
android:textColor=
"
@color/reaction_text
"
android:textSize=
"16sp"
tools:text=
":)"
/>
...
...
@@ -48,13 +50,12 @@
android:paddingEnd=
"4dp"
android:paddingRight=
"4dp"
android:paddingBottom=
"4dp"
android:textColor=
"
#868585
"
android:textColor=
"
@color/reaction_text
"
android:textSize=
"16sp"
android:textStyle=
"bold"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/view_flipper_reaction"
app:layout_constraintTop_toTopOf=
"parent"
tools:text=
"12"
/>
</
androidx.constraintlayout.widget.Constraint
Layout>
</
Linear
Layout>
app/src/main/res/layout/layout_reactions.xml
View file @
db35dc16
...
...
@@ -2,4 +2,4 @@
<androidx.recyclerview.widget.RecyclerView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/recycler_view_reactions"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
\ No newline at end of file
android:layout_height=
"wrap_content"
/>
app/src/main/res/values/colors.xml
View file @
db35dc16
...
...
@@ -59,4 +59,6 @@
<!-- Default Background Color -->
<color
name=
"default_background"
>
#FAFAFA
</color>
<color
name=
"reaction_text"
>
#868585
</color>
</resources>
build.gradle
View file @
db35dc16
...
...
@@ -10,7 +10,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:3.
3.0-alpha12
'
classpath
'com.android.tools.build:gradle:3.
2.1
'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath
"org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}"
classpath
'com.google.gms:google-services:4.0.2'
...
...
dependencies.gradle
View file @
db35dc16
...
...
@@ -25,7 +25,7 @@ ext {
firebaseAnalytics
:
'16.0.3'
,
playServices
:
'16.0.0'
,
exoPlayer
:
'2.8.2'
,
flexbox
:
'1.
0
.0'
,
flexbox
:
'1.
1
.0'
,
material
:
'1.0.0-beta01'
,
room
:
'2.0.0'
,
...
...
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