当前位置: 首页>>代码示例>>Java>>正文


Java Deferred.promise方法代码示例

本文整理汇总了Java中org.jdeferred.Deferred.promise方法的典型用法代码示例。如果您正苦于以下问题:Java Deferred.promise方法的具体用法?Java Deferred.promise怎么用?Java Deferred.promise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdeferred.Deferred的用法示例。


在下文中一共展示了Deferred.promise方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changePassword

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<Void, BError, Void> changePassword(String email, String oldPassword, String newPassword){
    
    final Deferred<Void, BError, Void> deferred = new DeferredObject<>();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    OnCompleteListener<Void> resultHandler = new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                deferred.resolve(null);
            } else {
                deferred.reject(getFirebaseError(DatabaseError.fromException(task.getException())));

            }
        }
    };

    user.updatePassword(newPassword).addOnCompleteListener(resultHandler);

    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:24,代码来源:BChatcatNetworkAdapter.java

示例2: removeUserWithEntityID

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/**
 *Remove the thread from the given user threads ref.
 **/
public Promise<BThread, BError, Void> removeUserWithEntityID(String entityId){

    final Deferred<BThread, BError, Void>  deferred = new DeferredObject<>();

    BUser user = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, entityId);

    DatabaseReference ref = FirebasePaths.threadRef(this.entityId).child(BFirebaseDefines.Path.BUsersPath).child(entityId);

    ref.removeValue(new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
            if (firebaseError == null)
                deferred.resolve(BThreadWrapper.this.model);
            else
                deferred.reject(getFirebaseError(firebaseError));
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:24,代码来源:BThreadWrapper.java

示例3: isOnline

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<Boolean, BError, Void> isOnline(){

        final Deferred<Boolean, BError, Void> deferred = new DeferredObject<>();

        if (currentUserModel() == null)
        {
            return  deferred.reject(BError.getError(BError.Code.NULL, "Current user is null"));
        }

        FirebasePaths.userOnlineRef(currentUserModel().getEntityID()).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                
                updateLastOnline();
                
                deferred.resolve((Boolean) snapshot.getValue());
            }

            @Override
            public void onCancelled(DatabaseError firebaseError) {
                deferred.reject(getFirebaseError(firebaseError));
            }
        });

        return deferred.promise();
    }
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:27,代码来源:BChatcatNetworkAdapter.java

示例4: removeThreadWithEntityId

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<BUserWrapper, DatabaseError, Void> removeThreadWithEntityId(String entityId){

        final Deferred<BUserWrapper, DatabaseError, Void> deferred = new DeferredObject<>();

        DatabaseReference userThreadRef = FirebasePaths.userRef(entityId).child(BFirebaseDefines.Path.BThreadPath).child(entityId);

        userThreadRef.removeValue(new DatabaseReference.CompletionListener() {
            @Override
            public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
                if (firebaseError == null)
                {
                    deferred.resolve(BUserWrapper.this);
                }
                else
                {
                    deferred.reject(firebaseError);
                }
            }
        });
        
        return deferred.promise();

    }
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:24,代码来源:BUserWrapper.java

示例5: addUserWithEntityID

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/**
 * Add the thread from the given user threads ref.
 **/
public Promise<BThread, BError, Void> addUserWithEntityID(String entityId){

    final Deferred<BThread, BError, Void>  deferred = new DeferredObject<>();
    
    DatabaseReference ref = FirebasePaths.threadRef(this.entityId)
            .child(BFirebaseDefines.Path.BUsersPath)
            .child(entityId);

    BUser user = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, entityId);
    
    Map<String, Object> values = new HashMap<String, Object>();

    // If metaname is null the data wont be saved so we have to do so.
    values.put(BDefines.Keys.BName, (user.getMetaName() == null ? "no_name" : user.getMetaName()));
    
    ref.setValue(values, new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
            if (firebaseError == null)
                deferred.resolve(BThreadWrapper.this.model);
            else
                deferred.reject(getFirebaseError(firebaseError));
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:31,代码来源:BThreadWrapper.java

示例6: push

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<BUser, BError, Void> push(){
    if (DEBUG) Timber.v("push");
    
    final Deferred<BUser, BError, Void> deferred = new DeferredObject<>();
    
    ref().updateChildren(serialize(), new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
            if (firebaseError == null)
            {
                deferred.resolve(model);
            }
            else deferred.reject(getFirebaseError(firebaseError));
        }
    });

    // index should be updated whenever the user is pushed
    updateIndex();
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:22,代码来源:BUserWrapper.java

示例7: addUser

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/**
 * Adding a user to the thread. 
 * If the thread is private the thread will be added to the user thread ref.
 **/
public Promise<BThread, BError, Void> addUser(final BUserWrapper user){
    final Deferred<BThread, BError, Void>  deferred = new DeferredObject<>();

    // Adding the user.
    addUserWithEntityID(user.entityId).done(new DoneCallback<BThread>() {
        @Override
        public void onDone(BThread bThreadWrapper) {

            // If the thread is private we are adding the thread to the user.
            if (model.getTypeSafely() == BThread.Type.Private) {
                user.addThreadWithEntityId(model.getEntityID()).done(new DoneCallback<BUserWrapper>() {
                    @Override
                    public void onDone(BUserWrapper bUserWrapper) {
                        deferred.resolve(BThreadWrapper.this.model);
                    }
                }).fail(new FailCallback<DatabaseError>() {
                    @Override
                    public void onFail(DatabaseError firebaseError) {
                        deferred.reject(getFirebaseError(firebaseError));
                    }
                });
            } else deferred.resolve(null);
        }
    })
    .fail(new FailCallback<BError>() {
        @Override
        public void onFail(BError error) {
            deferred.reject(error);
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:38,代码来源:BThreadWrapper.java

示例8: getUserDetails

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public static Promise<GraphObject, BError, Void> getUserDetails(){

        final Deferred<GraphObject, BError, Void> deferred = new DeferredObject<>();
        
        if (Session.getActiveSession().getState().isOpened())
        {
            // Request user data and show the results
            Request.newMeRequest(Session.getActiveSession(), new Request.GraphUserCallback()
            {
                @Override
                public void onCompleted(GraphUser user, Response response)
                {
                    if (response != null)
                    {
                        try
                        {
                            deferred.resolve(user);
                        }
                        catch (Exception e)
                        {
                            deferred.reject(BError.getExceptionError(e));
                        }

                    }
                }
            }).executeAsync();
        } else deferred.reject(new BError(BError.Code.SESSION_CLOSED));
        
        return deferred.promise();
    }
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:31,代码来源:BFacebookManager.java

示例9: push

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<BMessage, BError, BMessage>  push(){
    if (DEBUG) Timber.v("push");

    final Deferred<BMessage, BError, BMessage> deferred = new DeferredObject<>();
    
    // Getting the message ref. Will be created if not exist.
    DatabaseReference ref = ref();
    model.setEntityID(ref.getKey());

    DaoCore.updateEntity(model);

    ref.setValue(serialize(), ServerValue.TIMESTAMP, new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {

            if (DEBUG) Timber.v("push message, onDone");

            if (firebaseError == null) {
                deferred.resolve(BMessageWrapper.this.model);
            } else {
                deferred.reject(getFirebaseError(firebaseError));
            }
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:28,代码来源:BMessageWrapper.java

示例10: send

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<BMessage, BError, BMessage> send(){
    if (DEBUG) Timber.v("send");
    
    if (model.getThread() != null)
    {
        return push();
    }else
    {
        final Deferred<BMessage, BError, BMessage> deferred = new DeferredObject<>();
        deferred.reject(null);
        return deferred.promise();
    }           
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:14,代码来源:BMessageWrapper.java

示例11: recoverPrivateThread

import org.jdeferred.Deferred; //导入方法依赖的package包/类
public Promise<BThread, BError, Void> recoverPrivateThread(){

        if (DEBUG) Timber.v("recoverPrivateThread");
        final Deferred<BThread, BError, Void> deferred = new DeferredObject<>();
        // Removing the deleted value from firebase.
        DatabaseReference threadUserRef = FirebasePaths.threadRef(entityId)
            .child(BFirebaseDefines.Path.BUsersPath)
            .child(BNetworkManager.sharedManager().getNetworkAdapter().currentUserModel().getEntityID())
            .child(BDefines.Keys.BDeleted);

        threadUserRef.removeValue();

        this.getModel().setDeleted(false);
        this.getModel().setType(BThread.Type.Private);
        final BThread toBeUpdated = this.getModel();
        this.loadMessages().done(new DoneCallback<List<BMessage>>() {
            @Override
            public void onDone(List<BMessage> bMessages) {
                toBeUpdated.setMessages(bMessages);
                DaoCore.updateEntity(toBeUpdated);
                deferred.resolve(toBeUpdated);
            }
        }).fail(new FailCallback<Void>() {
            @Override
            public void onFail(Void aVoid) {
                deferred.resolve(toBeUpdated);
            }
        });
        DaoCore.updateEntity(this.model);
        
        return deferred.promise();
        
    }
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:34,代码来源:BThreadWrapper.java

示例12: onSessionStateChange

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/** Re authenticate after session state changed.*/
public static Promise<Object, BError, Void> onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (DEBUG) Timber.i("Session changed state");

    // If we can start the login process with no errors this promise wont be used. 
    // The returned promise will be from the loginWithFacebook.
    Deferred<Object, BError, Void> deferred = new DeferredObject<>();
    
    if (exception != null)
    {
        exception.printStackTrace();
        if (exception instanceof FacebookOperationCanceledException)
        {
            deferred.reject(new BError(BError.Code.EXCEPTION, exception));
            return deferred.promise();
        }
    }

    if (state.isOpened()) {
        if (DEBUG) Timber.i("Session is open.");

        // We will need this session later to make request.
        userFacebookAccessToken = Session.getActiveSession().getAccessToken();

        return loginWithFacebook();

    } else if (state.isClosed()) {
        // Logged out of Facebook
        if (DEBUG) Timber.i("Session is closed.");
        deferred.reject(new BError(BError.Code.SESSION_CLOSED, "Facebook session is closed."));
    }
    
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:36,代码来源:BFacebookManager.java

示例13: getInvitableFriendsList

import org.jdeferred.Deferred; //导入方法依赖的package包/类
/** Does not work if your app dosent have facebook game app privileges.*/
public static Promise<List<JSONObject>, BError, Void> getInvitableFriendsList(){

    final Deferred<List<JSONObject>, BError, Void> deferred = new DeferredObject<>();
    
    final Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {

        // Get a list of friends who have _not installed_ the game.
        Request invitableFriendsRequest = Request.newGraphPathRequest(session,
                "/me/invitable_friends", new Request.Callback() {

                    @Override
                    public void onCompleted(Response response) {

                        FacebookRequestError error = response.getError();
                        if (error != null) {
                            if (DEBUG) Timber.e(error.toString());
                            deferred.reject(new BError(BError.Code.TAGGED, "Error while fetching invitable friends.", error));
                        } else if (session == Session.getActiveSession()) {
                            if (response != null) {
                                // Get the result
                                GraphObject graphObject = response.getGraphObject();
                                JSONArray dataArray = (JSONArray)graphObject.getProperty("data");

                                List<JSONObject> invitableFriends = new ArrayList<JSONObject>();
                                if (dataArray.length() > 0) {
                                    // Ensure the user has at least one friend ...

                                    for (int i=0; i<dataArray.length(); i++) {
                                        invitableFriends.add(dataArray.optJSONObject(i));
                                    }
                                }
                                deferred.resolve(invitableFriends);
                            }
                        }
                    }

                });

        Bundle invitableParams = new Bundle();
        invitableParams.putString("fields", "id,first_name,picture");
        invitableFriendsRequest.setParameters(invitableParams);
        invitableFriendsRequest.executeAsync();
    }
    else
    {
        if (DEBUG) Timber.d("Session is closed");
        deferred.reject(new BError(BError.Code.SESSION_CLOSED));
    }
    
    return deferred.promise();

}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:55,代码来源:BFacebookManager.java

示例14: removeUsersFromThread

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<BThread, BError, Void> removeUsersFromThread(final BThread thread, List<BUser> users) {
    final Deferred<BThread, BError, Void>  deferred = new DeferredObject<>();

    if (thread == null)
    {
        if (DEBUG) Timber.e("addUsersToThread, Thread is null" );
        return deferred.reject(new BError(BError.Code.NULL, "Thread is null"));
    }

    if (DEBUG) Timber.d("Users Amount: %s", users.size());

    Promise[] promises = new Promise[users.size()];

    BThreadWrapper threadWrapper = new BThreadWrapper(thread);

    int count = 0;
    for (BUser user : users){

        // Breaking the connection in the internal database between the thread and the user.
        DaoCore.breakUserAndThread(user, thread);

        promises[count] = threadWrapper.removeUser(BUserWrapper.initWithModel(user));
        count++;
    }

    MasterDeferredObject masterDeferredObject = new MasterDeferredObject(promises);

    masterDeferredObject.progress(new ProgressCallback<MasterProgress>() {
        @Override
        public void onProgress(MasterProgress masterProgress) {
            if (masterProgress.getFail() + masterProgress.getDone() == masterProgress.getTotal())
            {
                // Reject the promise if all promisses failed.
                if (masterProgress.getFail() == masterProgress.getTotal())
                {
                    deferred.reject(null);
                }
                else
                    deferred.resolve(thread);
            }
        }
    });
    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:47,代码来源:BChatcatNetworkAdapter.java

示例15: getFollowers

import org.jdeferred.Deferred; //导入方法依赖的package包/类
@Override
public Promise<List<BUser>, BError, Void> getFollowers(String entityId){
    if (DEBUG) Timber.v("getFollowers, Id: %s", entityId);

    final Deferred<List<BUser>, BError, Void> deferred = new DeferredObject<>();
    
    if (StringUtils.isEmpty(entityId))
    {
        return deferred.reject(BError.getError(BError.Code.NULL, "Entity id is empty"));
    }

    final BUser user = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, entityId);

    DatabaseReference followersRef = FirebasePaths.userFollowersRef(entityId);

    followersRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {

            final List<BUser> followers = new ArrayList<BUser>();

            for (DataSnapshot snap : snapshot.getChildren())
            {
                String followingUserID = snap.getKey();

                if (StringUtils.isNotEmpty(followingUserID))
                {
                    BUser follwer = DaoCore.fetchOrCreateEntityWithEntityID(BUser.class, followingUserID);

                    FollowerLink f = user.fetchOrCreateFollower(follwer, FollowerLink.Type.FOLLOWER);

                    followers.add(follwer);
                } else if (DEBUG) Timber.e("Follower id is empty");
            }

            Promise[] promises= new Promise[followers.size()];
            
            int count = 0;
            for (BUser u : followers)
            {
                promises[count] = BUserWrapper.initWithModel(u).once();

                count++;
            }
            
            MasterDeferredObject masterDeferredObject = new MasterDeferredObject(promises);

            masterDeferredObject.progress(new ProgressCallback<MasterProgress>() {
                @Override
                public void onProgress(MasterProgress masterProgress) {

                    if (DEBUG) Timber.d("MasterDeferredProgress, done: %s, failed: %s, total: %s", masterProgress.getDone(), masterProgress.getFail(), masterProgress.getTotal());

                    // Reject the promise if all promisses failed.
                    if (masterProgress.getFail() == masterProgress.getTotal())
                    {
                        deferred.reject(BError.getError(BError.Code.OPERATION_FAILED, "All promises failed"));
                    }
                    else
                        deferred.resolve(followers);
                }
            });
        }

        @Override
        public void onCancelled(DatabaseError firebaseError) {
            deferred.reject(getFirebaseError(firebaseError));
        }
    });

    
    return deferred.promise();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:74,代码来源:BChatcatNetworkAdapter.java


注:本文中的org.jdeferred.Deferred.promise方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。