Commit 14ea5777 authored by Yusuke Iwaki's avatar Yusuke Iwaki

just rename methods and variables

parent e427d271
...@@ -5,6 +5,7 @@ import com.google.android.gms.iid.InstanceIDListenerService; ...@@ -5,6 +5,7 @@ import com.google.android.gms.iid.InstanceIDListenerService;
import android.content.Intent; import android.content.Intent;
import java.util.List; import java.util.List;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.model.ddp.PublicSetting; import chat.rocket.android.model.ddp.PublicSetting;
import chat.rocket.android.model.ddp.PublicSettingsConstants; import chat.rocket.android.model.ddp.PublicSettingsConstants;
...@@ -15,7 +16,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService { ...@@ -15,7 +16,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
@Override @Override
public void onTokenRefresh() { public void onTokenRefresh() {
updateSyncPushTokenIfNeeded(); syncGcmPushAvailability();
if (!shouldRefreshToken()) { if (!shouldRefreshToken()) {
return; return;
...@@ -25,7 +26,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService { ...@@ -25,7 +26,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
startService(intent); startService(intent);
} }
private void updateSyncPushTokenIfNeeded() { private void syncGcmPushAvailability() {
final RealmHelper realmHelper = RealmStore.getDefault(); final RealmHelper realmHelper = RealmStore.getDefault();
List<ServerConfig> serverConfigs = realmHelper.executeTransactionForReadResults( List<ServerConfig> serverConfigs = realmHelper.executeTransactionForReadResults(
realm -> realm.where(ServerConfig.class).findAll()); realm -> realm.where(ServerConfig.class).findAll());
...@@ -36,15 +37,15 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService { ...@@ -36,15 +37,15 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
continue; continue;
} }
boolean isPushEnable = PublicSetting boolean isPushEnabled = PublicSetting
.getBoolean(serverRealmHelper, PublicSettingsConstants.Push.ENABLE, false); .getBoolean(serverRealmHelper, PublicSettingsConstants.Push.ENABLE, false);
String senderId = PublicSetting String senderId = PublicSetting
.getString(serverRealmHelper, PublicSettingsConstants.Push.GCM_PROJECT_NUMBER, "").trim(); .getString(serverRealmHelper, PublicSettingsConstants.Push.GCM_PROJECT_NUMBER, "").trim();
boolean syncPushToken = isPushEnable && !"".equals(senderId); boolean gcmPushAvailable = isPushEnabled && !TextUtils.isEmpty(senderId);
if (serverConfig.shouldSyncPushToken() != syncPushToken) { if (serverConfig.shouldSyncPushToken() != gcmPushAvailable) {
serverConfig.setSyncPushToken(syncPushToken); serverConfig.setSyncPushToken(gcmPushAvailable);
realmHelper.executeTransaction(realm -> realm.copyToRealmOrUpdate(serverConfig)); realmHelper.executeTransaction(realm -> realm.copyToRealmOrUpdate(serverConfig));
} }
} }
......
...@@ -31,9 +31,9 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> { ...@@ -31,9 +31,9 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
.equalTo(ServerConfig.HOSTNAME, ServerPolicyHelper.enforceHostname(hostname)) .equalTo(ServerConfig.HOSTNAME, ServerPolicyHelper.enforceHostname(hostname))
.findFirst()); .findFirst());
boolean syncPushToken = shouldEnablePush(results); boolean gcmPushAvailable = isGcmPushEnabled(results);
if (serverConfig.shouldSyncPushToken() != syncPushToken) { if (serverConfig.shouldSyncPushToken() != gcmPushAvailable) {
serverConfig.setSyncPushToken(syncPushToken); serverConfig.setSyncPushToken(gcmPushAvailable);
RealmStore.getDefault() RealmStore.getDefault()
.executeTransaction(realm -> realm.copyToRealmOrUpdate(serverConfig)) .executeTransaction(realm -> realm.copyToRealmOrUpdate(serverConfig))
...@@ -59,7 +59,7 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> { ...@@ -59,7 +59,7 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
.findAll(); .findAll();
} }
private boolean shouldEnablePush(List<PublicSetting> results) { private boolean isGcmPushEnabled(List<PublicSetting> results) {
return isPushEnabled(results) && hasValidGcmConfig(results); return isPushEnabled(results) && hasValidGcmConfig(results);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment