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
Show 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
;
package
chat
.
rocket
.
android
.
repositories
;
import
android.os.Looper
;
import
io.realm.Realm
;
import
io.realm.Realm
;
import
io.realm.RealmResults
;
import
io.realm.RealmResults
;
...
@@ -11,8 +12,9 @@ import chat.rocket.android.model.ddp.RoomSubscription;
...
@@ -11,8 +12,9 @@ import chat.rocket.android.model.ddp.RoomSubscription;
import
chat.rocket.android.model.internal.LoadMessageProcedure
;
import
chat.rocket.android.model.internal.LoadMessageProcedure
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.persistence.realm.RealmStore
;
import
rx.Observable
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
public
class
RealmRoomRepository
implements
RoomRepository
{
public
class
RealmRoomRepository
extends
RealmRepository
implements
RoomRepository
{
private
final
String
hostname
;
private
final
String
hostname
;
...
@@ -24,6 +26,7 @@ public class RealmRoomRepository implements RoomRepository {
...
@@ -24,6 +26,7 @@ public class RealmRoomRepository implements RoomRepository {
public
Observable
<
List
<
Room
>>
getOpenRooms
()
{
public
Observable
<
List
<
Room
>>
getOpenRooms
()
{
return
Observable
.
defer
(()
->
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
return
Observable
.
just
(
null
);
...
@@ -33,6 +36,8 @@ public class RealmRoomRepository implements RoomRepository {
...
@@ -33,6 +36,8 @@ public class RealmRoomRepository implements RoomRepository {
.
equalTo
(
RoomSubscription
.
OPEN
,
true
)
.
equalTo
(
RoomSubscription
.
OPEN
,
true
)
.
findAll
()
.
findAll
()
.
asObservable
()
.
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
roomSubscriptions
->
roomSubscriptions
!=
null
&&
roomSubscriptions
.
isLoaded
()
.
filter
(
roomSubscriptions
->
roomSubscriptions
!=
null
&&
roomSubscriptions
.
isLoaded
()
&&
roomSubscriptions
.
isValid
())
&&
roomSubscriptions
.
isValid
())
.
map
(
roomSubscriptions
->
toList
(
roomSubscriptions
));
.
map
(
roomSubscriptions
->
toList
(
roomSubscriptions
));
...
@@ -43,6 +48,7 @@ public class RealmRoomRepository implements RoomRepository {
...
@@ -43,6 +48,7 @@ public class RealmRoomRepository implements RoomRepository {
public
Observable
<
Room
>
getById
(
String
roomId
)
{
public
Observable
<
Room
>
getById
(
String
roomId
)
{
return
Observable
.
defer
(()
->
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
return
Observable
.
just
(
null
);
...
@@ -52,6 +58,8 @@ public class RealmRoomRepository implements RoomRepository {
...
@@ -52,6 +58,8 @@ public class RealmRoomRepository implements RoomRepository {
.
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
)
.
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
)
.
findFirstAsync
()
.
findFirstAsync
()
.<
RoomSubscription
>
asObservable
()
.<
RoomSubscription
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
roomSubscription
->
roomSubscription
!=
null
&&
roomSubscription
.
isLoaded
()
.
filter
(
roomSubscription
->
roomSubscription
!=
null
&&
roomSubscription
.
isLoaded
()
&&
roomSubscription
.
isValid
())
&&
roomSubscription
.
isValid
())
.
map
(
roomSubscription
->
roomSubscription
.
asRoom
());
.
map
(
roomSubscription
->
roomSubscription
.
asRoom
());
...
@@ -62,6 +70,7 @@ public class RealmRoomRepository implements RoomRepository {
...
@@ -62,6 +70,7 @@ public class RealmRoomRepository implements RoomRepository {
public
Observable
<
RoomHistoryState
>
getHistoryStateByRoomId
(
String
roomId
)
{
public
Observable
<
RoomHistoryState
>
getHistoryStateByRoomId
(
String
roomId
)
{
return
Observable
.
defer
(()
->
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
return
Observable
.
just
(
null
);
...
@@ -71,6 +80,8 @@ public class RealmRoomRepository implements RoomRepository {
...
@@ -71,6 +80,8 @@ public class RealmRoomRepository implements RoomRepository {
.
equalTo
(
LoadMessageProcedure
.
ID
,
roomId
)
.
equalTo
(
LoadMessageProcedure
.
ID
,
roomId
)
.
findFirstAsync
()
.
findFirstAsync
()
.<
LoadMessageProcedure
>
asObservable
()
.<
LoadMessageProcedure
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
loadMessageProcedure
->
loadMessageProcedure
!=
null
.
filter
(
loadMessageProcedure
->
loadMessageProcedure
!=
null
&&
loadMessageProcedure
.
isLoaded
()
&&
loadMessageProcedure
.
isValid
())
&&
loadMessageProcedure
.
isLoaded
()
&&
loadMessageProcedure
.
isValid
())
.
map
(
loadMessageProcedure
->
loadMessageProcedure
.
asRoomHistoryState
());
.
map
(
loadMessageProcedure
->
loadMessageProcedure
.
asRoomHistoryState
());
...
...
app/src/main/java/chat/rocket/android/repositories/RealmUserRepository.java
View file @
50453051
package
chat
.
rocket
.
android
.
repositories
;
package
chat
.
rocket
.
android
.
repositories
;
import
android.os.Looper
;
import
io.realm.Realm
;
import
io.realm.Realm
;
import
chat.rocket.android.model.core.User
;
import
chat.rocket.android.model.core.User
;
import
chat.rocket.android.model.ddp.RealmUser
;
import
chat.rocket.android.model.ddp.RealmUser
;
import
chat.rocket.persistence.realm.RealmStore
;
import
chat.rocket.persistence.realm.RealmStore
;
import
rx.Observable
;
import
rx.Observable
;
import
rx.android.schedulers.AndroidSchedulers
;
public
class
RealmUserRepository
implements
UserRepository
{
public
class
RealmUserRepository
extends
RealmRepository
implements
UserRepository
{
private
final
String
hostname
;
private
final
String
hostname
;
...
@@ -19,6 +21,7 @@ public class RealmUserRepository implements UserRepository {
...
@@ -19,6 +21,7 @@ public class RealmUserRepository implements UserRepository {
public
Observable
<
User
>
getCurrentUser
()
{
public
Observable
<
User
>
getCurrentUser
()
{
return
Observable
.
defer
(()
->
{
return
Observable
.
defer
(()
->
{
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Realm
realm
=
RealmStore
.
getRealm
(
hostname
);
final
Looper
looper
=
Looper
.
myLooper
();
if
(
realm
==
null
)
{
if
(
realm
==
null
)
{
return
Observable
.
just
(
null
);
return
Observable
.
just
(
null
);
...
@@ -29,11 +32,14 @@ public class RealmUserRepository implements UserRepository {
...
@@ -29,11 +32,14 @@ public class RealmUserRepository implements UserRepository {
.
findFirst
();
.
findFirst
();
if
(
realmUser
==
null
)
{
if
(
realmUser
==
null
)
{
realm
.
close
();
return
Observable
.
just
(
null
);
return
Observable
.
just
(
null
);
}
}
return
realmUser
return
realmUser
.<
RealmUser
>
asObservable
()
.<
RealmUser
>
asObservable
()
.
unsubscribeOn
(
AndroidSchedulers
.
from
(
looper
))
.
doOnUnsubscribe
(()
->
close
(
realm
,
looper
))
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
filter
(
it
->
it
!=
null
&&
it
.
isLoaded
()
&&
it
.
isValid
())
.
map
(
it
->
it
.
asUser
());
.
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