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
44953579
Commit
44953579
authored
Jan 25, 2017
by
Yusuke Iwaki
Committed by
GitHub
Jan 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #178 from RocketChat/feature/attachment-improvement
Better handling of attachments
parents
d1bcc7c5
1921ce2c
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
447 additions
and
70 deletions
+447
-70
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+15
-11
Message.java
app/src/main/java/chat/rocket/android/model/ddp/Message.java
+28
-0
MessageRenderer.java
...in/java/chat/rocket/android/renderer/MessageRenderer.java
+47
-8
UserRenderer.java
.../main/java/chat/rocket/android/renderer/UserRenderer.java
+15
-3
MessageAttachmentFieldLayout.java
.../android/widget/message/MessageAttachmentFieldLayout.java
+65
-0
RocketChatMessageAttachmentsLayout.java
...id/widget/message/RocketChatMessageAttachmentsLayout.java
+166
-37
RocketChatMessageLayout.java
...ocket/android/widget/message/RocketChatMessageLayout.java
+4
-0
message_inline_attachment.xml
...widgets/src/main/res/layout/message_inline_attachment.xml
+75
-7
message_inline_attachment_field.xml
...s/src/main/res/layout/message_inline_attachment_field.xml
+21
-0
message_styles.xml
...at-android-widgets/src/main/res/values/message_styles.xml
+11
-4
No files found.
app/src/main/java/chat/rocket/android/helper/Avatar.java
View file @
44953579
...
@@ -99,7 +99,11 @@ public class Avatar {
...
@@ -99,7 +99,11 @@ public class Avatar {
.
into
(
imageView
);
.
into
(
imageView
);
}
}
private
Drawable
getTextDrawable
(
Context
context
)
{
public
Drawable
getTextDrawable
(
Context
context
)
{
if
(
username
==
null
)
{
return
null
;
}
int
round
=
(
int
)
(
4
*
context
.
getResources
().
getDisplayMetrics
().
density
);
int
round
=
(
int
)
(
4
*
context
.
getResources
().
getDisplayMetrics
().
density
);
return
TextDrawable
.
builder
()
return
TextDrawable
.
builder
()
...
@@ -114,16 +118,16 @@ public class Avatar {
...
@@ -114,16 +118,16 @@ public class Avatar {
// Picasso can be triggered only on Main Thread.
// Picasso can be triggered only on Main Thread.
if
(
Looper
.
myLooper
()
!=
Looper
.
getMainLooper
())
{
if
(
Looper
.
myLooper
()
!=
Looper
.
getMainLooper
())
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(()
->
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(()
->
getBitmap
(
context
,
size
).
continueWith
(
_task
->
{
getBitmap
(
context
,
size
)
if
(
_task
.
isFaulted
())
{
.
continueWith
(
_task
->
{
task
.
setError
(
_task
.
getError
());
if
(
_task
.
isFaulted
())
{
}
else
{
task
.
setError
(
_task
.
getError
());
task
.
setResult
(
_task
.
getResult
());
}
else
{
}
task
.
setResult
(
_task
.
getResult
());
return
null
;
}
})
;
return
null
;
}
);
})
);
return
task
.
getTask
();
return
task
.
getTask
();
}
}
...
...
app/src/main/java/chat/rocket/android/model/ddp/Message.java
View file @
44953579
...
@@ -38,6 +38,8 @@ public class Message extends RealmObject {
...
@@ -38,6 +38,8 @@ public class Message extends RealmObject {
private
String
msg
;
private
String
msg
;
private
User
u
;
private
User
u
;
private
boolean
groupable
;
private
boolean
groupable
;
private
String
alias
;
private
String
avatar
;
private
String
attachments
;
//JSONArray.
private
String
attachments
;
//JSONArray.
private
String
urls
;
//JSONArray.
private
String
urls
;
//JSONArray.
...
@@ -133,6 +135,22 @@ public class Message extends RealmObject {
...
@@ -133,6 +135,22 @@ public class Message extends RealmObject {
this
.
urls
=
urls
;
this
.
urls
=
urls
;
}
}
public
String
getAlias
()
{
return
alias
;
}
public
void
setAlias
(
String
alias
)
{
this
.
alias
=
alias
;
}
public
String
getAvatar
()
{
return
avatar
;
}
public
void
setAvatar
(
String
avatar
)
{
this
.
avatar
=
avatar
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Message{"
+
return
"Message{"
+
...
@@ -144,6 +162,8 @@ public class Message extends RealmObject {
...
@@ -144,6 +162,8 @@ public class Message extends RealmObject {
", msg='"
+
msg
+
'\''
+
", msg='"
+
msg
+
'\''
+
", u="
+
u
+
", u="
+
u
+
", groupable="
+
groupable
+
", groupable="
+
groupable
+
", alias='"
+
alias
+
'\''
+
", avatar='"
+
avatar
+
'\''
+
", attachments='"
+
attachments
+
'\''
+
", attachments='"
+
attachments
+
'\''
+
", urls='"
+
urls
+
'\''
+
", urls='"
+
urls
+
'\''
+
'}'
;
'}'
;
...
@@ -184,6 +204,12 @@ public class Message extends RealmObject {
...
@@ -184,6 +204,12 @@ public class Message extends RealmObject {
if
(
u
!=
null
?
!
u
.
equals
(
message
.
u
)
:
message
.
u
!=
null
)
{
if
(
u
!=
null
?
!
u
.
equals
(
message
.
u
)
:
message
.
u
!=
null
)
{
return
false
;
return
false
;
}
}
if
(
alias
!=
null
?
!
alias
.
equals
(
message
.
alias
)
:
message
.
alias
!=
null
)
{
return
false
;
}
if
(
avatar
!=
null
?
!
avatar
.
equals
(
message
.
avatar
)
:
message
.
avatar
!=
null
)
{
return
false
;
}
if
(
attachments
!=
null
?
!
attachments
.
equals
(
message
.
attachments
)
if
(
attachments
!=
null
?
!
attachments
.
equals
(
message
.
attachments
)
:
message
.
attachments
!=
null
)
{
:
message
.
attachments
!=
null
)
{
return
false
;
return
false
;
...
@@ -202,6 +228,8 @@ public class Message extends RealmObject {
...
@@ -202,6 +228,8 @@ public class Message extends RealmObject {
result
=
31
*
result
+
(
msg
!=
null
?
msg
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
msg
!=
null
?
msg
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
u
!=
null
?
u
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
u
!=
null
?
u
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
groupable
?
1
:
0
);
result
=
31
*
result
+
(
groupable
?
1
:
0
);
result
=
31
*
result
+
(
alias
!=
null
?
alias
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
avatar
!=
null
?
avatar
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
attachments
!=
null
?
attachments
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
attachments
!=
null
?
attachments
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
urls
!=
null
?
urls
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
urls
!=
null
?
urls
.
hashCode
()
:
0
);
return
result
;
return
result
;
...
...
app/src/main/java/chat/rocket/android/renderer/MessageRenderer.java
View file @
44953579
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
);
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
);
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 @
44953579
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.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.TextView
;
...
@@ -19,7 +23,7 @@ public class UserRenderer extends AbstractRenderer<User> {
...
@@ -19,7 +23,7 @@ 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
)
{
if
(!
shouldHandle
(
imageView
))
{
if
(!
shouldHandle
(
imageView
))
{
...
@@ -33,14 +37,22 @@ public class UserRenderer extends AbstractRenderer<User> {
...
@@ -33,14 +37,22 @@ public class UserRenderer extends AbstractRenderer<User> {
}
}
/**
/**
* show Username in textView
.
* show Username in textView
*/
*/
public
UserRenderer
usernameInto
(
TextView
textView
)
{
public
UserRenderer
usernameInto
(
TextView
textView
)
{
if
(!
shouldHandle
(
textView
))
{
if
(!
shouldHandle
(
textView
))
{
return
this
;
return
this
;
}
}
textView
.
setText
(
object
.
getUsername
());
final
SpannableStringBuilder
spannableStringBuilder
=
new
SpannableStringBuilder
();
final
ForegroundColorSpan
foregroundColorSpan
=
new
ForegroundColorSpan
(
Color
.
BLACK
);
spannableStringBuilder
.
append
(
object
.
getUsername
());
spannableStringBuilder
.
setSpan
(
foregroundColorSpan
,
0
,
object
.
getUsername
().
length
(),
Spannable
.
SPAN_INCLUSIVE_INCLUSIVE
);
textView
.
setText
(
spannableStringBuilder
);
return
this
;
return
this
;
}
}
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/MessageAttachmentFieldLayout.java
0 → 100644
View file @
44953579
package
chat
.
rocket
.
android
.
widget
.
message
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.os.Build
;
import
android.util.AttributeSet
;
import
android.view.LayoutInflater
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
com.emojione.Emojione
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.InlineHightlighter
;
import
chat.rocket.android.widget.helper.Linkify
;
import
chat.rocket.android.widget.helper.MarkDown
;
public
class
MessageAttachmentFieldLayout
extends
LinearLayout
{
private
TextView
titleView
;
private
TextView
valueView
;
public
MessageAttachmentFieldLayout
(
Context
context
)
{
super
(
context
);
initialize
(
context
,
null
);
}
public
MessageAttachmentFieldLayout
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
initialize
(
context
,
attrs
);
}
public
MessageAttachmentFieldLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
initialize
(
context
,
attrs
);
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
public
MessageAttachmentFieldLayout
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
super
(
context
,
attrs
,
defStyleAttr
,
defStyleRes
);
initialize
(
context
,
attrs
);
}
private
void
initialize
(
Context
context
,
AttributeSet
attrs
)
{
setOrientation
(
VERTICAL
);
LayoutInflater
.
from
(
context
)
.
inflate
(
R
.
layout
.
message_inline_attachment_field
,
this
,
true
);
titleView
=
(
TextView
)
findViewById
(
R
.
id
.
field_title
);
valueView
=
(
TextView
)
findViewById
(
R
.
id
.
field_value
);
}
public
void
setTitle
(
String
title
)
{
titleView
.
setText
(
title
);
}
public
void
setValue
(
String
value
)
{
valueView
.
setText
(
Emojione
.
shortnameToUnicode
(
value
,
false
));
MarkDown
.
apply
(
valueView
);
Linkify
.
markup
(
valueView
);
InlineHightlighter
.
highlight
(
valueView
);
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageAttachmentsLayout.java
View file @
44953579
...
@@ -3,13 +3,16 @@ package chat.rocket.android.widget.message;
...
@@ -3,13 +3,16 @@ package chat.rocket.android.widget.message;
import
android.annotation.TargetApi
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Color
;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Build
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.AttributeSet
;
import
android.util.AttributeSet
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
...
@@ -21,7 +24,6 @@ import org.json.JSONObject;
...
@@ -21,7 +24,6 @@ import org.json.JSONObject;
import
java.io.IOException
;
import
java.io.IOException
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.ImageFormat
;
import
okhttp3.Interceptor
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Request
;
...
@@ -81,10 +83,15 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -81,10 +83,15 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
// uid/token is required to download attachment files.
// uid/token is required to download attachment files.
// see: RocketChat:lib/fileUpload.coffee
// see: RocketChat:lib/fileUpload.coffee
Request
newRequest
=
chain
.
request
().
newBuilder
()
.
header
(
"Cookie"
,
"rc_uid="
+
userId
+
";rc_token="
+
token
)
if
(
chain
.
request
().
url
().
host
().
equals
(
hostname
))
{
.
build
();
Request
newRequest
=
chain
.
request
().
newBuilder
()
return
chain
.
proceed
(
newRequest
);
.
header
(
"Cookie"
,
"rc_uid="
+
userId
+
";rc_token="
+
token
)
.
build
();
return
chain
.
proceed
(
newRequest
);
}
return
chain
.
proceed
(
chain
.
request
());
}
}
};
};
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
()
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
()
...
@@ -114,56 +121,178 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -114,56 +121,178 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
}
}
private
void
appendAttachmentView
(
JSONObject
attachmentObj
)
throws
JSONException
{
private
void
appendAttachmentView
(
JSONObject
attachmentObj
)
throws
JSONException
{
if
(
attachmentObj
.
isNull
(
"image_url"
)
)
{
if
(
attachmentObj
==
null
)
{
return
;
return
;
}
}
String
imageURL
=
attachmentObj
.
getString
(
"image_url"
);
View
attachmentView
=
inflater
.
inflate
(
R
.
layout
.
message_inline_attachment
,
this
,
false
);
String
imageType
=
attachmentObj
.
getString
(
"image_type"
);
colorizeAttachmentBar
(
attachmentObj
,
attachmentView
);
showAuthorAttachment
(
attachmentObj
,
attachmentView
);
showTitleAttachment
(
attachmentObj
,
attachmentView
);
showReferenceAttachment
(
attachmentObj
,
attachmentView
);
showImageAttachment
(
attachmentObj
,
attachmentView
);
// audio
// video
showFieldsAttachment
(
attachmentObj
,
attachmentView
);
addView
(
attachmentView
);
}
private
void
colorizeAttachmentBar
(
JSONObject
attachmentObj
,
View
attachmentView
)
throws
JSONException
{
final
View
attachmentStrip
=
attachmentView
.
findViewById
(
R
.
id
.
attachment_strip
);
if
(
TextUtils
.
isEmpty
(
imageURL
)
final
String
colorString
=
attachmentObj
.
optString
(
"color"
);
||
!
imageType
.
startsWith
(
"image/"
)
if
(
TextUtils
.
isEmpty
(
colorString
))
{
||
!
ImageFormat
.
SUPPORTED_LIST
.
contains
(
imageType
))
{
attachmentStrip
.
setBackgroundResource
(
R
.
color
.
inline_attachment_quote_line
);
return
;
return
;
}
}
View
attachmentView
=
inflater
.
inflate
(
R
.
layout
.
message_inline_attachment
,
this
,
false
);
try
{
attachmentStrip
.
setBackgroundColor
(
Color
.
parseColor
(
colorString
));
}
catch
(
Exception
e
)
{
attachmentStrip
.
setBackgroundResource
(
R
.
color
.
inline_attachment_quote_line
);
}
}
new
Picasso
.
Builder
(
getContext
())
private
void
showAuthorAttachment
(
JSONObject
attachmentObj
,
View
attachmentView
)
.
downloader
(
getDownloader
())
throws
JSONException
{
.
build
()
final
View
authorBox
=
attachmentView
.
findViewById
(
R
.
id
.
author_box
);
.
load
(
absolutize
(
imageURL
))
if
(
attachmentObj
.
isNull
(
"author_name"
)
||
attachmentObj
.
isNull
(
"author_link"
)
.
placeholder
(
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_dummy
,
null
))
||
attachmentObj
.
isNull
(
"author_icon"
))
{
.
error
(
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_error
,
null
))
authorBox
.
setVisibility
(
GONE
);
.
into
((
ImageView
)
attachmentView
.
findViewById
(
R
.
id
.
image
));
return
;
}
authorBox
.
setVisibility
(
VISIBLE
);
loadImage
(
attachmentObj
.
getString
(
"author_icon"
),
(
ImageView
)
attachmentView
.
findViewById
(
R
.
id
.
author_icon
));
final
TextView
authorName
=
(
TextView
)
attachmentView
.
findViewById
(
R
.
id
.
author_name
);
authorName
.
setText
(
attachmentObj
.
getString
(
"author_name"
));
final
String
link
=
absolutize
(
attachmentObj
.
getString
(
"author_link"
));
authorName
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
link
));
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
view
.
getContext
().
startActivity
(
intent
);
}
});
// timestamp and link - need to format time
}
private
void
showTitleAttachment
(
JSONObject
attachmentObj
,
View
attachmentView
)
throws
JSONException
{
TextView
titleView
=
(
TextView
)
attachmentView
.
findViewById
(
R
.
id
.
title
);
TextView
titleView
=
(
TextView
)
attachmentView
.
findViewById
(
R
.
id
.
title
);
if
(
attachmentObj
.
isNull
(
"title"
))
{
if
(
attachmentObj
.
isNull
(
"title"
))
{
titleView
.
setVisibility
(
View
.
GONE
);
titleView
.
setVisibility
(
View
.
GONE
);
return
;
}
titleView
.
setVisibility
(
View
.
VISIBLE
);
titleView
.
setText
(
attachmentObj
.
getString
(
"title"
));
if
(
attachmentObj
.
isNull
(
"title_link"
))
{
titleView
.
setOnClickListener
(
null
);
titleView
.
setClickable
(
false
);
}
else
{
}
else
{
titleView
.
setVisibility
(
View
.
VISIBLE
);
final
String
link
=
absolutize
(
attachmentObj
.
getString
(
"title_link"
));
titleView
.
setText
(
attachmentObj
.
getString
(
"title"
));
titleView
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
if
(
attachmentObj
.
isNull
(
"title_link"
))
{
public
void
onClick
(
View
view
)
{
titleView
.
setOnClickListener
(
null
);
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
link
));
titleView
.
setClickable
(
false
);
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
}
else
{
view
.
getContext
().
startActivity
(
intent
);
final
String
link
=
absolutize
(
attachmentObj
.
getString
(
"title_link"
));
}
titleView
.
setOnClickListener
(
new
OnClickListener
()
{
});
@Override
TextViewCompat
.
setTextAppearance
(
titleView
,
public
void
onClick
(
View
view
)
{
R
.
style
.
TextAppearance_RocketChat_MessageAttachment_Title_Link
);
Intent
intent
=
new
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
link
));
intent
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NEW_TASK
);
view
.
getContext
().
startActivity
(
intent
);
}
});
}
}
}
}
addView
(
attachmentView
);
private
void
showReferenceAttachment
(
JSONObject
attachmentObj
,
View
attachmentView
)
throws
JSONException
{
final
View
refBox
=
attachmentView
.
findViewById
(
R
.
id
.
ref_box
);
if
(
attachmentObj
.
isNull
(
"thumb_url"
)
&&
attachmentObj
.
isNull
(
"text"
))
{
refBox
.
setVisibility
(
GONE
);
return
;
}
refBox
.
setVisibility
(
VISIBLE
);
final
ImageView
thumbImage
=
(
ImageView
)
refBox
.
findViewById
(
R
.
id
.
thumb
);
final
String
thumbUrl
=
attachmentObj
.
optString
(
"thumb_url"
);
if
(
TextUtils
.
isEmpty
(
thumbUrl
))
{
thumbImage
.
setVisibility
(
GONE
);
}
else
{
thumbImage
.
setVisibility
(
VISIBLE
);
loadImage
(
thumbUrl
,
thumbImage
);
}
final
TextView
refText
=
(
TextView
)
refBox
.
findViewById
(
R
.
id
.
text
);
final
String
refString
=
attachmentObj
.
optString
(
"text"
);
if
(
TextUtils
.
isEmpty
(
refString
))
{
refText
.
setVisibility
(
GONE
);
}
else
{
refText
.
setVisibility
(
VISIBLE
);
refText
.
setText
(
refString
);
}
}
private
void
showImageAttachment
(
JSONObject
attachmentObj
,
View
attachmentView
)
throws
JSONException
{
final
ImageView
attachedImage
=
(
ImageView
)
attachmentView
.
findViewById
(
R
.
id
.
image
);
if
(
attachmentObj
.
isNull
(
"image_url"
))
{
attachedImage
.
setVisibility
(
GONE
);
return
;
}
attachedImage
.
setVisibility
(
VISIBLE
);
loadImage
(
attachmentObj
.
getString
(
"image_url"
),
attachedImage
);
}
private
void
showFieldsAttachment
(
JSONObject
attachmentObj
,
View
attachmentView
)
throws
JSONException
{
if
(
attachmentObj
.
isNull
(
"fields"
))
{
return
;
}
final
ViewGroup
attachmentContent
=
(
ViewGroup
)
attachmentView
.
findViewById
(
R
.
id
.
attachment_content
);
final
JSONArray
fields
=
attachmentObj
.
getJSONArray
(
"fields"
);
for
(
int
i
=
0
,
size
=
fields
.
length
();
i
<
size
;
i
++)
{
final
JSONObject
fieldObject
=
fields
.
getJSONObject
(
i
);
if
(
fieldObject
.
isNull
(
"title"
)
||
fieldObject
.
isNull
(
"value"
))
{
return
;
}
MessageAttachmentFieldLayout
fieldLayout
=
new
MessageAttachmentFieldLayout
(
getContext
());
fieldLayout
.
setTitle
(
fieldObject
.
getString
(
"title"
));
fieldLayout
.
setValue
(
fieldObject
.
getString
(
"value"
));
attachmentContent
.
addView
(
fieldLayout
);
}
}
}
private
String
absolutize
(
String
url
)
{
private
String
absolutize
(
String
url
)
{
return
url
.
startsWith
(
"/"
)
?
"https://"
+
hostname
+
url
:
url
;
return
url
.
startsWith
(
"/"
)
?
"https://"
+
hostname
+
url
:
url
;
}
}
private
void
loadImage
(
String
url
,
ImageView
imageView
)
{
new
Picasso
.
Builder
(
getContext
())
.
downloader
(
getDownloader
())
.
build
()
.
load
(
absolutize
(
url
))
.
placeholder
(
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_dummy
,
null
))
.
error
(
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_error
,
null
))
.
into
(
imageView
);
}
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageLayout.java
View file @
44953579
...
@@ -75,6 +75,10 @@ public class RocketChatMessageLayout extends LinearLayout {
...
@@ -75,6 +75,10 @@ public class RocketChatMessageLayout extends LinearLayout {
}
}
private
void
appendTextView
(
String
text
)
{
private
void
appendTextView
(
String
text
)
{
if
(
TextUtils
.
isEmpty
(
text
))
{
return
;
}
TextView
textView
=
(
TextView
)
inflater
.
inflate
(
R
.
layout
.
message_body
,
this
,
false
);
TextView
textView
=
(
TextView
)
inflater
.
inflate
(
R
.
layout
.
message_body
,
this
,
false
);
textView
.
setText
(
Emojione
.
shortnameToUnicode
(
text
,
false
));
textView
.
setText
(
Emojione
.
shortnameToUnicode
(
text
,
false
));
...
...
rocket-chat-android-widgets/src/main/res/layout/message_inline_attachment.xml
View file @
44953579
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:orientation=
"horizontal"
android:
layout_margin
=
"4dp"
android:
paddingTop
=
"4dp"
android:padding=
"4dp"
>
android:padding
Bottom
=
"4dp"
>
<View
<View
android:id=
"@+id/attachment_strip"
android:layout_width=
"3dp"
android:layout_width=
"3dp"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginRight=
"5dp"
android:layout_marginRight=
"5dp"
android:background=
"@color/inline_attachment_quote_line"
/>
android:background=
"@color/inline_attachment_quote_line"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/attachment_content"
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<LinearLayout
android:id=
"@+id/author_box"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical"
android:orientation=
"horizontal"
android:layout_marginBottom=
"8dp"
>
<ImageView
android:id=
"@+id/author_icon"
android:layout_width=
"16dp"
android:layout_height=
"16dp"
tools:src=
"@drawable/circle_black"
/>
<android.support.v4.widget.Space
android:layout_width=
"8dp"
android:layout_height=
"8dp"
/>
<TextView
android:id=
"@+id/author_name"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textAppearance=
"@style/TextAppearance.RocketChat.MessageAttachment.Title.Link"
tools:text=
"Bradley Hilton"
/>
<android.support.v4.widget.Space
android:layout_width=
"8dp"
android:layout_height=
"8dp"
/>
<TextView
android:id=
"@+id/timestamp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
tools:text=
"14:53"
/>
</LinearLayout>
<TextView
<TextView
android:id=
"@+id/title"
android:id=
"@+id/title"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2dp"
android:layout_marginBottom=
"8dp"
android:layout_marginBottom=
"2dp"
android:textAppearance=
"@style/TextAppearance.RocketChat.MessageAttachment.Title"
android:textAppearance=
"@style/TextAppearance.RocketChat.MessageAttachment.Title"
android:background=
"?attr/selectableItemBackground"
/>
android:background=
"?attr/selectableItemBackground"
tools:text=
"Attachment Example"
/>
<LinearLayout
android:id=
"@+id/ref_box"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_vertical"
android:orientation=
"horizontal"
android:layout_marginBottom=
"8dp"
>
<ImageView
android:id=
"@+id/thumb"
android:layout_width=
"32dp"
android:layout_height=
"32dp"
tools:src=
"@drawable/circle_black"
/>
<android.support.v4.widget.Space
android:layout_width=
"8dp"
android:layout_height=
"8dp"
/>
<TextView
android:id=
"@+id/text"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
tools:text=
"Bradley Hilton"
/>
</LinearLayout>
<ImageView
<ImageView
android:id=
"@+id/image"
android:id=
"@+id/image"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:maxHeight=
"200dp"
android:maxHeight=
"200dp"
android:layout_marginTop=
"4dp"
android:layout_marginBottom=
"8dp"
android:layout_marginRight=
"8dp"
android:adjustViewBounds=
"true"
android:adjustViewBounds=
"true"
android:scaleType=
"fitStart"
/>
android:scaleType=
"fitStart"
/>
<!-- audio -->
<!-- video -->
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
rocket-chat-android-widgets/src/main/res/layout/message_inline_attachment_field.xml
0 → 100644
View file @
44953579
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/field_title"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textAppearance=
"@style/TextAppearance.RocketChat.MessageAttachment.Field.Title"
tools:text=
"Test"
/>
<TextView
android:id=
"@+id/field_value"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
tools:text=
"Test"
/>
</LinearLayout>
\ No newline at end of file
rocket-chat-android-widgets/src/main/res/values/message_styles.xml
View file @
44953579
<?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,10 +13,13 @@
...
@@ -13,10 +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
name=
"TextAppearance.RocketChat.MessageAttachment.Title.Link"
>
<item
name=
"android:textColor"
>
?android:attr/textColorLink
</item>
<item
name=
"android:textColor"
>
?android:attr/textColorLink
</item>
</style>
</style>
...
@@ -24,11 +27,15 @@
...
@@ -24,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