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
5c6ee196
Commit
5c6ee196
authored
Sep 26, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update AvatarHelper.kt
parent
9d46f182
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
+22
-4
AvatarHelper.kt
...in/java/chat/rocket/android/widget/helper/AvatarHelper.kt
+22
-4
No files found.
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/AvatarHelper.kt
View file @
5c6ee196
package
chat.rocket.android.widget.helper
package
chat.rocket.android.widget.helper
import
android.content.Context
import
android.content.Context
import
android.graphics.Bitmap
import
android.graphics.Typeface
import
android.graphics.Typeface
import
android.graphics.drawable.Drawable
import
android.graphics.drawable.Drawable
import
chat.rocket.android.widget.AbsoluteUrl
import
chat.rocket.android.widget.AbsoluteUrl
import
com.amulyakhare.textdrawable.TextDrawable
import
com.amulyakhare.textdrawable.TextDrawable
import
java.net.URLEncoder
import
java.net.URLEncoder
/**
* Created by Filipe de Lima Brito (filipedelimabrito@gmail.com) on 8/02/17.
*/
object
AvatarHelper
{
object
AvatarHelper
{
/**
/**
...
@@ -45,6 +49,7 @@ object AvatarHelper {
...
@@ -45,6 +49,7 @@ object AvatarHelper {
* @param username The username.
* @param username The username.
* @param context The context.
* @param context The context.
* @return A drawable with username initials.
* @return A drawable with username initials.
* @see getTextBitmap
* @see getUsernameInitials
* @see getUsernameInitials
*/
*/
fun
getTextDrawable
(
username
:
String
,
context
:
Context
):
Drawable
{
fun
getTextDrawable
(
username
:
String
,
context
:
Context
):
Drawable
{
...
@@ -57,6 +62,19 @@ object AvatarHelper {
...
@@ -57,6 +62,19 @@ object AvatarHelper {
.
buildRoundRect
(
getUsernameInitials
(
username
),
getUserAvatarBackgroundColor
(
username
),
round
)
.
buildRoundRect
(
getUsernameInitials
(
username
),
getUserAvatarBackgroundColor
(
username
),
round
)
}
}
/**
* Returns a bitmap with username initials.
*
* @param username The username.
* @param context The context.
* @return A bitmap with username initials.
* @see getTextDrawable
*/
fun
getTextBitmap
(
username
:
String
,
context
:
Context
):
Bitmap
{
val
textDrawable
=
getTextDrawable
(
username
,
context
)
return
DrawableHelper
.
getBitmapFromDrawable
(
textDrawable
,
96
,
96
)
}
/**
/**
* Returns a string with the username initials. For example: username John.Doe returns JD initials.
* Returns a string with the username initials. For example: username John.Doe returns JD initials.
*
*
...
@@ -70,15 +88,15 @@ object AvatarHelper {
...
@@ -70,15 +88,15 @@ object AvatarHelper {
val
splitUsername
=
username
.
split
(
"."
)
val
splitUsername
=
username
.
split
(
"."
)
val
splitCount
=
splitUsername
.
size
val
splitCount
=
splitUsername
.
size
if
(
splitCount
>
1
&&
splitUsername
[
0
].
isNotEmpty
()
&&
splitUsername
[
splitCount
-
1
].
isNotEmpty
())
{
return
if
(
splitCount
>
1
&&
splitUsername
[
0
].
isNotEmpty
()
&&
splitUsername
[
splitCount
-
1
].
isNotEmpty
())
{
val
firstInitial
=
splitUsername
[
0
].
substring
(
0
,
1
)
val
firstInitial
=
splitUsername
[
0
].
substring
(
0
,
1
)
val
secondInitial
=
splitUsername
[
splitCount
-
1
].
substring
(
0
,
1
)
val
secondInitial
=
splitUsername
[
splitCount
-
1
].
substring
(
0
,
1
)
return
(
firstInitial
+
secondInitial
).
toUpperCase
()
(
firstInitial
+
secondInitial
).
toUpperCase
()
}
else
{
}
else
{
if
(
username
.
length
>
1
)
{
if
(
username
.
length
>
1
)
{
return
username
.
substring
(
0
,
2
).
toUpperCase
()
username
.
substring
(
0
,
2
).
toUpperCase
()
}
else
{
}
else
{
return
username
.
substring
(
0
,
1
).
toUpperCase
()
username
.
substring
(
0
,
1
).
toUpperCase
()
}
}
}
}
}
}
...
...
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