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
5f6b098d
Commit
5f6b098d
authored
Jan 09, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
define RealmHelper#isObjectExists
parent
56692224
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
RealmHelper.java
...in/java/chat/rocket/android/realm_helper/RealmHelper.java
+15
-1
RealmObjectObserver.java
...chat/rocket/android/realm_helper/RealmObjectObserver.java
+2
-7
No files found.
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmHelper.java
View file @
5f6b098d
...
...
@@ -7,6 +7,7 @@ import android.support.v7.widget.RecyclerView;
import
io.realm.Realm
;
import
io.realm.RealmConfiguration
;
import
io.realm.RealmObject
;
import
io.realm.RealmQuery
;
import
io.realm.RealmResults
;
import
org.json.JSONException
;
...
...
@@ -73,6 +74,19 @@ public class RealmHelper {
}
}
public
interface
Query
<
T
extends
RealmObject
>
{
RealmQuery
<
T
>
query
(
Realm
realm
);
}
public
<
T
extends
RealmObject
>
boolean
isObjectExists
(
Query
<
T
>
query
)
{
try
(
Realm
realm
=
instance
())
{
return
query
.
query
(
realm
).
count
()
>
0
;
}
catch
(
Exception
exception
)
{
RCLog
.
w
(
exception
);
return
false
;
}
}
private
boolean
shouldUseSync
()
{
// ref: realm-java:realm/realm-library/src/main/java/io/realm/AndroidNotifier.java
// #isAutoRefreshAvailable()
...
...
@@ -140,7 +154,7 @@ public class RealmHelper {
}
public
<
T
extends
RealmObject
>
RealmObjectObserver
<
T
>
createObjectObserver
(
Realm
ObjectObserv
er
.
Query
<
T
>
query
)
{
Realm
Help
er
.
Query
<
T
>
query
)
{
return
new
RealmObjectObserver
<
T
>(
this
,
query
);
}
...
...
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmObjectObserver.java
View file @
5f6b098d
...
...
@@ -3,17 +3,16 @@ package chat.rocket.android.realm_helper;
import
io.realm.Realm
;
import
io.realm.RealmChangeListener
;
import
io.realm.RealmObject
;
import
io.realm.RealmQuery
;
import
io.realm.RealmResults
;
public
class
RealmObjectObserver
<
T
extends
RealmObject
>
extends
AbstractRealmResultsObserver
<
T
>
{
private
final
Query
<
T
>
query
;
private
final
RealmHelper
.
Query
<
T
>
query
;
private
OnUpdateListener
<
T
>
onUpdateListener
;
private
Impl
<
T
>
impl
;
private
String
previousResultString
;
/*package*/
RealmObjectObserver
(
RealmHelper
helper
,
Query
<
T
>
query
)
{
/*package*/
RealmObjectObserver
(
RealmHelper
helper
,
RealmHelper
.
Query
<
T
>
query
)
{
super
(
helper
);
this
.
query
=
query
;
setImpl
(
new
Impl
<
T
>());
...
...
@@ -54,10 +53,6 @@ public class RealmObjectObserver<T extends RealmObject> extends AbstractRealmRes
super
.
sub
();
}
public
interface
Query
<
T
extends
RealmObject
>
{
RealmQuery
<
T
>
query
(
Realm
realm
);
}
public
interface
OnUpdateListener
<
T
extends
RealmObject
>
{
void
onUpdateObject
(
T
element
);
}
...
...
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