// Path: app/src/main/java/wseemann/media/romote/tasks/RequestCallback.java
// public abstract class RequestCallback {
//     public abstract void requestResult(RokuRequestTypes rokuRequestType, RequestTask.Result result);
//     public abstract void onErrorResponse(RequestTask.Result result);
// }
// 
// Path: app/src/main/java/wseemann/media/romote/tasks/RequestTask.java
// public class RequestTask extends AsyncTask<RokuRequestTypes, Void, RequestTask.Result> {
// 
//     private RequestCallback mCallback;
// 
//     private JakuRequest request;
//     private RokuRequestTypes rokuRequestType;
// 
//     public RequestTask(JakuRequest request, RequestCallback callback) {
//         this.request = request;
//         setCallback(callback);
//     }
// 
//     void setCallback(RequestCallback callback) {
//         mCallback = callback;
//     }
// 
//     /**
//      * Wrapper class that serves as a union of a result value and an exception. When the download
//      * task has completed, either the result value or exception can be a non-null value.
//      * This allows you to pass exceptions to the UI thread that were thrown during doInBackground().
//      */
//     public static class Result {
//         public Object mResultValue;
//         public Exception mException;
//         public Result(Object resultValue) {
//             mResultValue = resultValue;
//         }
//         public Result(Exception exception) {
//             mException = exception;
//         }
//     }
// 
//     /**
//      * Cancel background network operation if we do not have network connectivity.
//      */
//     @Override
//     protected void onPreExecute() {
// 
//     }
// 
//     @Override
//     protected RequestTask.Result doInBackground(RokuRequestTypes... requestTypes) {
//         Result result = null;
//         if (!isCancelled() && requestTypes != null && requestTypes.length > 0) {
//             RokuRequestTypes requestType = requestTypes[0];
//             try {
//                 if (requestType.equals(RokuRequestTypes.query_active_app)) {
//                     JakuResponse response = request.send();
//                     List<Channel> channels = (List<Channel>) response.getResponseData();
//                     result = new Result(channels);
//                 } else if (requestType.equals(RokuRequestTypes.query_device_info)) {
//                     JakuResponse response = request.send();
//                     Device device = Device.Companion.fromDevice((com.jaku.model.Device) response.getResponseData());
//                     result = new Result(device);
//                 } else if (requestType.equals(RokuRequestTypes.query_icon)) {
//                     JakuResponse response = request.send();
//                     byte [] data = ((ByteArrayOutputStream) response.getResponseData()).toByteArray();
//                     result = new Result(data);
//                 } else {
//                     request.send();
//                 }
//             } catch(Exception e) {
//                 e.printStackTrace();
//                 result = new Result(e);
//             }
//         }
//         return result;
//     }
// 
//     /**
//      * Updates the DownloadCallback with the result.
//      */
//     @Override
//     protected void onPostExecute(Result result) {
//         if (result != null && mCallback != null) {
//             if (result.mException != null) {
//                 mCallback.onErrorResponse(result);
//             } else if (result.mResultValue != null) {
//                 mCallback.requestResult(rokuRequestType, result);
//             }
//         }
//     }
// 
//     /**
//      * Override to add special behavior for cancelled AsyncTask.
//      */
//     @Override
//     protected void onCancelled(Result result) {
//     }
// }
// 
// Path: app/src/main/java/wseemann/media/romote/utils/CommandHelper.java
// public class CommandHelper {
// 
//     private CommandHelper() {
// 
//     }
// 
//     public static String getDeviceURL(Context context) {
//         String url = "";
// 
//         try {
//             Device device = PreferenceUtils.getConnectedDevice(context);
// 
//             url = device.getHost();
//         } catch (Exception ex) {
//         }
// 
//         return url;
//     }
// 
//     public static String getIconURL(Context context, String channelId) {
//         String url = "";
// 
//         try {
//             Device device = PreferenceUtils.getConnectedDevice(context);
// 
//             url = device.getHost() + "/query/icon/" + channelId;
//         } catch (Exception ex) {
//         }
// 
//         return url;
//     }
// 
//     public static String getDeviceInfoURL(Context context, String host) {
//         String url = host;
// 
//         return url;
//     }
// 
//     public static String getConnectedDeviceInfoURL(Context context, String host) {
//         String url = "";
// 
//         try {
//             Device device = PreferenceUtils.getConnectedDevice(context);
// 
//             url = device.getHost();
//         } catch (Exception ex) {
//         }
// 
//         return url;
//     }
// }
// 
// Path: app/src/main/java/wseemann/media/romote/utils/RokuRequestTypes.java
// public enum RokuRequestTypes {
//     query_active_app("query/active-app"),
//     query_device_info("query/device-info"),
//     launch("launch"),
//     keypress("keypress"),
//     query_icon("query/icon"),
//     search("search/browse?");
// 
//     private final String method;
// 
//     RokuRequestTypes(String method) {
//         this.method = method;
//     }
// 
//     public String getValue() {
//         return method;
//     }
// }


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import com.jaku.core.JakuRequest;
import com.jaku.core.KeypressKeyValues;
import com.jaku.request.KeypressRequest;
import wseemann.media.romote.tasks.RequestCallback;
import wseemann.media.romote.tasks.RequestTask;
import wseemann.media.romote.utils.CommandHelper;
import wseemann.media.romote.utils.RokuRequestTypes;
package wseemann.media.romote.receiver;




/**
 * Created by wseemann on 4/14/18.
 */

public class CommandReceiver extends BroadcastReceiver {

    private static final String TAG = CommandReceiver.class.getName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
// Path: app/src/main/java/wseemann/media/romote/tasks/RequestCallback.java
// public abstract class RequestCallback {
//     public abstract void requestResult(RokuRequestTypes rokuRequestType, RequestTask.Result result);
//     public abstract void onErrorResponse(RequestTask.Result result);
// }
// 
// Path: app/src/main/java/wseemann/media/romote/tasks/RequestTask.java
// public class RequestTask extends AsyncTask<RokuRequestTypes, Void, RequestTask.Result> {
// 
//     private RequestCallback mCallback;
// 
//     private JakuRequest request;
//     private RokuRequestTypes rokuRequestType;
// 
//     public RequestTask(JakuRequest request, RequestCallback callback) {
//         this.request = request;
//         setCallback(callback);
//     }
// 
//     void setCallback(RequestCallback callback) {
//         mCallback = callback;
//     }
// 
//     /**
//      * Wrapper class that serves as a union of a result value and an exception. When the download
//      * task has completed, either the result value or exception can be a non-null value.
//      * This allows you to pass exceptions to the UI thread that were thrown during doInBackground().
//      */
//     public static class Result {
//         public Object mResultValue;
//         public Exception mException;
//         public Result(Object resultValue) {
//             mResultValue = resultValue;
//         }
//         public Result(Exception exception) {
//             mException = exception;
//         }
//     }
// 
//     /**
//      * Cancel background network operation if we do not have network connectivity.
//      */
//     @Override
//     protected void onPreExecute() {
// 
//     }
// 
//     @Override
//     protected RequestTask.Result doInBackground(RokuRequestTypes... requestTypes) {
//         Result result = null;
//         if (!isCancelled() && requestTypes != null && requestTypes.length > 0) {
//             RokuRequestTypes requestType = requestTypes[0];
//             try {
//                 if (requestType.equals(RokuRequestTypes.query_active_app)) {
//                     JakuResponse response = request.send();
//                     List<Channel> channels = (List<Channel>) response.getResponseData();
//                     result = new Result(channels);
//                 } else if (requestType.equals(RokuRequestTypes.query_device_info)) {
//                     JakuResponse response = request.send();
//                     Device device = Device.Companion.fromDevice((com.jaku.model.Device) response.getResponseData());
//                     result = new Result(device);
//                 } else if (requestType.equals(RokuRequestTypes.query_icon)) {
//                     JakuResponse response = request.send();
//                     byte [] data = ((ByteArrayOutputStream) response.getResponseData()).toByteArray();
//                     result = new Result(data);
//                 } else {
//                     request.send();
//                 }
//             } catch(Exception e) {
//                 e.printStackTrace();
//                 result = new Result(e);
//             }
//         }
//         return result;
//     }
// 
//     /**
//      * Updates the DownloadCallback with the result.
//      */
//     @Override
//     protected void onPostExecute(Result result) {
//         if (result != null && mCallback != null) {
//             if (result.mException != null) {
//                 mCallback.onErrorResponse(result);
//             } else if (result.mResultValue != null) {
//                 mCallback.requestResult(rokuRequestType, result);
//             }
//         }
//     }
// 
//     /**
//      * Override to add special behavior for cancelled AsyncTask.
//      */
//     @Override
//     protected void onCancelled(Result result) {
//     }
// }
// 
// Path: app/src/main/java/wseemann/media/romote/utils/CommandHelper.java
// public class CommandHelper {
// 
//     private CommandHelper() {
// 
//     }
// 
//     public static String getDeviceURL(Context context) {
//         String url = "";
// 
//         try {
//             Device device = PreferenceUtils.getConnectedDevice(context);
// 
//             url = device.getHost();
//         } catch (Exception ex) {
//         }
// 
//         return url;
//     }
// 
//     public static String getIconURL(Context context, String channelId) {
//         String url = "";
// 
//         try {
//             Device device = PreferenceUtils.getConnectedDevice(context);
// 
//             url = device.getHost() + "/query/icon/" + channelId;
//         } catch (Exception ex) {
//         }
// 
//         return url;
//     }
// 
//     public static String getDeviceInfoURL(Context context, String host) {
//         String url = host;
// 
//         return url;
//     }
// 
//     public static String getConnectedDeviceInfoURL(Context context, String host) {
//         String url = "";
// 
//         try {
//             Device device = PreferenceUtils.getConnectedDevice(context);
// 
//             url = device.getHost();
//         } catch (Exception ex) {
//         }
// 
//         return url;
//     }
// }
// 
// Path: app/src/main/java/wseemann/media/romote/utils/RokuRequestTypes.java
// public enum RokuRequestTypes {
//     query_active_app("query/active-app"),
//     query_device_info("query/device-info"),
//     launch("launch"),
//     keypress("keypress"),
//     query_icon("query/icon"),
//     search("search/browse?");
// 
//     private final String method;
// 
//     RokuRequestTypes(String method) {
//         this.method = method;
//     }
// 
//     public String getValue() {
//         return method;
//     }
// }


// Path: app/src/main/java/wseemann/media/romote/receiver/CommandReceiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import com.jaku.core.JakuRequest;
import com.jaku.core.KeypressKeyValues;
import com.jaku.request.KeypressRequest;
import wseemann.media.romote.tasks.RequestCallback;
import wseemann.media.romote.tasks.RequestTask;
import wseemann.media.romote.utils.CommandHelper;
import wseemann.media.romote.utils.RokuRequestTypes;

package wseemann.media.romote.receiver;




/**
 * Created by wseemann on 4/14/18.
 */

public class CommandReceiver extends BroadcastReceiver {

    private static final String TAG = CommandReceiver.class.getName();

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            String url = CommandHelper.getDeviceURL(context);