Proyectos de Subversion Android Microlearning - Inconcert

Rev

| Ultima modificación | Ver Log |

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