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
a9085e1c
Commit
a9085e1c
authored
Feb 26, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release/2.0.0-beta7' into emoji-keyboard
parents
d87e13a3
5c44395b
Changes
35
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
830 additions
and
462 deletions
+830
-462
build.gradle
app/build.gradle
+2
-2
AudioAttachmentViewHolder.kt
...ket/android/chatroom/adapter/AudioAttachmentViewHolder.kt
+27
-0
BaseViewHolder.kt
...va/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
+15
-0
ChatRoomAdapter.kt
...a/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
+111
-0
ImageAttachmentViewHolder.kt
...ket/android/chatroom/adapter/ImageAttachmentViewHolder.kt
+22
-0
MessageViewHolder.kt
...chat/rocket/android/chatroom/adapter/MessageViewHolder.kt
+78
-0
UrlPreviewViewHolder.kt
...t/rocket/android/chatroom/adapter/UrlPreviewViewHolder.kt
+30
-0
VideoAttachmentViewHolder.kt
...ket/android/chatroom/adapter/VideoAttachmentViewHolder.kt
+27
-0
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+19
-4
ChatRoomView.kt
...chat/rocket/android/chatroom/presentation/ChatRoomView.kt
+4
-4
PinnedMessagesPresenter.kt
.../android/chatroom/presentation/PinnedMessagesPresenter.kt
+5
-4
PinnedMessagesView.kt
...ocket/android/chatroom/presentation/PinnedMessagesView.kt
+2
-2
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+10
-8
PinnedMessagesAdapter.kt
.../chat/rocket/android/chatroom/ui/PinnedMessagesAdapter.kt
+0
-133
PinnedMessagesFragment.kt
...chat/rocket/android/chatroom/ui/PinnedMessagesFragment.kt
+7
-5
AudioAttachmentViewModel.kt
...et/android/chatroom/viewmodel/AudioAttachmentViewModel.kt
+17
-0
BaseFileAttachmentViewModel.kt
...android/chatroom/viewmodel/BaseFileAttachmentViewModel.kt
+7
-0
BaseMessageViewModel.kt
...rocket/android/chatroom/viewmodel/BaseMessageViewModel.kt
+9
-0
BaseViewModel.kt
...a/chat/rocket/android/chatroom/viewmodel/BaseViewModel.kt
+25
-0
ImageAttachmentViewModel.kt
...et/android/chatroom/viewmodel/ImageAttachmentViewModel.kt
+17
-0
MessageViewModel.kt
...hat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
+16
-230
MessageViewModelMapper.kt
...cket/android/chatroom/viewmodel/MessageViewModelMapper.kt
+0
-39
UrlPreviewViewModel.kt
.../rocket/android/chatroom/viewmodel/UrlPreviewViewModel.kt
+18
-0
VideoAttachmentViewModel.kt
...et/android/chatroom/viewmodel/VideoAttachmentViewModel.kt
+17
-0
ViewModelMapper.kt
...chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
+255
-0
ChatRoomsAdapter.kt
...java/chat/rocket/android/chatrooms/ui/ChatRoomsAdapter.kt
+27
-11
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+4
-0
MessageParser.kt
...src/main/java/chat/rocket/android/helper/MessageParser.kt
+1
-1
SettingsRepository.kt
...a/chat/rocket/android/server/domain/SettingsRepository.kt
+3
-1
Text.kt
...src/main/java/chat/rocket/android/util/extensions/Text.kt
+1
-1
item_chat.xml
app/src/main/res/layout/item_chat.xml
+0
-1
item_message.xml
app/src/main/res/layout/item_message.xml
+1
-11
message_attachment.xml
app/src/main/res/layout/message_attachment.xml
+6
-5
message_url_preview.xml
app/src/main/res/layout/message_url_preview.xml
+46
-0
colors.xml
app/src/main/res/values/colors.xml
+1
-0
No files found.
app/build.gradle
View file @
a9085e1c
...
@@ -12,8 +12,8 @@ android {
...
@@ -12,8 +12,8 @@ android {
applicationId
"chat.rocket.android"
applicationId
"chat.rocket.android"
minSdkVersion
21
minSdkVersion
21
targetSdkVersion
versions
.
targetSdk
targetSdkVersion
versions
.
targetSdk
versionCode
100
8
versionCode
100
9
versionName
"2.0.0-dev
6
"
versionName
"2.0.0-dev
7
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled
true
multiDexEnabled
true
}
}
...
...
app/src/main/java/chat/rocket/android/chatroom/adapter/AudioAttachmentViewHolder.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.view.View
import
chat.rocket.android.chatroom.viewmodel.AudioAttachmentViewModel
import
chat.rocket.android.player.PlayerActivity
import
chat.rocket.android.util.extensions.setVisible
import
kotlinx.android.synthetic.main.message_attachment.view.*
class
AudioAttachmentViewHolder
(
itemView
:
View
)
:
BaseViewHolder
<
AudioAttachmentViewModel
>(
itemView
)
{
init
{
with
(
itemView
)
{
image_attachment
.
setVisible
(
false
)
audio_video_attachment
.
setVisible
(
true
)
}
}
override
fun
bindViews
(
data
:
AudioAttachmentViewModel
)
{
with
(
itemView
)
{
file_name
.
text
=
data
.
attachmentTitle
audio_video_attachment
.
setOnClickListener
{
view
->
data
.
attachmentUrl
.
let
{
url
->
PlayerActivity
.
play
(
view
.
context
,
url
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/BaseViewHolder.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.support.v7.widget.RecyclerView
import
android.view.View
abstract
class
BaseViewHolder
<
T
>(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
var
data
:
T
?
=
null
fun
bind
(
data
:
T
)
{
this
.
data
=
data
bindViews
(
data
)
}
abstract
fun
bindViews
(
data
:
T
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/ChatRoomAdapter.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.support.v7.widget.RecyclerView
import
android.view.ViewGroup
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.viewmodel.*
import
chat.rocket.android.util.extensions.inflate
import
timber.log.Timber
import
java.security.InvalidParameterException
class
ChatRoomAdapter
(
private
val
roomType
:
String
,
private
val
roomName
:
String
,
private
val
presenter
:
ChatRoomPresenter
?,
private
val
enableActions
:
Boolean
=
true
)
:
RecyclerView
.
Adapter
<
BaseViewHolder
<*>>()
{
private
val
dataSet
=
ArrayList
<
BaseViewModel
<*>>()
init
{
setHasStableIds
(
true
)
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
BaseViewHolder
<
*
>
{
return
when
(
viewType
.
toViewType
())
{
BaseViewModel
.
ViewType
.
MESSAGE
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_message
)
MessageViewHolder
(
view
,
roomName
,
roomType
,
presenter
,
enableActions
)
}
BaseViewModel
.
ViewType
.
IMAGE_ATTACHMENT
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
message_attachment
)
ImageAttachmentViewHolder
(
view
)
}
BaseViewModel
.
ViewType
.
AUDIO_ATTACHMENT
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
message_attachment
)
AudioAttachmentViewHolder
(
view
)
}
BaseViewModel
.
ViewType
.
VIDEO_ATTACHMENT
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
message_attachment
)
VideoAttachmentViewHolder
(
view
)
}
BaseViewModel
.
ViewType
.
URL_PREVIEW
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
message_url_preview
)
UrlPreviewViewHolder
(
view
)
}
else
->
{
throw
InvalidParameterException
(
"TODO - implement for ${viewType.toViewType()}"
)
}
}
}
override
fun
getItemViewType
(
position
:
Int
):
Int
{
return
dataSet
[
position
].
viewType
}
override
fun
getItemCount
():
Int
{
return
dataSet
.
size
}
override
fun
onBindViewHolder
(
holder
:
BaseViewHolder
<
*
>,
position
:
Int
)
{
when
(
holder
)
{
is
MessageViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
MessageViewModel
)
is
ImageAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
ImageAttachmentViewModel
)
is
AudioAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
AudioAttachmentViewModel
)
is
VideoAttachmentViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
VideoAttachmentViewModel
)
is
UrlPreviewViewHolder
->
holder
.
bind
(
dataSet
[
position
]
as
UrlPreviewViewModel
)
}
}
override
fun
getItemId
(
position
:
Int
):
Long
{
val
model
=
dataSet
[
position
]
return
when
(
model
)
{
is
MessageViewModel
->
model
.
messageId
.
hashCode
().
toLong
()
is
BaseFileAttachmentViewModel
->
model
.
id
else
->
return
position
.
toLong
()
}
}
fun
appendData
(
dataSet
:
List
<
BaseViewModel
<*
>>)
{
val
previousDataSetSize
=
this
.
dataSet
.
size
this
.
dataSet
.
addAll
(
dataSet
)
notifyItemChanged
(
previousDataSetSize
,
dataSet
.
size
)
}
fun
prependData
(
dataSet
:
List
<
BaseViewModel
<*
>>)
{
this
.
dataSet
.
addAll
(
0
,
dataSet
)
notifyItemRangeInserted
(
0
,
dataSet
.
size
)
}
fun
updateItem
(
message
:
BaseViewModel
<
*
>)
{
val
index
=
dataSet
.
indexOfLast
{
it
.
messageId
==
message
.
messageId
}
Timber
.
d
(
"index: $index"
)
if
(
index
>
-
1
)
{
dataSet
[
index
]
=
message
notifyItemChanged
(
index
)
}
}
fun
removeItem
(
messageId
:
String
)
{
val
index
=
dataSet
.
indexOfFirst
{
it
.
messageId
==
messageId
}
if
(
index
>
-
1
)
{
val
oldSize
=
dataSet
.
size
val
newSet
=
dataSet
.
filterNot
{
it
.
messageId
==
messageId
}
dataSet
.
clear
()
dataSet
.
addAll
(
newSet
)
val
newSize
=
dataSet
.
size
notifyItemRangeRemoved
(
index
,
oldSize
-
newSize
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/ImageAttachmentViewHolder.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.view.View
import
chat.rocket.android.chatroom.viewmodel.ImageAttachmentViewModel
import
com.stfalcon.frescoimageviewer.ImageViewer
import
kotlinx.android.synthetic.main.message_attachment.view.*
class
ImageAttachmentViewHolder
(
itemView
:
View
)
:
BaseViewHolder
<
ImageAttachmentViewModel
>(
itemView
)
{
override
fun
bindViews
(
data
:
ImageAttachmentViewModel
)
{
with
(
itemView
)
{
image_attachment
.
setImageURI
(
data
.
attachmentUrl
)
file_name
.
text
=
data
.
attachmentTitle
image_attachment
.
setOnClickListener
{
view
->
// TODO - implement a proper image viewer with a proper Transition
ImageViewer
.
Builder
(
view
.
context
,
listOf
(
data
.
attachmentUrl
))
.
setStartPosition
(
0
)
.
show
()
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/MessageViewHolder.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.text.method.LinkMovementMethod
import
android.view.MenuItem
import
android.view.View
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.ui.bottomsheet.BottomSheetMenu
import
chat.rocket.android.chatroom.ui.bottomsheet.adapter.ActionListAdapter
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
kotlinx.android.synthetic.main.avatar.view.*
import
kotlinx.android.synthetic.main.item_message.view.*
import
ru.whalemare.sheetmenu.extension.inflate
import
ru.whalemare.sheetmenu.extension.toList
class
MessageViewHolder
(
itemView
:
View
,
private
val
roomType
:
String
,
private
val
roomName
:
String
,
private
val
presenter
:
ChatRoomPresenter
?,
enableActions
:
Boolean
)
:
BaseViewHolder
<
MessageViewModel
>(
itemView
),
MenuItem
.
OnMenuItemClickListener
{
init
{
itemView
.
text_content
.
movementMethod
=
LinkMovementMethod
()
if
(
enableActions
)
{
itemView
.
setOnLongClickListener
{
if
(
data
?.
isSystemMessage
==
false
)
{
val
menuItems
=
it
.
context
.
inflate
(
R
.
menu
.
message_actions
).
toList
()
menuItems
.
find
{
it
.
itemId
==
R
.
id
.
action_menu_msg_pin_unpin
}
?.
apply
{
val
isPinned
=
data
?.
isPinned
?:
false
setTitle
(
if
(
isPinned
)
R
.
string
.
action_msg_unpin
else
R
.
string
.
action_msg_pin
)
isChecked
=
isPinned
}
val
adapter
=
ActionListAdapter
(
menuItems
,
this
@MessageViewHolder
)
BottomSheetMenu
(
adapter
).
apply
{
}.
show
(
it
.
context
)
}
true
}
}
}
override
fun
bindViews
(
data
:
MessageViewModel
)
{
with
(
itemView
)
{
text_message_time
.
text
=
data
.
time
text_sender
.
text
=
data
.
senderName
text_content
.
text
=
data
.
content
image_avatar
.
setImageURI
(
data
.
avatar
)
}
}
override
fun
onMenuItemClick
(
item
:
MenuItem
):
Boolean
{
data
?.
rawData
?.
apply
{
when
(
item
.
itemId
)
{
R
.
id
.
action_menu_msg_delete
->
presenter
?.
deleteMessage
(
roomId
,
id
)
R
.
id
.
action_menu_msg_quote
->
presenter
?.
citeMessage
(
roomType
,
roomName
,
id
,
false
)
R
.
id
.
action_menu_msg_reply
->
presenter
?.
citeMessage
(
roomType
,
roomName
,
id
,
true
)
R
.
id
.
action_menu_msg_copy
->
presenter
?.
copyMessage
(
id
)
R
.
id
.
action_menu_msg_edit
->
presenter
?.
editMessage
(
roomId
,
id
,
message
)
R
.
id
.
action_menu_msg_pin_unpin
->
{
with
(
item
)
{
if
(!
isChecked
)
{
presenter
?.
pinMessage
(
id
)
}
else
{
presenter
?.
unpinMessage
(
id
)
}
}
}
else
->
TODO
(
"Not implemented"
)
}
}
return
true
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/UrlPreviewViewHolder.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.content.Intent
import
android.net.Uri
import
android.view.View
import
chat.rocket.android.chatroom.viewmodel.UrlPreviewViewModel
import
chat.rocket.android.util.extensions.content
import
chat.rocket.android.util.extensions.setVisible
import
kotlinx.android.synthetic.main.message_url_preview.view.*
class
UrlPreviewViewHolder
(
itemView
:
View
)
:
BaseViewHolder
<
UrlPreviewViewModel
>(
itemView
)
{
override
fun
bindViews
(
data
:
UrlPreviewViewModel
)
{
with
(
itemView
)
{
if
(
data
.
thumbUrl
.
isNullOrEmpty
())
{
image_preview
.
setVisible
(
false
)
}
else
{
image_preview
.
setImageURI
(
data
.
thumbUrl
)
image_preview
.
setVisible
(
true
)
}
text_host
.
content
=
data
.
hostname
text_title
.
content
=
data
.
title
text_description
.
content
=
data
.
description
?:
""
url_preview_layout
.
setOnClickListener
{
view
->
view
.
context
.
startActivity
(
Intent
(
Intent
.
ACTION_VIEW
,
Uri
.
parse
(
data
.
rawData
.
url
)))
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/adapter/VideoAttachmentViewHolder.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.adapter
import
android.view.View
import
chat.rocket.android.chatroom.viewmodel.VideoAttachmentViewModel
import
chat.rocket.android.player.PlayerActivity
import
chat.rocket.android.util.extensions.setVisible
import
kotlinx.android.synthetic.main.message_attachment.view.*
class
VideoAttachmentViewHolder
(
itemView
:
View
)
:
BaseViewHolder
<
VideoAttachmentViewModel
>(
itemView
)
{
init
{
with
(
itemView
)
{
image_attachment
.
setVisible
(
false
)
audio_video_attachment
.
setVisible
(
true
)
}
}
override
fun
bindViews
(
data
:
VideoAttachmentViewModel
)
{
with
(
itemView
)
{
file_name
.
text
=
data
.
attachmentTitle
audio_video_attachment
.
setOnClickListener
{
view
->
data
.
attachmentUrl
.
let
{
url
->
PlayerActivity
.
play
(
view
.
context
,
url
)
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
a9085e1c
...
@@ -3,7 +3,7 @@ package chat.rocket.android.chatroom.presentation
...
@@ -3,7 +3,7 @@ package chat.rocket.android.chatroom.presentation
import
android.net.Uri
import
android.net.Uri
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.domain.UriInteractor
import
chat.rocket.android.chatroom.domain.UriInteractor
import
chat.rocket.android.chatroom.viewmodel.
Message
ViewModelMapper
import
chat.rocket.android.chatroom.viewmodel.ViewModelMapper
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
...
@@ -34,7 +34,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -34,7 +34,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
private
val
uriInteractor
:
UriInteractor
,
private
val
uriInteractor
:
UriInteractor
,
private
val
messagesRepository
:
MessagesRepository
,
private
val
messagesRepository
:
MessagesRepository
,
factory
:
RocketChatClientFactory
,
factory
:
RocketChatClientFactory
,
private
val
mapper
:
Message
ViewModelMapper
)
{
private
val
mapper
:
ViewModelMapper
)
{
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
var
subId
:
String
?
=
null
private
var
subId
:
String
?
=
null
private
var
settings
:
Map
<
String
,
Value
<
Any
>>
=
getSettingsInteractor
.
get
(
serverInteractor
.
get
()
!!
)
!!
private
var
settings
:
Map
<
String
,
Value
<
Any
>>
=
getSettingsInteractor
.
get
(
serverInteractor
.
get
()
!!
)
!!
...
@@ -48,7 +48,11 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -48,7 +48,11 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
client
.
messages
(
chatRoomId
,
roomTypeOf
(
chatRoomType
),
offset
,
30
).
result
messagesRepository
.
saveAll
(
messages
)
messagesRepository
.
saveAll
(
messages
)
val
messagesViewModels
=
mapper
.
mapToViewModelList
(
messages
,
settings
)
// TODO: For now we are marking the room as read if we can get the messages (I mean, no exception occurs)
// but should mark only when the user see the first unread message.
markRoomAsRead
(
chatRoomId
)
val
messagesViewModels
=
mapper
.
map
(
messages
)
view
.
showMessages
(
messagesViewModels
)
view
.
showMessages
(
messagesViewModels
)
// Subscribe after getting the first page of messages from REST
// Subscribe after getting the first page of messages from REST
...
@@ -127,6 +131,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -127,6 +131,17 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
}
}
fun
markRoomAsRead
(
roomId
:
String
)
{
launchUI
(
strategy
)
{
try
{
client
.
markAsRead
(
roomId
)
}
catch
(
ex
:
RocketChatException
)
{
view
.
showMessage
(
ex
.
message
!!
)
// TODO Remove.
Timber
.
e
(
ex
)
// FIXME: Right now we are only catching the exception with Timber.
}
}
}
private
fun
subscribeMessages
(
roomId
:
String
)
{
private
fun
subscribeMessages
(
roomId
:
String
)
{
client
.
addStateChannel
(
stateChannel
)
client
.
addStateChannel
(
stateChannel
)
launch
(
CommonPool
+
strategy
.
jobs
)
{
launch
(
CommonPool
+
strategy
.
jobs
)
{
...
@@ -315,7 +330,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -315,7 +330,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
private
fun
updateMessage
(
streamedMessage
:
Message
)
{
private
fun
updateMessage
(
streamedMessage
:
Message
)
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
val
viewModelStreamedMessage
=
mapper
.
map
ToViewModel
(
streamedMessage
,
settings
)
val
viewModelStreamedMessage
=
mapper
.
map
(
streamedMessage
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
roomMessages
=
messagesRepository
.
getByRoomId
(
streamedMessage
.
roomId
)
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
val
index
=
roomMessages
.
indexOfFirst
{
msg
->
msg
.
id
==
streamedMessage
.
id
}
if
(
index
>
-
1
)
{
if
(
index
>
-
1
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomView.kt
View file @
a9085e1c
package
chat.rocket.android.chatroom.presentation
package
chat.rocket.android.chatroom.presentation
import
android.net.Uri
import
android.net.Uri
import
chat.rocket.android.chatroom.viewmodel.
Messag
eViewModel
import
chat.rocket.android.chatroom.viewmodel.
Bas
eViewModel
import
chat.rocket.android.core.behaviours.LoadingView
import
chat.rocket.android.core.behaviours.LoadingView
import
chat.rocket.android.core.behaviours.MessageView
import
chat.rocket.android.core.behaviours.MessageView
...
@@ -12,7 +12,7 @@ interface ChatRoomView : LoadingView, MessageView {
...
@@ -12,7 +12,7 @@ interface ChatRoomView : LoadingView, MessageView {
*
*
* @param dataSet The data set to show.
* @param dataSet The data set to show.
*/
*/
fun
showMessages
(
dataSet
:
List
<
MessageViewModel
>)
fun
showMessages
(
dataSet
:
List
<
BaseViewModel
<*
>
>)
/**
/**
* Send a message to a chat room.
* Send a message to a chat room.
...
@@ -43,7 +43,7 @@ interface ChatRoomView : LoadingView, MessageView {
...
@@ -43,7 +43,7 @@ interface ChatRoomView : LoadingView, MessageView {
*
*
* @param message The (recent) message sent to a chat room.
* @param message The (recent) message sent to a chat room.
*/
*/
fun
showNewMessage
(
message
:
MessageViewModel
)
fun
showNewMessage
(
message
:
List
<
BaseViewModel
<*
>>
)
/**
/**
* Dispatch to the recycler views adapter that we should remove a message.
* Dispatch to the recycler views adapter that we should remove a message.
...
@@ -57,7 +57,7 @@ interface ChatRoomView : LoadingView, MessageView {
...
@@ -57,7 +57,7 @@ interface ChatRoomView : LoadingView, MessageView {
*
*
* @param index The index of the changed message
* @param index The index of the changed message
*/
*/
fun
dispatchUpdateMessage
(
index
:
Int
,
message
:
MessageViewModel
)
fun
dispatchUpdateMessage
(
index
:
Int
,
message
:
List
<
BaseViewModel
<*
>>
)
/**
/**
* Show reply status above the message composer.
* Show reply status above the message composer.
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/PinnedMessagesPresenter.kt
View file @
a9085e1c
package
chat.rocket.android.chatroom.presentation
package
chat.rocket.android.chatroom.presentation
import
chat.rocket.android.chatroom.viewmodel.MessageViewModelMapper
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.chatroom.viewmodel.ViewModelMapper
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.GetChatRoomsInteractor
import
chat.rocket.android.server.domain.GetChatRoomsInteractor
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
...
@@ -18,7 +19,7 @@ class PinnedMessagesPresenter @Inject constructor(private val view: PinnedMessag
...
@@ -18,7 +19,7 @@ class PinnedMessagesPresenter @Inject constructor(private val view: PinnedMessag
private
val
strategy
:
CancelStrategy
,
private
val
strategy
:
CancelStrategy
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
roomsInteractor
:
GetChatRoomsInteractor
,
private
val
roomsInteractor
:
GetChatRoomsInteractor
,
private
val
mapper
:
Message
ViewModelMapper
,
private
val
mapper
:
ViewModelMapper
,
factory
:
RocketChatClientFactory
,
factory
:
RocketChatClientFactory
,
getSettingsInteractor
:
GetSettingsInteractor
)
{
getSettingsInteractor
:
GetSettingsInteractor
)
{
...
@@ -41,8 +42,8 @@ class PinnedMessagesPresenter @Inject constructor(private val view: PinnedMessag
...
@@ -41,8 +42,8 @@ class PinnedMessagesPresenter @Inject constructor(private val view: PinnedMessag
val
pinnedMessages
=
val
pinnedMessages
=
client
.
getRoomPinnedMessages
(
roomId
,
room
.
type
,
pinnedMessagesListOffset
)
client
.
getRoomPinnedMessages
(
roomId
,
room
.
type
,
pinnedMessagesListOffset
)
pinnedMessagesListOffset
=
pinnedMessages
.
offset
.
toInt
()
pinnedMessagesListOffset
=
pinnedMessages
.
offset
.
toInt
()
val
messageList
=
mapper
.
map
ToViewModelList
(
pinnedMessages
.
result
,
settings
)
val
messageList
=
mapper
.
map
(
pinnedMessages
.
result
)
.
filterNot
{
it
.
isSystemMessage
}
.
filter
{
it
is
MessageViewModel
}.
filterNot
{
(
it
as
MessageViewModel
)
.
isSystemMessage
}
view
.
showPinnedMessages
(
messageList
)
view
.
showPinnedMessages
(
messageList
)
view
.
hideLoading
()
view
.
hideLoading
()
}.
ifNull
{
}.
ifNull
{
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/PinnedMessagesView.kt
View file @
a9085e1c
package
chat.rocket.android.chatroom.presentation
package
chat.rocket.android.chatroom.presentation
import
chat.rocket.android.chatroom.viewmodel.
Messag
eViewModel
import
chat.rocket.android.chatroom.viewmodel.
Bas
eViewModel
import
chat.rocket.android.core.behaviours.LoadingView
import
chat.rocket.android.core.behaviours.LoadingView
import
chat.rocket.android.core.behaviours.MessageView
import
chat.rocket.android.core.behaviours.MessageView
...
@@ -11,5 +11,5 @@ interface PinnedMessagesView : MessageView, LoadingView {
...
@@ -11,5 +11,5 @@ interface PinnedMessagesView : MessageView, LoadingView {
*
*
* @param pinnedMessages The list of pinned messages.
* @param pinnedMessages The list of pinned messages.
*/
*/
fun
showPinnedMessages
(
pinnedMessages
:
List
<
MessageViewModel
>)
fun
showPinnedMessages
(
pinnedMessages
:
List
<
BaseViewModel
<*
>
>)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
a9085e1c
...
@@ -15,9 +15,10 @@ import android.support.v7.widget.LinearLayoutManager
...
@@ -15,9 +15,10 @@ import android.support.v7.widget.LinearLayoutManager
import
android.support.v7.widget.RecyclerView
import
android.support.v7.widget.RecyclerView
import
android.view.*
import
android.view.*
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.ChatRoomAdapter
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.presentation.ChatRoomPresenter
import
chat.rocket.android.chatroom.presentation.ChatRoomView
import
chat.rocket.android.chatroom.presentation.ChatRoomView
import
chat.rocket.android.chatroom.viewmodel.
Messag
eViewModel
import
chat.rocket.android.chatroom.viewmodel.
Bas
eViewModel
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.KeyboardHelper
import
chat.rocket.android.helper.KeyboardHelper
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.helper.MessageParser
...
@@ -144,7 +145,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
...
@@ -144,7 +145,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
return
true
return
true
}
}
override
fun
showMessages
(
dataSet
:
List
<
MessageViewModel
>)
{
override
fun
showMessages
(
dataSet
:
List
<
BaseViewModel
<*
>
>)
{
activity
?.
apply
{
activity
?.
apply
{
if
(
recycler_view
.
adapter
==
null
)
{
if
(
recycler_view
.
adapter
==
null
)
{
adapter
=
ChatRoomAdapter
(
chatRoomType
,
chatRoomName
,
presenter
)
adapter
=
ChatRoomAdapter
(
chatRoomType
,
chatRoomName
,
presenter
)
...
@@ -161,9 +162,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
...
@@ -161,9 +162,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
})
})
}
}
}
}
val
oldMessagesCount
=
adapter
.
itemCount
val
oldMessagesCount
=
adapter
.
itemCount
adapter
.
a
ddDataSet
(
dataSet
)
adapter
.
a
ppendData
(
dataSet
)
if
(
oldMessagesCount
==
0
&&
dataSet
.
size
>
0
)
{
if
(
oldMessagesCount
==
0
&&
dataSet
.
isNotEmpty
()
)
{
recycler_view
.
scrollToPosition
(
0
)
recycler_view
.
scrollToPosition
(
0
)
}
}
}
}
...
@@ -182,8 +184,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
...
@@ -182,8 +184,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
override
fun
showInvalidFileMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_invalid_file
))
override
fun
showInvalidFileMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_invalid_file
))
override
fun
showNewMessage
(
message
:
MessageViewModel
)
{
override
fun
showNewMessage
(
message
:
List
<
BaseViewModel
<*
>>
)
{
adapter
.
addItem
(
message
)
adapter
.
prependData
(
message
)
recycler_view
.
scrollToPosition
(
0
)
recycler_view
.
scrollToPosition
(
0
)
}
}
...
@@ -204,8 +206,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
...
@@ -204,8 +206,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
actionSnackbar
.
dismiss
()
actionSnackbar
.
dismiss
()
}
}
override
fun
dispatchUpdateMessage
(
index
:
Int
,
message
:
MessageViewModel
)
{
override
fun
dispatchUpdateMessage
(
index
:
Int
,
message
:
List
<
BaseViewModel
<*
>>
)
{
adapter
.
updateItem
(
message
)
adapter
.
updateItem
(
message
.
last
()
)
}
}
override
fun
dispatchDeleteMessage
(
msgId
:
String
)
{
override
fun
dispatchDeleteMessage
(
msgId
:
String
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/PinnedMessagesAdapter.kt
deleted
100644 → 0
View file @
d87e13a3
package
chat.rocket.android.chatroom.ui
import
android.support.v7.widget.RecyclerView
import
android.text.method.LinkMovementMethod
import
android.view.View
import
android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.viewmodel.AttachmentType
import
chat.rocket.android.chatroom.viewmodel.MessageViewModel
import
chat.rocket.android.player.PlayerActivity
import
chat.rocket.android.util.extensions.content
import
chat.rocket.android.util.extensions.inflate
import
chat.rocket.android.util.extensions.setVisible
import
com.facebook.drawee.view.SimpleDraweeView
import
com.stfalcon.frescoimageviewer.ImageViewer
import
kotlinx.android.synthetic.main.avatar.view.*
import
kotlinx.android.synthetic.main.item_message.view.*
import
kotlinx.android.synthetic.main.message_attachment.view.*
class
PinnedMessagesAdapter
:
RecyclerView
.
Adapter
<
PinnedMessagesAdapter
.
ViewHolder
>()
{
init
{
setHasStableIds
(
true
)
}
val
dataSet
=
ArrayList
<
MessageViewModel
>()
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
=
ViewHolder
(
parent
.
inflate
(
R
.
layout
.
item_message
))
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
=
holder
.
bind
(
dataSet
[
position
])
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
,
payloads
:
MutableList
<
Any
>?)
{
onBindViewHolder
(
holder
,
position
)
}
override
fun
getItemCount
():
Int
=
dataSet
.
size
override
fun
getItemViewType
(
position
:
Int
):
Int
=
position
fun
addDataSet
(
dataSet
:
List
<
MessageViewModel
>)
{
val
previousDataSetSize
=
this
.
dataSet
.
size
this
.
dataSet
.
addAll
(
previousDataSetSize
,
dataSet
)
notifyItemRangeInserted
(
previousDataSetSize
,
dataSet
.
size
)
}
fun
addItem
(
message
:
MessageViewModel
)
{
dataSet
.
add
(
0
,
message
)
notifyItemInserted
(
0
)
}
fun
updateItem
(
message
:
MessageViewModel
)
{
val
index
=
dataSet
.
indexOfFirst
{
it
.
id
==
message
.
id
}
if
(
index
>
-
1
)
{
dataSet
[
index
]
=
message
notifyItemChanged
(
index
)
}
}
fun
removeItem
(
messageId
:
String
)
{
val
index
=
dataSet
.
indexOfFirst
{
it
.
id
==
messageId
}
if
(
index
>
-
1
)
{
dataSet
.
removeAt
(
index
)
notifyItemRemoved
(
index
)
}
}
override
fun
getItemId
(
position
:
Int
):
Long
{
return
dataSet
[
position
].
id
.
hashCode
().
toLong
()
}
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
private
lateinit
var
messageViewModel
:
MessageViewModel
fun
bind
(
message
:
MessageViewModel
)
=
with
(
itemView
)
{
messageViewModel
=
message
image_avatar
.
setImageURI
(
message
.
avatarUri
)
text_sender
.
content
=
message
.
senderName
text_message_time
.
content
=
message
.
time
text_content
.
content
=
message
.
content
text_content
.
movementMethod
=
LinkMovementMethod
()
bindAttachment
(
message
,
message_attachment
,
image_attachment
,
audio_video_attachment
,
file_name
)
}
private
fun
bindAttachment
(
message
:
MessageViewModel
,
attachment_container
:
View
,
image_attachment
:
SimpleDraweeView
,
audio_video_attachment
:
View
,
file_name
:
TextView
)
{
with
(
message
)
{
if
(
attachmentUrl
==
null
||
attachmentType
==
null
)
{
attachment_container
.
setVisible
(
false
)
return
}
var
imageVisible
=
false
var
videoVisible
=
false
attachment_container
.
setVisible
(
true
)
when
(
message
.
attachmentType
)
{
is
AttachmentType
.
Image
->
{
imageVisible
=
true
image_attachment
.
setImageURI
(
message
.
attachmentUrl
)
image_attachment
.
setOnClickListener
{
view
->
// TODO - implement a proper image viewer with a proper Transition
ImageViewer
.
Builder
(
view
.
context
,
listOf
(
message
.
attachmentUrl
))
.
setStartPosition
(
0
)
.
show
()
}
}
is
AttachmentType
.
Video
,
is
AttachmentType
.
Audio
->
{
videoVisible
=
true
audio_video_attachment
.
setOnClickListener
{
view
->
message
.
attachmentUrl
?.
let
{
url
->
PlayerActivity
.
play
(
view
.
context
,
url
)
}
}
}
}
image_attachment
.
setVisible
(
imageVisible
)
audio_video_attachment
.
setVisible
(
videoVisible
)
file_name
.
text
=
message
.
attachmentTitle
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/PinnedMessagesFragment.kt
View file @
a9085e1c
...
@@ -9,9 +9,10 @@ import android.view.LayoutInflater
...
@@ -9,9 +9,10 @@ import android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.chatroom.adapter.ChatRoomAdapter
import
chat.rocket.android.chatroom.presentation.PinnedMessagesPresenter
import
chat.rocket.android.chatroom.presentation.PinnedMessagesPresenter
import
chat.rocket.android.chatroom.presentation.PinnedMessagesView
import
chat.rocket.android.chatroom.presentation.PinnedMessagesView
import
chat.rocket.android.chatroom.viewmodel.
Messag
eViewModel
import
chat.rocket.android.chatroom.viewmodel.
Bas
eViewModel
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.util.extensions.setVisible
import
chat.rocket.android.util.extensions.setVisible
import
chat.rocket.android.util.extensions.showToast
import
chat.rocket.android.util.extensions.showToast
...
@@ -39,7 +40,7 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
...
@@ -39,7 +40,7 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
private
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomId
:
String
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomType
:
String
private
lateinit
var
chatRoomType
:
String
private
lateinit
var
adapter
:
PinnedMessages
Adapter
private
lateinit
var
adapter
:
ChatRoom
Adapter
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -71,10 +72,11 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
...
@@ -71,10 +72,11 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
override
fun
showGenericErrorMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_generic_error
))
override
fun
showGenericErrorMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_generic_error
))
override
fun
showPinnedMessages
(
pinnedMessages
:
List
<
MessageViewModel
>)
{
override
fun
showPinnedMessages
(
pinnedMessages
:
List
<
BaseViewModel
<*
>
>)
{
activity
?.
apply
{
activity
?.
apply
{
if
(
recycler_view_pinned
.
adapter
==
null
)
{
if
(
recycler_view_pinned
.
adapter
==
null
)
{
adapter
=
PinnedMessagesAdapter
()
// TODO - add a better constructor for this case...
adapter
=
ChatRoomAdapter
(
chatRoomType
,
chatRoomName
,
null
,
false
)
recycler_view_pinned
.
adapter
=
adapter
recycler_view_pinned
.
adapter
=
adapter
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
false
)
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
false
)
recycler_view_pinned
.
layoutManager
=
linearLayoutManager
recycler_view_pinned
.
layoutManager
=
linearLayoutManager
...
@@ -88,7 +90,7 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
...
@@ -88,7 +90,7 @@ class PinnedMessagesFragment : Fragment(), PinnedMessagesView {
}
}
}
}
adapter
.
a
ddDataSet
(
pinnedMessages
)
adapter
.
a
ppendData
(
pinnedMessages
)
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/AudioAttachmentViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
import
chat.rocket.android.R
import
chat.rocket.core.model.attachment.AudioAttachment
data class
AudioAttachmentViewModel
(
override
val
rawData
:
AudioAttachment
,
override
val
messageId
:
String
,
override
val
attachmentUrl
:
String
,
override
val
attachmentTitle
:
CharSequence
,
override
val
id
:
Long
)
:
BaseFileAttachmentViewModel
<
AudioAttachment
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
AUDIO_ATTACHMENT
.
viewType
override
val
layoutId
:
Int
get
()
=
R
.
layout
.
message_attachment
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseFileAttachmentViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
interface
BaseFileAttachmentViewModel
<
out
T
>
:
BaseViewModel
<
T
>
{
val
attachmentUrl
:
String
val
attachmentTitle
:
CharSequence
val
id
:
Long
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseMessageViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
interface
BaseMessageViewModel
<
out
T
>
:
BaseViewModel
<
T
>
{
val
avatar
:
String
val
time
:
CharSequence
val
senderName
:
CharSequence
val
content
:
CharSequence
val
isPinned
:
Boolean
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/BaseViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
import
java.security.InvalidParameterException
interface
BaseViewModel
<
out
T
>
{
val
rawData
:
T
val
messageId
:
String
val
viewType
:
Int
val
layoutId
:
Int
enum
class
ViewType
(
val
viewType
:
Int
)
{
MESSAGE
(
0
),
SYSTEM_MESSAGE
(
1
),
URL_PREVIEW
(
2
),
IMAGE_ATTACHMENT
(
3
),
VIDEO_ATTACHMENT
(
4
),
AUDIO_ATTACHMENT
(
5
),
MESSAGE_ATTACHMENT
(
6
)
}
}
internal
fun
Int
.
toViewType
():
BaseViewModel
.
ViewType
{
return
BaseViewModel
.
ViewType
.
values
().
firstOrNull
{
it
.
viewType
==
this
}
?:
throw
InvalidParameterException
(
"Invalid viewType: $this for BaseViewModel.ViewType"
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ImageAttachmentViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
import
chat.rocket.android.R
import
chat.rocket.core.model.attachment.ImageAttachment
data class
ImageAttachmentViewModel
(
override
val
rawData
:
ImageAttachment
,
override
val
messageId
:
String
,
override
val
attachmentUrl
:
String
,
override
val
attachmentTitle
:
CharSequence
,
override
val
id
:
Long
)
:
BaseFileAttachmentViewModel
<
ImageAttachment
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
IMAGE_ATTACHMENT
.
viewType
override
val
layoutId
:
Int
get
()
=
R
.
layout
.
message_attachment
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/MessageViewModel.kt
View file @
a9085e1c
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/chatroom/viewmodel/MessageViewModelMapper.kt
deleted
100644 → 0
View file @
d87e13a3
package
chat.rocket.android.chatroom.viewmodel
import
android.content.Context
import
chat.rocket.android.helper.MessageParser
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.CurrentServerRepository
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.core.TokenRepository
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.withContext
import
javax.inject.Inject
class
MessageViewModelMapper
@Inject
constructor
(
private
val
context
:
Context
,
private
val
tokenRepository
:
TokenRepository
,
private
val
messageParser
:
MessageParser
,
private
val
messagesRepository
:
MessagesRepository
,
private
val
localRepository
:
LocalRepository
,
private
val
currentServerRepository
:
CurrentServerRepository
)
{
suspend
fun
mapToViewModel
(
message
:
Message
,
settings
:
Map
<
String
,
Value
<
Any
>>):
MessageViewModel
=
withContext
(
CommonPool
)
{
MessageViewModel
(
this
@MessageViewModelMapper
.
context
,
tokenRepository
.
get
(),
message
,
settings
,
messageParser
,
messagesRepository
,
localRepository
,
currentServerRepository
)
}
suspend
fun
mapToViewModelList
(
messageList
:
List
<
Message
>,
settings
:
Map
<
String
,
Value
<
Any
>>):
List
<
MessageViewModel
>
{
return
messageList
.
map
{
MessageViewModel
(
context
,
tokenRepository
.
get
(),
it
,
settings
,
messageParser
,
messagesRepository
,
localRepository
,
currentServerRepository
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/UrlPreviewViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
import
chat.rocket.android.R
import
chat.rocket.core.model.url.Url
data class
UrlPreviewViewModel
(
override
val
rawData
:
Url
,
override
val
messageId
:
String
,
val
title
:
CharSequence
?,
val
hostname
:
String
,
val
description
:
CharSequence
?,
val
thumbUrl
:
String
?
)
:
BaseViewModel
<
Url
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
URL_PREVIEW
.
viewType
override
val
layoutId
:
Int
get
()
=
R
.
layout
.
message_url_preview
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/VideoAttachmentViewModel.kt
0 → 100644
View file @
a9085e1c
package
chat.rocket.android.chatroom.viewmodel
import
chat.rocket.android.R
import
chat.rocket.core.model.attachment.VideoAttachment
data class
VideoAttachmentViewModel
(
override
val
rawData
:
VideoAttachment
,
override
val
messageId
:
String
,
override
val
attachmentUrl
:
String
,
override
val
attachmentTitle
:
CharSequence
,
override
val
id
:
Long
)
:
BaseFileAttachmentViewModel
<
VideoAttachment
>
{
override
val
viewType
:
Int
get
()
=
BaseViewModel
.
ViewType
.
VIDEO_ATTACHMENT
.
viewType
override
val
layoutId
:
Int
get
()
=
R
.
layout
.
message_attachment
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/viewmodel/ViewModelMapper.kt
0 → 100644
View file @
a9085e1c
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsAdapter.kt
View file @
a9085e1c
...
@@ -2,16 +2,18 @@ package chat.rocket.android.chatrooms.ui
...
@@ -2,16 +2,18 @@ package chat.rocket.android.chatrooms.ui
import
DateTimeHelper
import
DateTimeHelper
import
android.content.Context
import
android.content.Context
import
android.support.v4.content.
res.Resources
Compat
import
android.support.v4.content.
Context
Compat
import
android.support.v7.widget.RecyclerView
import
android.support.v7.widget.RecyclerView
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.TextView
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.helper.UrlHelper
import
chat.rocket.android.util.extensions.content
import
chat.rocket.android.util.extensions.inflate
import
chat.rocket.android.util.extensions.inflate
import
chat.rocket.android.util.extensions.setVisible
import
chat.rocket.android.util.extensions.setVisible
import
chat.rocket.android.util.extensions.textContent
import
chat.rocket.android.util.extensions.textContent
import
chat.rocket.common.model.RoomType
import
chat.rocket.core.model.ChatRoom
import
chat.rocket.core.model.ChatRoom
import
com.facebook.drawee.view.SimpleDraweeView
import
com.facebook.drawee.view.SimpleDraweeView
import
kotlinx.android.synthetic.main.avatar.view.*
import
kotlinx.android.synthetic.main.avatar.view.*
...
@@ -28,8 +30,6 @@ class ChatRoomsAdapter(private val context: Context,
...
@@ -28,8 +30,6 @@ class ChatRoomsAdapter(private val context: Context,
override
fun
getItemCount
():
Int
=
dataSet
.
size
override
fun
getItemCount
():
Int
=
dataSet
.
size
override
fun
getItemViewType
(
position
:
Int
):
Int
=
position
fun
updateRooms
(
newRooms
:
List
<
ChatRoom
>)
{
fun
updateRooms
(
newRooms
:
List
<
ChatRoom
>)
{
dataSet
.
clear
()
dataSet
.
clear
()
dataSet
.
addAll
(
newRooms
)
dataSet
.
addAll
(
newRooms
)
...
@@ -45,27 +45,40 @@ class ChatRoomsAdapter(private val context: Context,
...
@@ -45,27 +45,40 @@ class ChatRoomsAdapter(private val context: Context,
bindUnreadMessages
(
chatRoom
,
text_total_unread_messages
)
bindUnreadMessages
(
chatRoom
,
text_total_unread_messages
)
if
(
chatRoom
.
alert
||
chatRoom
.
unread
>
0
)
{
if
(
chatRoom
.
alert
||
chatRoom
.
unread
>
0
)
{
text_chat_name
.
alpha
=
1F
text_chat_name
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
text_last_message_date_time
.
setTextColor
(
ResourcesCompat
.
getColor
(
resources
,
R
.
color
.
colorAccent
,
null
))
R
.
color
.
colorPrimaryText
))
text_last_message
.
setTextColor
(
ResourcesCompat
.
getColor
(
resources
,
android
.
R
.
color
.
primary_text_light
,
null
))
text_last_message_date_time
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorAccent
))
text_last_message
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
android
.
R
.
color
.
primary_text_light
))
}
else
{
text_chat_name
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorSecondaryText
))
text_last_message_date_time
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorSecondaryText
))
text_last_message
.
setTextColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorSecondaryText
))
}
}
setOnClickListener
{
listener
(
chatRoom
)
}
setOnClickListener
{
listener
(
chatRoom
)
}
}
}
private
fun
bindAvatar
(
chatRoom
:
ChatRoom
,
drawee
:
SimpleDraweeView
)
{
private
fun
bindAvatar
(
chatRoom
:
ChatRoom
,
drawee
:
SimpleDraweeView
)
{
drawee
.
setImageURI
(
UrlHelper
.
getAvatarUrl
(
chatRoom
.
client
.
url
,
chatRoom
.
name
))
val
avatarId
=
if
(
chatRoom
.
type
is
RoomType
.
DirectMessage
)
chatRoom
.
name
else
"@${chatRoom.name}"
drawee
.
setImageURI
(
UrlHelper
.
getAvatarUrl
(
chatRoom
.
client
.
url
,
avatarId
))
}
}
private
fun
bindName
(
chatRoom
:
ChatRoom
,
textView
:
TextView
)
{
private
fun
bindName
(
chatRoom
:
ChatRoom
,
textView
:
TextView
)
{
textView
.
textC
ontent
=
chatRoom
.
name
textView
.
c
ontent
=
chatRoom
.
name
}
}
private
fun
bindLastMessageDateTime
(
chatRoom
:
ChatRoom
,
textView
:
TextView
)
{
private
fun
bindLastMessageDateTime
(
chatRoom
:
ChatRoom
,
textView
:
TextView
)
{
val
lastMessage
=
chatRoom
.
lastMessage
val
lastMessage
=
chatRoom
.
lastMessage
if
(
lastMessage
!=
null
)
{
if
(
lastMessage
!=
null
)
{
val
localDateTime
=
DateTimeHelper
.
getLocalDateTime
(
lastMessage
.
timestamp
)
val
localDateTime
=
DateTimeHelper
.
getLocalDateTime
(
lastMessage
.
timestamp
)
textView
.
textContent
=
DateTimeHelper
.
getDate
(
localDateTime
,
context
)
textView
.
content
=
DateTimeHelper
.
getDate
(
localDateTime
,
context
)
}
else
{
textView
.
content
=
""
}
}
}
}
...
@@ -77,16 +90,18 @@ class ChatRoomsAdapter(private val context: Context,
...
@@ -77,16 +90,18 @@ class ChatRoomsAdapter(private val context: Context,
val
senderUsername
=
lastMessageSender
.
username
val
senderUsername
=
lastMessageSender
.
username
when
(
senderUsername
)
{
when
(
senderUsername
)
{
chatRoom
.
name
->
{
chatRoom
.
name
->
{
textView
.
textC
ontent
=
message
textView
.
c
ontent
=
message
}
}
// TODO Change to MySelf
// TODO Change to MySelf
// chatRoom.user?.username -> {
// chatRoom.user?.username -> {
// holder.lastMessage.textContent = context.getString(R.string.msg_you) + ": $message"
// holder.lastMessage.textContent = context.getString(R.string.msg_you) + ": $message"
// }
// }
else
->
{
else
->
{
textView
.
textC
ontent
=
"@$senderUsername: $message"
textView
.
c
ontent
=
"@$senderUsername: $message"
}
}
}
}
}
else
{
textView
.
content
=
""
}
}
}
}
...
@@ -101,6 +116,7 @@ class ChatRoomsAdapter(private val context: Context,
...
@@ -101,6 +116,7 @@ class ChatRoomsAdapter(private val context: Context,
textView
.
textContent
=
context
.
getString
(
R
.
string
.
msg_more_than_ninety_nine_unread_messages
)
textView
.
textContent
=
context
.
getString
(
R
.
string
.
msg_more_than_ninety_nine_unread_messages
)
textView
.
setVisible
(
true
)
textView
.
setVisible
(
true
)
}
}
else
->
textView
.
setVisible
(
false
)
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
a9085e1c
...
@@ -39,6 +39,7 @@ import ru.noties.markwon.il.AsyncDrawableLoader
...
@@ -39,6 +39,7 @@ import ru.noties.markwon.il.AsyncDrawableLoader
import
ru.noties.markwon.spans.SpannableTheme
import
ru.noties.markwon.spans.SpannableTheme
import
timber.log.Timber
import
timber.log.Timber
import
java.util.concurrent.Executors
import
java.util.concurrent.Executors
import
java.util.concurrent.TimeUnit
import
javax.inject.Singleton
import
javax.inject.Singleton
@Module
@Module
...
@@ -101,6 +102,9 @@ class AppModule {
...
@@ -101,6 +102,9 @@ class AppModule {
fun
provideOkHttpClient
(
logger
:
HttpLoggingInterceptor
):
OkHttpClient
{
fun
provideOkHttpClient
(
logger
:
HttpLoggingInterceptor
):
OkHttpClient
{
return
OkHttpClient
.
Builder
().
apply
{
return
OkHttpClient
.
Builder
().
apply
{
addInterceptor
(
logger
)
addInterceptor
(
logger
)
connectTimeout
(
15
,
TimeUnit
.
SECONDS
)
readTimeout
(
20
,
TimeUnit
.
SECONDS
)
writeTimeout
(
15
,
TimeUnit
.
SECONDS
)
}.
build
()
}.
build
()
}
}
...
...
app/src/main/java/chat/rocket/android/helper/MessageParser.kt
View file @
a9085e1c
...
@@ -56,7 +56,7 @@ class MessageParser @Inject constructor(val context: Application, private val co
...
@@ -56,7 +56,7 @@ class MessageParser @Inject constructor(val context: Application, private val co
var
quoteNode
=
parser
.
parse
(
"> $senderName $time"
)
var
quoteNode
=
parser
.
parse
(
"> $senderName $time"
)
parentNode
.
appendChild
(
quoteNode
)
parentNode
.
appendChild
(
quoteNode
)
quoteNode
.
accept
(
QuoteMessageSenderVisitor
(
context
,
configuration
,
builder
,
senderName
.
length
))
quoteNode
.
accept
(
QuoteMessageSenderVisitor
(
context
,
configuration
,
builder
,
senderName
.
length
))
quoteNode
=
parser
.
parse
(
"> ${toLenientMarkdown(quote.
getOriginalMessage()
)}"
)
quoteNode
=
parser
.
parse
(
"> ${toLenientMarkdown(quote.
rawData.message
)}"
)
quoteNode
.
accept
(
QuoteMessageBodyVisitor
(
context
,
configuration
,
builder
))
quoteNode
.
accept
(
QuoteMessageBodyVisitor
(
context
,
configuration
,
builder
))
}
}
parentNode
.
accept
(
LinkVisitor
(
builder
))
parentNode
.
accept
(
LinkVisitor
(
builder
))
...
...
app/src/main/java/chat/rocket/android/server/domain/SettingsRepository.kt
View file @
a9085e1c
...
@@ -83,3 +83,5 @@ fun Map<String, Value<Any>>.uploadMimeTypeFilter(): Array<String> {
...
@@ -83,3 +83,5 @@ fun Map<String, Value<Any>>.uploadMimeTypeFilter(): Array<String> {
fun
Map
<
String
,
Value
<
Any
>>.
uploadMaxFileSize
():
Int
{
fun
Map
<
String
,
Value
<
Any
>>.
uploadMaxFileSize
():
Int
{
return
this
[
UPLOAD_MAX_FILE_SIZE
]
?.
value
?.
let
{
it
as
Int
}
?:
Int
.
MAX_VALUE
return
this
[
UPLOAD_MAX_FILE_SIZE
]
?.
value
?.
let
{
it
as
Int
}
?:
Int
.
MAX_VALUE
}
}
fun
Map
<
String
,
Value
<
Any
>>.
baseUrl
()
:
String
?
=
this
[
SITE_URL
]
?.
value
as
String
\ No newline at end of file
app/src/main/java/chat/rocket/android/util/extensions/Text.kt
View file @
a9085e1c
...
@@ -43,7 +43,7 @@ var TextView.hintContent: String
...
@@ -43,7 +43,7 @@ var TextView.hintContent: String
hint
=
value
hint
=
value
}
}
var
TextView
.
content
:
CharSequence
var
TextView
.
content
:
CharSequence
?
get
()
=
text
get
()
=
text
set
(
value
)
{
set
(
value
)
{
Markwon
.
unscheduleDrawables
(
this
)
Markwon
.
unscheduleDrawables
(
this
)
...
...
app/src/main/res/layout/item_chat.xml
View file @
a9085e1c
...
@@ -31,7 +31,6 @@
...
@@ -31,7 +31,6 @@
style=
"@style/ChatRoom.Name.TextView"
style=
"@style/ChatRoom.Name.TextView"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:alpha=
"0.6"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toLeftOf=
"@+id/text_last_message_date_time"
app:layout_constraintRight_toLeftOf=
"@+id/text_last_message_date_time"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
...
...
app/src/main/res/layout/item_message.xml
View file @
a9085e1c
...
@@ -48,20 +48,10 @@
...
@@ -48,20 +48,10 @@
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"5dp"
android:layout_marginTop=
"5dp"
android:layout_marginBottom=
"2dp"
app:layout_constraintLeft_toLeftOf=
"@id/top_container"
app:layout_constraintLeft_toLeftOf=
"@id/top_container"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/top_container"
app:layout_constraintTop_toBottomOf=
"@+id/top_container"
tools:text=
"This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!"
/>
tools:text=
"This is a multiline chat message from Bertie that will take more than just one line of text. I have sure that everything is amazing!"
/>
<!-- TODO - Use separate adapter items for messages and attachments. -->
<include
android:id=
"@+id/message_attachment"
layout=
"@layout/message_attachment"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"4dp"
app:layout_constraintLeft_toLeftOf=
"@id/top_container"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/text_content"
/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/message_attachment.xml
View file @
a9085e1c
...
@@ -5,16 +5,17 @@
...
@@ -5,16 +5,17 @@
android:id=
"@+id/attachment_container"
android:id=
"@+id/attachment_container"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"72dp"
android:layout_marginEnd=
"@dimen/screen_edge_left_and_right_margins"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<com.facebook.drawee.view.SimpleDraweeView
<com.facebook.drawee.view.SimpleDraweeView
android:id=
"@+id/image_attachment"
android:id=
"@+id/image_attachment"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"150dp"
android:layout_height=
"150dp"
android:visibility=
"gone"
android:visibility=
"visible"
fresco:actualImageScaleType=
"fitStart"
fresco:actualImageScaleType=
"centerCrop"
fresco:placeholderImage=
"@drawable/image_dummy"
fresco:placeholderImage=
"@drawable/image_dummy"
/>
tools:visibility=
"visible"
/>
<FrameLayout
<FrameLayout
android:id=
"@+id/audio_video_attachment"
android:id=
"@+id/audio_video_attachment"
...
@@ -22,7 +23,7 @@
...
@@ -22,7 +23,7 @@
android:layout_height=
"150dp"
android:layout_height=
"150dp"
android:background=
"@color/black"
android:background=
"@color/black"
android:visibility=
"gone"
android:visibility=
"gone"
tools:visibility=
"
gon
e"
>
tools:visibility=
"
visibl
e"
>
<ImageView
<ImageView
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
...
...
app/src/main/res/layout/message_url_preview.xml
0 → 100644
View file @
a9085e1c
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:id=
"@+id/url_preview_layout"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"72dp"
android:layout_marginEnd=
"24dp"
>
<com.facebook.drawee.view.SimpleDraweeView
android:id=
"@+id/image_preview"
android:layout_width=
"70dp"
android:layout_height=
"50dp"
app:actualImageScaleType=
"centerCrop"
/>
<TextView
android:id=
"@+id/text_host"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"8dp"
android:textColor=
"@color/colorSecondaryText"
tools:text=
"www.uol.com.br"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/image_preview"
/>
<TextView
android:id=
"@+id/text_title"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:textColor=
"@color/colorAccent"
tools:text=
"Web page title"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"@+id/text_host"
app:layout_constraintTop_toBottomOf=
"@id/text_host"
/>
<TextView
android:id=
"@+id/text_description"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
tools:text=
"description"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"@+id/text_host"
app:layout_constraintTop_toBottomOf=
"@id/text_title"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
a9085e1c
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
<!-- Text colors -->
<!-- Text colors -->
<color
name=
"colorPrimaryText"
>
#DE000000
</color>
<color
name=
"colorPrimaryText"
>
#DE000000
</color>
<color
name=
"colorSecondaryText"
>
#787878
</color>
<!-- User status colors -->
<!-- User status colors -->
<color
name=
"colorUserStatusOnline"
>
#2FE1A8
</color>
<color
name=
"colorUserStatusOnline"
>
#2FE1A8
</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