Proyectos de Subversion Android Microlearning

Rev

Rev 8 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
package com.cesams.twogetskills.receiver;
2
 
3
import android.content.BroadcastReceiver;
4
import android.content.Context;
5
import android.content.Intent;
6
import android.util.Log;
7
 
8
import com.cesams.twogetskills.Constants;
9
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
10
 
11
public class InternalReceiver extends BroadcastReceiver {
12
    private final static String TAG = "C2GS - InternalReceiver";
13
 
14
    @Override
15
    public void onReceive(Context context, Intent intent) {
16
        try {
17
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_NOTIFICATION)) {
18
 
19
                String title = intent.getExtras().getString("title");
20
                String body = intent.getExtras().getString("body");
21
 
22
 
23
                int new_capsules = 0;
24
                if(intent.getExtras().containsKey("new_capsules")) {
25
                    new_capsules = intent.getExtras().getInt("new_capsules");
26
                }
27
 
28
                Log.d(TAG, "Recibiendo una nueva NOTIFICACION");
29
                Log.d(TAG, "Title : " + title);
30
                Log.d(TAG, "Body : " + body);
31
                Log.d(TAG, "New Capsules : " + new_capsules);
32
 
33
                if(context instanceof ITwoGetSkills) {
34
                    ((ITwoGetSkills) context).showFcmNotification(title, body, new_capsules);
35
                }
36
            }
37
 
38
 
39
 
40
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_TOKEN)) {
41
 
42
                String token = intent.getStringExtra("token");
43
 
44
                Log.d(TAG, "Recibiendo un nuevo TOKEN");
45
                Log.d(TAG, "Token : " + token);
46
 
47
                if(context instanceof ITwoGetSkills) {
48
                    ((ITwoGetSkills) context).createSyncRecordNewToken(token);
49
                }
50
            }
51
 
52
 
53
 
54
 
55
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_COMMAND)) {
56
 
57
 
58
                String command = intent.getStringExtra("command");
59
                Log.d(TAG, "Recibiendo un nuevo COMAND");
60
                Log.d(TAG, "Command : " + command);
61
 
62
                if(context instanceof ITwoGetSkills) {
63
                    ((ITwoGetSkills) context).executeFcmCommand(command);
64
                }
65
            }
66
 
67
            /*
68
              if (intent.getAction().equals(Constants.BROADCAST_TYPE_REFRESH_CONTENT)) {
69
 
70
                Log.d(TAG, "Hay que refrescar el contenido");
71
 
72
                if(context instanceof ITwoGetSkills) {
73
                    ((ITwoGetSkills) context).requestCheckChanges();
74
                }
75
            }
76
            */
77
 
78
            /*
79
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_SYNC_TO_SERVER)) {
80
                Log.d(TAG, "Sync Data");
81
                if(context instanceof ITwoGetSkills) {
82
                    ((ITwoGetSkills) context).syncToServer();
83
                }
84
            }
85
            */
86
            if (intent.getAction().equals(Constants.BROADCAST_TYPE_SYNC_TO_SERVER_OR_CHECK_CHANGES)) {
87
                Log.d(TAG, "Sync Data");
88
                if(context instanceof ITwoGetSkills) {
89
                    ((ITwoGetSkills) context).syncToServerOrCheckChanges();
90
                }
91
            }
92
 
93
 
94
        } catch (NullPointerException e) {
95
            e.printStackTrace();
96
        }
97
    }
98
 
99
 
100
}