All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mortezaj8.fcmserver.FirebaseNotification Maven / Gradle / Ivy

package com.github.mortezaj8.fcmserver;

import java.util.ArrayList;
import java.util.List;


/**
 * created by: Morteza
 * company: mobin
 * project name:  FCM Server
 * 19 March 2019
 **/
public abstract class FirebaseNotification {




    protected abstract String getFirebaseRemoteToken();





    public void sendNotification(List playerIds, String type, Object payload) {


        playerIds = fetchNoneNullItems(playerIds);
        if(playerIds.isEmpty()){
            return;
        }

        FirebaseNotificationRequest request = new FirebaseNotificationRequest(new FirebaseNotificationData(type.toString() , payload) , playerIds );
        FirebaseNotificationRunnable runnable = new FirebaseNotificationRunnable( request , getFirebaseRemoteToken() );

        (new Thread(runnable)).start();

    }


    public void sendNotification(String playerId, String type, Object payload) {
        List lisIds = new ArrayList();
        lisIds.add(playerId);
        sendNotification(lisIds , type , payload );
    }


    protected List < String > fetchNoneNullItems(List < String > playerIds) {

        if(playerIds == null){
            return null;
        }

        List ids = new ArrayList < String >(  );

        for(String e : playerIds){
            if(!isNullOrEmpty( e )){
                ids.add( e );
            }
        }
        return ids;
    }



    protected boolean isNullOrEmpty(String e) {
        return e == null || e.length() == 0;
    }





}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy