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
4b61077d
Commit
4b61077d
authored
Oct 31, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create an Operation queue for DB write operations
parent
62a28388
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
132 additions
and
56 deletions
+132
-56
ChatRoomPresenter.kt
...rocket/android/chatroom/presentation/ChatRoomPresenter.kt
+3
-1
RoomUiModelMapper.kt
...hat/rocket/android/chatrooms/adapter/RoomUiModelMapper.kt
+4
-1
RoomViewHolder.kt
...a/chat/rocket/android/chatrooms/adapter/RoomViewHolder.kt
+1
-1
RoomsAdapter.kt
...ava/chat/rocket/android/chatrooms/adapter/RoomsAdapter.kt
+14
-10
DatabaseManager.kt
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
+104
-40
DatabaseMessagesRepository.kt
...roid/server/infraestructure/DatabaseMessagesRepository.kt
+2
-3
T.kt
app/src/main/java/chat/rocket/android/util/extensions/T.kt
+4
-0
No files found.
app/src/main/java/chat/rocket/android/chatroom/presentation/ChatRoomPresenter.kt
View file @
4b61077d
...
...
@@ -174,7 +174,9 @@ class ChatRoomPresenter @Inject constructor(
view
.
showLoading
()
try
{
if
(
offset
==
0L
)
{
val
localMessages
=
messagesRepository
.
getByRoomId
(
chatRoomId
)
// FIXME - load just 50 messages from DB to speed up. We will reload from Network after that
// FIXME - We need to handle the pagination, first fetch from DB, then from network
val
localMessages
=
messagesRepository
.
getRecentMessages
(
chatRoomId
,
50
)
val
oldMessages
=
mapper
.
map
(
localMessages
,
RoomUiModel
(
roles
=
chatRoles
,
...
...
app/src/main/java/chat/rocket/android/chatrooms/adapter/RoomUiModelMapper.kt
View file @
4b61077d
...
...
@@ -24,6 +24,7 @@ import chat.rocket.common.model.roomTypeOf
import
chat.rocket.common.model.userStatusOf
import
chat.rocket.core.model.Room
import
chat.rocket.core.model.SpotlightResult
import
ru.noties.markwon.Markwon
class
RoomUiModelMapper
(
private
val
context
:
Application
,
...
...
@@ -119,6 +120,8 @@ class RoomUiModelMapper(
type
is
RoomType
.
DirectMessage
)
}
else
{
null
}
val
open
=
open
val
lastMessageMarkdown
=
lastMessage
?.
let
{
Markwon
.
markdown
(
context
,
it
.
toString
()).
toString
()
}
RoomUiModel
(
id
=
id
,
name
=
roomName
,
...
...
@@ -128,7 +131,7 @@ class RoomUiModelMapper(
date
=
timestamp
,
unread
=
unread
,
alert
=
isUnread
,
lastMessage
=
lastMessage
,
lastMessage
=
lastMessage
Markdown
,
status
=
status
,
username
=
if
(
type
is
RoomType
.
DirectMessage
)
name
else
null
)
...
...
app/src/main/java/chat/rocket/android/chatrooms/adapter/RoomViewHolder.kt
View file @
4b61077d
...
...
@@ -33,7 +33,7 @@ class RoomViewHolder(itemView: View, private val listener: (RoomUiModel) -> Unit
if
(
room
.
lastMessage
!=
null
)
{
text_last_message
.
isVisible
=
true
text_last_message
.
text
=
Markwon
.
markdown
(
context
,
room
.
lastMessage
.
toString
()).
toString
()
text_last_message
.
text
=
room
.
lastMessage
}
else
{
text_last_message
.
isGone
=
true
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/adapter/RoomsAdapter.kt
View file @
4b61077d
...
...
@@ -19,17 +19,21 @@ class RoomsAdapter(private val listener: (RoomUiModel) -> Unit) : RecyclerView.A
}
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
<
*
>
{
if
(
viewType
==
VIEW_TYPE_ROOM
)
{
return
when
(
viewType
)
{
VIEW_TYPE_ROOM
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_chat
)
return
RoomViewHolder
(
view
,
listener
)
}
else
if
(
viewType
==
VIEW_TYPE_HEADER
)
{
RoomViewHolder
(
view
,
listener
)
}
VIEW_TYPE_HEADER
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_chatroom_header
)
return
HeaderViewHolder
(
view
)
}
else
if
(
viewType
==
VIEW_TYPE_LOADING
)
{
HeaderViewHolder
(
view
)
}
VIEW_TYPE_LOADING
->
{
val
view
=
parent
.
inflate
(
R
.
layout
.
item_loading
)
return
LoadingViewHolder
(
view
)
LoadingViewHolder
(
view
)
}
else
->
throw
IllegalStateException
(
"View type must be either Room, Header or Loading"
)
}
throw
IllegalStateException
(
"View type must be either Room, Header or Loading"
)
}
override
fun
getItemCount
()
=
values
.
size
...
...
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
View file @
4b61077d
This diff is collapsed.
Click to expand it.
app/src/main/java/chat/rocket/android/server/infraestructure/DatabaseMessagesRepository.kt
View file @
4b61077d
package
chat.rocket.android.server.infraestructure
import
chat.rocket.android.db.DatabaseManager
import
chat.rocket.android.db.Operation
import
chat.rocket.android.db.model.MessagesSync
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.core.model.Message
...
...
@@ -61,9 +62,7 @@ class DatabaseMessagesRepository(
}
override
suspend
fun
saveLastSyncDate
(
roomId
:
String
,
timeMillis
:
Long
)
{
withContext
(
dbManager
.
dbContext
)
{
dbManager
.
messageDao
().
saveLastSync
(
MessagesSync
(
roomId
,
timeMillis
))
}
dbManager
.
sendOperation
(
Operation
.
SaveLastSync
(
MessagesSync
(
roomId
,
timeMillis
)))
}
override
suspend
fun
getLastSyncDate
(
roomId
:
String
):
Long
?
=
withContext
(
CommonPool
)
{
...
...
app/src/main/java/chat/rocket/android/util/extensions/T.kt
0 → 100644
View file @
4b61077d
package
chat.rocket.android.util.extensions
val
<
T
>
T
.
exhaustive
:
T
get
()
=
this
\ 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