Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 3 | Rev 27 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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