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
f65dffb3
Commit
f65dffb3
authored
Jun 18, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves the logic to presenter.
parent
255224dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
75 deletions
+78
-75
CreateChannelPresenter.kt
...roid/createchannel/presentation/CreateChannelPresenter.kt
+8
-2
CreateChannelView.kt
...t/android/createchannel/presentation/CreateChannelView.kt
+15
-0
CreateChannelFragment.kt
.../rocket/android/createchannel/ui/CreateChannelFragment.kt
+55
-73
No files found.
app/src/main/java/chat/rocket/android/createchannel/presentation/CreateChannelPresenter.kt
View file @
f65dffb3
...
...
@@ -53,16 +53,22 @@ class CreateChannelPresenter @Inject constructor(
fun
searchUser
(
query
:
String
)
{
launchUI
(
strategy
)
{
view
.
showSuggestionViewInProgress
()
try
{
val
users
=
client
.
spotlight
(
query
).
users
val
memberUiModelMapper
=
mapper
.
mapToUiModelList
(
users
)
view
.
showUserSuggestion
(
memberUiModelMapper
)
if
(
users
.
isEmpty
())
{
view
.
showNoUserSuggestion
()
}
else
{
view
.
showUserSuggestion
(
mapper
.
mapToUiModelList
(
users
))
}
}
catch
(
ex
:
RocketChatException
)
{
ex
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
view
.
showGenericErrorMessage
()
}
}
finally
{
view
.
hideSuggestionViewInProgress
()
}
}
}
...
...
app/src/main/java/chat/rocket/android/createchannel/presentation/CreateChannelView.kt
View file @
f65dffb3
...
...
@@ -13,6 +13,21 @@ interface CreateChannelView : LoadingView, MessageView {
*/
fun
showUserSuggestion
(
dataSet
:
List
<
MemberUiModel
>)
/**
* Shows no server's users suggestion.
*/
fun
showNoUserSuggestion
()
/**
* Shows the SuggestionView in progress.
*/
fun
showSuggestionViewInProgress
()
/**
* Hides the progress shown in the SuggestionView.
*/
fun
hideSuggestionViewInProgress
()
/**
* Shows the navigation drawer with the chat item checked before showing the chat list.
* This function is invoked after successfully created the channel.
...
...
app/src/main/java/chat/rocket/android/createchannel/ui/CreateChannelFragment.kt
View file @
f65dffb3
...
...
@@ -71,6 +71,36 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
unsubscribeEditTexts
()
}
override
fun
onCreateActionMode
(
mode
:
ActionMode
,
menu
:
Menu
):
Boolean
{
mode
.
menuInflater
.
inflate
(
R
.
menu
.
create_channel
,
menu
)
mode
.
title
=
getString
(
R
.
string
.
title_create_channel
)
return
true
}
override
fun
onPrepareActionMode
(
mode
:
ActionMode
,
menu
:
Menu
):
Boolean
=
false
override
fun
onActionItemClicked
(
mode
:
ActionMode
,
menuItem
:
MenuItem
):
Boolean
{
return
when
(
menuItem
.
itemId
)
{
R
.
id
.
action_create_channel
->
{
createChannelPresenter
.
createChannel
(
roomTypeOf
(
channelType
),
text_channel_name
.
text
.
toString
(),
memberList
,
isChannelReadOnly
)
mode
.
finish
()
true
}
else
->
{
false
}
}
}
override
fun
onDestroyActionMode
(
mode
:
ActionMode
)
{
actionMode
=
null
}
override
fun
showLoading
()
{
ui
{
view_loading
.
isVisible
=
true
...
...
@@ -100,13 +130,28 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
}
override
fun
showUserSuggestion
(
dataSet
:
List
<
MemberUiModel
>)
{
// Hiding the progress because we are showing it already.
hideSuggestionViewInProgress
()
if
(
dataSet
.
isEmpty
())
{
showNoSuggestionView
()
}
else
{
showSuggestionViewResults
(
dataSet
)
}
adapter
.
clearData
()
adapter
.
prependData
(
dataSet
)
text_member_not_found
.
isVisible
=
false
recycler_view
.
isVisible
=
true
view_member_suggestion
.
isVisible
=
true
}
override
fun
showNoUserSuggestion
()
{
recycler_view
.
isVisible
=
false
text_member_not_found
.
isVisible
=
true
view_member_suggestion
.
isVisible
=
true
}
override
fun
showSuggestionViewInProgress
()
{
recycler_view
.
isVisible
=
false
text_member_not_found
.
isVisible
=
false
view_member_suggestion_loading
.
isVisible
=
true
view_member_suggestion
.
isVisible
=
true
}
override
fun
hideSuggestionViewInProgress
()
{
view_member_suggestion_loading
.
isVisible
=
false
}
override
fun
prepareToShowChatList
()
{
...
...
@@ -134,36 +179,6 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
text_invite_members
.
isEnabled
=
false
}
override
fun
onCreateActionMode
(
mode
:
ActionMode
,
menu
:
Menu
):
Boolean
{
mode
.
menuInflater
.
inflate
(
R
.
menu
.
create_channel
,
menu
)
mode
.
title
=
getString
(
R
.
string
.
title_create_channel
)
return
true
}
override
fun
onPrepareActionMode
(
mode
:
ActionMode
,
menu
:
Menu
):
Boolean
=
false
override
fun
onActionItemClicked
(
mode
:
ActionMode
,
menuItem
:
MenuItem
):
Boolean
{
return
when
(
menuItem
.
itemId
)
{
R
.
id
.
action_create_channel
->
{
createChannelPresenter
.
createChannel
(
roomTypeOf
(
channelType
),
text_channel_name
.
text
.
toString
(),
memberList
,
isChannelReadOnly
)
mode
.
finish
()
true
}
else
->
{
false
}
}
}
override
fun
onDestroyActionMode
(
mode
:
ActionMode
)
{
actionMode
=
null
}
private
fun
setupToolBar
()
{
(
activity
as
AppCompatActivity
?)
?.
supportActionBar
?.
title
=
getString
(
R
.
string
.
title_create_channel
)
...
...
@@ -217,12 +232,12 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
val
inviteMembersDisposable
=
text_invite_members
.
asObservable
()
.
debounce
(
500
,
TimeUnit
.
MILLISECONDS
,
AndroidSchedulers
.
mainThread
())
.
filter
{
t
->
t
.
isNotBlank
()
}
.
subscribe
{
if
(
it
.
length
>=
3
)
{
showSuggestionViewInProgress
()
createChannelPresenter
.
searchUser
(
it
.
toString
())
}
else
{
hideSuggestionView
()
view_member_suggestion
.
isVisible
=
false
}
}
...
...
@@ -247,7 +262,7 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
if
(
memberList
.
contains
(
username
))
{
showMessage
(
getString
(
R
.
string
.
msg_member_already_added
))
}
else
{
hideSuggestionView
()
view_member_suggestion
.
isVisible
=
false
text_invite_members
.
setText
(
""
)
addMember
(
username
)
addChip
(
username
)
...
...
@@ -288,37 +303,4 @@ class CreateChannelFragment : Fragment(), CreateChannelView, ActionMode.Callback
private
fun
processChipGroupVisibility
()
{
chip_group_member
.
isVisible
=
memberList
.
isNotEmpty
()
}
private
fun
showSuggestionView
()
{
view_member_suggestion
.
isVisible
=
true
}
private
fun
hideSuggestionView
()
{
view_member_suggestion
.
isVisible
=
false
}
private
fun
showSuggestionViewInProgress
()
{
recycler_view
.
isVisible
=
false
text_member_not_found
.
isVisible
=
false
view_member_suggestion_loading
.
isVisible
=
true
showSuggestionView
()
}
private
fun
hideSuggestionViewInProgress
()
{
view_member_suggestion_loading
.
isVisible
=
false
}
private
fun
showSuggestionViewResults
(
dataSet
:
List
<
MemberUiModel
>)
{
adapter
.
clearData
()
adapter
.
prependData
(
dataSet
)
text_member_not_found
.
isVisible
=
false
recycler_view
.
isVisible
=
true
showSuggestionView
()
}
private
fun
showNoSuggestionView
()
{
recycler_view
.
isVisible
=
false
text_member_not_found
.
isVisible
=
true
showSuggestionView
()
}
}
\ 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