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
8471796e
Commit
8471796e
authored
Aug 02, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update UserViewHolder class.
parent
3e43f04a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
57 deletions
+4
-57
UserViewHolder.java
...roid/widget/message/autocomplete/user/UserViewHolder.java
+4
-57
No files found.
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/autocomplete/user/UserViewHolder.java
View file @
8471796e
package
chat
.
rocket
.
android
.
widget
.
message
.
autocomplete
.
user
;
import
android.content.Context
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.Drawable
;
import
android.view.View
;
import
android.widget.ImageView
;
...
...
@@ -9,23 +7,16 @@ import android.widget.TextView;
import
chat.rocket.android.widget.AbsoluteUrl
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.RocketChatAvatar
;
import
chat.rocket.android.widget.helper.UserAvatarHelper
;
import
chat.rocket.android.widget.message.autocomplete.AutocompleteViewHolder
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
public
class
UserViewHolder
extends
AutocompleteViewHolder
<
UserItem
>
{
private
final
TextView
titleTextView
;
private
final
RocketChatAvatar
avatar
;
private
final
ImageView
status
;
private
static
final
int
[]
COLORS
=
new
int
[]
{
0xFFF44336
,
0xFFE91E63
,
0xFF9C27B0
,
0xFF673AB7
,
0xFF3F51B5
,
0xFF2196F3
,
0xFF03A9F4
,
0xFF00BCD4
,
0xFF009688
,
0xFF4CAF50
,
0xFF8BC34A
,
0xFFCDDC39
,
0xFFFFC107
,
0xFFFF9800
,
0xFFFF5722
,
0xFF795548
,
0xFF9E9E9E
,
0xFF607D8B
};
public
UserViewHolder
(
View
itemView
,
final
AutocompleteViewHolder
.
OnClickListener
<
UserItem
>
onClickListener
)
{
super
(
itemView
);
...
...
@@ -54,7 +45,9 @@ public class UserViewHolder extends AutocompleteViewHolder<UserItem> {
}
if
(
avatar
!=
null
)
{
avatar
.
loadImage
(
getImageUrl
(
suggestion
,
userItem
.
getAbsoluteUrl
()),
getTextDrawable
(
itemView
.
getContext
(),
suggestion
));
String
absoluteUri
=
UserAvatarHelper
.
INSTANCE
.
getAbsoluteUri
(
userItem
.
getAbsoluteUrl
(),
suggestion
);
Drawable
placeholderDrawable
=
UserAvatarHelper
.
INSTANCE
.
getTextDrawable
(
suggestion
,
itemView
.
getContext
());
avatar
.
loadImage
(
absoluteUri
,
placeholderDrawable
);
}
if
(
status
!=
null
)
{
...
...
@@ -68,50 +61,4 @@ public class UserViewHolder extends AutocompleteViewHolder<UserItem> {
avatar
.
setVisibility
(
View
.
GONE
);
titleTextView
.
setText
(
R
.
string
.
no_user_found
);
}
private
String
getImageUrl
(
String
username
,
AbsoluteUrl
absoluteUrl
)
{
//from Rocket.Chat:packages/rocketchat-ui/lib/avatar.coffee
//REMARK! this is often SVG image! (see: Rocket.Chat:server/startup/avatar.coffee)
try
{
final
String
avatarUrl
=
"/avatar/"
+
URLEncoder
.
encode
(
username
,
"UTF-8"
);
// TODO why absoluteUrl is nullable? By allowing that, the app tries to load non-existing images
if
(
absoluteUrl
==
null
)
{
return
avatarUrl
;
}
return
absoluteUrl
.
from
(
avatarUrl
);
}
catch
(
UnsupportedEncodingException
exception
)
{
return
null
;
}
}
private
Drawable
getTextDrawable
(
Context
context
,
String
username
)
{
int
round
=
(
int
)
(
4
*
context
.
getResources
().
getDisplayMetrics
().
density
);
return
TextDrawable
.
builder
()
.
beginConfig
()
.
useFont
(
Typeface
.
SANS_SERIF
)
.
endConfig
()
.
buildRoundRect
(
getUsernameInitials
(
username
),
getUserAvatarBackgroundColor
(
username
),
round
);
}
private
String
getUsernameInitials
(
String
username
)
{
if
(
username
.
isEmpty
())
{
return
"?"
;
}
String
[]
splitUsername
=
username
.
split
(
"."
);
if
(
splitUsername
.
length
>
1
)
{
return
(
splitUsername
[
0
].
substring
(
0
,
1
)
+
splitUsername
[
splitUsername
.
length
-
1
].
substring
(
0
,
1
)).
toUpperCase
();
}
else
{
if
(
username
.
length
()
>
1
)
{
return
username
.
substring
(
0
,
2
).
toUpperCase
();
}
else
{
return
username
.
substring
(
0
,
1
).
toUpperCase
();
}
}
}
private
int
getUserAvatarBackgroundColor
(
String
username
)
{
return
COLORS
[
username
.
length
()
%
COLORS
.
length
];
}
}
\ 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