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
79bc2d7d
Unverified
Commit
79bc2d7d
authored
Oct 19, 2018
by
Leonardo Aramaki
Committed by
GitHub
Oct 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1735 from kb0304/search_click
[NEW] Not show last message on search icon click
parents
aceef97b
dc38b200
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
13 deletions
+23
-13
RoomUiModelMapper.kt
...hat/rocket/android/chatrooms/adapter/RoomUiModelMapper.kt
+12
-10
ChatRoomsFragment.kt
...ava/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
+3
-0
ChatRoomsViewModel.kt
.../rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
+8
-3
No files found.
app/src/main/java/chat/rocket/android/chatrooms/adapter/RoomUiModelMapper.kt
View file @
79bc2d7d
...
...
@@ -42,27 +42,28 @@ class RoomUiModelMapper(
userInteractor
.
get
()
}
fun
map
(
rooms
:
List
<
ChatRoom
>,
grouped
:
Boolean
=
false
):
List
<
ItemHolder
<*
>>
{
fun
map
(
rooms
:
List
<
ChatRoom
>,
grouped
:
Boolean
=
false
,
showLastMessage
:
Boolean
=
true
):
List
<
ItemHolder
<*
>>
{
val
list
=
ArrayList
<
ItemHolder
<*>>(
rooms
.
size
+
4
)
var
lastType
:
String
?
=
null
rooms
.
forEach
{
room
->
if
(
grouped
&&
lastType
!=
room
.
chatRoom
.
type
)
{
list
.
add
(
HeaderItemHolder
(
roomType
(
room
.
chatRoom
.
type
)))
}
list
.
add
(
RoomItemHolder
(
map
(
room
)))
list
.
add
(
RoomItemHolder
(
map
(
room
,
showLastMessage
)))
lastType
=
room
.
chatRoom
.
type
}
return
list
}
fun
map
(
spotlight
:
SpotlightResult
):
List
<
ItemHolder
<*
>>
{
fun
map
(
spotlight
:
SpotlightResult
,
showLastMessage
:
Boolean
=
true
):
List
<
ItemHolder
<*
>>
{
val
list
=
ArrayList
<
ItemHolder
<*>>(
spotlight
.
users
.
size
+
spotlight
.
rooms
.
size
)
spotlight
.
users
.
filterNot
{
it
.
username
.
isNullOrEmpty
()
}.
forEach
{
user
->
list
.
add
(
RoomItemHolder
(
mapUser
(
user
)))
}
spotlight
.
rooms
.
filterNot
{
it
.
name
.
isNullOrEmpty
()
}.
forEach
{
room
->
list
.
add
(
RoomItemHolder
(
mapRoom
(
room
)))
list
.
add
(
RoomItemHolder
(
mapRoom
(
room
,
showLastMessage
)))
}
return
list
...
...
@@ -86,21 +87,21 @@ class RoomUiModelMapper(
}
}
private
fun
mapRoom
(
room
:
Room
):
RoomUiModel
{
private
fun
mapRoom
(
room
:
Room
,
showLastMessage
:
Boolean
=
true
):
RoomUiModel
{
return
with
(
room
)
{
RoomUiModel
(
id
=
id
,
name
=
name
!!
,
type
=
type
,
avatar
=
serverUrl
.
avatarUrl
(
name
!!
,
isGroupOrChannel
=
true
),
lastMessage
=
mapLastMessage
(
lastMessage
?.
sender
?.
id
,
lastMessage
?.
sender
?.
username
,
lastMessage
=
if
(
showLastMessage
)
{
mapLastMessage
(
lastMessage
?.
sender
?.
id
,
lastMessage
?.
sender
?.
username
,
lastMessage
?.
sender
?.
name
,
lastMessage
?.
message
,
isDirectMessage
=
type
is
RoomType
.
DirectMessage
)
isDirectMessage
=
type
is
RoomType
.
DirectMessage
)
}
else
{
null
}
)
}
}
fun
map
(
chatRoom
:
ChatRoom
):
RoomUiModel
{
fun
map
(
chatRoom
:
ChatRoom
,
showLastMessage
:
Boolean
=
true
):
RoomUiModel
{
return
with
(
chatRoom
.
chatRoom
)
{
val
isUnread
=
alert
||
unread
>
0
val
type
=
roomTypeOf
(
type
)
...
...
@@ -113,9 +114,9 @@ class RoomUiModelMapper(
serverUrl
.
avatarUrl
(
name
,
isGroupOrChannel
=
true
)
}
val
unread
=
mapUnread
(
unread
)
val
lastMessage
=
mapLastMessage
(
lastMessageUserId
,
chatRoom
.
lastMessageUserName
,
val
lastMessage
=
if
(
showLastMessage
)
{
mapLastMessage
(
lastMessageUserId
,
chatRoom
.
lastMessageUserName
,
chatRoom
.
lastMessageUserFullName
,
lastMessageText
,
isUnread
,
type
is
RoomType
.
DirectMessage
)
type
is
RoomType
.
DirectMessage
)
}
else
{
null
}
val
open
=
open
RoomUiModel
(
...
...
@@ -148,6 +149,7 @@ class RoomUiModelMapper(
private
fun
mapLastMessage
(
userId
:
String
?,
name
:
String
?,
fullName
:
String
?,
text
:
String
?,
unread
:
Boolean
=
false
,
isDirectMessage
:
Boolean
=
false
):
CharSequence
?
{
return
if
(!
settings
.
showLastMessage
())
{
null
}
else
if
(
name
!=
null
&&
text
!=
null
)
{
...
...
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
View file @
79bc2d7d
...
...
@@ -178,11 +178,14 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override
fun
onMenuItemActionCollapse
(
item
:
MenuItem
):
Boolean
{
// Simply setting sortView to visible won't work, so we invalidate the options
// to recreate the entire menu...
viewModel
.
showLastMessage
=
true
activity
?.
invalidateOptionsMenu
()
queryChatRoomsByName
(
null
)
return
true
}
override
fun
onMenuItemActionExpand
(
item
:
MenuItem
):
Boolean
{
viewModel
.
showLastMessage
=
false
sortView
?.
isVisible
=
false
return
true
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
View file @
79bc2d7d
...
...
@@ -30,6 +30,7 @@ import timber.log.Timber
import
java.security.InvalidParameterException
import
kotlin.coroutines.experimental.coroutineContext
class
ChatRoomsViewModel
(
private
val
connectionManager
:
ConnectionManager
,
private
val
interactor
:
FetchChatRoomsInteractor
,
...
...
@@ -41,9 +42,11 @@ class ChatRoomsViewModel(
private
val
runContext
=
newSingleThreadContext
(
"chat-rooms-view-model"
)
private
val
client
=
connectionManager
.
client
private
var
loaded
=
false
var
showLastMessage
=
true
fun
getChatRooms
():
LiveData
<
RoomsModel
>
{
return
Transformations
.
switchMap
(
query
)
{
query
->
return
@switchMap
if
(
query
.
isSearch
())
{
this
@ChatRoomsViewModel
.
query
.
wrap
(
runContext
)
{
_
,
data
:
MutableLiveData
<
RoomsModel
>
->
val
string
=
(
query
as
Query
.
Search
).
query
...
...
@@ -53,11 +56,13 @@ class ChatRoomsViewModel(
// TODO - find a better way for cancellation checking
if
(!
coroutineContext
.
isActive
)
return
@wrap
val
rooms
=
repository
.
search
(
string
).
let
{
mapper
.
map
(
it
)
}
val
rooms
=
repository
.
search
(
string
).
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
data
.
postValue
(
rooms
.
toMutableList
()
+
LoadingItemHolder
())
if
(!
coroutineContext
.
isActive
)
return
@wrap
val
spotlight
=
spotlight
(
query
.
query
)
?.
let
{
mapper
.
map
(
it
)
}
val
spotlight
=
spotlight
(
query
.
query
)
?.
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
if
(!
coroutineContext
.
isActive
)
return
@wrap
spotlight
?.
let
{
...
...
@@ -72,7 +77,7 @@ class ChatRoomsViewModel(
.
distinct
()
.
transform
(
runContext
)
{
rooms
->
val
mappedRooms
=
rooms
?.
let
{
mapper
.
map
(
rooms
,
query
.
isGrouped
())
mapper
.
map
(
rooms
,
query
.
isGrouped
()
,
this
.
showLastMessage
)
}
if
(
loaded
&&
mappedRooms
?.
isEmpty
()
==
true
)
{
loadingState
.
postValue
(
LoadingState
.
Loaded
(
0
))
...
...
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