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
7e6f4841
Commit
7e6f4841
authored
Jun 20, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gets the room from DB instead of in-memory.
parent
0f21d5e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
17 deletions
+42
-17
MentionsFragmentModule.kt
...chat/rocket/android/mentions/di/MentionsFragmentModule.kt
+26
-6
MentionsPresenter.kt
...ocket/android/mentions/presentention/MentionsPresenter.kt
+16
-10
fragment_mentions.xml
app/src/main/res/layout/fragment_mentions.xml
+0
-1
No files found.
app/src/main/java/chat/rocket/android/mentions/di/MentionsFragmentModule.kt
View file @
7e6f4841
...
...
@@ -3,34 +3,54 @@ package chat.rocket.android.mentions.di
import
androidx.lifecycle.LifecycleOwner
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.dagger.scope.PerFragment
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.DatabaseManagerFactory
import
chat.rocket.android.mentions.presentention.MentionsView
import
chat.rocket.android.mentions.ui.MentionsFragment
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
dagger.Module
import
dagger.Provides
import
kotlinx.coroutines.experimental.Job
import
javax.inject.Named
@Module
class
MentionsFragmentModule
{
@Provides
@PerFragment
fun
provideJob
()
=
Job
()
fun
provideMentionsView
(
frag
:
MentionsFragment
):
MentionsView
{
return
frag
}
@Provides
@PerFragment
fun
provideLifecycleOwner
(
frag
:
MentionsFragment
):
LifecycleOwner
{
return
frag
@Named
(
"currentServer"
)
fun
provideCurrentServer
(
currentServerInteractor
:
GetCurrentServerInteractor
):
String
{
return
currentServerInteractor
.
get
()
!!
}
@Provides
@PerFragment
fun
provideCancelStrategy
(
owner
:
LifecycleOwner
,
jobs
:
Job
):
CancelStrategy
{
return
CancelStrategy
(
owner
,
jobs
)
fun
provideDatabaseManager
(
factory
:
DatabaseManagerFactory
,
@Named
(
"currentServer"
)
currentServer
:
String
):
DatabaseManager
{
return
factory
.
create
(
currentServer
)
}
@Provides
@PerFragment
fun
provideMentionsView
(
frag
:
MentionsFragment
):
MentionsView
{
fun
provideJob
()
=
Job
()
@Provides
@PerFragment
fun
provideLifecycleOwner
(
frag
:
MentionsFragment
):
LifecycleOwner
{
return
frag
}
@Provides
@PerFragment
fun
provideCancelStrategy
(
owner
:
LifecycleOwner
,
jobs
:
Job
):
CancelStrategy
{
return
CancelStrategy
(
owner
,
jobs
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/mentions/presentention/MentionsPresenter.kt
View file @
7e6f4841
...
...
@@ -2,39 +2,40 @@ package chat.rocket.android.mentions.presentention
import
chat.rocket.android.chatroom.uimodel.UiModelMapper
import
chat.rocket.android.core.lifecycle.CancelStrategy
import
chat.rocket.android.server.domain.ChatRoomsInteractor
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.server.infraestructure.RocketChatClientFactory
import
chat.rocket.android.util.extensions.launchUI
import
chat.rocket.common.RocketChatException
import
chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.internal.rest.getMentions
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Named
class
MentionsPresenter
@Inject
constructor
(
private
val
view
:
MentionsView
,
private
val
dbManager
:
DatabaseManager
,
@Named
(
"currentServer"
)
private
val
currentServer
:
String
,
private
val
strategy
:
CancelStrategy
,
private
val
roomsInteractor
:
ChatRoomsInteractor
,
private
val
mapper
:
UiModelMapper
,
val
serverInteractor
:
GetCurrentServerInteractor
,
val
factory
:
RocketChatClientFactory
)
{
private
val
serverUrl
=
serverInteractor
.
get
()
!!
private
val
client
=
factory
.
create
(
serverUrl
)
private
val
client
=
factory
.
create
(
currentServer
)
private
var
offset
:
Long
=
0
/**
* Loads all mentions for the given room id.
* Loads all
the authenticated user
mentions for the given room id.
*
* @param roomId The id of the room to get the mentions from.
* @param roomId The id of the room to get the mentions f
or the authenticated user f
rom.
*/
fun
loadMentions
(
roomId
:
String
)
{
launchUI
(
strategy
)
{
try
{
view
.
showLoading
()
roomsInteractor
.
getById
(
serverUrl
,
roomId
)
?.
let
{
val
mentions
=
client
.
getMentions
(
roomId
,
it
.
type
,
offset
,
30
)
dbManager
.
getRoom
(
roomId
)
?.
let
{
val
mentions
=
client
.
getMentions
(
roomId
,
roomTypeOf
(
it
.
chatRoom
.
type
),
offset
,
30
)
val
mentionsList
=
mapper
.
map
(
mentions
.
result
,
asNotReversed
=
true
)
view
.
showMentions
(
mentionsList
)
offset
+=
1
*
30
...
...
@@ -43,6 +44,11 @@ class MentionsPresenter @Inject constructor(
}
}
catch
(
exception
:
RocketChatException
)
{
Timber
.
e
(
exception
)
exception
.
message
?.
let
{
view
.
showMessage
(
it
)
}.
ifNull
{
view
.
showGenericErrorMessage
()
}
}
finally
{
view
.
hideLoading
()
}
...
...
app/src/main/res/layout/fragment_mentions.xml
View file @
7e6f4841
...
...
@@ -2,7 +2,6 @@
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/root_layout"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".mentions.ui.MentionsFragment"
>
...
...
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