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
ee2dee06
Commit
ee2dee06
authored
Oct 01, 2018
by
Lucio Maciel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused code
parent
c14c48d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
143 deletions
+0
-143
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+0
-10
SharedPreferencesMessagesRepository.kt
...er/infraestructure/SharedPreferencesMessagesRepository.kt
+0
-133
No files found.
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
ee2dee06
...
...
@@ -255,16 +255,6 @@ class AppModule {
return
SharedPreferencesMultiServerTokenRepository
(
repository
,
moshi
)
}
/*@Provides
@Singleton
fun provideMessageRepository(
@ForMessages preferences: SharedPreferences,
moshi: Moshi,
currentServerInteractor: GetCurrentServerInteractor
): MessagesRepository {
return SharedPreferencesMessagesRepository(preferences, moshi, currentServerInteractor)
}*/
@Provides
fun
provideMessageRepository
(
databaseManager
:
DatabaseManager
):
MessagesRepository
{
return
DatabaseMessagesRepository
(
databaseManager
,
DatabaseMessageMapper
(
databaseManager
))
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/SharedPreferencesMessagesRepository.kt
deleted
100644 → 0
View file @
c14c48d1
package
chat.rocket.android.server.infraestructure
import
android.content.SharedPreferences
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.core.model.Message
import
com.squareup.moshi.Moshi
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.withContext
class
SharedPreferencesMessagesRepository
(
private
val
prefs
:
SharedPreferences
,
private
val
moshi
:
Moshi
,
private
val
currentServerInteractor
:
GetCurrentServerInteractor
)
:
MessagesRepository
{
private
val
KEY_LAST_SYNC_DATE
=
"KEY_LAST_SYNC_DATE"
override
suspend
fun
saveLastSyncDate
(
rid
:
String
,
timeMillis
:
Long
)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
let
{
prefs
.
edit
().
putLong
(
getSyncDateKey
(
it
,
rid
),
timeMillis
).
apply
()
}
}
}
override
suspend
fun
getLastSyncDate
(
rid
:
String
):
Long
?
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
if
(!
prefs
.
contains
(
getSyncDateKey
(
server
,
rid
)))
return
@withContext
null
val
time
=
prefs
.
getLong
(
getSyncDateKey
(
server
,
rid
),
-
1
)
return
@withContext
if
(
time
==
-
1L
)
null
else
time
}
return
@withContext
null
}
private
fun
getSyncDateKey
(
server
:
String
,
rid
:
String
)
=
"${KEY_LAST_SYNC_DATE}_$server $rid"
override
suspend
fun
getById
(
id
:
String
):
Message
?
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
if
(
prefs
.
all
.
values
.
isEmpty
())
{
return
@withContext
null
}
val
adapter
=
moshi
.
adapter
<
Message
>(
Message
::
class
.
java
)
val
values
=
prefs
.
all
.
entries
.
filter
{
it
.
key
.
startsWith
(
server
)
}
.
map
{
it
.
value
}
as
Collection
<
String
>
return
@withContext
values
.
map
{
adapter
.
fromJson
(
it
)
}.
firstOrNull
{
it
?.
id
==
id
}
}
return
@withContext
null
}
override
suspend
fun
getByRoomId
(
rid
:
String
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
val
adapter
=
moshi
.
adapter
<
Message
>(
Message
::
class
.
java
)
if
(
prefs
.
all
.
values
.
isEmpty
())
{
return
@withContext
emptyList
<
Message
>()
}
val
values
=
prefs
.
all
.
entries
.
filter
{
it
.
key
.
startsWith
(
server
)
}
.
map
{
it
.
value
}
as
Collection
<
String
>
return
@withContext
values
.
mapNotNull
{
adapter
.
fromJson
(
it
)
}.
filter
{
it
.
roomId
==
rid
}.
toList
().
sortedWith
(
compareBy
(
Message
::
timestamp
)).
reversed
()
}
return
@withContext
emptyList
<
Message
>()
}
override
suspend
fun
getRecentMessages
(
rid
:
String
,
count
:
Long
):
List
<
Message
>
=
withContext
(
CommonPool
)
{
return
@withContext
getByRoomId
(
rid
).
sortedByDescending
{
it
.
timestamp
}
.
distinctBy
{
it
.
sender
}.
take
(
count
.
toInt
())
}
override
suspend
fun
getAllUnsent
():
List
<
Message
>
=
withContext
(
CommonPool
)
{
if
(
prefs
.
all
.
values
.
isEmpty
())
{
return
@withContext
emptyList
<
Message
>()
}
currentServerInteractor
.
get
()
?.
also
{
server
->
val
values
=
prefs
.
all
.
entries
.
filter
{
it
.
key
.
startsWith
(
server
)
}
.
map
{
it
.
value
}
as
Collection
<
String
>
val
adapter
=
moshi
.
adapter
<
Message
>(
Message
::
class
.
java
)
return
@withContext
values
.
mapNotNull
{
adapter
.
fromJson
(
it
)
}
.
filterNot
{
it
.
synced
?:
false
}
}
return
@withContext
emptyList
<
Message
>()
}
override
suspend
fun
save
(
message
:
Message
)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
val
adapter
=
moshi
.
adapter
<
Message
>(
Message
::
class
.
java
)
prefs
.
edit
().
putString
(
"${it}_${message.id}"
,
adapter
.
toJson
(
message
)).
apply
()
}
}
}
override
suspend
fun
saveAll
(
newMessages
:
List
<
Message
>)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
val
adapter
=
moshi
.
adapter
<
Message
>(
Message
::
class
.
java
)
val
editor
=
prefs
.
edit
()
for
(
msg
in
newMessages
)
{
editor
.
putString
(
"${it}_${msg.id}"
,
adapter
.
toJson
(
msg
))
}
editor
.
apply
()
}
}
}
override
suspend
fun
removeById
(
id
:
String
)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
prefs
.
edit
().
putString
(
"${it}_$id"
,
null
).
apply
()
}
}
}
override
suspend
fun
removeByRoomId
(
rid
:
String
)
{
withContext
(
CommonPool
)
{
currentServerInteractor
.
get
()
?.
also
{
server
->
val
adapter
=
moshi
.
adapter
<
Message
>(
Message
::
class
.
java
)
val
editor
=
prefs
.
edit
()
prefs
.
all
.
entries
.
forEach
{
val
value
=
it
.
value
if
(
value
is
String
)
{
val
message
=
adapter
.
fromJson
(
value
)
if
(
message
?.
roomId
==
rid
)
{
editor
.
putString
(
"${server}_${message.id}"
,
null
)
}
}
}
editor
.
apply
()
}
}
}
}
\ 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