package com.avg.zaap.crashlibrary.offline.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.avg.zaap.crashlibrary.offline.IConnectivityHelper;

/**
 * This broadcast receivers listens ón the
 * <p/>
 * Created by marek.osvald on 27.7.2016.
 */
public class CrashReportingServiceBroadcastReceiver extends BroadcastReceiver {

    private ICrashReportingServiceBroadcastReceiverCallback mCallback;
    private ICrashReportingServiceBroadcastReceiverCallbackFactory mFactory;

    /**
     * Parametric constructor. Sets callback.
     *
     * @param callback callback to be set
     */
    public CrashReportingServiceBroadcastReceiver(ICrashReportingServiceBroadcastReceiverCallback callback) {
        this(callback, new CrashReportingServiceBroadcastReceiverCallbackFactory());
    }

    /**
     * Parametric constructor. Sets callback and dependency factory to be used.
     *
     * @param callback callback to be set
     * @param factory  dependency factory to be used
     */
    public CrashReportingServiceBroadcastReceiver(ICrashReportingServiceBroadcastReceiverCallback callback, ICrashReportingServiceBroadcastReceiverCallbackFactory factory) {
        mCallback = callback;
        mFactory = factory;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        IConnectivityHelper connectivityHelper = mFactory.getConnectivityHelper(context);
        mCallback.onConnectionChange(connectivityHelper.getConnectionStatus());
    }

}
