package com.cube.storm.message.lib.service;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.cube.storm.MessageSettings;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

/**
 * This class registers the application for a GCM token. Must be defined in your Application manifest, and MessageSettings
 * class.
 * <pre>
 * 	&lt;service android:name="com.cube.storm.message.lib.service.TokenService" android:exported="false" /&gt;
 * </pre>
 * <pre>
 *	new MessageSettings.Builder(this)
 *		.tokenService(TokenService.class)
 *		.build()
 * </pre>
 *
 * @author Callum Taylor
 * @project LightningMessage
 */
public class TokenService extends FirebaseInstanceIdService
{
	@Override public void onTokenRefresh()
	{
		super.onTokenRefresh();

		if (TextUtils.isEmpty(MessageSettings.getInstance().getProjectNumber()))
		{
			throw new IllegalArgumentException("Project number can not be empty");
		}

		String token = FirebaseInstanceId.getInstance().getToken();

		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
		prefs.edit().putString("push_id", token).putLong("push_id_time", System.currentTimeMillis()).apply();

		onTokenReceived(token);
	}

	/**
	 * Called when a token has been retrieved from the GCM provider
	 * @param token The token received
	 */
	public void onTokenReceived(String token)
	{
		if (MessageSettings.getInstance().getRegisterListener() != null)
		{
			MessageSettings.getInstance().getRegisterListener().onDeviceRegistered(this, token);
		}
	}
}

@@ -42,95 +42,8 @@
 e;%0A%0A
-import android.content.SharedPreferences;%0Aimport android.preference.PreferenceManager;%0A
 impo
@@ -1009,214 +1009,8 @@
 ();%0A
-%0A%09%09SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());%0A%09%09prefs.edit().putString(%22push_id%22, token).putLong(%22push_id_time%22, System.currentTimeMillis()).apply();%0A%0A
 %09%09on

Remove token registration in preferences