package ti.geoloqi.proxy.common;

import org.appcelerator.kroll.KrollDict;

import ti.geoloqi.GeoloqiModule;
import ti.geoloqi.common.MLog;
import ti.geoloqi.common.MUtils;
import ti.geoloqi.proxy.LQTrackerProxy;
import android.content.Context;
import android.location.Location;

import com.geoloqi.android.sdk.LQTracker.LQTrackerProfile;
import com.geoloqi.android.sdk.receiver.LQBroadcastReceiver;

/**
 * This class is an implementation of LQBroadcastReceiver of geoloqi
 * 
 * @see com.geoloqi.android.sdk.receiver.LQBroadcastReceiver
 */
public class LQBroadcastReceiverImpl extends LQBroadcastReceiver {

	public static final String LCAT = LQBroadcastReceiverImpl.class.getSimpleName();
	private static final String OLD_PROFILE = "OLD_PROFILE";
	private static final String NEW_PROFILE = "NEW_PROFILE";
	private static final String LOCATION_ATTRIB = "location";

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.geoloqi.android.sdk.receiver.LQBroadcastReceiver#onLocationChanged
	 * (android.content.Context, android.location.Location)
	 */
	@Override
	public void onLocationChanged(Context context, Location location) {
		MLog.d(LCAT, "in onLocationChanged");
		KrollDict locationKD = new KrollDict(1);
		locationKD.put(LOCATION_ATTRIB, MUtils.locationToDictionary(location));
		GeoloqiModule.getInstance().fireEvent(GeoloqiModule.LOCATION_CHANGED, locationKD);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.geoloqi.android.sdk.receiver.LQBroadcastReceiver#onLocationUploaded
	 * (android.content.Context, int)
	 */
	@Override
	public void onLocationUploaded(Context context, int numberOfLocationsUploaded) {
		MLog.d(LCAT, "in onLocationUploaded, Number of Locations Uploaded: " + numberOfLocationsUploaded);
		GeoloqiModule.getInstance().fireEvent(GeoloqiModule.LOCATION_UPLOADED, numberOfLocationsUploaded);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.geoloqi.android.sdk.receiver.LQBroadcastReceiver#onTrackerProfileChanged
	 * (android.content.Context,
	 * com.geoloqi.android.sdk.LQTracker.LQTrackerProfile,
	 * com.geoloqi.android.sdk.LQTracker.LQTrackerProfile)
	 */
	@Override
	public void onTrackerProfileChanged(Context context, LQTrackerProfile oldProfile, LQTrackerProfile newProfile) {
		MLog.d(LCAT, "in onTrackerProfileChanged.");
		KrollDict profileKD = new KrollDict(2);
		profileKD.put(OLD_PROFILE, LQTrackerProxy.profileToString(oldProfile));
		profileKD.put(NEW_PROFILE, LQTrackerProxy.profileToString(newProfile));
		GeoloqiModule.getInstance().fireEvent(GeoloqiModule.TRACKER_PROFILE_CHANGED, profileKD);
	}

}

@@ -271,16 +271,42 @@
 ocation;
+%0Aimport android.os.Bundle;
 %0A%0Aimport
@@ -2559,10 +2559,389 @@
 D);%0A%09%7D%0A%0A
+%09/*%0A%09 * (non-Javadoc)%0A%09 * %0A%09 * @see%0A%09 * com.geoloqi.android.sdk.receiver.LQBroadcastReceiver#onPushMessageReceived%0A%09 * (android.content.Context, android.os.Bundle)%0A%09 */%0A%09@Override%0A%09public void onPushMessageReceived(Context context, Bundle data) %7B%0A%09%09MLog.d(LCAT, %22in onPushMessageReceived.%22);%0A%09%09GeoloqiModule.getInstance().fireEvent(GeoloqiModule.PUSH_MESSAGE_RECEIVED, data);%0A%09%7D%0A
 %7D%0A

Add the onPushMessageReceived callback to the LQBroadcastReceiver proxy.