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
2ed64d4b
Commit
2ed64d4b
authored
Dec 10, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show attachments in message.
parent
fef9ccd9
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
20 deletions
+141
-20
MessageViewHolder.java
...cket/android/layouthelper/chatroom/MessageViewHolder.java
+1
-1
MessageRenderer.java
...in/java/chat/rocket/android/renderer/MessageRenderer.java
+3
-1
ImageFormat.java
...n/java/chat/rocket/android/widget/helper/ImageFormat.java
+23
-0
RocketChatMessageAttachmentsLayout.java
...id/widget/message/RocketChatMessageAttachmentsLayout.java
+63
-0
RocketChatMessageUrlsLayout.java
...t/android/widget/message/RocketChatMessageUrlsLayout.java
+2
-11
message_inline_attachment.xml
...widgets/src/main/res/layout/message_inline_attachment.xml
+40
-0
message_inline_embed_url.xml
...-widgets/src/main/res/layout/message_inline_embed_url.xml
+4
-3
message_styles.xml
...at-android-widgets/src/main/res/values/message_styles.xml
+5
-4
No files found.
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageViewHolder.java
View file @
2ed64d4b
...
@@ -57,7 +57,7 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
...
@@ -57,7 +57,7 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
.
timestampInto
(
timestamp
)
.
timestampInto
(
timestamp
)
.
bodyInto
(
body
)
.
bodyInto
(
body
)
.
urlsInto
(
urls
)
.
urlsInto
(
urls
)
.
attachmentsInto
(
attachments
);
.
attachmentsInto
(
attachments
,
hostname
);
if
(
pairedMessage
.
target
!=
null
)
{
if
(
pairedMessage
.
target
!=
null
)
{
int
syncstate
=
pairedMessage
.
target
.
getSyncstate
();
int
syncstate
=
pairedMessage
.
target
.
getSyncstate
();
...
...
app/src/main/java/chat/rocket/android/renderer/MessageRenderer.java
View file @
2ed64d4b
...
@@ -104,7 +104,8 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -104,7 +104,8 @@ public class MessageRenderer extends AbstractRenderer<Message> {
/**
/**
* show urls in RocketChatMessageUrlsLayout.
* show urls in RocketChatMessageUrlsLayout.
*/
*/
public
MessageRenderer
attachmentsInto
(
RocketChatMessageAttachmentsLayout
attachmentsLayout
)
{
public
MessageRenderer
attachmentsInto
(
RocketChatMessageAttachmentsLayout
attachmentsLayout
,
String
hostname
)
{
if
(!
shouldHandle
(
attachmentsLayout
))
{
if
(!
shouldHandle
(
attachmentsLayout
))
{
return
this
;
return
this
;
}
}
...
@@ -114,6 +115,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -114,6 +115,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
attachmentsLayout
.
setVisibility
(
View
.
GONE
);
attachmentsLayout
.
setVisibility
(
View
.
GONE
);
}
else
{
}
else
{
attachmentsLayout
.
setVisibility
(
View
.
VISIBLE
);
attachmentsLayout
.
setVisibility
(
View
.
VISIBLE
);
attachmentsLayout
.
setHostname
(
hostname
);
attachmentsLayout
.
setAttachments
(
attachments
);
attachmentsLayout
.
setAttachments
(
attachments
);
}
}
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/ImageFormat.java
0 → 100644
View file @
2ed64d4b
package
chat
.
rocket
.
android
.
widget
.
helper
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
*/
public
interface
ImageFormat
{
String
PNG
=
"image/png"
;
String
JPG
=
"image/jpg"
;
String
JPEG
=
"image/jpeg"
;
String
WEBP
=
"image/webp"
;
List
<
String
>
SUPPORTED_LIST
=
Collections
.
unmodifiableList
(
new
ArrayList
<
String
>()
{
{
add
(
PNG
);
add
(
JPG
);
add
(
JPEG
);
add
(
WEBP
);
}
});
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageAttachmentsLayout.java
View file @
2ed64d4b
...
@@ -2,10 +2,19 @@ package chat.rocket.android.widget.message;
...
@@ -2,10 +2,19 @@ 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.net.Uri
;
import
android.os.Build
;
import
android.os.Build
;
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.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.ImageFormat
;
import
com.squareup.picasso.Picasso
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -14,6 +23,7 @@ import org.json.JSONObject;
...
@@ -14,6 +23,7 @@ import org.json.JSONObject;
*/
*/
public
class
RocketChatMessageAttachmentsLayout
extends
LinearLayout
{
public
class
RocketChatMessageAttachmentsLayout
extends
LinearLayout
{
private
LayoutInflater
inflater
;
private
LayoutInflater
inflater
;
private
String
hostname
;
public
RocketChatMessageAttachmentsLayout
(
Context
context
)
{
public
RocketChatMessageAttachmentsLayout
(
Context
context
)
{
super
(
context
);
super
(
context
);
...
@@ -42,6 +52,10 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -42,6 +52,10 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
setOrientation
(
VERTICAL
);
setOrientation
(
VERTICAL
);
}
}
public
void
setHostname
(
String
hostname
)
{
this
.
hostname
=
hostname
;
}
public
void
setAttachments
(
String
attachmentsString
)
{
public
void
setAttachments
(
String
attachmentsString
)
{
removeAllViews
();
removeAllViews
();
...
@@ -57,6 +71,55 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -57,6 +71,55 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
}
}
private
void
appendAttachmentView
(
JSONObject
attachmentObj
)
throws
JSONException
{
private
void
appendAttachmentView
(
JSONObject
attachmentObj
)
throws
JSONException
{
if
(
attachmentObj
.
isNull
(
"image_url"
))
{
return
;
}
String
imageURL
=
attachmentObj
.
getString
(
"image_url"
);
String
imageType
=
attachmentObj
.
getString
(
"image_type"
);
if
(
TextUtils
.
isEmpty
(
imageURL
)
||
!
imageType
.
startsWith
(
"image/"
)
||
!
ImageFormat
.
SUPPORTED_LIST
.
contains
(
imageType
))
{
return
;
}
View
attachmentView
=
inflater
.
inflate
(
R
.
layout
.
message_inline_attachment
,
this
,
false
);
imageURL
=
absolutize
(
imageURL
);
Picasso
.
with
(
getContext
())
.
load
(
imageURL
)
.
placeholder
(
R
.
drawable
.
image_dummy
)
.
error
(
R
.
drawable
.
image_error
)
.
into
((
ImageView
)
attachmentView
.
findViewById
(
R
.
id
.
image
));
TextView
titleView
=
(
TextView
)
attachmentView
.
findViewById
(
R
.
id
.
title
);
if
(
attachmentObj
.
isNull
(
"title"
))
{
titleView
.
setVisibility
(
View
.
GONE
);
}
else
{
titleView
.
setVisibility
(
View
.
VISIBLE
);
titleView
.
setText
(
attachmentObj
.
getString
(
"title"
));
if
(
attachmentObj
.
isNull
(
"title_link"
))
{
titleView
.
setOnClickListener
(
null
);
titleView
.
setClickable
(
false
);
}
else
{
final
String
link
=
absolutize
(
attachmentObj
.
getString
(
"title_link"
));
titleView
.
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
);
}
});
}
}
addView
(
attachmentView
);
}
private
String
absolutize
(
String
url
)
{
return
url
.
startsWith
(
"/"
)
?
"https://"
+
hostname
+
url
:
url
;
}
}
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageUrlsLayout.java
View file @
2ed64d4b
...
@@ -13,8 +13,8 @@ import android.widget.ImageView;
...
@@ -13,8 +13,8 @@ import android.widget.ImageView;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.ImageFormat
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Picasso
;
import
java.util.HashSet
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
...
@@ -22,15 +22,6 @@ import org.json.JSONObject;
...
@@ -22,15 +22,6 @@ import org.json.JSONObject;
/**
/**
*/
*/
public
class
RocketChatMessageUrlsLayout
extends
LinearLayout
{
public
class
RocketChatMessageUrlsLayout
extends
LinearLayout
{
private
static
final
HashSet
<
String
>
SUPPORTED_IMAGE_FORMATS
=
new
HashSet
<
String
>()
{
{
add
(
"image/png"
);
add
(
"image/jpg"
);
add
(
"image/jpeg"
);
add
(
"image/webp"
);
}
};
private
LayoutInflater
inflater
;
private
LayoutInflater
inflater
;
public
RocketChatMessageUrlsLayout
(
Context
context
)
{
public
RocketChatMessageUrlsLayout
(
Context
context
)
{
...
@@ -78,7 +69,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
...
@@ -78,7 +69,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
final
String
url
=
urlObj
.
getString
(
"url"
);
final
String
url
=
urlObj
.
getString
(
"url"
);
String
contentType
=
urlObj
.
getJSONObject
(
"headers"
).
getString
(
"contentType"
);
String
contentType
=
urlObj
.
getJSONObject
(
"headers"
).
getString
(
"contentType"
);
if
(
contentType
.
startsWith
(
"image/"
)
&&
SUPPORTED_IMAGE_FORMATS
.
contains
(
contentType
))
{
if
(
contentType
.
startsWith
(
"image/"
)
&&
ImageFormat
.
SUPPORTED_LIST
.
contains
(
contentType
))
{
View
inlineImage
=
inflater
.
inflate
(
R
.
layout
.
message_inline_image
,
this
,
false
);
View
inlineImage
=
inflater
.
inflate
(
R
.
layout
.
message_inline_image
,
this
,
false
);
Picasso
.
with
(
getContext
())
Picasso
.
with
(
getContext
())
.
load
(
url
)
.
load
(
url
)
...
...
rocket-chat-android-widgets/src/main/res/layout/message_inline_attachment.xml
0 → 100644
View file @
2ed64d4b
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_margin=
"4dp"
android:padding=
"4dp"
>
<View
android:layout_width=
"3dp"
android:layout_height=
"match_parent"
android:layout_marginRight=
"5dp"
android:background=
"@color/inline_attachment_quote_line"
/>
<LinearLayout
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/title"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2dp"
android:layout_marginBottom=
"2dp"
android:textAppearance=
"@style/TextAppearance.RocketChat.MessageAttachment.Title"
android:background=
"?attr/selectableItemBackground"
/>
<ImageView
android:id=
"@+id/image"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:maxHeight=
"200dp"
android:layout_marginTop=
"4dp"
android:layout_marginRight=
"8dp"
android:adjustViewBounds=
"true"
android:scaleType=
"fitStart"
/>
</LinearLayout>
</LinearLayout>
rocket-chat-android-widgets/src/main/res/layout/message_inline_embed_url.xml
View file @
2ed64d4b
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
android:layout_width=
"3dp"
android:layout_width=
"3dp"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginEnd=
"5dp"
android:layout_marginEnd=
"5dp"
android:background=
"#FFCCCCCC"
/>
android:background=
"@color/inline_attachment_quote_line"
/>
<ImageView
<ImageView
android:id=
"@+id/image"
android:id=
"@+id/image"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
...
@@ -41,7 +42,7 @@
...
@@ -41,7 +42,7 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2dp"
android:layout_marginTop=
"2dp"
android:layout_marginBottom=
"2dp"
android:layout_marginBottom=
"2dp"
android:textAppearance=
"@style/TextAppearance.RocketChat.Message
Url
.Title"
/>
android:textAppearance=
"@style/TextAppearance.RocketChat.Message
Attachment
.Title"
/>
<TextView
<TextView
android:id=
"@+id/description"
android:id=
"@+id/description"
...
@@ -49,7 +50,7 @@
...
@@ -49,7 +50,7 @@
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"2dp"
android:layout_marginTop=
"2dp"
android:layout_marginBottom=
"2dp"
android:layout_marginBottom=
"2dp"
android:textAppearance=
"@style/TextAppearance.RocketChat.Message
Url
.Description"
/>
android:textAppearance=
"@style/TextAppearance.RocketChat.Message
Attachment
.Description"
/>
</LinearLayout>
</LinearLayout>
...
...
rocket-chat-android-widgets/src/main/res/values/message_styles.xml
View file @
2ed64d4b
...
@@ -10,15 +10,15 @@
...
@@ -10,15 +10,15 @@
<item
name=
"android:textStyle"
>
bold
</item>
<item
name=
"android:textStyle"
>
bold
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.Message
Url
"
parent=
"TextAppearance.AppCompat.Body1"
/>
<style
name=
"TextAppearance.RocketChat.Message
Attachment
"
parent=
"TextAppearance.AppCompat.Body1"
/>
<style
name=
"TextAppearance.RocketChat.Message
Url
.Title"
parent=
"TextAppearance.AppCompat.Title"
>
<style
name=
"TextAppearance.RocketChat.Message
Attachment
.Title"
parent=
"TextAppearance.AppCompat.Title"
>
<item
name=
"android:textSize"
>
14sp
</item>
<item
name=
"android:textSize"
>
14sp
</item>
<item
name=
"android:textColor"
>
?android:attr/textColorLink
</item>
<item
name=
"android:textColor"
>
?android:attr/textColorLink
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.Message
Url
.Description"
>
<style
name=
"TextAppearance.RocketChat.Message
Attachment
.Description"
>
<item
name=
"android:textSize"
>
12sp
</item>
<item
name=
"android:textSize"
>
12sp
</item>
</style>
</style>
<style
name=
"TextAppearance.RocketChat.Message
Url
.Hostname"
<style
name=
"TextAppearance.RocketChat.Message
Attachment
.Hostname"
parent=
"TextAppearance.AppCompat.Caption"
>
parent=
"TextAppearance.AppCompat.Caption"
>
<item
name=
"android:textSize"
>
8sp
</item>
<item
name=
"android:textSize"
>
8sp
</item>
</style>
</style>
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
<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>
<color
name=
"inline_attachment_quote_line"
>
#FFCCCCCC
</color>
<color
name=
"inline_attachment_box_outline"
>
#FFF0F0F0
</color>
<color
name=
"inline_attachment_box_outline"
>
#FFF0F0F0
</color>
<color
name=
"inline_attachment_box_background"
>
@android:color/white
</color>
<color
name=
"inline_attachment_box_background"
>
@android:color/white
</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