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
8b18a0f2
Commit
8b18a0f2
authored
Aug 02, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete RocketChatUserAvatar and RocketChatUserAvatarTest class.
parent
1efd2a14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
117 deletions
+0
-117
RocketChatUserAvatar.kt
...n/java/chat/rocket/android/helper/RocketChatUserAvatar.kt
+0
-95
RocketChatUserAvatarTest.kt
app/src/test/kotlin/RocketChatUserAvatarTest.kt
+0
-22
No files found.
app/src/main/java/chat/rocket/android/helper/RocketChatUserAvatar.kt
deleted
100644 → 0
View file @
1efd2a14
package
chat.rocket.android.helper
import
android.content.Context
import
android.graphics.Typeface
import
android.graphics.drawable.Drawable
import
com.amulyakhare.textdrawable.TextDrawable
import
java.net.URLEncoder
object
RocketChatUserAvatar
{
/**
* Returns the user avatar URI.
*
* REMARK: This is often a SVG image (Rocket.Chat:server/startup/avatar.js).
*
* @param hostname The server's hostname.
* @param username The username.
* @return The user avatar URI.
* @see getImageFormat
*/
fun
getUri
(
hostname
:
String
,
username
:
String
):
String
{
return
"https://"
+
hostname
.
replace
(
"http://"
,
""
).
replace
(
"https://"
,
""
)
+
"/avatar/"
+
URLEncoder
.
encode
(
username
,
"UTF-8"
)
}
/**
* Returns the user avatar image format.
*
* @param uri The user avatar image URI to get the image format.
* @return The user avatar image format. Possible values are: "image/jpeg", "image/png" and "image/svg+xml".
* @see getUri
*/
fun
getImageFormat
(
uri
:
String
):
String
{
return
OkHttpHelper
.
getContentType
(
uri
)
}
/**
* Returns a drawable with username initials.
*
* @param username The username.
* @param context The context.
* @return A drawable with username initials.
* @see getUsernameInitials
*/
fun
getTextDrawable
(
username
:
String
,
context
:
Context
):
Drawable
{
val
round
=
(
4
*
context
.
resources
.
displayMetrics
.
density
).
toInt
()
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRoundRect
(
getUsernameInitials
(
username
),
getUserAvatarBackgroundColor
(
username
),
round
)
}
/**
* Returns a string with the username initials. For example: username John Doe returns JD initials.
*
* @param username The username.
* @return A string with username initials.
*/
fun
getUsernameInitials
(
username
:
String
):
String
{
if
(
username
.
isEmpty
())
{
return
"?"
}
val
splitUsername
=
username
.
split
(
"."
)
if
(
splitUsername
.
size
>
1
)
{
return
(
splitUsername
[
0
].
substring
(
0
,
1
)
+
splitUsername
[
splitUsername
.
size
-
1
].
substring
(
0
,
1
)).
toUpperCase
()
}
else
{
if
(
username
.
length
>
1
)
{
return
username
.
substring
(
0
,
2
).
toUpperCase
()
}
else
{
return
username
.
substring
(
0
,
1
).
toUpperCase
()
}
}
}
/**
* Returns a background color to be rendered on the user avatar (Rocket.Chat:server/startup/avatar.js).
*
* @param username The username.
* @return A hexadecimal color.
*/
fun
getUserAvatarBackgroundColor
(
username
:
String
):
Int
{
return
COLORS
[
username
.
length
%
COLORS
.
size
]
}
private
val
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
())
}
\ No newline at end of file
app/src/test/kotlin/RocketChatUserAvatarTest.kt
deleted
100644 → 0
View file @
1efd2a14
import
chat.rocket.android.helper.RocketChatUserAvatar
import
org.junit.Test
class
RocketChatUserAvatarTest
{
@Test
fun
getUsernameInitialsTest
()
{
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
""
)
==
"?"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"?"
)
==
"?"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"f"
)
==
"F"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"B"
)
==
"B"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"fo"
)
==
"FO"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"FO"
)
==
"FO"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"fOo"
)
==
"FO"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"FOO"
)
==
"FO"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"F.O"
)
==
"FO"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"F.o"
)
==
"FO"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"Foo.bar"
)
==
"FB"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"Foobar.bar"
)
==
"FB"
)
assert
(
RocketChatUserAvatar
.
getUsernameInitials
(
"Foobar.bar.zab"
)
==
"FZ"
)
}
}
\ No newline at end of file
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