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
e427d271
Commit
e427d271
authored
Jan 09, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
just refactor
parent
4d709b6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
PushSettingsObserver.java
...rocket/android/service/observer/PushSettingsObserver.java
+22
-20
No files found.
app/src/main/java/chat/rocket/android/service/observer/PushSettingsObserver.java
View file @
e427d271
...
...
@@ -9,6 +9,7 @@ import java.util.List;
import
chat.rocket.android.api.DDPClientWrapper
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.ServerPolicyHelper
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.PublicSetting
;
import
chat.rocket.android.model.ddp.PublicSettingsConstants
;
...
...
@@ -25,27 +26,28 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
@Override
public
void
onUpdateResults
(
List
<
PublicSetting
>
results
)
{
RealmHelper
realmHelper
=
RealmStore
.
getDefault
();
final
ServerConfig
serverConfig
=
realmHelper
.
executeTransactionForRead
(
realm
->
final
ServerConfig
serverConfig
=
RealmStore
.
getDefault
().
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
ServerConfig
.
HOSTNAME
,
ServerPolicyHelper
.
enforceHostname
(
hostname
))
.
findFirst
());
serverConfig
.
setSyncPushToken
(
isPushEnabled
(
results
));
boolean
syncPushToken
=
shouldEnablePush
(
results
);
if
(
serverConfig
.
shouldSyncPushToken
()
!=
syncPushToken
)
{
serverConfig
.
setSyncPushToken
(
syncPushToken
);
realmHelper
.
executeTransaction
(
realm
->
realm
.
copyToRealmOrUpdate
(
serverConfig
))
.
continueWith
(
task
->
{
if
(
serverConfig
.
shouldSyncPushToken
())
{
Intent
intent
=
new
Intent
(
context
.
getApplicationContext
(),
GcmRegistrationIntentService
.
class
);
context
.
getApplicationContext
().
startService
(
intent
);
}
RealmStore
.
getDefault
()
.
executeTransaction
(
realm
->
realm
.
copyToRealmOrUpdate
(
serverConfig
))
.
continueWith
(
task
->
{
if
(
serverConfig
.
shouldSyncPushToken
())
{
Intent
intent
=
new
Intent
(
context
.
getApplicationContext
(),
GcmRegistrationIntentService
.
class
);
context
.
getApplicationContext
().
startService
(
intent
);
}
return
task
;
})
.
continueWith
(
new
LogcatIfError
());
return
task
;
})
.
continueWith
(
new
LogcatIfError
());
}
}
@Override
...
...
@@ -57,11 +59,11 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
.
findAll
();
}
private
boolean
isPushEnabled
(
List
<
PublicSetting
>
results
)
{
return
isPushEnable
(
results
)
&&
isGcmValid
(
results
);
private
boolean
shouldEnablePush
(
List
<
PublicSetting
>
results
)
{
return
isPushEnable
d
(
results
)
&&
hasValidGcmConfig
(
results
);
}
private
boolean
isPushEnable
(
List
<
PublicSetting
>
results
)
{
private
boolean
isPushEnable
d
(
List
<
PublicSetting
>
results
)
{
for
(
PublicSetting
setting
:
results
)
{
if
(
PublicSettingsConstants
.
Push
.
ENABLE
.
equals
(
setting
.
getId
()))
{
return
"true"
.
equals
(
setting
.
getValue
());
...
...
@@ -70,10 +72,10 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
return
false
;
}
private
boolean
isGcmValid
(
List
<
PublicSetting
>
results
)
{
private
boolean
hasValidGcmConfig
(
List
<
PublicSetting
>
results
)
{
for
(
PublicSetting
setting
:
results
)
{
if
(
PublicSettingsConstants
.
Push
.
GCM_PROJECT_NUMBER
.
equals
(
setting
.
getId
()))
{
return
setting
.
getValue
()
!=
null
&&
!
""
.
equals
(
setting
.
getValue
());
return
!
TextUtils
.
isEmpty
(
setting
.
getValue
());
}
}
return
false
;
...
...
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