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;
import android.content.Intent;
import java.util.List;
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;
......@@ -15,7 +16,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
@Override
public void onTokenRefresh() {
updateSyncPushTokenIfNeeded();
syncGcmPushAvailability();
if (!shouldRefreshToken()) {
return;
......@@ -25,7 +26,7 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
startService(intent);
}
private void updateSyncPushTokenIfNeeded() {
private void syncGcmPushAvailability() {
final RealmHelper realmHelper = RealmStore.getDefault();
List<ServerConfig> serverConfigs = realmHelper.executeTransactionForReadResults(
realm -> realm.where(ServerConfig.class).findAll());
......@@ -36,15 +37,15 @@ public class GcmInstanceIDListenerService extends InstanceIDListenerService {
continue;
}
boolean isPushEnable = PublicSetting
boolean isPushEnabled = PublicSetting
.getBoolean(serverRealmHelper, PublicSettingsConstants.Push.ENABLE, false);
String senderId = PublicSetting
.getString(serverRealmHelper, PublicSettingsConstants.Push.GCM_PROJECT_NUMBER, "").trim();
boolean syncPushToken = isPushEnable && !"".equals(senderId);
boolean gcmPushAvailable = isPushEnabled && !TextUtils.isEmpty(senderId);
if (serverConfig.shouldSyncPushToken() != syncPushToken) {
serverConfig.setSyncPushToken(syncPushToken);
if (serverConfig.shouldSyncPushToken() != gcmPushAvailable) {
serverConfig.setSyncPushToken(gcmPushAvailable);
realmHelper.executeTransaction(realm -> realm.copyToRealmOrUpdate(serverConfig));
}
}
......
......@@ -31,9 +31,9 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
.equalTo(ServerConfig.HOSTNAME, ServerPolicyHelper.enforceHostname(hostname))
.findFirst());
boolean syncPushToken = shouldEnablePush(results);
if (serverConfig.shouldSyncPushToken() != syncPushToken) {
serverConfig.setSyncPushToken(syncPushToken);
boolean gcmPushAvailable = isGcmPushEnabled(results);
if (serverConfig.shouldSyncPushToken() != gcmPushAvailable) {
serverConfig.setSyncPushToken(gcmPushAvailable);
RealmStore.getDefault()
.executeTransaction(realm -> realm.copyToRealmOrUpdate(serverConfig))
......@@ -59,7 +59,7 @@ public class PushSettingsObserver extends AbstractModelObserver<PublicSetting> {
.findAll();
}
private boolean shouldEnablePush(List<PublicSetting> results) {
private boolean isGcmPushEnabled(List<PublicSetting> 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