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
465a8596
Commit
465a8596
authored
May 15, 2019
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing parameters.
parent
0102cdc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
14 deletions
+25
-14
DatabaseManager.kt
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
+15
-9
DatabaseManagerFactory.kt
...ain/java/chat/rocket/android/db/DatabaseManagerFactory.kt
+10
-5
No files found.
app/src/main/java/chat/rocket/android/db/DatabaseManager.kt
View file @
465a8596
...
...
@@ -25,6 +25,7 @@ import chat.rocket.android.util.retryDB
import
chat.rocket.common.model.BaseRoom
import
chat.rocket.common.model.RoomType
import
chat.rocket.common.model.SimpleUser
import
chat.rocket.common.model.Token
import
chat.rocket.common.model.User
import
chat.rocket.core.internal.model.Subscription
import
chat.rocket.core.internal.realtime.socket.model.StreamMessage
...
...
@@ -51,8 +52,7 @@ import kotlin.collections.component2
import
kotlin.collections.set
import
kotlin.system.measureTimeMillis
class
DatabaseManager
(
val
context
:
Application
,
val
serverUrl
:
String
)
{
class
DatabaseManager
(
val
context
:
Application
,
val
serverUrl
:
String
,
val
token
:
Token
)
{
private
val
database
:
RCDatabase
=
androidx
.
room
.
Room
.
databaseBuilder
(
context
,
RCDatabase
::
class
.
java
,
serverUrl
.
databaseName
()
...
...
@@ -61,23 +61,23 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
.
build
()
private
val
dbContext
=
newSingleThreadContext
(
"$serverUrl-db-context"
)
private
val
dbManagerContext
=
newSingleThreadContext
(
"$serverUrl-db-manager-context"
)
private
val
writeChannel
=
Channel
<
Operation
>(
Channel
.
UNLIMITED
)
private
var
dbJob
:
Job
?
=
null
private
val
insertSubs
=
HashMap
<
String
,
Subscription
>()
private
val
insertRooms
=
HashMap
<
String
,
Room
>()
private
val
updateSubs
=
LinkedHashMap
<
String
,
Subscription
>()
private
val
updateRooms
=
LinkedHashMap
<
String
,
Room
>()
fun
chatRoomDao
():
ChatRoomDao
=
database
.
chatRoomDao
()
fun
userDao
():
UserDao
=
database
.
userDao
()
fun
messageDao
():
MessageDao
=
database
.
messageDao
()
init
{
start
()
}
fun
chatRoomDao
():
ChatRoomDao
=
database
.
chatRoomDao
()
fun
userDao
():
UserDao
=
database
.
userDao
()
fun
messageDao
():
MessageDao
=
database
.
messageDao
()
fun
start
()
{
dbJob
?.
cancel
()
dbJob
=
GlobalScope
.
launch
(
dbContext
)
{
...
...
@@ -196,7 +196,13 @@ class DatabaseManager(val context: Application, val serverUrl: String) {
myself
.
name
==
null
&&
myself
.
username
==
null
)
{
user
?.
username
?.
let
{
Fresco
.
getImagePipeline
().
evictFromCache
(
serverUrl
.
avatarUrl
(
it
).
toUri
())
Fresco
.
getImagePipeline
().
evictFromCache
(
serverUrl
.
avatarUrl
(
it
,
token
.
userId
,
token
.
authToken
).
toUri
()
)
}
}
...
...
app/src/main/java/chat/rocket/android/db/DatabaseManagerFactory.kt
View file @
465a8596
package
chat.rocket.android.db
import
android.app.Application
import
chat.rocket.android.server.domain.TokenRepository
import
timber.log.Timber
import
javax.inject.Inject
import
javax.inject.Singleton
@Singleton
class
DatabaseManagerFactory
@Inject
constructor
(
private
val
context
:
Application
)
{
class
DatabaseManagerFactory
@Inject
constructor
(
private
val
context
:
Application
,
private
val
tokenRepository
:
TokenRepository
)
{
private
val
cache
=
HashMap
<
String
,
DatabaseManager
>()
fun
create
(
serverUrl
:
String
):
DatabaseManager
{
...
...
@@ -15,9 +19,10 @@ class DatabaseManagerFactory @Inject constructor(private val context: Applicatio
return
it
}
Timber
.
d
(
"Returning FRESH database for $serverUrl"
)
val
db
=
DatabaseManager
(
context
,
serverUrl
)
cache
[
serverUrl
]
=
db
return
db
Timber
.
d
(
"Returning fresh database for $serverUrl"
)
with
(
DatabaseManager
(
context
,
serverUrl
,
tokenRepository
.
get
(
serverUrl
)
!!
))
{
cache
[
serverUrl
]
=
this
return
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