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
56fb3177
Commit
56fb3177
authored
Dec 08, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
introduce retrolambda also into realm-helpers
parent
9f7e2efa
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
49 deletions
+50
-49
lint.xml
app/lint.xml
+3
-0
build.gradle
realm-helpers/build.gradle
+7
-0
lint.xml
realm-helpers/lint.xml
+5
-0
AbstractRealmResultsObserver.java
...et/android/realm_helper/AbstractRealmResultsObserver.java
+2
-0
RealmHelper.java
...in/java/chat/rocket/android/realm_helper/RealmHelper.java
+15
-21
RealmListObserver.java
...a/chat/rocket/android/realm_helper/RealmListObserver.java
+3
-5
RealmModelListAdapter.java
...at/rocket/android/realm_helper/RealmModelListAdapter.java
+5
-11
RealmObjectObserver.java
...chat/rocket/android/realm_helper/RealmObjectObserver.java
+10
-12
No files found.
app/lint.xml
View file @
56fb3177
...
...
@@ -2,4 +2,7 @@
<issue
id=
"InvalidPackage"
>
<ignore
regexp=
"okio.*jar"
/>
</issue>
<issue
id=
"NewApi"
>
<ignore
regexp=
"Try-with-resources requires API level 19"
/>
</issue>
</lint>
\ No newline at end of file
realm-helpers/build.gradle
View file @
56fb3177
apply
plugin:
'com.android.library'
apply
plugin:
'realm-android'
apply
plugin:
'me.tatarka.retrolambda'
buildscript
{
repositories
{
...
...
@@ -8,6 +9,8 @@ buildscript {
dependencies
{
classpath
rootProject
.
ext
.
androidPlugin
classpath
rootProject
.
ext
.
realmPlugin
classpath
rootProject
.
ext
.
retroLambdaPlugin
classpath
rootProject
.
ext
.
retroLambdaPatch
}
}
...
...
@@ -15,6 +18,10 @@ android {
compileSdkVersion
rootProject
.
ext
.
compileSdkVersion
buildToolsVersion
rootProject
.
ext
.
buildToolsVersion
compileOptions
{
sourceCompatibility
JavaVersion
.
VERSION_1_8
targetCompatibility
JavaVersion
.
VERSION_1_8
}
defaultConfig
{
minSdkVersion
rootProject
.
ext
.
minSdkVersion
targetSdkVersion
rootProject
.
ext
.
compileSdkVersion
...
...
realm-helpers/lint.xml
0 → 100644
View file @
56fb3177
<lint>
<issue
id=
"NewApi"
>
<ignore
regexp=
"Try-with-resources requires API level 19"
/>
</issue>
</lint>
\ No newline at end of file
realm-helpers/src/main/java/chat/rocket/android/realm_helper/AbstractRealmResultsObserver.java
View file @
56fb3177
...
...
@@ -9,7 +9,9 @@ abstract class AbstractRealmResultsObserver<T extends RealmObject> {
protected
Realm
realm
;
private
RealmChangeListener
<
RealmResults
<
T
>>
listener
;
protected
abstract
RealmResults
<
T
>
queryItems
(
Realm
realm
);
protected
abstract
RealmChangeListener
<
RealmResults
<
T
>>
getListener
();
private
RealmResults
<
T
>
results
;
...
...
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmHelper.java
View file @
56fb3177
...
...
@@ -104,27 +104,21 @@ public class RealmHelper {
final
TaskCompletionSource
<
Void
>
task
=
new
TaskCompletionSource
<>();
final
Realm
realm
=
instance
();
realm
.
executeTransactionAsync
(
new
Realm
.
Transaction
()
{
@Override
public
void
execute
(
Realm
realm
)
{
try
{
transaction
.
execute
(
realm
);
}
catch
(
JSONException
exception
)
{
throw
new
RuntimeException
(
exception
);
}
}
},
new
Realm
.
Transaction
.
OnSuccess
()
{
@Override
public
void
onSuccess
()
{
realm
.
close
();
task
.
setResult
(
null
);
realm
.
executeTransactionAsync
(
_realm
->
{
try
{
transaction
.
execute
(
_realm
);
}
catch
(
JSONException
exception
)
{
throw
new
RuntimeException
(
exception
);
}
},
new
Realm
.
Transaction
.
OnError
()
{
@Override
public
void
onError
(
Throwable
error
)
{
realm
.
close
();
if
(
error
instanceof
Exception
)
{
task
.
setError
((
Exception
)
error
);
}
else
{
task
.
setError
(
new
Exception
(
error
));
}
},
()
->
{
realm
.
close
();
task
.
setResult
(
null
);
},
error
->
{
realm
.
close
();
if
(
error
instanceof
Exception
)
{
task
.
setError
((
Exception
)
error
);
}
else
{
task
.
setError
(
new
Exception
(
error
));
}
});
...
...
@@ -143,7 +137,7 @@ public class RealmHelper {
public
<
T
extends
RealmObject
,
VM
,
VH
extends
RealmModelViewHolder
<
VM
>>
RecyclerView
.
Adapter
<
VH
>
createListAdapter
(
Context
context
,
RealmListObserver
.
Query
<
T
>
query
,
RealmModelListAdapter
.
Constructor
<
T
,
VM
,
VH
>
constructor
)
{
RealmModelListAdapter
.
Constructor
<
T
,
VM
,
VH
>
constructor
)
{
return
constructor
.
getNewInstance
(
context
).
initializeWith
(
this
,
query
);
}
}
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmListObserver.java
View file @
56fb3177
...
...
@@ -32,11 +32,9 @@ public class RealmListObserver<T extends RealmObject> extends AbstractRealmResul
}
@Override
public
final
RealmChangeListener
<
RealmResults
<
T
>>
getListener
()
{
return
new
RealmChangeListener
<
RealmResults
<
T
>>()
{
@Override
public
void
onChange
(
RealmResults
<
T
>
element
)
{
if
(
onUpdateListener
!=
null
)
{
onUpdateListener
.
onUpdateResults
(
element
);
}
return
element
->
{
if
(
onUpdateListener
!=
null
)
{
onUpdateListener
.
onUpdateResults
(
element
);
}
};
}
...
...
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmModelListAdapter.java
View file @
56fb3177
...
...
@@ -32,11 +32,7 @@ public abstract class RealmModelListAdapter<T extends RealmObject, VM,
/*package*/
RealmModelListAdapter
<
T
,
VM
,
VH
>
initializeWith
(
final
RealmHelper
realmHelper
,
RealmListObserver
.
Query
<
T
>
query
)
{
realmListObserver
=
new
RealmListObserver
<>(
realmHelper
,
query
)
.
setOnUpdateListener
(
new
RealmListObserver
.
OnUpdateListener
<
T
>()
{
@Override
public
void
onUpdateResults
(
List
<
T
>
results
)
{
updateData
(
realmHelper
.
copyFromRealm
(
results
));
}
});
.
setOnUpdateListener
(
results
->
updateData
(
realmHelper
.
copyFromRealm
(
results
)));
return
this
;
}
...
...
@@ -71,12 +67,10 @@ public abstract class RealmModelListAdapter<T extends RealmObject, VM,
@Override
public
void
onBindViewHolder
(
VH
holder
,
int
position
)
{
VM
model
=
getItem
(
position
);
holder
.
itemView
.
setTag
(
model
);
holder
.
itemView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
VM
model2
=
(
VM
)
(
view
.
getTag
());
if
(
model2
!=
null
&&
onItemClickListener
!=
null
)
{
onItemClickListener
.
onItemClick
(
model2
);
}
holder
.
itemView
.
setOnClickListener
(
view
->
{
VM
model2
=
(
VM
)
(
view
.
getTag
());
if
(
model2
!=
null
&&
onItemClickListener
!=
null
)
{
onItemClickListener
.
onItemClick
(
model2
);
}
});
holder
.
bind
(
model
);
...
...
realm-helpers/src/main/java/chat/rocket/android/realm_helper/RealmObjectObserver.java
View file @
56fb3177
...
...
@@ -48,18 +48,16 @@ public class RealmObjectObserver<T extends RealmObject> extends AbstractRealmRes
}
@Override
protected
final
RealmChangeListener
<
RealmResults
<
T
>>
getListener
()
{
return
new
RealmChangeListener
<
RealmResults
<
T
>>()
{
@Override
public
void
onChange
(
RealmResults
<
T
>
element
)
{
T
currentResult
=
impl
.
extractObjectFromResults
(
element
);
String
currentResultString
=
currentResult
!=
null
?
currentResult
.
toString
()
:
null
;
if
(
previousResultString
!=
null
&&
previousResultString
.
equals
(
currentResultString
))
{
return
;
}
previousResultString
=
currentResultString
;
if
(
onUpdateListener
!=
null
)
{
onUpdateListener
.
onUpdateObject
(
currentResult
!=
null
?
realm
.
copyFromRealm
(
currentResult
)
:
null
);
}
return
element
->
{
T
currentResult
=
impl
.
extractObjectFromResults
(
element
);
String
currentResultString
=
currentResult
!=
null
?
currentResult
.
toString
()
:
null
;
if
(
previousResultString
!=
null
&&
previousResultString
.
equals
(
currentResultString
))
{
return
;
}
previousResultString
=
currentResultString
;
if
(
onUpdateListener
!=
null
)
{
onUpdateListener
.
onUpdateObject
(
currentResult
!=
null
?
realm
.
copyFromRealm
(
currentResult
)
:
null
);
}
};
}
...
...
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