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
4bfa9448
Commit
4bfa9448
authored
Jan 24, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PR feedback
parent
8088bf55
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
60 deletions
+70
-60
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+6
-16
MessageRenderer.java
...in/java/chat/rocket/android/renderer/MessageRenderer.java
+47
-8
UserRenderer.java
.../main/java/chat/rocket/android/renderer/UserRenderer.java
+7
-29
message_inline_attachment_field.xml
...s/src/main/res/layout/message_inline_attachment_field.xml
+1
-2
message_styles.xml
...at-android-widgets/src/main/res/values/message_styles.xml
+9
-5
No files found.
app/src/main/java/chat/rocket/android/helper/Avatar.java
View file @
4bfa9448
...
@@ -30,16 +30,10 @@ public class Avatar {
...
@@ -30,16 +30,10 @@ public class Avatar {
};
};
private
final
String
hostname
;
private
final
String
hostname
;
private
final
String
username
;
private
final
String
username
;
private
final
String
avatarUrl
;
public
Avatar
(
String
hostname
,
String
username
)
{
public
Avatar
(
String
hostname
,
String
username
)
{
this
(
hostname
,
username
,
null
);
}
public
Avatar
(
String
hostname
,
String
username
,
String
avatarUrl
)
{
this
.
hostname
=
hostname
;
this
.
hostname
=
hostname
;
this
.
username
=
username
;
this
.
username
=
username
;
this
.
avatarUrl
=
avatarUrl
;
}
}
private
static
int
getColorForUser
(
String
username
)
{
private
static
int
getColorForUser
(
String
username
)
{
...
@@ -82,15 +76,11 @@ public class Avatar {
...
@@ -82,15 +76,11 @@ public class Avatar {
private
String
getImageUrl
()
{
private
String
getImageUrl
()
{
//from Rocket.Chat:packages/rocketchat-ui/lib/avatar.coffee
//from Rocket.Chat:packages/rocketchat-ui/lib/avatar.coffee
//REMARK! this is often SVG image! (see: Rocket.Chat:server/startup/avatar.coffee)
//REMARK! this is often SVG image! (see: Rocket.Chat:server/startup/avatar.coffee)
if
(
TextUtils
.
isEmpty
(
avatarUrl
))
{
try
{
try
{
return
"https://"
+
hostname
+
"/avatar/"
+
URLEncoder
.
encode
(
username
,
"UTF-8"
)
+
".jpg"
;
return
"https://"
+
hostname
+
"/avatar/"
+
URLEncoder
.
encode
(
username
,
"UTF-8"
)
+
".jpg"
;
}
catch
(
UnsupportedEncodingException
exception
)
{
}
catch
(
UnsupportedEncodingException
exception
)
{
RCLog
.
e
(
exception
,
"failed to get URL for user: %s"
,
username
);
RCLog
.
e
(
exception
,
"failed to get URL for user: %s"
,
username
);
return
null
;
return
null
;
}
}
else
{
return
avatarUrl
;
}
}
}
}
...
@@ -109,7 +99,7 @@ public class Avatar {
...
@@ -109,7 +99,7 @@ public class Avatar {
.
into
(
imageView
);
.
into
(
imageView
);
}
}
p
rivate
Drawable
getTextDrawable
(
Context
context
)
{
p
ublic
Drawable
getTextDrawable
(
Context
context
)
{
if
(
username
==
null
)
{
if
(
username
==
null
)
{
return
null
;
return
null
;
}
}
...
...
app/src/main/java/chat/rocket/android/renderer/MessageRenderer.java
View file @
4bfa9448
package
chat
.
rocket
.
android
.
renderer
;
package
chat
.
rocket
.
android
.
renderer
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Color
;
import
android.text.Spannable
;
import
android.text.SpannableStringBuilder
;
import
android.text.style.ForegroundColorSpan
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.squareup.picasso.Picasso
;
import
chat.rocket.android.R
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.Avatar
;
import
chat.rocket.android.helper.DateTime
;
import
chat.rocket.android.helper.DateTime
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.SyncState
;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.model.ddp.Message
;
import
chat.rocket.android.model.ddp.User
;
import
chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
;
import
chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
;
...
@@ -30,13 +38,14 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -30,13 +38,14 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show Avatar image.
* show Avatar image.
*/
*/
public
MessageRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
public
MessageRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
switch
(
object
.
getSyncState
())
{
if
(
object
.
getSyncState
()
==
SyncState
.
FAILED
)
{
case
SyncState
.
FAILED
:
imageView
.
setImageResource
(
R
.
drawable
.
ic_error_outline_black_24dp
);
imageView
.
setImageResource
(
R
.
drawable
.
ic_error_outline_black_24dp
);
}
else
if
(
TextUtils
.
isEmpty
(
object
.
getAvatar
()))
{
break
;
userRenderer
.
avatarInto
(
imageView
,
hostname
);
default
:
}
else
{
userRenderer
.
avatarInto
(
imageView
,
hostname
,
object
.
getAvatar
());
final
User
user
=
object
.
getUser
();
break
;
setAvatarInto
(
object
.
getAvatar
(),
hostname
,
user
==
null
?
null
:
user
.
getUsername
(),
imageView
);
}
}
return
this
;
return
this
;
}
}
...
@@ -45,7 +54,12 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -45,7 +54,12 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show Username in textView.
* show Username in textView.
*/
*/
public
MessageRenderer
usernameInto
(
TextView
textView
)
{
public
MessageRenderer
usernameInto
(
TextView
textView
)
{
userRenderer
.
usernameInto
(
textView
,
object
.
getAlias
());
if
(
TextUtils
.
isEmpty
(
object
.
getAlias
()))
{
userRenderer
.
usernameInto
(
textView
);
}
else
{
final
User
user
=
object
.
getUser
();
setAliasInto
(
object
.
getAlias
(),
user
==
null
?
null
:
user
.
getUsername
(),
textView
);
}
return
this
;
return
this
;
}
}
...
@@ -124,4 +138,29 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -124,4 +138,29 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return
this
;
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
setAliasInto
(
String
alias
,
String
username
,
TextView
textView
)
{
final
SpannableStringBuilder
spannableStringBuilder
=
new
SpannableStringBuilder
();
final
ForegroundColorSpan
foregroundColorSpan
=
new
ForegroundColorSpan
(
Color
.
BLACK
);
spannableStringBuilder
.
append
(
alias
);
if
(
username
!=
null
)
{
spannableStringBuilder
.
append
(
" @"
);
spannableStringBuilder
.
append
(
username
);
}
spannableStringBuilder
.
setSpan
(
foregroundColorSpan
,
0
,
alias
.
length
(),
Spannable
.
SPAN_INCLUSIVE_INCLUSIVE
);
textView
.
setText
(
spannableStringBuilder
);
}
}
}
app/src/main/java/chat/rocket/android/renderer/UserRenderer.java
View file @
4bfa9448
...
@@ -23,37 +23,23 @@ public class UserRenderer extends AbstractRenderer<User> {
...
@@ -23,37 +23,23 @@ public class UserRenderer extends AbstractRenderer<User> {
}
}
/**
/**
* show Avatar image
.
* show Avatar image
*/
*/
public
UserRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
public
UserRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
)
{
return
avatarInto
(
imageView
,
hostname
,
null
);
}
/**
* show Avatar image - overriding the user default.
*/
public
UserRenderer
avatarInto
(
ImageView
imageView
,
String
hostname
,
String
avatar
)
{
if
(!
shouldHandle
(
imageView
))
{
if
(!
shouldHandle
(
imageView
))
{
return
this
;
return
this
;
}
}
if
(!
TextUtils
.
isEmpty
(
object
.
getUsername
())
||
!
TextUtils
.
isEmpty
(
avatar
)
)
{
if
(!
TextUtils
.
isEmpty
(
object
.
getUsername
()))
{
new
Avatar
(
hostname
,
object
.
getUsername
()
,
avatar
).
into
(
imageView
);
new
Avatar
(
hostname
,
object
.
getUsername
()).
into
(
imageView
);
}
}
return
this
;
return
this
;
}
}
/**
/**
* show Username in textView
.
* show Username in textView
*/
*/
public
UserRenderer
usernameInto
(
TextView
textView
)
{
public
UserRenderer
usernameInto
(
TextView
textView
)
{
return
usernameInto
(
textView
,
null
);
}
/**
* show Username in textView - adding the alias first.
*/
public
UserRenderer
usernameInto
(
TextView
textView
,
String
alias
)
{
if
(!
shouldHandle
(
textView
))
{
if
(!
shouldHandle
(
textView
))
{
return
this
;
return
this
;
}
}
...
@@ -61,17 +47,9 @@ public class UserRenderer extends AbstractRenderer<User> {
...
@@ -61,17 +47,9 @@ public class UserRenderer extends AbstractRenderer<User> {
final
SpannableStringBuilder
spannableStringBuilder
=
new
SpannableStringBuilder
();
final
SpannableStringBuilder
spannableStringBuilder
=
new
SpannableStringBuilder
();
final
ForegroundColorSpan
foregroundColorSpan
=
new
ForegroundColorSpan
(
Color
.
BLACK
);
final
ForegroundColorSpan
foregroundColorSpan
=
new
ForegroundColorSpan
(
Color
.
BLACK
);
if
(
TextUtils
.
isEmpty
(
alias
))
{
spannableStringBuilder
.
append
(
object
.
getUsername
());
spannableStringBuilder
.
append
(
object
.
getUsername
());
spannableStringBuilder
.
setSpan
(
foregroundColorSpan
,
0
,
object
.
getUsername
().
length
(),
spannableStringBuilder
.
setSpan
(
foregroundColorSpan
,
0
,
object
.
getUsername
().
length
(),
Spannable
.
SPAN_INCLUSIVE_INCLUSIVE
);
Spannable
.
SPAN_INCLUSIVE_INCLUSIVE
);
}
else
{
spannableStringBuilder
.
append
(
alias
);
spannableStringBuilder
.
append
(
" @"
);
spannableStringBuilder
.
append
(
object
.
getUsername
());
spannableStringBuilder
.
setSpan
(
foregroundColorSpan
,
0
,
alias
.
length
(),
Spannable
.
SPAN_INCLUSIVE_INCLUSIVE
);
}
textView
.
setText
(
spannableStringBuilder
);
textView
.
setText
(
spannableStringBuilder
);
...
...
rocket-chat-android-widgets/src/main/res/layout/message_inline_attachment_field.xml
View file @
4bfa9448
...
@@ -9,8 +9,7 @@
...
@@ -9,8 +9,7 @@
android:id=
"@+id/field_title"
android:id=
"@+id/field_title"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:textStyle=
"bold"
android:textAppearance=
"@style/TextAppearance.RocketChat.MessageAttachment.Field.Title"
android:textColor=
"@android:color/black"
tools:text=
"Test"
/>
tools:text=
"Test"
/>
<TextView
<TextView
...
...
rocket-chat-android-widgets/src/main/res/values/message_styles.xml
View file @
4bfa9448
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<style
name=
"TextAppearance.RocketChat"
parent=
"TextAppearance.AppCompat"
/>
<style
name=
"TextAppearance.RocketChat"
parent=
"TextAppearance.AppCompat"
/>
<style
name=
"TextAppearance.RocketChat.MessageBody"
parent=
"TextAppearance.AppCompat.Body1"
>
<style
name=
"TextAppearance.RocketChat.MessageBody"
parent=
"TextAppearance.AppCompat.Body1"
>
...
@@ -13,13 +13,13 @@
...
@@ -13,13 +13,13 @@
<item
name=
"android:textStyle"
>
bold
</item>
<item
name=
"android:textStyle"
>
bold
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.MessageAttachment"
parent=
"TextAppearance.AppCompat.Body1"
/>
<style
name=
"TextAppearance.RocketChat.MessageAttachment"
parent=
"TextAppearance.AppCompat.Body1"
/>
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Title"
parent=
"TextAppearance.AppCompat.Title"
>
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Title"
parent=
"TextAppearance.AppCompat.Title"
>
<item
name=
"android:textSize"
>
14sp
</item>
<item
name=
"android:textSize"
>
14sp
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Title.Link"
parent=
"TextAppearance.RocketChat.MessageAttachment.Title"
>
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Title.Link"
>
<item
name=
"android:textColor"
>
?android:attr/textColorLink
</item>
<item
name=
"android:textColor"
>
?android:attr/textColorLink
</item>
</style>
</style>
...
@@ -27,11 +27,15 @@
...
@@ -27,11 +27,15 @@
<item
name=
"android:textSize"
>
12sp
</item>
<item
name=
"android:textSize"
>
12sp
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Hostname"
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Hostname"
parent=
"TextAppearance.AppCompat.Caption"
>
parent=
"TextAppearance.AppCompat.Caption"
>
<item
name=
"android:textSize"
>
8sp
</item>
<item
name=
"android:textSize"
>
8sp
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.MessageAttachment.Field.Title"
parent=
"TextAppearance.AppCompat.Body1"
>
<item
name=
"android:textStyle"
>
bold
</item>
<item
name=
"android:textColor"
>
@android:color/black
</item>
</style>
<color
name=
"highlight_text_color"
>
#333
</color>
<color
name=
"highlight_text_color"
>
#333
</color>
<color
name=
"highlight_text_background_color"
>
#f8f8f8
</color>
<color
name=
"highlight_text_background_color"
>
#f8f8f8
</color>
<color
name=
"highlight_text_border_color"
>
#ccc
</color>
<color
name=
"highlight_text_border_color"
>
#ccc
</color>
...
...
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