Proyectos de Subversion Android Microlearning - Inconcert

Rev

Autoría | Ultima modificación | Ver Log |

package com.cesams.twogetskills.inconcert.receiver;

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

import com.cesams.twogetskills.inconcert.Constants;
import com.cesams.twogetskills.inconcert.skeleton.ITwoGetSkills;

public class InternalReceiver extends BroadcastReceiver {
    private final static String TAG = "C2GS - InternalReceiver";

    public InternalReceiver()
    {
        Log.e("BUG Token", "InternalReceiver - Constructor");
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e(TAG, "Recibiendo Internal");

        try {
            Log.e(TAG,""+intent.getAction());

            if (intent.getAction().equals(Constants.BROADCAST_TYPE_NOTIFICATION)) {

                String title = intent.getExtras().getString("title");
                String body = intent.getExtras().getString("body");
                String url = intent.getExtras().getString("url");


                int new_capsules = 0;
                if(intent.getExtras().containsKey("new_capsules")) {
                    new_capsules = intent.getExtras().getInt("new_capsules");
                }

                boolean content_refresh = false;
                if(intent.getExtras().containsKey("content_refresh")) {
                    content_refresh = intent.getExtras().getBoolean("content_refresh");
                }




                Log.e(TAG, "Recibiendo una nueva NOTIFICACION");
                Log.d(TAG, "Title : " + title);
                Log.d(TAG, "Body : " + body);
                Log.d(TAG, "New Capsules : " + new_capsules);


                if(context instanceof ITwoGetSkills) {
                    ((ITwoGetSkills) context).showFcmNotification(title, body, new_capsules,url, content_refresh);

                }
            }



          if (intent.getAction().equals(Constants.BROADCAST_TYPE_TOKEN)) {

                String token = intent.getStringExtra("token");


                if(context instanceof ITwoGetSkills) {
                    ((ITwoGetSkills) context).createSyncRecordNewToken(token);
                }
            }




            if (intent.getAction().equals(Constants.BROADCAST_TYPE_COMMAND)) {


                String command = intent.getStringExtra("command");
                Log.d(TAG, "Recibiendo un nuevo COMAND");
                Log.d(TAG, "Command : " + command);

                if(context instanceof ITwoGetSkills) {
                    ((ITwoGetSkills) context).executeFcmCommand(command);
                }
            }

            /*
              if (intent.getAction().equals(Constants.BROADCAST_TYPE_REFRESH_CONTENT)) {

                Log.d(TAG, "Hay que refrescar el contenido");

                if(context instanceof ITwoGetSkills) {
                    ((ITwoGetSkills) context).requestCheckChanges();
                }
            }
            */

            /*
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_SYNC_TO_SERVER)) {
                Log.d(TAG, "Sync Data");
                if(context instanceof ITwoGetSkills) {
                    ((ITwoGetSkills) context).syncToServer();
                }
            }
            */

            if (intent.getAction().equals(Constants.BROADCAST_TYPE_SYNC_TO_SERVER_OR_CHECK_CHANGES)) {
                Log.d(TAG, "Sync Data");
                if(context instanceof ITwoGetSkills) {
                    ((ITwoGetSkills) context).syncToServerOrCheckChanges();
                }
            }



        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }


}