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