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
9e61eb4a
Commit
9e61eb4a
authored
Jan 27, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RocketChatAvatar widget to deal with avatar loading.
No more Picasso
parent
3ed31364
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
109 additions
and
42 deletions
+109
-42
build.gradle
app/build.gradle
+0
-1
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+2
-1
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+6
-10
AbstractMessageViewHolder.java
...roid/layouthelper/chatroom/AbstractMessageViewHolder.java
+3
-2
RoomUserViewHolder.java
...roid/layouthelper/chatroom/dialog/RoomUserViewHolder.java
+3
-2
SuggestUserAdapter.java
...droid/layouthelper/sidebar/dialog/SuggestUserAdapter.java
+2
-1
MessageRenderer.java
...in/java/chat/rocket/android/renderer/MessageRenderer.java
+10
-12
UserRenderer.java
.../main/java/chat/rocket/android/renderer/UserRenderer.java
+4
-3
fragment_sidebar_main.xml
app/src/main/res/layout/fragment_sidebar_main.xml
+1
-1
list_item_normal_message.xml
app/src/main/res/layout/list_item_normal_message.xml
+2
-3
list_item_system_message.xml
app/src/main/res/layout/list_item_system_message.xml
+2
-3
listitem_room_user.xml
app/src/main/res/layout/listitem_room_user.xml
+1
-1
dependencies.gradle
dependencies.gradle
+0
-2
RocketChatAvatar.java
.../chat/rocket/android/widget/message/RocketChatAvatar.java
+66
-0
message_avatar.xml
...at-android-widgets/src/main/res/layout/message_avatar.xml
+7
-0
No files found.
app/build.gradle
View file @
9e61eb4a
...
...
@@ -108,7 +108,6 @@ dependencies {
compile
'com.google.android.gms:play-services-gcm:10.0.0'
compile
rootProject
.
ext
.
okhttp3
compile
rootProject
.
ext
.
picasso
compile
'com.facebook.stetho:stetho:1.4.1'
compile
'com.facebook.stetho:stetho-okhttp3:1.4.1'
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
9e61eb4a
...
...
@@ -28,6 +28,7 @@ import chat.rocket.android.realm_helper.RealmListObserver;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.renderer.UserRenderer
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
public
class
SidebarMainFragment
extends
AbstractFragment
{
...
...
@@ -147,7 +148,7 @@ public class SidebarMainFragment extends AbstractFragment {
private
void
onRenderCurrentUser
(
User
user
)
{
if
(
user
!=
null
&&
!
TextUtils
.
isEmpty
(
hostname
))
{
new
UserRenderer
(
getContext
(),
user
)
.
avatarInto
((
ImageView
)
rootView
.
findViewById
(
R
.
id
.
current_user_avatar
),
hostname
)
.
avatarInto
((
RocketChatAvatar
)
rootView
.
findViewById
(
R
.
id
.
current_user_avatar
),
hostname
)
.
usernameInto
((
TextView
)
rootView
.
findViewById
(
R
.
id
.
current_user_name
))
.
statusColorInto
((
ImageView
)
rootView
.
findViewById
(
R
.
id
.
current_user_status
));
}
...
...
app/src/main/java/chat/rocket/android/helper/Avatar.java
View file @
9e61eb4a
...
...
@@ -6,13 +6,12 @@ import android.graphics.Canvas;
import
android.graphics.Typeface
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.widget.ImageView
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
com.squareup.picasso.Picasso
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
chat.rocket.android.log.RCLog
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
/**
* Helper for rendering user avatar image.
...
...
@@ -80,18 +79,15 @@ public class Avatar {
}
/**
* render avatar into
imageView
.
* render avatar into
RocketChatAvatar
.
*/
public
void
into
(
final
ImageView
imageView
)
{
if
(
ViewDataCache
.
isStored
(
username
,
imageView
))
{
public
void
into
(
final
RocketChatAvatar
rocketChatAvatar
)
{
if
(
ViewDataCache
.
isStored
(
username
,
rocketChatAvatar
))
{
return
;
}
final
Context
context
=
imageView
.
getContext
();
Picasso
.
with
(
context
)
.
load
(
getImageUrl
())
.
placeholder
(
getTextDrawable
(
context
))
.
into
(
imageView
);
final
Context
context
=
rocketChatAvatar
.
getContext
();
rocketChatAvatar
.
loadImage
(
getImageUrl
(),
getTextDrawable
(
context
));
}
public
Drawable
getTextDrawable
(
Context
context
)
{
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/AbstractMessageViewHolder.java
View file @
9e61eb4a
...
...
@@ -10,9 +10,10 @@ import chat.rocket.android.helper.DateTime;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.realm_helper.RealmModelViewHolder
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
public
abstract
class
AbstractMessageViewHolder
extends
RealmModelViewHolder
<
PairedMessage
>
{
protected
final
ImageView
avatar
;
protected
final
RocketChatAvatar
avatar
;
protected
final
TextView
username
;
protected
final
TextView
subUsername
;
protected
final
TextView
timestamp
;
...
...
@@ -28,7 +29,7 @@ public abstract class AbstractMessageViewHolder extends RealmModelViewHolder<Pai
*/
public
AbstractMessageViewHolder
(
View
itemView
,
String
hostname
,
String
userId
,
String
token
)
{
super
(
itemView
);
avatar
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
user_avatar
);
avatar
=
(
RocketChatAvatar
)
itemView
.
findViewById
(
R
.
id
.
user_avatar
);
username
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
username
);
subUsername
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
sub_username
);
timestamp
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
timestamp
);
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/dialog/RoomUserViewHolder.java
View file @
9e61eb4a
...
...
@@ -6,13 +6,14 @@ import android.widget.ImageView;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
/**
* ViewHolder for UsersOfRoom.
*/
public
class
RoomUserViewHolder
extends
RecyclerView
.
ViewHolder
{
ImageView
status
;
ImageView
avatar
;
RocketChatAvatar
avatar
;
TextView
username
;
/**
...
...
@@ -21,7 +22,7 @@ public class RoomUserViewHolder extends RecyclerView.ViewHolder {
public
RoomUserViewHolder
(
View
itemView
)
{
super
(
itemView
);
status
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_status
);
avatar
=
(
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_avatar
);
avatar
=
(
RocketChatAvatar
)
itemView
.
findViewById
(
R
.
id
.
room_user_avatar
);
username
=
(
TextView
)
itemView
.
findViewById
(
R
.
id
.
room_user_name
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/sidebar/dialog/SuggestUserAdapter.java
View file @
9e61eb4a
...
...
@@ -10,6 +10,7 @@ import chat.rocket.android.R;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.realm_helper.RealmAutoCompleteAdapter
;
import
chat.rocket.android.renderer.UserRenderer
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
/**
* adapter to suggest user names.
...
...
@@ -26,7 +27,7 @@ public class SuggestUserAdapter extends RealmAutoCompleteAdapter<User> {
protected
void
onBindItemView
(
View
itemView
,
User
user
)
{
new
UserRenderer
(
itemView
.
getContext
(),
user
)
.
statusColorInto
((
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_status
))
.
avatarInto
((
ImageView
)
itemView
.
findViewById
(
R
.
id
.
room_user_avatar
),
hostname
);
.
avatarInto
((
RocketChatAvatar
)
itemView
.
findViewById
(
R
.
id
.
room_user_avatar
),
hostname
);
}
@Override
...
...
app/src/main/java/chat/rocket/android/renderer/MessageRenderer.java
View file @
9e61eb4a
package
chat
.
rocket
.
android
.
renderer
;
import
android.content.Context
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.squareup.picasso.Picasso
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.Avatar
;
...
...
@@ -13,6 +12,7 @@ import chat.rocket.android.helper.TextUtils;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
import
chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
;
...
...
@@ -32,15 +32,16 @@ public class MessageRenderer extends AbstractRenderer<Message> {
/**
* show Avatar image.
*/
public
MessageRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
public
MessageRenderer
avatarInto
(
RocketChatAvatar
rocketChatAvatar
,
String
hostname
)
{
if
(
object
.
getSyncState
()
==
SyncState
.
FAILED
)
{
imageView
.
setImageResource
(
R
.
drawable
.
ic_error_outline_black_24dp
);
rocketChatAvatar
.
loadImage
(
VectorDrawableCompat
.
create
(
context
.
getResources
(),
R
.
drawable
.
ic_error_outline_black_24dp
,
null
));
}
else
if
(
TextUtils
.
isEmpty
(
object
.
getAvatar
()))
{
userRenderer
.
avatarInto
(
imageView
,
hostname
);
userRenderer
.
avatarInto
(
rocketChatAvatar
,
hostname
);
}
else
{
final
User
user
=
object
.
getUser
();
setAvatarInto
(
object
.
getAvatar
(),
hostname
,
user
==
null
?
null
:
user
.
getUsername
(),
imageView
);
rocketChatAvatar
);
}
return
this
;
}
...
...
@@ -134,12 +135,9 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return
this
;
}
private
void
setAvatarInto
(
String
avatar
,
String
hostname
,
String
username
,
ImageView
imageView
)
{
Picasso
.
with
(
context
)
.
load
(
avatar
)
.
placeholder
(
new
Avatar
(
hostname
,
username
).
getTextDrawable
(
context
))
.
into
(
imageView
);
private
void
setAvatarInto
(
String
avatar
,
String
hostname
,
String
username
,
RocketChatAvatar
imageView
)
{
imageView
.
loadImage
(
avatar
,
new
Avatar
(
hostname
,
username
).
getTextDrawable
(
context
));
}
private
void
aliasAndUsernameInto
(
TextView
aliasTextView
,
TextView
usernameTextView
)
{
...
...
app/src/main/java/chat/rocket/android/renderer/UserRenderer.java
View file @
9e61eb4a
...
...
@@ -8,6 +8,7 @@ import chat.rocket.android.R;
import
chat.rocket.android.helper.Avatar
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.widget.message.RocketChatAvatar
;
/**
* Renderer for User model.
...
...
@@ -21,13 +22,13 @@ public class UserRenderer extends AbstractRenderer<User> {
/**
* show Avatar image
*/
public
UserRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
if
(!
shouldHandle
(
imageView
))
{
public
UserRenderer
avatarInto
(
RocketChatAvatar
rocketChatAvatar
,
String
hostname
)
{
if
(!
shouldHandle
(
rocketChatAvatar
))
{
return
this
;
}
if
(!
TextUtils
.
isEmpty
(
object
.
getUsername
()))
{
new
Avatar
(
hostname
,
object
.
getUsername
()).
into
(
imageView
);
new
Avatar
(
hostname
,
object
.
getUsername
()).
into
(
rocketChatAvatar
);
}
return
this
;
}
...
...
app/src/main/res/layout/fragment_sidebar_main.xml
View file @
9e61eb4a
...
...
@@ -30,7 +30,7 @@
android:layout_width=
"@dimen/margin_8"
android:layout_height=
"wrap_content"
/>
<
ImageView
<
chat.rocket.android.widget.message.RocketChatAvatar
android:id=
"@+id/current_user_avatar"
android:layout_width=
"40dp"
android:layout_height=
"40dp"
/>
...
...
app/src/main/res/layout/list_item_normal_message.xml
View file @
9e61eb4a
...
...
@@ -13,12 +13,11 @@
android:layout_height=
"wrap_content"
android:layout_marginBottom=
"2dp"
>
<
ImageView
<
chat.rocket.android.widget.message.RocketChatAvatar
android:id=
"@+id/user_avatar"
android:layout_width=
"32dp"
android:layout_height=
"32dp"
android:layout_margin=
"8dp"
tools:src=
"@drawable/ic_default_avatar"
/>
android:layout_margin=
"8dp"
/>
<LinearLayout
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/list_item_system_message.xml
View file @
9e61eb4a
...
...
@@ -12,12 +12,11 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<
ImageView
<
chat.rocket.android.widget.message.RocketChatAvatar
android:id=
"@+id/user_avatar"
android:layout_width=
"32dp"
android:layout_height=
"32dp"
android:layout_margin=
"8dp"
tools:src=
"@drawable/ic_default_avatar"
/>
android:layout_margin=
"8dp"
/>
<LinearLayout
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/listitem_room_user.xml
View file @
9e61eb4a
...
...
@@ -11,7 +11,7 @@
android:layout_height=
"8dp"
android:layout_margin=
"@dimen/margin_8"
/>
<
ImageView
<
chat.rocket.android.widget.message.RocketChatAvatar
android:id=
"@+id/room_user_avatar"
android:layout_width=
"24dp"
android:layout_height=
"24dp"
/>
...
...
dependencies.gradle
View file @
9e61eb4a
...
...
@@ -24,8 +24,6 @@ ext {
rxJava
=
'io.reactivex:rxjava:1.2.3'
boltsTask
=
'com.parse.bolts:bolts-tasks:1.4.0'
okhttp3
=
'com.squareup.okhttp3:okhttp:3.5.0'
picasso
=
'com.squareup.picasso:picasso:2.5.2'
picasso2Okhttp3Downloader
=
'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
textDrawable
=
'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
preDexLibs
=
!
"true"
.
equals
(
System
.
getenv
(
"CI"
))
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatAvatar.java
0 → 100644
View file @
9e61eb4a
package
chat
.
rocket
.
android
.
widget
.
message
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.graphics.drawable.Drawable
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.util.AttributeSet
;
import
android.view.LayoutInflater
;
import
android.widget.FrameLayout
;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.generic.GenericDraweeHierarchy
;
import
com.facebook.drawee.interfaces.DraweeController
;
import
com.facebook.drawee.view.SimpleDraweeView
;
import
chat.rocket.android.widget.R
;
public
class
RocketChatAvatar
extends
FrameLayout
{
private
SimpleDraweeView
draweeView
;
public
RocketChatAvatar
(
Context
context
)
{
super
(
context
);
initialize
(
context
,
null
);
}
public
RocketChatAvatar
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
initialize
(
context
,
attrs
);
}
public
RocketChatAvatar
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
initialize
(
context
,
attrs
);
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
public
RocketChatAvatar
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
super
(
context
,
attrs
,
defStyleAttr
,
defStyleRes
);
initialize
(
context
,
attrs
);
}
private
void
initialize
(
Context
context
,
AttributeSet
attrs
)
{
LayoutInflater
.
from
(
context
)
.
inflate
(
R
.
layout
.
message_avatar
,
this
,
true
);
draweeView
=
(
SimpleDraweeView
)
findViewById
(
R
.
id
.
drawee_avatar
);
}
public
void
loadImage
(
Drawable
drawable
)
{
final
GenericDraweeHierarchy
hierarchy
=
draweeView
.
getHierarchy
();
hierarchy
.
setImage
(
drawable
,
100
,
true
);
// Is there a better way?
}
public
void
loadImage
(
String
url
,
Drawable
placeholder
)
{
final
GenericDraweeHierarchy
hierarchy
=
draweeView
.
getHierarchy
();
hierarchy
.
setPlaceholderImage
(
placeholder
);
final
DraweeController
controller
=
Fresco
.
newDraweeControllerBuilder
()
.
setUri
(
Uri
.
parse
(
url
))
.
setAutoPlayAnimations
(
true
)
.
build
();
draweeView
.
setController
(
controller
);
}
}
rocket-chat-android-widgets/src/main/res/layout/message_avatar.xml
0 → 100644
View file @
9e61eb4a
<?xml version="1.0" encoding="utf-8"?>
<com.facebook.drawee.view.SimpleDraweeView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:fresco=
"http://schemas.android.com/apk/res-auto"
android:id=
"@+id/drawee_avatar"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
fresco:actualImageScaleType=
"fitCenter"
/>
\ 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