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
8344d9ee
Commit
8344d9ee
authored
May 04, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving code readability.
parent
1eda85ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
15 deletions
+28
-15
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+27
-13
Rx.kt
app/src/main/java/chat/rocket/android/util/extensions/Rx.kt
+1
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
8344d9ee
...
...
@@ -30,12 +30,15 @@ import chat.rocket.android.util.extensions.*
import
chat.rocket.android.widget.emoji.*
import
chat.rocket.core.internal.realtime.socket.model.State
import
dagger.android.support.AndroidSupportInjection
import
io.reactivex.Observable
import
io.reactivex.disposables.CompositeDisposable
import
io.reactivex.
functions.Consumer
import
io.reactivex.
disposables.Disposable
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.TimeUnit
import
java.util.concurrent.atomic.AtomicInteger
import
javax.inject.Inject
...
...
@@ -149,7 +152,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
presenter
.
unsubscribeMessages
(
chatRoomId
)
handler
.
removeCallbacksAndMessages
(
null
)
unsubscribeTextMessage
()
unsubscribe
Compose
TextMessage
()
// Hides the keyboard (if it's opened) before going to any view.
activity
?.
apply
{
...
...
@@ -568,7 +571,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_show_attachment_options
.
alpha
=
1f
button_show_attachment_options
.
setVisible
(
true
)
subscribeTextMessage
()
subscribe
Compose
TextMessage
()
emojiKeyboardPopup
=
EmojiKeyboardPopup
(
activity
!!
,
activity
!!
.
findViewById
(
R
.
id
.
fragment_container
))
emojiKeyboardPopup
.
listener
=
this
text_message
.
listener
=
object
:
ComposerEditText
.
ComposerEditTextListener
{
...
...
@@ -673,21 +676,30 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
})
}
private
fun
subscribeTextMessage
()
{
val
composeButtonsDisposable
=
text_message
.
asObservable
(
0
)
.
subscribe
{
t
->
setupComposeMessageButtons
(
t
)
}
private
fun
subscribeComposeTextMessage
()
{
val
editTextObservable
=
text_message
.
asObservable
()
val
typingStatusDisposable
=
text_message
.
asObservable
(
300
)
.
subscribe
{
t
->
sendTypingStatus
(
t
)
}
compositeDisposable
.
addAll
(
composeButtonsDisposable
,
typingStatusDisposable
)
compositeDisposable
.
addAll
(
subscribeComposeButtons
(
editTextObservable
),
subscribeComposeTypingStatus
(
editTextObservable
)
)
}
private
fun
unsubscribeTextMessage
()
{
private
fun
unsubscribe
Compose
TextMessage
()
{
compositeDisposable
.
clear
()
}
private
fun
setupComposeMessageButtons
(
charSequence
:
CharSequence
)
{
private
fun
subscribeComposeButtons
(
observable
:
Observable
<
CharSequence
>):
Disposable
{
return
observable
.
subscribe
{
t
->
setupComposeButtons
(
t
)
}
}
private
fun
subscribeComposeTypingStatus
(
observable
:
Observable
<
CharSequence
>):
Disposable
{
return
observable
.
debounce
(
300
,
TimeUnit
.
MILLISECONDS
)
.
skip
(
1
)
.
subscribe
{
t
->
sendTypingStatus
(
t
)
}
}
private
fun
setupComposeButtons
(
charSequence
:
CharSequence
)
{
if
(
charSequence
.
isNotEmpty
()
&&
playComposeMessageButtonsAnimation
)
{
button_show_attachment_options
.
fadeOut
(
1F
,
0F
,
120
)
button_send
.
fadeIn
(
0F
,
1F
,
120
)
...
...
@@ -702,9 +714,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
private
fun
sendTypingStatus
(
charSequence
:
CharSequence
)
{
if
(
charSequence
.
isNotEmpty
())
{
if
(
charSequence
.
isNotBlank
())
{
Timber
.
i
(
"SENDING $charSequence"
)
presenter
.
sendTyping
()
}
else
{
Timber
.
i
(
"SENDING FOR NOT $charSequence"
)
presenter
.
sendNotTyping
()
}
}
...
...
app/src/main/java/chat/rocket/android/util/extensions/Rx.kt
View file @
8344d9ee
...
...
@@ -6,9 +6,8 @@ import io.reactivex.Observable
import
io.reactivex.android.schedulers.AndroidSchedulers
import
java.util.concurrent.TimeUnit
fun
EditText
.
asObservable
(
debounceTimeout
:
Long
=
100
):
Observable
<
CharSequence
>
{
fun
EditText
.
asObservable
():
Observable
<
CharSequence
>
{
return
RxTextView
.
textChanges
(
this
)
.
debounce
(
debounceTimeout
,
TimeUnit
.
MILLISECONDS
)
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribeOn
(
AndroidSchedulers
.
mainThread
())
}
\ 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