package com.ajhodges.wificallingcontrols.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.ajhodges.wificallingcontrols.NotCompatibleException;
import com.ajhodges.wificallingcontrols.bundle.BundleScrubber;
import com.ajhodges.wificallingcontrols.bundle.PluginBundleManager;
import com.ajhodges.wificallingcontrols.ipphone.WifiCallingManager;

/**
 * Created by Adam on 3/9/14.
 */
public class ToggleReceiver extends BroadcastReceiver{
    public static final String TOGGLE_WFC_ACTION = "com.ajhodges.wificallingcontrols.TOGGLE_WFC";
    @Override
    public void onReceive(Context context, Intent intent) {
        if(!com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction()) || !TOGGLE_WFC_ACTION.equals(intent.getAction())){
            //unexpected intent
            return;
        }
        BundleScrubber.scrub(intent);

        final Bundle bundle = intent.getBundleExtra(com.twofortyfouram.locale.Intent.EXTRA_BUNDLE);
        BundleScrubber.scrub(bundle);

        if (PluginBundleManager.isBundleValid(bundle))
        {
            final int mode = bundle.getInt(PluginBundleManager.BUNDLE_EXTRA_INT_MODE);

            try{
                WifiCallingManager wifiCallingManager = WifiCallingManager.getInstance(context);

                if(mode < WifiCallingManager.PREFER_WIFI) {
                    wifiCallingManager.toggleWifi(context, mode);
                    context.getSharedPreferences("ToggleWidgetProvider", Context.MODE_PRIVATE).edit().putBoolean("widgetUpdating", false);
                }
                else {
                    wifiCallingManager.setPreferred(context, mode);
                }
            } catch(NotCompatibleException ex){
                Toast.makeText(context, ex.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

@@ -195,22 +195,98 @@
 oid.
-widget.Toast;%0A
+util.Log;%0Aimport android.widget.Toast;%0A%0Aimport com.ajhodges.wificallingcontrols.Constants;
 %0Aimp
@@ -823,16 +823,17 @@
     if(!
+(
 com.twof
@@ -910,10 +910,55 @@
 ) %7C%7C
+%0A                                             
  
-!
 TOGG
@@ -998,16 +998,17 @@
 tion()))
+)
 %7B%0A      
@@ -1055,32 +1055,33 @@
 turn;%0A        %7D%0A
+%0A
         BundleSc
@@ -1098,25 +1098,24 @@
 ub(intent);%0A
-%0A
         fina
@@ -1565,24 +1565,86 @@
 FER_WIFI) %7B%0A
+                    Log.v(Constants.LOG_TAG, %22Toggling WFC%22);%0A
             

Fix regression from 'launching other tasker plugins' fix