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
398a1fa9
Commit
398a1fa9
authored
Feb 22, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Honor auto load image flag
parent
3e1bb00a
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
205 additions
and
72 deletions
+205
-72
RoomContract.java
...a/chat/rocket/android/fragment/chatroom/RoomContract.java
+4
-0
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+14
-4
RoomPresenter.java
.../chat/rocket/android/fragment/chatroom/RoomPresenter.java
+23
-0
ExtModelListAdapter.java
...chat/rocket/android/layouthelper/ExtModelListAdapter.java
+2
-2
AbstractMessageViewHolder.java
...roid/layouthelper/chatroom/AbstractMessageViewHolder.java
+3
-3
MessageListAdapter.java
...ket/android/layouthelper/chatroom/MessageListAdapter.java
+12
-1
MessageNormalViewHolder.java
...ndroid/layouthelper/chatroom/MessageNormalViewHolder.java
+2
-2
MessageSystemViewHolder.java
...ndroid/layouthelper/chatroom/MessageSystemViewHolder.java
+2
-2
ModelListAdapter.java
...ocket/android/layouthelper/chatroom/ModelListAdapter.java
+3
-1
ModelViewHolder.java
...rocket/android/layouthelper/chatroom/ModelViewHolder.java
+1
-1
MessageRenderer.java
...in/java/chat/rocket/android/renderer/MessageRenderer.java
+5
-3
FrescoHelper.java
.../java/chat/rocket/android/widget/helper/FrescoHelper.java
+40
-0
RocketChatMessageAttachmentsLayout.java
...id/widget/message/RocketChatMessageAttachmentsLayout.java
+34
-28
RocketChatMessageUrlsLayout.java
...t/android/widget/message/RocketChatMessageUrlsLayout.java
+31
-20
message_inline_attachment.xml
...widgets/src/main/res/layout/message_inline_attachment.xml
+20
-5
message_inline_image.xml
...roid-widgets/src/main/res/layout/message_inline_image.xml
+8
-0
strings.xml
rocket-chat-android-widgets/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomContract.java
View file @
398a1fa9
...
@@ -22,6 +22,10 @@ public interface RoomContract {
...
@@ -22,6 +22,10 @@ public interface RoomContract {
void
showMessages
(
List
<
Message
>
messages
);
void
showMessages
(
List
<
Message
>
messages
);
void
showMessageSendFailure
(
Message
message
);
void
showMessageSendFailure
(
Message
message
);
void
autoloadImages
();
void
manualLoadImages
();
}
}
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
interface
Presenter
extends
BaseContract
.
Presenter
<
View
>
{
...
...
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
398a1fa9
...
@@ -78,14 +78,14 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -78,14 +78,14 @@ public class RoomFragment extends AbstractChatRoomFragment
private
LoadMoreScrollListener
scrollListener
;
private
LoadMoreScrollListener
scrollListener
;
private
MessageFormManager
messageFormManager
;
private
MessageFormManager
messageFormManager
;
private
RecyclerViewAutoScrollManager
autoScrollManager
;
private
RecyclerViewAutoScrollManager
autoScrollManager
;
pr
ivate
AbstractNewMessageIndicatorManager
newMessageIndicatorManager
;
pr
otected
AbstractNewMessageIndicatorManager
newMessageIndicatorManager
;
pr
ivate
Snackbar
unreadIndicator
;
pr
otected
Snackbar
unreadIndicator
;
private
boolean
previousUnreadMessageExists
;
private
boolean
previousUnreadMessageExists
;
private
MessageListAdapter
adapter
;
private
MessageListAdapter
adapter
;
private
List
<
AbstractExtraActionItem
>
extraActionItems
;
private
List
<
AbstractExtraActionItem
>
extraActionItems
;
pr
ivate
RoomContract
.
Presenter
presenter
;
pr
otected
RoomContract
.
Presenter
presenter
;
public
RoomFragment
()
{
public
RoomFragment
()
{
}
}
...
@@ -203,7 +203,7 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -203,7 +203,7 @@ public class RoomFragment extends AbstractChatRoomFragment
}
}
}
}
pr
ivate
Snackbar
getUnreadCountIndicatorView
(
int
count
)
{
pr
otected
Snackbar
getUnreadCountIndicatorView
(
int
count
)
{
// TODO: replace with another custom View widget, not to hide message composer.
// TODO: replace with another custom View widget, not to hide message composer.
final
String
caption
=
getResources
().
getString
(
final
String
caption
=
getResources
().
getString
(
R
.
string
.
fmt_dialog_view_latest_message_title
,
count
);
R
.
string
.
fmt_dialog_view_latest_message_title
,
count
);
...
@@ -447,4 +447,14 @@ public class RoomFragment extends AbstractChatRoomFragment
...
@@ -447,4 +447,14 @@ public class RoomFragment extends AbstractChatRoomFragment
(
dialog
,
which
)
->
presenter
.
deleteMessage
(
message
))
(
dialog
,
which
)
->
presenter
.
deleteMessage
(
message
))
.
show
();
.
show
();
}
}
@Override
public
void
autoloadImages
()
{
adapter
.
setAutoloadImages
(
true
);
}
@Override
public
void
manualLoadImages
()
{
adapter
.
setAutoloadImages
(
false
);
}
}
}
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomPresenter.java
View file @
398a1fa9
...
@@ -17,6 +17,7 @@ import chat.rocket.core.SyncState;
...
@@ -17,6 +17,7 @@ import chat.rocket.core.SyncState;
import
chat.rocket.core.interactors.MessageInteractor
;
import
chat.rocket.core.interactors.MessageInteractor
;
import
chat.rocket.core.models.Message
;
import
chat.rocket.core.models.Message
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.Room
;
import
chat.rocket.core.models.Settings
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.models.User
;
import
chat.rocket.core.repositories.RoomRepository
;
import
chat.rocket.core.repositories.RoomRepository
;
import
chat.rocket.core.repositories.UserRepository
;
import
chat.rocket.core.repositories.UserRepository
;
...
@@ -53,6 +54,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
...
@@ -53,6 +54,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
getRoomInfo
();
getRoomInfo
();
getRoomHistoryStateInfo
();
getRoomHistoryStateInfo
();
getMessages
();
getMessages
();
getUserPreferences
();
}
}
@Override
@Override
...
@@ -202,6 +204,27 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
...
@@ -202,6 +204,27 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
addSubscription
(
subscription
);
addSubscription
(
subscription
);
}
}
private
void
getUserPreferences
()
{
final
Disposable
subscription
=
userRepository
.
getCurrent
()
.
filter
(
Optional:
:
isPresent
)
.
map
(
Optional:
:
get
)
.
map
(
User:
:
getSettings
)
.
filter
(
settings
->
settings
!=
null
)
.
map
(
Settings:
:
getPreferences
)
.
distinctUntilChanged
()
.
subscribeOn
(
AndroidSchedulers
.
from
(
BackgroundLooper
.
get
()))
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
preferences
->
{
if
(
preferences
.
isAutoImageLoad
())
{
view
.
autoloadImages
();
}
else
{
view
.
manualLoadImages
();
}
});
addSubscription
(
subscription
);
}
private
Single
<
Pair
<
Room
,
User
>>
getRoomUserPair
()
{
private
Single
<
Pair
<
Room
,
User
>>
getRoomUserPair
()
{
return
Single
.
zip
(
return
Single
.
zip
(
getSingleRoom
(),
getSingleRoom
(),
...
...
app/src/main/java/chat/rocket/android/layouthelper/ExtModelListAdapter.java
View file @
398a1fa9
...
@@ -11,8 +11,8 @@ import chat.rocket.android.layouthelper.chatroom.ModelViewHolder;
...
@@ -11,8 +11,8 @@ import chat.rocket.android.layouthelper.chatroom.ModelViewHolder;
/**
/**
* ModelListAdapter with header and footer.
* ModelListAdapter with header and footer.
*/
*/
public
abstract
class
ExtModelListAdapter
<
T
,
VM
,
public
abstract
class
ExtModelListAdapter
<
T
,
VM
,
VH
extends
ModelViewHolder
<
VM
>>
VH
extends
ModelViewHolder
<
VM
>>
extends
ModelListAdapter
<
T
,
VM
,
VH
>
{
extends
ModelListAdapter
<
T
,
VM
,
VH
>
{
protected
static
final
int
VIEW_TYPE_HEADER
=
-
1
;
protected
static
final
int
VIEW_TYPE_HEADER
=
-
1
;
protected
static
final
int
VIEW_TYPE_FOOTER
=
-
2
;
protected
static
final
int
VIEW_TYPE_FOOTER
=
-
2
;
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/AbstractMessageViewHolder.java
View file @
398a1fa9
...
@@ -38,8 +38,8 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
...
@@ -38,8 +38,8 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
/**
/**
* bind the view model.
* bind the view model.
*/
*/
public
final
void
bind
(
PairedMessage
pairedMessage
)
{
public
final
void
bind
(
PairedMessage
pairedMessage
,
boolean
autoloadImages
)
{
bindMessage
(
pairedMessage
);
bindMessage
(
pairedMessage
,
autoloadImages
);
if
(
pairedMessage
.
target
!=
null
)
{
if
(
pairedMessage
.
target
!=
null
)
{
int
syncState
=
pairedMessage
.
target
.
getSyncState
();
int
syncState
=
pairedMessage
.
target
.
getSyncState
();
...
@@ -53,7 +53,7 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
...
@@ -53,7 +53,7 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
renderNewDayAndSequential
(
pairedMessage
);
renderNewDayAndSequential
(
pairedMessage
);
}
}
protected
abstract
void
bindMessage
(
PairedMessage
pairedMessage
);
protected
abstract
void
bindMessage
(
PairedMessage
pairedMessage
,
boolean
autoloadImages
);
private
void
renderNewDayAndSequential
(
PairedMessage
pairedMessage
)
{
private
void
renderNewDayAndSequential
(
PairedMessage
pairedMessage
)
{
//see Rocket.Chat:packages/rocketchat-livechat/app/client/views/message.coffee
//see Rocket.Chat:packages/rocketchat-livechat/app/client/views/message.coffee
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageListAdapter.java
View file @
398a1fa9
...
@@ -23,6 +23,8 @@ public class MessageListAdapter
...
@@ -23,6 +23,8 @@ public class MessageListAdapter
private
static
final
int
VIEW_TYPE_SYSTEM_MESSAGE
=
2
;
private
static
final
int
VIEW_TYPE_SYSTEM_MESSAGE
=
2
;
private
final
String
hostname
;
private
final
String
hostname
;
private
boolean
autoloadImages
=
false
;
private
boolean
hasNext
;
private
boolean
hasNext
;
private
boolean
isLoaded
;
private
boolean
isLoaded
;
...
@@ -31,6 +33,10 @@ public class MessageListAdapter
...
@@ -31,6 +33,10 @@ public class MessageListAdapter
this
.
hostname
=
hostname
;
this
.
hostname
=
hostname
;
}
}
public
void
setAutoloadImages
(
boolean
autoloadImages
)
{
this
.
autoloadImages
=
autoloadImages
;
}
/**
/**
* update Footer state considering hasNext and isLoaded.
* update Footer state considering hasNext and isLoaded.
*/
*/
...
@@ -88,7 +94,7 @@ public class MessageListAdapter
...
@@ -88,7 +94,7 @@ public class MessageListAdapter
default
:
default
:
return
new
AbstractMessageViewHolder
(
itemView
,
hostname
)
{
return
new
AbstractMessageViewHolder
(
itemView
,
hostname
)
{
@Override
@Override
protected
void
bindMessage
(
PairedMessage
pairedMessage
)
{
protected
void
bindMessage
(
PairedMessage
pairedMessage
,
boolean
autoloadImages
)
{
}
}
};
};
}
}
...
@@ -109,6 +115,11 @@ public class MessageListAdapter
...
@@ -109,6 +115,11 @@ public class MessageListAdapter
return
extMessages
;
return
extMessages
;
}
}
@Override
protected
boolean
shouldAutoloadImages
()
{
return
autoloadImages
;
}
@Override
@Override
protected
DiffUtil
.
Callback
getDiffCallback
(
List
<
PairedMessage
>
oldData
,
protected
DiffUtil
.
Callback
getDiffCallback
(
List
<
PairedMessage
>
oldData
,
List
<
PairedMessage
>
newData
)
{
List
<
PairedMessage
>
newData
)
{
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageNormalViewHolder.java
View file @
398a1fa9
...
@@ -28,8 +28,8 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder {
...
@@ -28,8 +28,8 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder {
}
}
@Override
@Override
protected
void
bindMessage
(
PairedMessage
pairedMessage
)
{
protected
void
bindMessage
(
PairedMessage
pairedMessage
,
boolean
autoloadImages
)
{
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
)
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
,
autoloadImages
)
.
avatarInto
(
avatar
,
hostname
)
.
avatarInto
(
avatar
,
hostname
)
.
usernameInto
(
username
,
subUsername
)
.
usernameInto
(
username
,
subUsername
)
.
timestampInto
(
timestamp
)
.
timestampInto
(
timestamp
)
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/MessageSystemViewHolder.java
View file @
398a1fa9
...
@@ -21,8 +21,8 @@ public class MessageSystemViewHolder extends AbstractMessageViewHolder {
...
@@ -21,8 +21,8 @@ public class MessageSystemViewHolder extends AbstractMessageViewHolder {
}
}
@Override
@Override
protected
void
bindMessage
(
PairedMessage
pairedMessage
)
{
protected
void
bindMessage
(
PairedMessage
pairedMessage
,
boolean
autoloadImages
)
{
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
)
new
MessageRenderer
(
itemView
.
getContext
(),
pairedMessage
.
target
,
autoloadImages
)
.
avatarInto
(
avatar
,
hostname
)
.
avatarInto
(
avatar
,
hostname
)
.
usernameInto
(
username
,
subUsername
)
.
usernameInto
(
username
,
subUsername
)
.
timestampInto
(
timestamp
);
.
timestampInto
(
timestamp
);
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/ModelListAdapter.java
View file @
398a1fa9
...
@@ -32,6 +32,8 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
...
@@ -32,6 +32,8 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
protected
abstract
List
<
VM
>
mapResultsToViewModel
(
List
<
T
>
results
);
protected
abstract
List
<
VM
>
mapResultsToViewModel
(
List
<
T
>
results
);
protected
abstract
boolean
shouldAutoloadImages
();
@Override
@Override
public
int
getItemViewType
(
int
position
)
{
public
int
getItemViewType
(
int
position
)
{
return
getRealmModelViewType
(
getItem
(
position
));
return
getRealmModelViewType
(
getItem
(
position
));
...
@@ -53,7 +55,7 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
...
@@ -53,7 +55,7 @@ public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
onItemClickListener
.
onItemClick
(
model2
);
onItemClickListener
.
onItemClick
(
model2
);
}
}
});
});
holder
.
bind
(
model
);
holder
.
bind
(
model
,
shouldAutoloadImages
()
);
}
}
@Override
@Override
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/ModelViewHolder.java
View file @
398a1fa9
...
@@ -9,5 +9,5 @@ public abstract class ModelViewHolder<T> extends RecyclerView.ViewHolder {
...
@@ -9,5 +9,5 @@ public abstract class ModelViewHolder<T> extends RecyclerView.ViewHolder {
super
(
itemView
);
super
(
itemView
);
}
}
public
abstract
void
bind
(
T
model
);
public
abstract
void
bind
(
T
model
,
boolean
autoloadImages
);
}
}
app/src/main/java/chat/rocket/android/renderer/MessageRenderer.java
View file @
398a1fa9
...
@@ -26,10 +26,12 @@ import chat.rocket.core.models.WebContent;
...
@@ -26,10 +26,12 @@ import chat.rocket.core.models.WebContent;
public
class
MessageRenderer
extends
AbstractRenderer
<
Message
>
{
public
class
MessageRenderer
extends
AbstractRenderer
<
Message
>
{
private
final
UserRenderer
userRenderer
;
private
final
UserRenderer
userRenderer
;
private
final
boolean
autoloadImages
;
public
MessageRenderer
(
Context
context
,
Message
message
)
{
public
MessageRenderer
(
Context
context
,
Message
message
,
boolean
autoloadImages
)
{
super
(
context
,
message
);
super
(
context
,
message
);
userRenderer
=
new
UserRenderer
(
context
,
message
.
getUser
());
userRenderer
=
new
UserRenderer
(
context
,
message
.
getUser
());
this
.
autoloadImages
=
autoloadImages
;
}
}
/**
/**
...
@@ -111,7 +113,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -111,7 +113,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
urlsLayout
.
setVisibility
(
View
.
GONE
);
urlsLayout
.
setVisibility
(
View
.
GONE
);
}
else
{
}
else
{
urlsLayout
.
setVisibility
(
View
.
VISIBLE
);
urlsLayout
.
setVisibility
(
View
.
VISIBLE
);
urlsLayout
.
setUrls
(
webContents
);
urlsLayout
.
setUrls
(
webContents
,
autoloadImages
);
}
}
return
this
;
return
this
;
...
@@ -132,7 +134,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
...
@@ -132,7 +134,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
}
else
{
}
else
{
attachmentsLayout
.
setVisibility
(
View
.
VISIBLE
);
attachmentsLayout
.
setVisibility
(
View
.
VISIBLE
);
attachmentsLayout
.
setHostname
(
hostname
);
attachmentsLayout
.
setHostname
(
hostname
);
attachmentsLayout
.
setAttachments
(
attachments
);
attachmentsLayout
.
setAttachments
(
attachments
,
autoloadImages
);
}
}
return
this
;
return
this
;
...
...
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/helper/FrescoHelper.java
0 → 100644
View file @
398a1fa9
package
chat
.
rocket
.
android
.
widget
.
helper
;
import
android.net.Uri
;
import
android.support.graphics.drawable.VectorDrawableCompat
;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.drawable.ProgressBarDrawable
;
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
FrescoHelper
{
private
FrescoHelper
()
{
}
public
static
void
setupDraweeAndLoadImage
(
String
imageUrl
,
SimpleDraweeView
draweeView
)
{
setupDrawee
(
draweeView
);
loadImage
(
imageUrl
,
draweeView
);
}
public
static
void
setupDrawee
(
SimpleDraweeView
draweeView
)
{
final
GenericDraweeHierarchy
hierarchy
=
draweeView
.
getHierarchy
();
hierarchy
.
setPlaceholderImage
(
VectorDrawableCompat
.
create
(
draweeView
.
getResources
(),
R
.
drawable
.
image_dummy
,
null
));
hierarchy
.
setFailureImage
(
VectorDrawableCompat
.
create
(
draweeView
.
getResources
(),
R
.
drawable
.
image_error
,
null
));
hierarchy
.
setProgressBarImage
(
new
ProgressBarDrawable
());
}
public
static
void
loadImage
(
String
imageUrl
,
SimpleDraweeView
draweeView
)
{
final
DraweeController
controller
=
Fresco
.
newDraweeControllerBuilder
()
.
setUri
(
Uri
.
parse
(
imageUrl
))
.
setAutoPlayAnimations
(
true
)
.
setTapToRetryEnabled
(
true
)
.
build
();
draweeView
.
setController
(
controller
);
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageAttachmentsLayout.java
View file @
398a1fa9
...
@@ -6,7 +6,6 @@ import android.content.Intent;
...
@@ -6,7 +6,6 @@ import android.content.Intent;
import
android.graphics.Color
;
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.v4.widget.TextViewCompat
;
import
android.support.v4.widget.TextViewCompat
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.util.AttributeSet
;
import
android.util.AttributeSet
;
...
@@ -15,13 +14,11 @@ import android.view.View;
...
@@ -15,13 +14,11 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
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
com.facebook.drawee.view.SimpleDraweeView
;
import
java.util.List
;
import
java.util.List
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.FrescoHelper
;
import
chat.rocket.core.models.Attachment
;
import
chat.rocket.core.models.Attachment
;
import
chat.rocket.core.models.AttachmentAuthor
;
import
chat.rocket.core.models.AttachmentAuthor
;
import
chat.rocket.core.models.AttachmentField
;
import
chat.rocket.core.models.AttachmentField
;
...
@@ -65,7 +62,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -65,7 +62,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
this
.
hostname
=
hostname
;
this
.
hostname
=
hostname
;
}
}
public
void
setAttachments
(
List
<
Attachment
>
attachments
)
{
public
void
setAttachments
(
List
<
Attachment
>
attachments
,
boolean
autoloadImages
)
{
if
(
this
.
attachments
!=
null
&&
this
.
attachments
.
equals
(
attachments
))
{
if
(
this
.
attachments
!=
null
&&
this
.
attachments
.
equals
(
attachments
))
{
return
;
return
;
}
}
...
@@ -73,11 +70,11 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -73,11 +70,11 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
removeAllViews
();
removeAllViews
();
for
(
int
i
=
0
,
size
=
attachments
.
size
();
i
<
size
;
i
++)
{
for
(
int
i
=
0
,
size
=
attachments
.
size
();
i
<
size
;
i
++)
{
appendAttachmentView
(
attachments
.
get
(
i
));
appendAttachmentView
(
attachments
.
get
(
i
)
,
autoloadImages
);
}
}
}
}
private
void
appendAttachmentView
(
Attachment
attachment
)
{
private
void
appendAttachmentView
(
Attachment
attachment
,
boolean
autoloadImages
)
{
if
(
attachment
==
null
)
{
if
(
attachment
==
null
)
{
return
;
return
;
}
}
...
@@ -88,7 +85,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -88,7 +85,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
showAuthorAttachment
(
attachment
,
attachmentView
);
showAuthorAttachment
(
attachment
,
attachmentView
);
showTitleAttachment
(
attachment
,
attachmentView
);
showTitleAttachment
(
attachment
,
attachmentView
);
showReferenceAttachment
(
attachment
,
attachmentView
);
showReferenceAttachment
(
attachment
,
attachmentView
);
showImageAttachment
(
attachment
,
attachmentView
);
showImageAttachment
(
attachment
,
attachmentView
,
autoloadImages
);
// audio
// audio
// video
// video
showFieldsAttachment
(
attachment
,
attachmentView
);
showFieldsAttachment
(
attachment
,
attachmentView
);
...
@@ -122,7 +119,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -122,7 +119,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
authorBox
.
setVisibility
(
VISIBLE
);
authorBox
.
setVisibility
(
VISIBLE
);
loadImage
(
author
.
getIconUrl
(
),
FrescoHelper
.
setupDraweeAndLoadImage
(
absolutize
(
author
.
getIconUrl
()
),
(
SimpleDraweeView
)
attachmentView
.
findViewById
(
R
.
id
.
author_icon
));
(
SimpleDraweeView
)
attachmentView
.
findViewById
(
R
.
id
.
author_icon
));
final
TextView
authorName
=
(
TextView
)
attachmentView
.
findViewById
(
R
.
id
.
author_name
);
final
TextView
authorName
=
(
TextView
)
attachmentView
.
findViewById
(
R
.
id
.
author_name
);
...
@@ -186,7 +183,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -186,7 +183,7 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
thumbImage
.
setVisibility
(
GONE
);
thumbImage
.
setVisibility
(
GONE
);
}
else
{
}
else
{
thumbImage
.
setVisibility
(
VISIBLE
);
thumbImage
.
setVisibility
(
VISIBLE
);
loadImage
(
thumbUrl
,
thumbImage
);
FrescoHelper
.
setupDraweeAndLoadImage
(
absolutize
(
thumbUrl
)
,
thumbImage
);
}
}
final
TextView
refText
=
(
TextView
)
refBox
.
findViewById
(
R
.
id
.
text
);
final
TextView
refText
=
(
TextView
)
refBox
.
findViewById
(
R
.
id
.
text
);
...
@@ -200,17 +197,21 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -200,17 +197,21 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
}
}
}
}
private
void
showImageAttachment
(
Attachment
attachment
,
View
attachmentView
)
{
private
void
showImageAttachment
(
Attachment
attachment
,
View
attachmentView
,
final
SimpleDraweeView
attachedImage
=
boolean
autoloadImages
)
{
(
SimpleDraweeView
)
attachmentView
.
findViewById
(
R
.
id
.
image
);
final
View
imageContainer
=
attachmentView
.
findViewById
(
R
.
id
.
image_container
);
if
(
attachment
.
getImageUrl
()
==
null
)
{
if
(
attachment
.
getImageUrl
()
==
null
)
{
attachedImage
.
setVisibility
(
GONE
);
imageContainer
.
setVisibility
(
GONE
);
return
;
return
;
}
}
attachedImage
.
setVisibility
(
VISIBLE
);
imageContainer
.
setVisibility
(
VISIBLE
);
final
SimpleDraweeView
attachedImage
=
(
SimpleDraweeView
)
attachmentView
.
findViewById
(
R
.
id
.
image
);
final
View
load
=
attachmentView
.
findViewById
(
R
.
id
.
image_load
);
loadImage
(
a
ttachment
.
getImageUrl
(),
attachedImage
);
loadImage
(
a
bsolutize
(
attachment
.
getImageUrl
()),
attachedImage
,
load
,
autoloadImages
);
}
}
private
void
showFieldsAttachment
(
Attachment
attachment
,
View
attachmentView
)
{
private
void
showFieldsAttachment
(
Attachment
attachment
,
View
attachmentView
)
{
...
@@ -240,17 +241,22 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
...
@@ -240,17 +241,22 @@ public class RocketChatMessageAttachmentsLayout extends LinearLayout {
return
url
.
startsWith
(
"/"
)
?
"https://"
+
hostname
+
url
:
url
;
return
url
.
startsWith
(
"/"
)
?
"https://"
+
hostname
+
url
:
url
;
}
}
private
void
loadImage
(
String
url
,
SimpleDraweeView
draweeView
)
{
private
void
loadImage
(
final
String
url
,
final
SimpleDraweeView
drawee
,
final
View
load
,
final
GenericDraweeHierarchy
hierarchy
=
draweeView
.
getHierarchy
();
boolean
autoloadImage
)
{
hierarchy
.
setPlaceholderImage
(
if
(
autoloadImage
)
{
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_dummy
,
null
));
load
.
setVisibility
(
GONE
);
hierarchy
.
setFailureImage
(
FrescoHelper
.
setupDraweeAndLoadImage
(
url
,
drawee
);
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_error
,
null
));
return
;
}
final
DraweeController
controller
=
Fresco
.
newDraweeControllerBuilder
()
FrescoHelper
.
setupDrawee
(
drawee
);
.
setUri
(
Uri
.
parse
(
absolutize
(
url
)))
load
.
setOnClickListener
(
new
OnClickListener
()
{
.
setAutoPlayAnimations
(
true
)
@Override
.
build
();
public
void
onClick
(
View
v
)
{
draweeView
.
setController
(
controller
);
load
.
setVisibility
(
GONE
);
load
.
setOnClickListener
(
null
);
FrescoHelper
.
loadImage
(
url
,
drawee
);
}
});
}
}
}
}
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/message/RocketChatMessageUrlsLayout.java
View file @
398a1fa9
...
@@ -13,6 +13,7 @@ import android.view.View;
...
@@ -13,6 +13,7 @@ import android.view.View;
import
android.widget.LinearLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.backends.pipeline.Fresco
;
import
com.facebook.drawee.drawable.ProgressBarDrawable
;
import
com.facebook.drawee.generic.GenericDraweeHierarchy
;
import
com.facebook.drawee.generic.GenericDraweeHierarchy
;
import
com.facebook.drawee.interfaces.DraweeController
;
import
com.facebook.drawee.interfaces.DraweeController
;
import
com.facebook.drawee.view.SimpleDraweeView
;
import
com.facebook.drawee.view.SimpleDraweeView
;
...
@@ -20,6 +21,7 @@ import com.facebook.drawee.view.SimpleDraweeView;
...
@@ -20,6 +21,7 @@ import com.facebook.drawee.view.SimpleDraweeView;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.R
;
import
chat.rocket.android.widget.helper.FrescoHelper
;
import
chat.rocket.android.widget.helper.ImageFormat
;
import
chat.rocket.android.widget.helper.ImageFormat
;
import
chat.rocket.core.models.WebContent
;
import
chat.rocket.core.models.WebContent
;
import
chat.rocket.core.models.WebContentHeaders
;
import
chat.rocket.core.models.WebContentHeaders
;
...
@@ -59,7 +61,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
...
@@ -59,7 +61,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
setOrientation
(
VERTICAL
);
setOrientation
(
VERTICAL
);
}
}
public
void
setUrls
(
List
<
WebContent
>
webContents
)
{
public
void
setUrls
(
List
<
WebContent
>
webContents
,
boolean
autoloadImages
)
{
if
(
this
.
webContents
!=
null
&&
this
.
webContents
.
equals
(
webContents
))
{
if
(
this
.
webContents
!=
null
&&
this
.
webContents
.
equals
(
webContents
))
{
return
;
return
;
}
}
...
@@ -68,20 +70,24 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
...
@@ -68,20 +70,24 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
removeAllViews
();
removeAllViews
();
for
(
int
i
=
0
,
size
=
webContents
.
size
();
i
<
size
;
i
++)
{
for
(
int
i
=
0
,
size
=
webContents
.
size
();
i
<
size
;
i
++)
{
appendUrlView
(
webContents
.
get
(
i
));
appendUrlView
(
webContents
.
get
(
i
)
,
autoloadImages
);
}
}
}
}
private
void
appendUrlView
(
WebContent
webContent
)
{
private
void
appendUrlView
(
WebContent
webContent
,
boolean
autoloadImages
)
{
final
String
url
=
webContent
.
getUrl
();
final
String
url
=
webContent
.
getUrl
();
final
WebContentHeaders
webContentHeaders
=
webContent
.
getHeaders
();
final
WebContentHeaders
webContentHeaders
=
webContent
.
getHeaders
();
String
contentType
=
webContentHeaders
!=
null
?
webContentHeaders
.
getContentType
()
:
""
;
String
contentType
=
webContentHeaders
!=
null
?
webContentHeaders
.
getContentType
()
:
""
;
if
(
contentType
!=
null
&&
contentType
.
startsWith
(
"image/"
)
if
(
contentType
!=
null
&&
contentType
.
startsWith
(
"image/"
)
&&
ImageFormat
.
SUPPORTED_LIST
.
contains
(
contentType
))
{
&&
ImageFormat
.
SUPPORTED_LIST
.
contains
(
contentType
))
{
View
inlineImage
=
inflater
.
inflate
(
R
.
layout
.
message_inline_image
,
this
,
false
);
final
View
inlineImageView
=
inflater
.
inflate
(
R
.
layout
.
message_inline_image
,
this
,
false
);
loadImage
(
url
,
(
SimpleDraweeView
)
inlineImage
.
findViewById
(
R
.
id
.
message_inline_image
));
final
SimpleDraweeView
addView
(
inlineImage
);
inlineImage
=
(
SimpleDraweeView
)
inlineImageView
.
findViewById
(
R
.
id
.
message_inline_image
);
final
View
loadView
=
inlineImageView
.
findViewById
(
R
.
id
.
message_inline_image_load
);
loadImage
(
url
,
inlineImage
,
loadView
,
autoloadImages
);
addView
(
inlineImageView
);
}
}
// see Rocket.Chat:packages/rocketchat-oembed/client/oembedUrlWidget.coffee
// see Rocket.Chat:packages/rocketchat-oembed/client/oembedUrlWidget.coffee
...
@@ -102,7 +108,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
...
@@ -102,7 +108,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
}
}
}
}
String
imageURL
=
webContent
.
getMetaImage
();
final
String
imageURL
=
webContent
.
getMetaImage
();
WebContentParsedUrl
parsedUrl
=
webContent
.
getParsedUrl
();
WebContentParsedUrl
parsedUrl
=
webContent
.
getParsedUrl
();
String
host
=
parsedUrl
!=
null
?
parsedUrl
.
getHost
()
:
null
;
String
host
=
parsedUrl
!=
null
?
parsedUrl
.
getHost
()
:
null
;
...
@@ -117,7 +123,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
...
@@ -117,7 +123,7 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
if
(
TextUtils
.
isEmpty
(
imageURL
))
{
if
(
TextUtils
.
isEmpty
(
imageURL
))
{
image
.
setVisibility
(
View
.
GONE
);
image
.
setVisibility
(
View
.
GONE
);
}
else
{
}
else
{
l
oadImage
(
imageURL
,
image
);
FrescoHelper
.
setupDraweeAndL
oadImage
(
imageURL
,
image
);
image
.
setVisibility
(
View
.
VISIBLE
);
image
.
setVisibility
(
View
.
VISIBLE
);
}
}
...
@@ -133,17 +139,22 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
...
@@ -133,17 +139,22 @@ public class RocketChatMessageUrlsLayout extends LinearLayout {
addView
(
embedUrl
);
addView
(
embedUrl
);
}
}
private
void
loadImage
(
String
imageUrl
,
SimpleDraweeView
draweeView
)
{
private
void
loadImage
(
final
String
url
,
final
SimpleDraweeView
drawee
,
final
View
load
,
final
GenericDraweeHierarchy
hierarchy
=
draweeView
.
getHierarchy
();
boolean
autoloadImage
)
{
hierarchy
.
setPlaceholderImage
(
if
(
autoloadImage
)
{
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_dummy
,
null
));
load
.
setVisibility
(
GONE
);
hierarchy
.
setFailureImage
(
FrescoHelper
.
setupDraweeAndLoadImage
(
url
,
drawee
);
VectorDrawableCompat
.
create
(
getResources
(),
R
.
drawable
.
image_error
,
null
));
return
;
}
final
DraweeController
controller
=
Fresco
.
newDraweeControllerBuilder
()
FrescoHelper
.
setupDrawee
(
drawee
);
.
setUri
(
Uri
.
parse
(
imageUrl
))
load
.
setOnClickListener
(
new
OnClickListener
()
{
.
setAutoPlayAnimations
(
true
)
@Override
.
build
();
public
void
onClick
(
View
v
)
{
draweeView
.
setController
(
controller
);
load
.
setVisibility
(
GONE
);
load
.
setOnClickListener
(
null
);
FrescoHelper
.
loadImage
(
url
,
drawee
);
}
});
}
}
}
}
rocket-chat-android-widgets/src/main/res/layout/message_inline_attachment.xml
View file @
398a1fa9
...
@@ -96,6 +96,11 @@
...
@@ -96,6 +96,11 @@
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id=
"@+id/image_container"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<com.facebook.drawee.view.SimpleDraweeView
<com.facebook.drawee.view.SimpleDraweeView
android:id=
"@+id/image"
android:id=
"@+id/image"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
@@ -103,6 +108,16 @@
...
@@ -103,6 +108,16 @@
android:layout_marginBottom=
"8dp"
android:layout_marginBottom=
"8dp"
fresco:actualImageScaleType=
"fitStart"
/>
fresco:actualImageScaleType=
"fitStart"
/>
<TextView
android:id=
"@+id/image_load"
android:layout_width=
"match_parent"
android:layout_height=
"150dp"
android:gravity=
"center_horizontal|bottom"
android:paddingBottom=
"16dp"
android:text=
"@string/click_to_load"
/>
</FrameLayout>
<!-- audio -->
<!-- audio -->
<!-- video -->
<!-- video -->
...
...
rocket-chat-android-widgets/src/main/res/layout/message_inline_image.xml
View file @
398a1fa9
...
@@ -11,4 +11,12 @@
...
@@ -11,4 +11,12 @@
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"150dp"
android:layout_height=
"150dp"
fresco:actualImageScaleType=
"fitStart"
/>
fresco:actualImageScaleType=
"fitStart"
/>
<TextView
android:id=
"@+id/message_inline_image_load"
android:layout_width=
"match_parent"
android:layout_height=
"150dp"
android:gravity=
"center_horizontal|bottom"
android:paddingBottom=
"16dp"
android:text=
"@string/click_to_load"
/>
</FrameLayout>
</FrameLayout>
rocket-chat-android-widgets/src/main/res/values/strings.xml
View file @
398a1fa9
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<string
name=
"message_composer_message_hint"
>
Message
</string>
<string
name=
"message_composer_message_hint"
>
Message
</string>
<string
name=
"click_to_load"
>
Click to load
</string>
</resources>
</resources>
\ 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