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
7f25987f
Commit
7f25987f
authored
Feb 14, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes TextDrawable library references.
parent
3414b6bb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
70 deletions
+11
-70
DrawableHelper.kt
app/src/main/java/chat/rocket/android/app/DrawableHelper.kt
+1
-33
ChatRoomsAdapter.kt
...java/chat/rocket/android/chatrooms/ui/ChatRoomsAdapter.kt
+3
-12
item_chat.xml
app/src/main/res/layout/item_chat.xml
+7
-25
No files found.
app/src/main/java/chat/rocket/android/app/DrawableHelper.kt
View file @
7f25987f
import
android.content.Context
import
android.graphics.Typeface
import
android.graphics.drawable.Drawable
import
android.support.v4.content.ContextCompat
import
android.support.v4.graphics.drawable.DrawableCompat
import
android.widget.EditText
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.helper.TextHelper
import
com.amulyakhare.textdrawable.TextDrawable
object
DrawableHelper
{
private
val
AVATAR_BACKGROUND_HEXADECIMAL_COLORS
=
intArrayOf
(
0
xFFF44336
.
toInt
(),
0
xFFE91E63
.
toInt
(),
0
xFF9C27B0
.
toInt
(),
0
xFF673AB7
.
toInt
(),
0
xFF3F51B5
.
toInt
(),
0
xFF2196F3
.
toInt
(),
0
xFF03A9F4
.
toInt
(),
0
xFF00BCD4
.
toInt
(),
0
xFF009688
.
toInt
(),
0
xFF4CAF50
.
toInt
(),
0
xFF8BC34A
.
toInt
(),
0
xFFCDDC39
.
toInt
(),
0
xFFFFC107
.
toInt
(),
0
xFFFF9800
.
toInt
(),
0
xFFFF5722
.
toInt
(),
0
xFF795548
.
toInt
(),
0
xFF9E9E9E
.
toInt
(),
0
xFF607D8B
.
toInt
())
/**
* Returns a Drawable from its ID.
*
...
...
@@ -123,29 +116,4 @@ object DrawableHelper {
}
return
userStatusDrawable
}
/**
* Returns a drawable with the first character from a string.
*
* @param string The string to get its first character and to get the avatar background color.
* @return A drawable with the string first character.
*/
fun
getTextDrawable
(
string
:
String
):
Drawable
{
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRoundRect
(
TextHelper
.
getFirstCharacter
(
string
),
getAvatarBackgroundColor
(
string
),
4
)
}
/**
* Returns a background color to be rendered on the avatar.
*
* @param string Gets the background color based on the provided string.
* @return A hexadecimal color.
* @see (Rocket.Chat/server/startup/avatar.js)
*/
private
fun
getAvatarBackgroundColor
(
string
:
String
):
Int
{
return
AVATAR_BACKGROUND_HEXADECIMAL_COLORS
[
string
.
length
%
AVATAR_BACKGROUND_HEXADECIMAL_COLORS
.
size
]
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsAdapter.kt
View file @
7f25987f
...
...
@@ -39,7 +39,7 @@ class ChatRoomsAdapter(private val context: Context,
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
fun
bind
(
chatRoom
:
ChatRoom
)
=
with
(
itemView
)
{
bindAvatar
(
chatRoom
,
layout_avatar
,
image_avatar
,
image_room
_avatar
)
bindAvatar
(
chatRoom
,
image
_avatar
)
bindName
(
chatRoom
,
text_chat_name
)
bindLastMessageDateTime
(
chatRoom
,
text_last_message_date_time
)
bindLastMessage
(
chatRoom
,
text_last_message
)
...
...
@@ -48,17 +48,8 @@ class ChatRoomsAdapter(private val context: Context,
setOnClickListener
{
listener
(
chatRoom
)
}
}
private
fun
bindAvatar
(
chatRoom
:
ChatRoom
,
avatarLayout
:
View
,
drawee
:
SimpleDraweeView
,
imageView
:
ImageView
)
{
val
chatRoomName
=
chatRoom
.
name
if
(
chatRoom
.
type
is
RoomType
.
DirectMessage
)
{
drawee
.
setImageURI
(
UrlHelper
.
getAvatarUrl
(
chatRoom
.
client
.
url
,
chatRoomName
))
imageView
.
setVisible
(
false
)
avatarLayout
.
setVisible
(
true
)
}
else
{
imageView
.
setImageDrawable
(
DrawableHelper
.
getTextDrawable
(
chatRoomName
))
avatarLayout
.
setVisible
(
false
)
imageView
.
setVisible
(
true
)
}
private
fun
bindAvatar
(
chatRoom
:
ChatRoom
,
drawee
:
SimpleDraweeView
)
{
drawee
.
setImageURI
(
UrlHelper
.
getAvatarUrl
(
chatRoom
.
client
.
url
,
chatRoom
.
name
))
}
private
fun
bindName
(
chatRoom
:
ChatRoom
,
textView
:
TextView
)
{
...
...
app/src/main/res/layout/item_chat.xml
View file @
7f25987f
...
...
@@ -9,33 +9,15 @@
android:layout_marginStart=
"@dimen/screen_edge_left_and_right_margins"
android:layout_marginTop=
"12dp"
>
<android.support.constraint.ConstraintLayout
android:id=
"@+id/avatar_container"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
<include
android:id=
"@+id/layout_avatar"
layout=
"@layout/avatar"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toLeftOf=
"@+id/middle_container"
app:layout_constraintTop_toTopOf=
"parent"
>
<include
android:id=
"@+id/layout_avatar"
layout=
"@layout/avatar"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:visibility=
"gone"
/>
<!-- We need to build the avatar with initials since the server returns a SVG file with a pre defined 50x50 pixel.
TODO: check to scale the SVG file on the app and remove the view bellow (or make the server to return a jpg file.
SVG scaling with fresco is impossible: http://frescolib.org/docs/resizing.html
-->
<ImageView
android:id=
"@+id/image_room_avatar"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
android:visibility=
"gone"
tools:ignore=
"contentDescription"
/>
</android.support.constraint.ConstraintLayout>
app:layout_constraintTop_toTopOf=
"parent"
/>
<android.support.constraint.ConstraintLayout
android:id=
"@+id/middle_container"
...
...
@@ -43,7 +25,7 @@
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"16dp"
android:layout_marginStart=
"16dp"
app:layout_constraintLeft_toRightOf=
"@+id/
avatar_containe
r"
app:layout_constraintLeft_toRightOf=
"@+id/
layout_avata
r"
app:layout_constraintRight_toLeftOf=
"@+id/right_container"
>
<TextView
...
...
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