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
820abca1
Unverified
Commit
820abca1
authored
Jan 12, 2018
by
Lucio Maciel
Committed by
GitHub
Jan 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #695 from RocketChat/spotlight
[NEW] Spotlight (local data)
parents
66cff88d
fc0ebff2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
1 deletion
+90
-1
ChatRoomsPresenter.kt
...cket/android/chatrooms/presentation/ChatRoomsPresenter.kt
+19
-1
ChatRoomsFragment.kt
...ava/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
+9
-0
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+8
-0
ChatRoomsRepository.kt
.../chat/rocket/android/server/domain/ChatRoomsRepository.kt
+8
-0
GetChatRoomsInteractor.kt
...at/rocket/android/server/domain/GetChatRoomsInteractor.kt
+22
-0
SaveChatRoomsInteractor.kt
...t/rocket/android/server/domain/SaveChatRoomsInteractor.kt
+8
-0
MemoryChatRoomsRepository.kt
...droid/server/infraestructure/MemoryChatRoomsRepository.kt
+16
-0
No files found.
app/src/main/java/chat/rocket/android/chatrooms/presentation/ChatRoomsPresenter.kt
View file @
820abca1
package
chat.rocket.android.chatrooms.presentation
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.GetChatRoomsInteractor
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.SaveChatRoomsInteractor
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.launchUI
import
chat.rocket.core.RocketChatClient
import
chat.rocket.core.internal.rest.chatRooms
import
chat.rocket.core.model.ChatRoom
import
kotlinx.coroutines.experimental.async
import
javax.inject.Inject
class
ChatRoomsPresenter
@Inject
constructor
(
private
val
view
:
ChatRoomsView
,
private
val
strategy
:
CancelStrategy
,
private
val
serverInteractor
:
GetCurrentServerInteractor
,
private
val
getChatRoomsInteractor
:
GetChatRoomsInteractor
,
private
val
saveChatRoomsInteractor
:
SaveChatRoomsInteractor
,
private
val
factory
:
RocketChatClientFactory
)
{
lateinit
var
client
:
RocketChatClient
fun
chatRooms
()
{
// TODO - check for current server
client
=
factory
.
create
(
serverInteractor
.
get
()
!!
)
val
currentServer
=
serverInteractor
.
get
()
!!
client
=
factory
.
create
(
currentServer
)
launchUI
(
strategy
)
{
view
.
showLoading
()
val
chatRooms
=
client
.
chatRooms
().
update
val
openChatRooms
=
getOpenChatRooms
(
chatRooms
)
val
sortedOpenChatRooms
=
sortChatRooms
(
openChatRooms
)
saveChatRoomsInteractor
.
save
(
currentServer
,
sortedOpenChatRooms
)
view
.
showChatRooms
(
sortedOpenChatRooms
.
toMutableList
())
view
.
hideLoading
()
}
}
/**
* Get a ChatRoom list from local repository. ChatRooms returned are filtered by name.
*/
fun
chatRoomsByName
(
name
:
String
)
{
val
currentServer
=
serverInteractor
.
get
()
!!
launchUI
(
strategy
)
{
val
roomList
=
getChatRoomsInteractor
.
getByName
(
currentServer
,
name
)
view
.
showChatRooms
(
roomList
.
toMutableList
())
}
}
private
fun
getOpenChatRooms
(
chatRooms
:
List
<
ChatRoom
>):
List
<
ChatRoom
>
{
return
chatRooms
.
filter
(
ChatRoom
::
open
)
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
View file @
820abca1
...
...
@@ -33,9 +33,18 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override
fun
onViewCreated
(
view
:
View
,
savedInstanceState
:
Bundle
?)
{
super
.
onViewCreated
(
view
,
savedInstanceState
)
presenter
.
chatRooms
()
floating_search_view
.
setOnQueryChangeListener
{
oldQuery
,
newQuery
->
floating_search_view
.
showProgress
()
presenter
.
chatRoomsByName
(
newQuery
)
if
(
oldQuery
.
isNotEmpty
()
&&
newQuery
.
isEmpty
())
{
floating_search_view
.
clearSuggestions
()
floating_search_view
.
hideProgress
()
}
}
}
override
fun
showChatRooms
(
dataSet
:
MutableList
<
ChatRoom
>)
{
floating_search_view
.
hideProgress
()
activity
?.
apply
{
recycler_view
.
layoutManager
=
LinearLayoutManager
(
this
,
LinearLayoutManager
.
VERTICAL
,
false
)
recycler_view
.
addItemDecoration
(
DividerItemDecoration
(
this
,
144
,
32
))
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
820abca1
...
...
@@ -9,8 +9,10 @@ import chat.rocket.android.app.RocketChatDatabase
import
chat.rocket.android.authentication.infraestructure.AuthTokenRepository
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.SettingsRepository
import
chat.rocket.android.server.infraestructure.MemoryChatRoomsRepository
import
chat.rocket.android.server.infraestructure.MemorySettingsRepository
import
chat.rocket.android.server.infraestructure.ServerDao
import
chat.rocket.android.server.infraestructure.SharedPrefsCurrentServerRepository
...
...
@@ -112,4 +114,10 @@ class AppModule {
fun
provideSettingsRepository
():
SettingsRepository
{
return
MemorySettingsRepository
()
}
@Provides
@Singleton
fun
provideChatRoomsRepository
():
ChatRoomsRepository
{
return
MemoryChatRoomsRepository
()
}
}
app/src/main/java/chat/rocket/android/server/domain/ChatRoomsRepository.kt
0 → 100644
View file @
820abca1
package
chat.rocket.android.server.domain
import
chat.rocket.core.model.ChatRoom
interface
ChatRoomsRepository
{
fun
save
(
url
:
String
,
chatRooms
:
List
<
ChatRoom
>)
fun
get
(
url
:
String
):
List
<
ChatRoom
>
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/GetChatRoomsInteractor.kt
0 → 100644
View file @
820abca1
package
chat.rocket.android.server.domain
import
chat.rocket.core.model.ChatRoom
import
kotlinx.coroutines.experimental.async
import
javax.inject.Inject
class
GetChatRoomsInteractor
@Inject
constructor
(
private
val
repository
:
ChatRoomsRepository
)
{
fun
get
(
url
:
String
)
=
repository
.
get
(
url
)
suspend
fun
getByName
(
url
:
String
,
name
:
String
):
List
<
ChatRoom
>
{
val
chatRooms
=
async
{
val
allChatRooms
=
repository
.
get
(
url
)
if
(
name
.
isEmpty
())
{
return
@async
allChatRooms
}
return
@async
allChatRooms
.
filter
{
it
.
name
.
contains
(
name
,
true
)
}
}
return
chatRooms
.
await
()
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/domain/SaveChatRoomsInteractor.kt
0 → 100644
View file @
820abca1
package
chat.rocket.android.server.domain
import
chat.rocket.core.model.ChatRoom
import
javax.inject.Inject
class
SaveChatRoomsInteractor
@Inject
constructor
(
private
val
repository
:
ChatRoomsRepository
)
{
fun
save
(
url
:
String
,
chatRooms
:
List
<
ChatRoom
>)
=
repository
.
save
(
url
,
chatRooms
)
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/server/infraestructure/MemoryChatRoomsRepository.kt
0 → 100644
View file @
820abca1
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.server.domain.ChatRoomsRepository
import
chat.rocket.core.model.ChatRoom
class
MemoryChatRoomsRepository
:
ChatRoomsRepository
{
val
cache
=
HashMap
<
String
,
List
<
ChatRoom
>>()
override
fun
save
(
url
:
String
,
chatRooms
:
List
<
ChatRoom
>)
{
//TODO: should diff the existing chatrooms and new chatroom dataset
cache
[
url
]
=
chatRooms
}
override
fun
get
(
url
:
String
):
List
<
ChatRoom
>
=
cache
[
url
]
?:
emptyList
()
}
\ 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