2016-07-05 3 views
3

Я разрабатываю приложение, в котором я использую Firebase Cloud Messaging. И я использую чистую архитектуру для своего приложения. Я хочу знать, где (в каком слое: данные, домен, презентация) лучшее решение для размещения моих классов, которые называются MyFirebaseMessagingService и MyFirebaseInstanceServiceID? Это мои занятия: myFirebaseMessagingService:FCMMessagingService в чистой архитектуре?

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); 


} 

И это 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. 
} 

ответ

1

Я думаю, что такого рода занятия должны идти в то, что вы назвали слой «презентации».

Дело в том, что вы упомянули только эти 3 слоя, но в соответствии с Uncle Bob's diagram последний слой может содержать не только часть презентации, но и весь «конкретный» код.

Мне кажется, что общение с Firebase - это полностью определенная часть структуры (как может быть поставщик контента, вызовы дооснащения и т. Д.).

Боковое примечание: в вашем коде вы используете DataBaseHelper непосредственно из своей службы, возможно, вам нужно пройти через UseCase, который будет использовать DataBaseHelper через интерфейс. Таким образом, если ваша реализация DatabaseHelper изменится, вам не нужно изменять свою службу.