I am developing an app where I am using Firebase Cloud Messaging. And I am using clean architecture for my app. I want to know where(in which layer:data, domain, presentation) is the best solution to put my classes which are called MyFirebaseMessagingService and MyFirebaseInstanceServiceID? These are my classes: myFirebaseMessagingService:
public class myFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG="MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("onMessageReceived", "Pozvana funkcija onMessageReceived");
Log.d(TAG, "From " + remoteMessage.getFrom());
Log.d(TAG, "Body " + remoteMessage.getNotification().getBody());
Log.d(TAG, "Location " + remoteMessage.getNotification().getClickAction());
Log.d(TAG, "Value " + remoteMessage.getData().get("click_action"));
sendNotification(remoteMessage);
Log.d("Function called", "sendNotification");
}
private void sendNotification(RemoteMessage remoteMessage) {
Intent intent = new Intent(myFirebaseMessagingService.this, MainActivity.class);
intent.putExtra("click_action", "goToFragment1");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notification=new NotificationCompat.Builder(this)
.setSmallIcon(logo)
.setContentText(remoteMessage.getNotification().getBody())
.setContentTitle("Title")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification.build());
String message=remoteMessage.getNotification().getBody();
DataBaseHelper db=new DataBaseHelper(this);
db.insertMsg(message);
intent.putExtra("poruka",message );
Log.d("Log>Poruka", message);
}
And this is myFirebaseInstanceServiceID:
public class myFirebaseInstanceServiceID extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
super.onTokenRefresh();
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// Add custom implementation, as needed.
}
I think this kind of classes should go into what you called the "presentation" layer.
The thing is that you mention only these 3 layers, but according to Uncle Bob's diagram the last layer can contain not only the presentation part but all "Framework specific" code.
It seems to me that communicating with Firebase is totally a framework specific part (as could be the Content Provider, the Retrofit calls, etc...).
Side note : in your code, you are using the DataBaseHelper directly from your service, maybe you should pass through a UseCase that will use the DataBaseHelper through an Interface. This way if your DatabaseHelper implementation change, no need to modify your Service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With