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
dbee09cd
Commit
dbee09cd
authored
Jun 05, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More idiomatic kotlin
parent
0c94ddd8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
17 deletions
+26
-17
ChatRoomsRepository.kt
...t/android/chatrooms/infrastructure/ChatRoomsRepository.kt
+4
-1
ChatRoomsViewModel.kt
.../rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
+13
-10
GroupedPush.kt
app/src/main/java/chat/rocket/android/push/GroupedPush.kt
+1
-1
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+1
-1
TransformedLiveData.kt
.../chat/rocket/android/util/livedata/TransformedLiveData.kt
+7
-4
No files found.
app/src/main/java/chat/rocket/android/chatrooms/infrastructure/ChatRoomsRepository.kt
View file @
dbee09cd
...
@@ -24,4 +24,7 @@ class ChatRoomsRepository @Inject constructor(val dao: ChatRoomDao){
...
@@ -24,4 +24,7 @@ class ChatRoomsRepository @Inject constructor(val dao: ChatRoomDao){
NAME
,
NAME
,
GROUPED_NAME
,
GROUPED_NAME
,
}
}
}
}
\ No newline at end of file
fun
ChatRoomsRepository
.
Order
.
isGrouped
():
Boolean
=
this
==
ChatRoomsRepository
.
Order
.
GROUPED_ACTIVITY
||
this
==
ChatRoomsRepository
.
Order
.
GROUPED_NAME
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
View file @
dbee09cd
...
@@ -8,12 +8,15 @@ import chat.rocket.android.chatrooms.adapter.ItemHolder
...
@@ -8,12 +8,15 @@ import chat.rocket.android.chatrooms.adapter.ItemHolder
import
chat.rocket.android.chatrooms.adapter.RoomMapper
import
chat.rocket.android.chatrooms.adapter.RoomMapper
import
chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor
import
chat.rocket.android.chatrooms.domain.FetchChatRoomsInteractor
import
chat.rocket.android.chatrooms.infrastructure.ChatRoomsRepository
import
chat.rocket.android.chatrooms.infrastructure.ChatRoomsRepository
import
chat.rocket.android.chatrooms.infrastructure.isGrouped
import
chat.rocket.android.server.infraestructure.ConnectionManager
import
chat.rocket.android.server.infraestructure.ConnectionManager
import
chat.rocket.android.util.livedata.TransformedLiveData
import
chat.rocket.android.util.livedata.TransformedLiveData
import
chat.rocket.android.util.livedata.transform
import
chat.rocket.core.internal.realtime.socket.model.State
import
chat.rocket.core.internal.realtime.socket.model.State
import
kotlinx.coroutines.experimental.launch
import
kotlinx.coroutines.experimental.launch
import
kotlinx.coroutines.experimental.newSingleThreadContext
import
kotlinx.coroutines.experimental.newSingleThreadContext
import
me.henrytao.livedataktx.distinct
import
me.henrytao.livedataktx.distinct
import
me.henrytao.livedataktx.map
import
me.henrytao.livedataktx.nonNull
import
me.henrytao.livedataktx.nonNull
import
timber.log.Timber
import
timber.log.Timber
...
@@ -33,25 +36,25 @@ class ChatRoomsViewModel(
...
@@ -33,25 +36,25 @@ class ChatRoomsViewModel(
fun
getChatRooms
():
LiveData
<
List
<
ItemHolder
<*
>>>
{
fun
getChatRooms
():
LiveData
<
List
<
ItemHolder
<*
>>>
{
return
Transformations
.
switchMap
(
ordering
)
{
order
->
return
Transformations
.
switchMap
(
ordering
)
{
order
->
Timber
.
d
(
"Querying rooms for order: $order"
)
Timber
.
d
(
"Querying rooms for order: $order"
)
val
grouped
=
order
==
ChatRoomsRepository
.
Order
.
GROUPED_ACTIVITY
repository
.
getChatRooms
(
order
)
||
order
==
ChatRoomsRepository
.
Order
.
GROUPED_NAME
.
nonNull
()
val
roomData
=
repository
.
getChatRooms
(
order
).
nonNull
()
.
distinct
()
.
distinct
()
TransformedLiveData
(
runContext
,
roomData
)
{
rooms
->
.
transform
(
runContext
)
{
rooms
->
rooms
?.
let
{
rooms
?.
let
{
mapper
.
map
(
rooms
,
grouped
)
mapper
.
map
(
rooms
,
order
.
isGrouped
()
)
}
}
}.
nonNull
()
}
}
}
}
}
fun
getStatus
():
MutableLiveData
<
State
>
{
fun
getStatus
():
MutableLiveData
<
State
>
{
return
Transformations
.
map
(
connectionManager
.
statusLiveData
.
nonNull
().
distinct
())
{
state
->
return
connectionManager
.
statusLiveData
.
nonNull
().
distinct
().
map
{
state
->
if
(
state
is
State
.
Connected
)
{
if
(
state
is
State
.
Connected
)
{
// TODO - add a loading status...
// TODO - add a loading status...
fetchRooms
()
fetchRooms
()
}
}
state
state
}
.
nonNull
()
}
}
}
private
fun
fetchRooms
()
{
private
fun
fetchRooms
()
{
...
...
app/src/main/java/chat/rocket/android/push/GroupedPush.kt
View file @
dbee09cd
...
@@ -6,7 +6,7 @@ import javax.inject.Singleton
...
@@ -6,7 +6,7 @@ import javax.inject.Singleton
typealias
TupleGroupIdMessageCount
=
Pair
<
Int
,
AtomicInteger
>
typealias
TupleGroupIdMessageCount
=
Pair
<
Int
,
AtomicInteger
>
class
GroupedPush
{
class
GroupedPush
{
// Notifications received from the same server are
g
rouped in a single bundled notification.
// Notifications received from the same server are
isG
rouped in a single bundled notification.
// This map associates a host to a group id.
// This map associates a host to a group id.
val
groupMap
=
HashMap
<
String
,
TupleGroupIdMessageCount
>()
val
groupMap
=
HashMap
<
String
,
TupleGroupIdMessageCount
>()
...
...
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
dbee09cd
...
@@ -273,7 +273,7 @@ class PushManager @Inject constructor(
...
@@ -273,7 +273,7 @@ class PushManager @Inject constructor(
private
fun
getContentIntent
(
context
:
Context
,
notificationId
:
Int
,
pushMessage
:
PushMessage
,
grouped
:
Boolean
=
false
):
PendingIntent
{
private
fun
getContentIntent
(
context
:
Context
,
notificationId
:
Int
,
pushMessage
:
PushMessage
,
grouped
:
Boolean
=
false
):
PendingIntent
{
val
notificationIntent
=
context
.
changeServerIntent
(
pushMessage
.
info
.
host
)
val
notificationIntent
=
context
.
changeServerIntent
(
pushMessage
.
info
.
host
)
// TODO - add support to go directly to the chatroom
// TODO - add support to go directly to the chatroom
/*if (!
g
rouped) {
/*if (!
isG
rouped) {
notificationIntent.putExtra(EXTRA_ROOM_ID, pushMessage.info.roomId)
notificationIntent.putExtra(EXTRA_ROOM_ID, pushMessage.info.roomId)
}*/
}*/
return
PendingIntent
.
getActivity
(
context
,
randomizer
.
nextInt
(),
notificationIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
return
PendingIntent
.
getActivity
(
context
,
randomizer
.
nextInt
(),
notificationIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
)
...
...
app/src/main/java/chat/rocket/android/util/livedata/TransformedLiveData.kt
View file @
dbee09cd
...
@@ -7,7 +7,6 @@ import kotlinx.coroutines.experimental.Job
...
@@ -7,7 +7,6 @@ import kotlinx.coroutines.experimental.Job
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
import
kotlinx.coroutines.experimental.launch
import
kotlinx.coroutines.experimental.withContext
import
kotlinx.coroutines.experimental.withContext
import
timber.log.Timber
import
kotlin.coroutines.experimental.CoroutineContext
import
kotlin.coroutines.experimental.CoroutineContext
...
@@ -22,6 +21,8 @@ class TransformedLiveData<Source, Output>(
...
@@ -22,6 +21,8 @@ class TransformedLiveData<Source, Output>(
job
?.
cancel
()
job
?.
cancel
()
job
=
launch
(
runContext
)
{
job
=
launch
(
runContext
)
{
transformation
(
source
)
?.
let
{
transformed
->
transformation
(
source
)
?.
let
{
transformed
->
// Could have used postValue instead, but using the UI context I can guarantee that
// a canceled job will never emit values.
withContext
(
UI
)
{
withContext
(
UI
)
{
value
=
transformed
value
=
transformed
}
}
...
@@ -30,13 +31,15 @@ class TransformedLiveData<Source, Output>(
...
@@ -30,13 +31,15 @@ class TransformedLiveData<Source, Output>(
}
}
override
fun
onActive
()
{
override
fun
onActive
()
{
Timber
.
d
(
"Attaching observer"
)
source
.
observeForever
(
observer
)
source
.
observeForever
(
observer
)
}
}
override
fun
onInactive
()
{
override
fun
onInactive
()
{
Timber
.
d
(
"Detaching observer"
)
job
?.
cancel
()
job
?.
cancel
()
source
.
removeObserver
(
observer
)
source
.
removeObserver
(
observer
)
}
}
}
}
\ No newline at end of file
fun
<
Source
,
Output
>
LiveData
<
Source
>.
transform
(
runContext
:
CoroutineContext
=
CommonPool
,
transformation
:
(
Source
?)
->
Output
?)
=
TransformedLiveData
(
runContext
,
this
,
transformation
)
\ 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