Proyectos de Subversion Android Microlearning

Rev

Rev 8 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

package com.cesams.twogetskills.receiver;

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

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

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

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_NOTIFICATION)) {

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


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

                Log.d(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);
                }
            }



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

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

                Log.d(TAG, "Recibiendo un nuevo TOKEN");
                Log.d(TAG, "Token : " + 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();
        }
    }


}