2016-07-05 2 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에 따르면 마지막 레이어에는 프레젠테이션 파트뿐만 아니라 모든 "프레임 워크 관련"코드가 포함될 수 있습니다.

파이어베이스와의 통신은 전적으로 프레임 워크 특정 부분입니다 (컨텐츠 제공자, 개조 호출 등).

사이드 노트 : 코드에서 서비스에서 직접 DataBaseHelper를 사용하고 있습니다. 아마도 인터페이스를 통해 DataBaseHelper를 사용할 유스 케이스를 통과해야합니다. 이 방법으로 DatabaseHelper 구현이 변경되면 서비스를 수정할 필요가 없습니다.