package it.near.sdk.push.fcmregistration;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

import it.near.sdk.communication.NearInstallation;
import it.near.sdk.GlobalConfig;
import it.near.sdk.logging.NearLog;

/**
 * Handles token refreshes. When a new device token is obtained it triggers a remote registration.
 * It either creates or update an installation.
 *
 * @author cattaneostefano
 */
public class MyInstanceIDListenerService extends FirebaseInstanceIdService {

    private static final String TAG = "NearInstIDListenerServ";

    @Override
    public void onTokenRefresh() {
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        NearLog.d(TAG, "Refreshed token: " + refreshedToken);
        sendRegistrationToServer(refreshedToken);
    }

    /**
     * Persist registration to NearIt servers.
     * <p>
     * Modify this method to associate the user's Fcm registration token with any server-side account
     * maintained by your application.
     *
     * @param token The new token.
     */
    private void sendRegistrationToServer(String token) {
        // Add custom implementation, as needed.
        GlobalConfig.getInstance(this.getApplicationContext()).setDeviceToken(token);
        NearInstallation.registerInstallation(this.getApplicationContext());
    }
}

@@ -169,71 +169,21 @@
 sdk.
-communication.NearInstallation;%0Aimport it.near.sdk.GlobalConfig
+NearItManager
 ;%0Aim
@@ -1166,20 +1166,51 @@
     
-GlobalConfig
+NearItManager nearItManager = NearItManager
 .get
@@ -1218,21 +1218,16 @@
 nstance(
-this.
 getAppli
@@ -1242,16 +1242,52 @@
 ntext())
+;%0A        nearItManager.globalConfig
 .setDevi
@@ -1306,25 +1306,39 @@
 n);%0A        
-N
+nearItManager.n
 earInstallat
@@ -1366,36 +1366,8 @@
 ion(
-this.getApplicationContext()
 );%0A 

remove static access in instance id listener service