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
bc4d466a
Commit
bc4d466a
authored
Apr 04, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep message on the composer if sending fails
parent
8bf2fec0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
14 deletions
+18
-14
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+8
-3
ChatRoomView.kt
...chat/rocket/android/chatroom/presentation/ChatRoomView.kt
+3
-1
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+7
-10
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
bc4d466a
...
...
@@ -34,6 +34,7 @@ import kotlinx.coroutines.experimental.channels.Channel
import
kotlinx.coroutines.experimental.launch
import
org.threeten.bp.Instant
import
timber.log.Timber
import
java.util.*
import
javax.inject.Inject
class
ChatRoomPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomView
,
...
...
@@ -102,19 +103,20 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
try
{
// ignore message for now, will receive it on the stream
val
message
=
if
(
messageId
==
null
)
{
client
.
sendMessage
(
chatRoomId
,
text
)
val
id
=
UUID
.
randomUUID
().
toString
()
client
.
sendMessage
(
id
,
chatRoomId
,
text
)
}
else
{
client
.
updateMessage
(
chatRoomId
,
messageId
,
text
)
}
view
.
clearMessageComposition
()
view
.
enableSendMessageButton
(
false
)
}
catch
(
ex
:
Exception
)
{
ex
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
view
.
showGenericErrorMessage
()
}
}
finally
{
view
.
enableSendMessageButton
()
view
.
enableSendMessageButton
(
true
)
}
}
}
...
...
@@ -511,9 +513,11 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
launchUI
(
strategy
)
{
try
{
if
(
text
.
length
==
1
)
{
view
.
disableSendMessageButton
()
// we have just the slash, post it anyway
sendMessage
(
roomId
,
text
,
null
)
}
else
{
view
.
disableSendMessageButton
()
val
command
=
text
.
split
(
" "
)
val
name
=
command
[
0
].
substring
(
1
)
var
params
:
String
=
""
...
...
@@ -527,6 +531,7 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
// failed, command is not valid so post it
sendMessage
(
roomId
,
text
,
null
)
}
view
.
enableSendMessageButton
(
false
)
}
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
...
...
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomView.kt
View file @
bc4d466a
...
...
@@ -92,8 +92,10 @@ interface ChatRoomView : LoadingView, MessageView {
/**
* Enables the send message button.
*
* @param sendFailed Whether the sent message has failed.
*/
fun
enableSendMessageButton
()
fun
enableSendMessageButton
(
sendFailed
:
Boolean
)
/**
* Clears the message composition.
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
bc4d466a
...
...
@@ -35,10 +35,8 @@ import kotlinx.android.synthetic.main.fragment_chat_room.*
import
kotlinx.android.synthetic.main.message_attachment_options.*
import
kotlinx.android.synthetic.main.message_composer.*
import
kotlinx.android.synthetic.main.message_list.*
import
timber.log.Timber
import
java.util.concurrent.atomic.AtomicInteger
import
javax.inject.Inject
import
kotlin.math.absoluteValue
fun
newInstance
(
chatRoomId
:
String
,
chatRoomName
:
String
,
...
...
@@ -126,7 +124,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
activity
?.
apply
{
(
this
as
?
ChatRoomActivity
)
?.
showRoomTypeIcon
(
true
)
}
}
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
...
...
@@ -217,10 +214,10 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
recycler_view
.
addOnLayoutChangeListener
{
_
,
_
,
_
,
_
,
bottom
,
_
,
_
,
_
,
oldBottom
->
val
y
=
oldBottom
-
bottom
if
(
y
.
absoluteValue
>
0
)
{
if
(
Math
.
abs
(
y
)
>
0
)
{
// if y is positive the keyboard is up else it's down
recycler_view
.
post
{
if
(
y
>
0
||
verticalScrollOffset
.
get
().
absoluteValue
>=
y
.
absoluteValue
)
{
if
(
y
>
0
||
Math
.
abs
(
verticalScrollOffset
.
get
())
>=
Math
.
abs
(
y
)
)
{
recycler_view
.
scrollBy
(
0
,
y
)
}
else
{
recycler_view
.
scrollBy
(
0
,
verticalScrollOffset
.
get
())
...
...
@@ -294,12 +291,15 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override
fun
disableSendMessageButton
()
{
button_send
.
isEnabled
=
false
text_message
.
isEnabled
=
false
}
override
fun
enableSendMessageButton
()
{
override
fun
enableSendMessageButton
(
sendFailed
:
Boolean
)
{
button_send
.
isEnabled
=
true
text_message
.
isEnabled
=
true
text_message
.
erase
()
if
(!
sendFailed
)
{
clearMessageComposition
()
}
}
override
fun
clearMessageComposition
()
{
...
...
@@ -465,7 +465,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
private
fun
setupRecyclerView
()
{
recycler_view
.
addOnScrollListener
(
object
:
RecyclerView
.
OnScrollListener
()
{
override
fun
onScrolled
(
recyclerView
:
RecyclerView
,
dx
:
Int
,
dy
:
Int
)
{
Timber
.
i
(
"Scrolling vertically: $dy"
)
if
(!
recyclerView
.
canScrollVertically
(
1
))
{
button_fab
.
hide
()
}
else
{
...
...
@@ -522,8 +521,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
var
textMessage
=
citation
?:
""
textMessage
+=
text_message
.
textContent
sendMessage
(
textMessage
)
clearMessageComposition
()
}
button_show_attachment_options
.
setOnClickListener
{
...
...
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