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
b6b6ef68
Commit
b6b6ef68
authored
Jan 09, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
just refactor
parent
5f6b098d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
24 deletions
+19
-24
GcmInstanceIDListenerService.java
...rocket/android/push/gcm/GcmInstanceIDListenerService.java
+19
-24
No files found.
app/src/main/java/chat/rocket/android/push/gcm/GcmInstanceIDListenerService.java
View file @
b6b6ef68
package
chat
.
rocket
.
android
.
push
.
gcm
;
import
android.content.Intent
;
import
com.google.android.gms.iid.InstanceIDListenerService
;
import
android.content.Intent
;
import
java.util.List
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.ddp.PublicSetting
;
...
...
@@ -15,11 +15,9 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
@Override
public
void
onTokenRefresh
()
{
List
<
ServerConfig
>
serverConfigs
=
getServerConfigs
();
updateSyncPushTokenIfNeeded
();
updateSyncPushToken
(
serverConfigs
);
if
(!
shouldRefreshToken
(
serverConfigs
))
{
if
(!
shouldRefreshToken
())
{
return
;
}
...
...
@@ -27,36 +25,33 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
startService
(
intent
);
}
private
List
<
ServerConfig
>
getServerConfigs
()
{
return
RealmStore
.
getDefault
().
executeTransactionForReadResults
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
findAll
());
}
private
void
updateSyncPushToken
(
List
<
ServerConfig
>
serverConfigs
)
{
private
void
updateSyncPushTokenIfNeeded
()
{
final
RealmHelper
realmHelper
=
RealmStore
.
getDefault
();
List
<
ServerConfig
>
serverConfigs
=
realmHelper
.
executeTransactionForReadResults
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
findAll
());
for
(
final
ServerConfig
serverConfig
:
serverConfigs
)
{
final
RealmHelper
serverRealmHelper
=
RealmStore
.
getOrCreate
(
serverConfig
.
getServerConfigId
());
final
RealmHelper
serverRealmHelper
=
RealmStore
.
get
(
serverConfig
.
getServerConfigId
());
if
(
serverRealmHelper
==
null
)
{
continue
;
}
boolean
isPushEnable
=
PublicSetting
.
getBoolean
(
serverRealmHelper
,
PublicSettingsConstants
.
Push
.
ENABLE
,
false
);
String
senderId
=
PublicSetting
.
getString
(
serverRealmHelper
,
PublicSettingsConstants
.
Push
.
GCM_PROJECT_NUMBER
,
""
).
trim
();
serverConfig
.
setSyncPushToken
(
isPushEnable
&&
!
""
.
equals
(
senderId
)
);
boolean
syncPushToken
=
isPushEnable
&&
!
""
.
equals
(
senderId
);
realmHelper
.
executeTransaction
(
realm
->
realm
.
copyToRealmOrUpdate
(
serverConfig
));
}
}
private
boolean
shouldRefreshToken
(
List
<
ServerConfig
>
serverConfigs
)
{
for
(
ServerConfig
serverConfig
:
serverConfigs
)
{
if
(
serverConfig
.
shouldSyncPushToken
())
{
return
true
;
if
(
serverConfig
.
shouldSyncPushToken
()
!=
syncPushToken
)
{
serverConfig
.
setSyncPushToken
(
syncPushToken
);
realmHelper
.
executeTransaction
(
realm
->
realm
.
copyToRealmOrUpdate
(
serverConfig
));
}
}
}
return
false
;
private
boolean
shouldRefreshToken
()
{
return
RealmStore
.
getDefault
().
isObjectExists
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
ServerConfig
.
SYNC_PUSH_TOKEN
,
true
));
}
}
\ No newline at end of file
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