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
6f85fabe
Commit
6f85fabe
authored
Jan 12, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send message using SDK
parent
bee51600
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
80 additions
and
6 deletions
+80
-6
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+17
-1
ChatRoomView.kt
...chat/rocket/android/chatroom/presentation/ChatRoomView.kt
+14
-0
ChatRoomAdapter.kt
...n/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
+5
-0
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+31
-5
message_composer.xml
app/src/main/res/layout/message_composer.xml
+11
-0
strings.xml
app/src/main/res/values-pt-rBR/strings.xml
+1
-0
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
6f85fabe
...
@@ -8,6 +8,7 @@ import chat.rocket.common.model.BaseRoom
...
@@ -8,6 +8,7 @@ import chat.rocket.common.model.BaseRoom
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.messages
import
chat.rocket.core.internal.rest.messages
import
chat.rocket.core.internal.rest.sendMessage
import
javax.inject.Inject
import
javax.inject.Inject
class
ChatRoomPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomView
,
class
ChatRoomPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomView
,
...
@@ -16,7 +17,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -16,7 +17,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
factory
:
RocketChatClientFactory
)
{
factory
:
RocketChatClientFactory
)
{
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
private
val
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
fun
m
essages
(
chatRoomId
:
String
,
chatRoomType
:
String
,
offset
:
Int
=
0
)
{
fun
loadM
essages
(
chatRoomId
:
String
,
chatRoomType
:
String
,
offset
:
Int
=
0
)
{
launchUI
(
strategy
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
view
.
showLoading
()
try
{
try
{
...
@@ -33,4 +34,19 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
...
@@ -33,4 +34,19 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
}
}
}
}
fun
sendMessage
(
chatRoomId
:
String
,
text
:
String
)
{
launchUI
(
strategy
)
{
try
{
val
message
=
client
.
sendMessage
(
chatRoomId
,
text
)
view
.
showSentMessage
(
message
)
}
catch
(
ex
:
Exception
)
{
ex
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
view
.
showGenericErrorMessage
()
}
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomView.kt
View file @
6f85fabe
...
@@ -13,4 +13,18 @@ interface ChatRoomView : LoadingView, MessageView {
...
@@ -13,4 +13,18 @@ interface ChatRoomView : LoadingView, MessageView {
* @param serverUrl The server URL.
* @param serverUrl The server URL.
*/
*/
fun
showMessages
(
dataSet
:
MutableList
<
Message
>,
serverUrl
:
String
)
fun
showMessages
(
dataSet
:
MutableList
<
Message
>,
serverUrl
:
String
)
/**
* Send a message to a chat room.
*
* @param text The text to send.
*/
fun
sendMessage
(
text
:
String
)
/**
* Shows a (recent) message sent to a chat room.
* @param message The (recent) message sent to a chat room.
*/
fun
showSentMessage
(
message
:
Message
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
View file @
6f85fabe
...
@@ -35,6 +35,11 @@ class ChatRoomAdapter(private val context: Context,
...
@@ -35,6 +35,11 @@ class ChatRoomAdapter(private val context: Context,
notifyItemRangeInserted
(
previousDataSetSize
,
dataSet
.
size
)
notifyItemRangeInserted
(
previousDataSetSize
,
dataSet
.
size
)
}
}
fun
addItem
(
message
:
Message
)
{
dataSet
.
add
(
0
,
message
)
notifyItemInserted
(
0
)
}
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
inner
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
fun
bind
(
message
:
Message
)
=
with
(
itemView
)
{
fun
bind
(
message
:
Message
)
=
with
(
itemView
)
{
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
6f85fabe
...
@@ -14,9 +14,11 @@ import chat.rocket.android.chatroom.presentation.ChatRoomView
...
@@ -14,9 +14,11 @@ import chat.rocket.android.chatroom.presentation.ChatRoomView
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import
chat.rocket.android.util.inflate
import
chat.rocket.android.util.inflate
import
chat.rocket.android.util.setVisibility
import
chat.rocket.android.util.setVisibility
import
chat.rocket.android.util.textContent
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
dagger.android.support.AndroidSupportInjection
import
dagger.android.support.AndroidSupportInjection
import
kotlinx.android.synthetic.main.fragment_chat_rooms.*
import
kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_composer.*
import
javax.inject.Inject
import
javax.inject.Inject
fun
newInstance
(
chatRoomId
:
String
,
chatRoomName
:
String
,
chatRoomType
:
String
,
isChatRoomOpen
:
Boolean
):
Fragment
{
fun
newInstance
(
chatRoomId
:
String
,
chatRoomName
:
String
,
chatRoomType
:
String
,
isChatRoomOpen
:
Boolean
):
Fragment
{
...
@@ -41,6 +43,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
...
@@ -41,6 +43,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomName
:
String
private
lateinit
var
chatRoomType
:
String
private
lateinit
var
chatRoomType
:
String
private
var
isChatRoomOpen
:
Boolean
=
true
private
var
isChatRoomOpen
:
Boolean
=
true
private
lateinit
var
adapter
:
ChatRoomAdapter
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
@@ -61,28 +64,42 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
...
@@ -61,28 +64,42 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
super
.
onViewCreated
(
view
,
savedInstanceState
)
super
.
onViewCreated
(
view
,
savedInstanceState
)
presenter
.
messages
(
chatRoomId
,
chatRoomType
)
presenter
.
loadMessages
(
chatRoomId
,
chatRoomType
)
setupComposer
()
}
}
override
fun
showMessages
(
dataSet
:
MutableList
<
Message
>,
serverUrl
:
String
)
{
override
fun
showMessages
(
dataSet
:
MutableList
<
Message
>,
serverUrl
:
String
)
{
activity
?.
apply
{
activity
?.
apply
{
if
(
recycler_view
.
adapter
==
null
)
{
if
(
recycler_view
.
adapter
==
null
)
{
recycler_view
.
adapter
=
ChatRoomAdapter
(
this
,
dataSet
,
serverUrl
)
adapter
=
ChatRoomAdapter
(
this
,
dataSet
,
serverUrl
)
recycler_view
.
adapter
=
adapter
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
val
linearLayoutManager
=
LinearLayoutManager
(
context
,
LinearLayoutManager
.
VERTICAL
,
true
)
recycler_view
.
layoutManager
=
linearLayoutManager
recycler_view
.
layoutManager
=
linearLayoutManager
if
(
dataSet
.
size
>=
30
)
{
if
(
dataSet
.
size
>=
30
)
{
recycler_view
.
addOnScrollListener
(
object
:
EndlessRecyclerViewScrollListener
(
linearLayoutManager
)
{
recycler_view
.
addOnScrollListener
(
object
:
EndlessRecyclerViewScrollListener
(
linearLayoutManager
)
{
override
fun
onLoadMore
(
page
:
Int
,
totalItemsCount
:
Int
,
recyclerView
:
RecyclerView
?)
{
override
fun
onLoadMore
(
page
:
Int
,
totalItemsCount
:
Int
,
recyclerView
:
RecyclerView
?)
{
presenter
.
m
essages
(
chatRoomId
,
chatRoomType
,
page
*
30
)
presenter
.
loadM
essages
(
chatRoomId
,
chatRoomType
,
page
*
30
)
}
}
})
})
}
}
}
else
{
}
else
{
(
recycler_view
.
adapter
as
ChatRoomAdapter
)
.
addDataSet
(
dataSet
)
adapter
.
addDataSet
(
dataSet
)
}
}
}
}
}
}
override
fun
sendMessage
(
text
:
String
)
{
if
(!
text
.
isBlank
())
{
presenter
.
sendMessage
(
chatRoomId
,
text
)
}
}
override
fun
showSentMessage
(
message
:
Message
)
{
text_message
.
textContent
=
""
adapter
.
addItem
(
message
)
recycler_view
.
smoothScrollToPosition
(
0
)
}
override
fun
showLoading
()
=
view_loading
.
setVisibility
(
true
)
override
fun
showLoading
()
=
view_loading
.
setVisibility
(
true
)
override
fun
hideLoading
()
=
view_loading
.
setVisibility
(
false
)
override
fun
hideLoading
()
=
view_loading
.
setVisibility
(
false
)
...
@@ -90,4 +107,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
...
@@ -90,4 +107,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override
fun
showMessage
(
message
:
String
)
=
Toast
.
makeText
(
activity
,
message
,
Toast
.
LENGTH_SHORT
).
show
()
override
fun
showMessage
(
message
:
String
)
=
Toast
.
makeText
(
activity
,
message
,
Toast
.
LENGTH_SHORT
).
show
()
override
fun
showGenericErrorMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_generic_error
))
override
fun
showGenericErrorMessage
()
=
showMessage
(
getString
(
R
.
string
.
msg_generic_error
))
private
fun
setupComposer
()
{
if
(
isChatRoomOpen
)
{
text_send
.
setOnClickListener
{
sendMessage
(
text_message
.
textContent
)
}
}
else
{
text_room_is_read_only
.
setVisibility
(
true
)
top_container
.
setVisibility
(
false
)
}
}
}
}
\ No newline at end of file
app/src/main/res/layout/message_composer.xml
View file @
6f85fabe
...
@@ -10,6 +10,17 @@
...
@@ -10,6 +10,17 @@
android:layout_height=
"1dp"
android:layout_height=
"1dp"
android:background=
"@color/colorDividerMessageComposer"
/>
android:background=
"@color/colorDividerMessageComposer"
/>
<TextView
android:id=
"@+id/text_room_is_read_only"
android:layout_width=
"match_parent"
android:layout_height=
"45dp"
android:background=
"@color/white"
android:gravity=
"center"
android:text=
"@string/msg_this_room_is_read_only"
android:textColor=
"@color/black"
android:visibility=
"gone"
app:layout_constraintTop_toBottomOf=
"@+id/divider"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/top_container"
android:id=
"@+id/top_container"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
...
app/src/main/res/values-pt-rBR/strings.xml
View file @
6f85fabe
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
<string
name=
"msg_invalid_2fa_code"
>
Código 2FA inválido
</string>
<string
name=
"msg_invalid_2fa_code"
>
Código 2FA inválido
</string>
<string
name=
"msg_yesterday"
>
ontem
</string>
<string
name=
"msg_yesterday"
>
ontem
</string>
<string
name=
"msg_message"
>
Messagem
</string>
<string
name=
"msg_message"
>
Messagem
</string>
<string
name=
"msg_this_room_is_read_only"
>
Este chat é apenas de leitura
</string>
<string
name=
"msg_content_description_log_in_using_facebook"
>
Fazer login através do Facebook
</string>
<string
name=
"msg_content_description_log_in_using_facebook"
>
Fazer login através do Facebook
</string>
<string
name=
"msg_content_description_log_in_using_github"
>
Fazer login através do Github
</string>
<string
name=
"msg_content_description_log_in_using_github"
>
Fazer login através do Github
</string>
<string
name=
"msg_content_description_log_in_using_google"
>
Fazer login através do Google
</string>
<string
name=
"msg_content_description_log_in_using_google"
>
Fazer login através do Google
</string>
...
...
app/src/main/res/values/strings.xml
View file @
6f85fabe
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
<string
name=
"msg_more_than_ninety_nine_unread_messages"
translatable=
"false"
>
99+
</string>
<string
name=
"msg_more_than_ninety_nine_unread_messages"
translatable=
"false"
>
99+
</string>
<string
name=
"msg_yesterday"
>
Yesterday
</string>
<string
name=
"msg_yesterday"
>
Yesterday
</string>
<string
name=
"msg_message"
>
Message
</string>
<string
name=
"msg_message"
>
Message
</string>
<string
name=
"msg_this_room_is_read_only"
>
This room is read only
</string>
<string
name=
"msg_content_description_log_in_using_facebook"
>
Login using Facebook
</string>
<string
name=
"msg_content_description_log_in_using_facebook"
>
Login using Facebook
</string>
<string
name=
"msg_content_description_log_in_using_github"
>
Login using Github
</string>
<string
name=
"msg_content_description_log_in_using_github"
>
Login using Github
</string>
<string
name=
"msg_content_description_log_in_using_google"
>
Login using Google
</string>
<string
name=
"msg_content_description_log_in_using_google"
>
Login using Google
</string>
...
...
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