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
6d84d280
Commit
6d84d280
authored
Jan 25, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
f09e71c4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
19 deletions
+90
-19
RocketChatApplication.kt
...ain/java/chat/rocket/android/app/RocketChatApplication.kt
+28
-0
AuthenticationModule.kt
.../rocket/android/authentication/di/AuthenticationModule.kt
+0
-10
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+45
-4
ChatRoomFragment.kt
.../java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
+1
-2
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+6
-1
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+8
-0
dependencies.gradle
dependencies.gradle
+2
-2
No files found.
app/src/main/java/chat/rocket/android/app/RocketChatApplication.kt
View file @
6d84d280
...
...
@@ -6,6 +6,11 @@ import android.app.Service
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.app.utils.CustomImageFormatConfigurator
import
chat.rocket.android.dagger.DaggerAppComponent
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.MultiServerTokenRepository
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.common.model.Token
import
chat.rocket.core.TokenRepository
import
com.facebook.drawee.backends.pipeline.DraweeConfig
import
com.facebook.drawee.backends.pipeline.Fresco
import
com.facebook.imagepipeline.core.ImagePipelineConfig
...
...
@@ -29,11 +34,24 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
lateinit
var
instance
:
RocketChatApplication
}
// TODO - remove this from here when we have a proper service handling the connection.
@Inject
lateinit
var
getCurrentServerInteractor
:
GetCurrentServerInteractor
@Inject
lateinit
var
multiServerRepository
:
MultiServerTokenRepository
@Inject
lateinit
var
settingsRepository
:
SettingsRepository
@Inject
lateinit
var
tokenRepository
:
TokenRepository
override
fun
onCreate
()
{
super
.
onCreate
()
DaggerAppComponent
.
builder
().
application
(
this
).
build
().
inject
(
this
)
// TODO - remove this when we have a proper service handling connection...
initCurrentServer
()
AndroidThreeTen
.
init
(
this
)
setupFresco
()
...
...
@@ -41,6 +59,16 @@ class RocketChatApplication : Application(), HasActivityInjector, HasServiceInje
instance
=
this
}
// TODO - remove this when we have a proper service handling connection...
private
fun
initCurrentServer
()
{
val
currentServer
=
getCurrentServerInteractor
.
get
()
val
serverToken
=
currentServer
?.
let
{
multiServerRepository
.
get
(
currentServer
)
}
val
settings
=
currentServer
?.
let
{
settingsRepository
.
get
(
currentServer
)
}
if
(
currentServer
!=
null
&&
serverToken
!=
null
&&
settings
!=
null
)
{
tokenRepository
.
save
(
Token
(
serverToken
.
userId
,
serverToken
.
authToken
))
}
}
private
fun
setupFresco
()
{
val
imagePipelineConfig
=
ImagePipelineConfig
.
newBuilder
(
this
)
.
setImageDecoderConfig
(
CustomImageFormatConfigurator
.
createImageDecoderConfig
())
...
...
app/src/main/java/chat/rocket/android/authentication/di/AuthenticationModule.kt
View file @
6d84d280
package
chat.rocket.android.authentication.di
import
android.content.Context
import
chat.rocket.android.authentication.infraestructure.SharedPreferencesMultiServerTokenRepository
import
chat.rocket.android.authentication.presentation.AuthenticationNavigator
import
chat.rocket.android.authentication.ui.AuthenticationActivity
import
chat.rocket.android.dagger.scope.PerActivity
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.server.domain.MultiServerTokenRepository
import
com.squareup.moshi.Moshi
import
dagger.Module
import
dagger.Provides
...
...
@@ -17,10 +13,4 @@ class AuthenticationModule {
@Provides
@PerActivity
fun
provideAuthenticationNavigator
(
activity
:
AuthenticationActivity
,
context
:
Context
)
=
AuthenticationNavigator
(
activity
,
context
)
@Provides
@PerActivity
fun
provideMultiServerTokenRepository
(
repository
:
LocalRepository
,
moshi
:
Moshi
):
MultiServerTokenRepository
{
return
SharedPreferencesMultiServerTokenRepository
(
repository
,
moshi
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
6d84d280
...
...
@@ -8,6 +8,8 @@ import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.common.model.BaseRoom
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.internal.realtime.State
import
chat.rocket.core.internal.realtime.connect
import
chat.rocket.core.internal.realtime.subscribeRoomMessages
import
chat.rocket.core.internal.realtime.unsubscibre
import
chat.rocket.core.internal.rest.messages
...
...
@@ -15,6 +17,7 @@ import chat.rocket.core.internal.rest.sendMessage
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Value
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.channels.Channel
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
import
javax.inject.Inject
...
...
@@ -33,16 +36,24 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
settings
=
getSettingsInteractor
.
get
(
serverInteractor
.
get
()
!!
)
}
fun
loadMessages
(
chatRoomId
:
String
,
chatRoomType
:
String
,
offset
:
Int
=
0
)
{
private
val
stateChannel
=
Channel
<
State
>()
fun
loadMessages
(
chatRoomId
:
String
,
chatRoomType
:
String
,
offset
:
Long
=
0
)
{
launchUI
(
strategy
)
{
view
.
showLoading
()
try
{
val
messages
=
client
.
messages
(
chatRoomId
,
BaseRoom
.
RoomType
.
valueOf
(
chatRoomType
),
offset
.
toLong
()
,
30
).
result
val
messages
=
client
.
messages
(
chatRoomId
,
BaseRoom
.
RoomType
.
valueOf
(
chatRoomType
),
offset
,
30
).
result
synchronized
(
roomMessages
)
{
roomMessages
.
addAll
(
messages
)
}
val
messagesViewModels
=
MessageViewModelMapper
.
mapToViewModelList
(
messages
,
settings
)
view
.
showMessages
(
messagesViewModels
,
serverInteractor
.
get
()
!!
)
// Subscribe after getting the first page of messages from REST
if
(
offset
==
0L
)
{
subscribeMessages
(
chatRoomId
)
}
}
catch
(
ex
:
Exception
)
{
ex
.
printStackTrace
()
ex
.
message
?.
let
{
...
...
@@ -77,16 +88,46 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
fun
subscribeMessages
(
roomId
:
String
)
{
launchUI
(
strategy
)
{
client
.
addStateChannel
(
stateChannel
)
launch
(
CommonPool
+
strategy
.
jobs
)
{
for
(
status
in
stateChannel
)
{
Timber
.
d
(
"Changing status to: $status"
)
when
(
status
)
{
State
.
Authenticating
->
Timber
.
d
(
"Authenticating"
)
State
.
Connected
->
{
Timber
.
d
(
"Connected"
)
subId
=
client
.
subscribeRoomMessages
(
roomId
)
{
Timber
.
d
(
"subscribe messages for $roomId: $it"
)
}
}
}
}
Timber
.
d
(
"Done on statusChannel"
)
}
when
(
client
.
state
)
{
State
.
Connected
->
{
Timber
.
d
(
"Already connected"
)
subId
=
client
.
subscribeRoomMessages
(
roomId
)
{
Timber
.
d
(
"subscribe messages for $roomId: $it"
)
}
}
else
->
client
.
connect
()
}
// TODO - when we have a proper service, we won't need to take care of connection, just
// subscribe and listen...
/*launchUI(strategy) {
subId = client.subscribeRoomMessages(roomId) {
Timber.d("subscribe messages for $roomId: $it")
}
listenMessages(roomId)
}
}
*/
}
fun
unsubscribeMessages
()
{
launch
(
CommonPool
)
{
client
.
removeStateChannel
(
stateChannel
)
subId
?.
let
{
subscriptionId
->
client
.
unsubscibre
(
subscriptionId
)
}
...
...
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
View file @
6d84d280
...
...
@@ -67,7 +67,6 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
super
.
onViewCreated
(
view
,
savedInstanceState
)
presenter
.
loadMessages
(
chatRoomId
,
chatRoomType
)
presenter
.
subscribeMessages
(
chatRoomId
)
setupComposer
()
}
...
...
@@ -87,7 +86,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
if
(
dataSet
.
size
>=
30
)
{
recycler_view
.
addOnScrollListener
(
object
:
EndlessRecyclerViewScrollListener
(
linearLayoutManager
)
{
override
fun
onLoadMore
(
page
:
Int
,
totalItemsCount
:
Int
,
recyclerView
:
RecyclerView
?)
{
presenter
.
loadMessages
(
chatRoomId
,
chatRoomType
,
page
*
30
)
presenter
.
loadMessages
(
chatRoomId
,
chatRoomType
,
page
*
30
L
)
}
})
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
6d84d280
...
...
@@ -13,6 +13,7 @@ import chat.rocket.core.internal.rest.chatRooms
import
chat.rocket.core.model.ChatRoom
import
chat.rocket.core.model.Room
import
kotlinx.coroutines.experimental.*
import
kotlinx.coroutines.experimental.channels.Channel
import
timber.log.Timber
import
javax.inject.Inject
...
...
@@ -27,6 +28,8 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
private
val
currentServer
=
serverInteractor
.
get
()
!!
private
var
reloadJob
:
Deferred
<
List
<
ChatRoom
>>?
=
null
private
val
stateChannel
=
Channel
<
State
>()
fun
loadChatRooms
()
{
launchUI
(
strategy
)
{
view
.
showLoading
()
...
...
@@ -80,8 +83,9 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
// TODO - Temporary stuff, remove when adding DB support
private
suspend
fun
subscribeRoomUpdates
()
{
client
.
addStateChannel
(
stateChannel
)
launch
(
CommonPool
+
strategy
.
jobs
)
{
for
(
status
in
client
.
status
Channel
)
{
for
(
status
in
state
Channel
)
{
Timber
.
d
(
"Changing status to: $status"
)
when
(
status
)
{
State
.
Authenticating
->
Timber
.
d
(
"Authenticating"
)
...
...
@@ -243,6 +247,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
}
fun
disconnect
()
{
client
.
removeStateChannel
(
stateChannel
)
client
.
disconnect
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
6d84d280
...
...
@@ -7,10 +7,12 @@ import android.content.SharedPreferences
import
chat.rocket.android.BuildConfig
import
chat.rocket.android.app.RocketChatDatabase
import
chat.rocket.android.authentication.infraestructure.MemoryTokenRepository
import
chat.rocket.android.authentication.infraestructure.SharedPreferencesMultiServerTokenRepository
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.SharedPrefsLocalRepository
import
chat.rocket.android.server.domain.ChatRoomsRepository
import
chat.rocket.android.server.domain.CurrentServerRepository
import
chat.rocket.android.server.domain.MultiServerTokenRepository
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.android.server.infraestructure.MemoryChatRoomsRepository
import
chat.rocket.android.server.infraestructure.ServerDao
...
...
@@ -135,4 +137,10 @@ class AppModule {
fun
provideMoshi
():
Moshi
{
return
Moshi
.
Builder
().
add
(
AppJsonAdapterFactory
.
INSTANCE
).
build
()
}
@Provides
@Singleton
fun
provideMultiServerTokenRepository
(
repository
:
LocalRepository
,
moshi
:
Moshi
):
MultiServerTokenRepository
{
return
SharedPreferencesMultiServerTokenRepository
(
repository
,
moshi
)
}
}
\ No newline at end of file
dependencies.gradle
View file @
6d84d280
...
...
@@ -4,8 +4,8 @@ ext {
compileSdk
:
27
,
targetSdk
:
27
,
buildTools
:
'27.0.3'
,
kotlin
:
'1.2.
10
'
,
coroutine
:
'0.2
1
'
,
kotlin
:
'1.2.
21
'
,
coroutine
:
'0.2
2
'
,
dokka
:
'0.9.15'
,
// Main dependencies
...
...
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