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
50453051
Commit
50453051
authored
Feb 09, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closing the realm. A little crude solution
parent
68e6306b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
2 deletions
+36
-2
RealmRepository.java
...ava/chat/rocket/android/repositories/RealmRepository.java
+17
-0
RealmRoomRepository.java
...chat/rocket/android/repositories/RealmRoomRepository.java
+12
-1
RealmUserRepository.java
...chat/rocket/android/repositories/RealmUserRepository.java
+7
-1
No files found.
app/src/main/java/chat/rocket/android/repositories/RealmRepository.java
0 → 100644
View file @
50453051
package
chat
.
rocket
.
android
.
repositories
;
import
android.os.Handler
;
import
android.os.Looper
;
import
io.realm.Realm
;
public
class
RealmRepository
{
protected
void
close
(
Realm
realm
,
Looper
looper
)
{
new
Handler
(
looper
).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
realm
.
close
();
}
});
}
}
app/src/main/java/chat/rocket/android/repositories/RealmRoomRepository.java
View file @
50453051
package
chat
.
rocket
.
android
.
repositories
;
import
android.os.Looper
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
...
...
@@ -11,8 +12,9 @@ import chat.rocket.android.model.ddp.RoomSubscription;
import
chat.rocket.android.model.internal.LoadMessageProcedure
;
import
chat.rocket.persistence.realm.RealmStore
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
public
class
RealmRoomRepository
implements
RoomRepository
{
public
class
RealmRoomRepository
extends
RealmRepository
implements
RoomRepository
{
private
final
String
hostname
;
...
...
@@ -24,6 +26,7 @@ public class RealmRoomRepository implements RoomRepository {
public
Observable
<
List
<
Room
>>
getOpenRooms
()
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
...
...
@@ -33,6 +36,8 @@ public class RealmRoomRepository implements RoomRepository {
.
equalTo
(
RoomSubscription
.
OPEN
,
true
)
.
findAll
()
.
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
roomSubscriptions
->
roomSubscriptions
!=
null
&&
roomSubscriptions
.
isLoaded
()
&&
roomSubscriptions
.
isValid
())
.
map
(
roomSubscriptions
->
toList
(
roomSubscriptions
));
...
...
@@ -43,6 +48,7 @@ public class RealmRoomRepository implements RoomRepository {
public
Observable
<
Room
>
getById
(
String
roomId
)
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
...
...
@@ -52,6 +58,8 @@ public class RealmRoomRepository implements RoomRepository {
.
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
)
.
findFirstAsync
()
.<
RoomSubscription
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
roomSubscription
->
roomSubscription
!=
null
&&
roomSubscription
.
isLoaded
()
&&
roomSubscription
.
isValid
())
.
map
(
roomSubscription
->
roomSubscription
.
asRoom
());
...
...
@@ -62,6 +70,7 @@ public class RealmRoomRepository implements RoomRepository {
public
Observable
<
RoomHistoryState
>
getHistoryStateByRoomId
(
String
roomId
)
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
...
...
@@ -71,6 +80,8 @@ public class RealmRoomRepository implements RoomRepository {
.
equalTo
(
LoadMessageProcedure
.
ID
,
roomId
)
.
findFirstAsync
()
.<
LoadMessageProcedure
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
loadMessageProcedure
->
loadMessageProcedure
!=
null
&&
loadMessageProcedure
.
isLoaded
()
&&
loadMessageProcedure
.
isValid
())
.
map
(
loadMessageProcedure
->
loadMessageProcedure
.
asRoomHistoryState
());
...
...
app/src/main/java/chat/rocket/android/repositories/RealmUserRepository.java
View file @
50453051
package
chat
.
rocket
.
android
.
repositories
;
import
android.os.Looper
;
import
io.realm.Realm
;
import
chat.rocket.android.model.core.User
;
import
chat.rocket.android.model.ddp.RealmUser
;
import
chat.rocket.persistence.realm.RealmStore
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
public
class
RealmUserRepository
implements
UserRepository
{
public
class
RealmUserRepository
extends
RealmRepository
implements
UserRepository
{
private
final
String
hostname
;
...
...
@@ -19,6 +21,7 @@ public class RealmUserRepository implements UserRepository {
public
Observable
<
User
>
getCurrentUser
()
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
...
...
@@ -29,11 +32,14 @@ public class RealmUserRepository implements UserRepository {
.
findFirst
();
if
(
realmUser
==
null
)
{
realm
.
close
();
return
Observable
.
just
(
null
);
}
return
realmUser
.<
RealmUser
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
map
(
it
->
it
.
asUser
());
});
...
...
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