• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MutableData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.firebase.database.MutableData的典型用法代码示例。如果您正苦于以下问题:Java MutableData类的具体用法?Java MutableData怎么用?Java MutableData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MutableData类属于com.google.firebase.database包,在下文中一共展示了MutableData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: runPostViewsCountTransition

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public static void runPostViewsCountTransition(DatabaseReference postRef) {
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Post post = mutableData.getValue(Post.class);
            if (post == null) {
                return Transaction.success(mutableData);
            }

            int viewsCount = post.getViews() + 1;

            post.setViews(viewsCount);
            mutableData.setValue(post);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
            showLog("runCommentsCountTransition " + (databaseError != null));

                    /* if (databaseError == null) {
                        errorListener.onError();
                    }*/
        }
    });
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:27,代码来源:Worker.java


示例2: updateProfileLikeCountAfterRemovingPost

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void updateProfileLikeCountAfterRemovingPost(Post post) {
    DatabaseReference profileRef = database.getReference("profiles/" + post.getAuthorId() + "/likesCount");
    final long likesByPostCount = post.getLikesCount();

    profileRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Integer currentValue = mutableData.getValue(Integer.class);
            if (currentValue != null && currentValue >= likesByPostCount) {
                mutableData.setValue(currentValue - likesByPostCount);
            }

            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
            LogUtil.logInfo(TAG, "Updating likes count transaction is completed.");
        }
    });

}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:23,代码来源:DatabaseHelper.java


示例3: decrementCommentsCount

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void decrementCommentsCount(String postId, final OnTaskCompleteListener onTaskCompleteListener) {
    DatabaseReference postRef = database.getReference("posts/" + postId + "/commentsCount");
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Integer currentValue = mutableData.getValue(Integer.class);
            if (currentValue != null && currentValue >= 1) {
                mutableData.setValue(currentValue - 1);
            }

            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
            LogUtil.logInfo(TAG, "Updating comments count transaction is completed.");
            if (onTaskCompleteListener != null) {
                onTaskCompleteListener.onTaskComplete(true);
            }
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:23,代码来源:DatabaseHelper.java


示例4: incrementWatchersCount

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void incrementWatchersCount(String postId) {
    DatabaseReference postRef = database.getReference("posts/" + postId + "/watchersCount");
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Integer currentValue = mutableData.getValue(Integer.class);
            if (currentValue == null) {
                mutableData.setValue(1);
            } else {
                mutableData.setValue(currentValue + 1);
            }

            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
            LogUtil.logInfo(TAG, "Updating Watchers count transaction is completed.");
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:22,代码来源:DatabaseHelper.java


示例5: subscribe

import com.google.firebase.database.MutableData; //导入依赖的package包/类
@Override public void subscribe(final CompletableEmitter emitter) {
  final Transaction.Handler handler = new Transaction.Handler() {
    @Override public Transaction.Result doTransaction(MutableData mutableData) {
      try {
        return task.apply(mutableData);
      } catch (Exception e) {
        //TODO: Is this enough?
        throw new RuntimeException(e);
      }
    }

    @Override public void onComplete(DatabaseError databaseError, boolean committed,
        DataSnapshot dataSnapshot) {
      if (!emitter.isDisposed()) {
        if (null == databaseError) {
          emitter.onComplete();
        } else {
          emitter.onError(databaseError.toException());
        }
      }
    }
  };

  ref.runTransaction(handler, fireLocalEvents);
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:26,代码来源:RunTransactionOnSubscribe.java


示例6: doTransaction

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void doTransaction(String uid, final OnMilestoneTransaction listener){
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user!=null) {
        String key;
        if(uid==null || uid.isEmpty())
            return;
        DatabaseReference mRef = mDatabase.child(Constants.FIREBASE_MILESTONES).child(user.getUid()).child(SessionSingleton.getInstance().currentCar.getid()).child(uid);
        mRef.runTransaction(new Transaction.Handler() {
            @Override
            public Transaction.Result doTransaction(MutableData mutableData) {
                Milestone milestone = mutableData.getValue(Milestone.class);
                if(milestone==null)
                    return Transaction.success(mutableData);
                milestone = listener.onTransaction(milestone);
                mutableData.setValue(milestone);
                return Transaction.success(mutableData);
            }

            @Override
            public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {

            }
        });
    }
}
 
开发者ID:Gaso-UFS,项目名称:gaso,代码行数:26,代码来源:MilestoneDAO.java


示例7: incrementUserSongRequestCount

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void incrementUserSongRequestCount(String partyTitle, String userId) {
    databaseReference
        .child(partyTitle)
        .child(FirebaseConstants.CHILD_USERS)
        .child(userId)
        .child(FirebaseConstants.CHILD_USERS_SONGS_REQUESTED)
        .runTransaction(new Transaction.Handler() {
            @Override
            public Transaction.Result doTransaction(MutableData currentData) {
                if (currentData.getValue() == null) {
                    currentData.setValue(1);
                }
                else {
                    currentData.setValue((Long) currentData.getValue() + 1);
                }
                return Transaction.success(currentData);
            }

            @Override
            public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {

            }
        });
}
 
开发者ID:ZinoKader,项目名称:SpotiQ,代码行数:25,代码来源:PartiesRepository.java


示例8: setLeader

import com.google.firebase.database.MutableData; //导入依赖的package包/类
@Override
public void setLeader(String deckId, final String leaderId) {
    DatabaseReference deckReference = mUserReference.child(deckId).child("leaderId");

    // Transactions will ensure concurrency errors don't occur.
    deckReference.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            // Set value and report transaction success.
            mutableData.setValue(leaderId);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Do nothing.
        }
    });
}
 
开发者ID:jamieadkins95,项目名称:Roach,代码行数:21,代码来源:DecksInteractorFirebase.java


示例9: renameDeck

import com.google.firebase.database.MutableData; //导入依赖的package包/类
@Override
public void renameDeck(final String deckId, final String newName) {
    DatabaseReference deckReference = mUserReference.child(deckId).child("name");

    // Transactions will ensure concurrency errors don't occur.
    deckReference.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            // Set value and report transaction success.
            mutableData.setValue(newName);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Do nothing.
        }
    });
}
 
开发者ID:jamieadkins95,项目名称:Roach,代码行数:21,代码来源:DecksInteractorFirebase.java


示例10: deleteDeck

import com.google.firebase.database.MutableData; //导入依赖的package包/类
@Override
public void deleteDeck(final String deckId) {
    DatabaseReference deckReference = mUserReference.child(deckId).child("deleted");

    // Transactions will ensure concurrency errors don't occur.
    deckReference.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            // Set value and report transaction success.
            mutableData.setValue(true);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Do nothing.
        }
    });
}
 
开发者ID:jamieadkins95,项目名称:Roach,代码行数:21,代码来源:DecksInteractorFirebase.java


示例11: onStarClicked

import com.google.firebase.database.MutableData; //导入依赖的package包/类
private void onStarClicked(DatabaseReference postRef) {
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Post p = mutableData.getValue(Post.class);
            if (p == null) {
                return Transaction.success(mutableData);
            }

            if (p.stars.containsKey(getUid())) {
                // Unstar the post and remove self from stars
                p.starCount = p.starCount - 1;
                p.stars.remove(getUid());
            } else {
                // Star the post and add self to stars
                p.starCount = p.starCount + 1;
                p.stars.put(getUid(), true);
            }

            // Set value and report transaction success
            mutableData.setValue(p);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Transaction completed
            Log.d(TAG, "postTransaction:onComplete:" + databaseError);
        }
    });
}
 
开发者ID:braulio94,项目名称:Quadro,代码行数:33,代码来源:PostListFragment.java


示例12: runTransaction

import com.google.firebase.database.MutableData; //导入依赖的package包/类
/**
 * Run a transaction on the data at this location. For more information on running transactions, see
 *
 * @param ref              reference represents a particular location in your database.
 * @param fireLocalEvents  boolean which allow to receive calls of your transaction in your local device.
 * @param transactionValue value of the transaction.
 * @return a {@link Single} which emits the final {@link DataSnapshot} value if the transaction success.
 */
@NonNull
public static Single<DataSnapshot> runTransaction(@NonNull final DatabaseReference ref,
                                                  @NonNull final boolean fireLocalEvents,
                                                  @NonNull final long transactionValue) {
   return Single.create(new SingleOnSubscribe<DataSnapshot>() {
      @Override public void subscribe(final SingleEmitter emitter) throws Exception {
         ref.runTransaction(new Transaction.Handler() {
            @Override
            public Transaction.Result doTransaction(MutableData mutableData) {
               Integer currentValue = mutableData.getValue(Integer.class);
               if (currentValue == null) {
                  mutableData.setValue(transactionValue);
               } else {
                  mutableData.setValue(currentValue + transactionValue);
               }
               return Transaction.success(mutableData);
            }

            @Override
            public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
               if (databaseError != null) {
                  emitter.onError(new RxFirebaseDataException(databaseError));
               } else {
                  emitter.onSuccess(dataSnapshot);
               }
            }
         }, fireLocalEvents);
      }
   });
}
 
开发者ID:DVT,项目名称:showcase-android,代码行数:39,代码来源:RxFirebaseDatabase.java


示例13: transaction

import com.google.firebase.database.MutableData; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <T, R extends T> void transaction(final Class<T> dataType, final TransactionCallback<R> transactionCallback, final CompleteCallback completeCallback)
{
    databaseReference().runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData)
        {
            R transactionData = null;
            if (dataType == List.class || dataType == Map.class) {
                transactionData = (R) mutableData.getValue();
            } else {
                transactionData = (R) mutableData.getValue(dataType);
            }
            mutableData.setValue(transactionCallback.run(transactionData));
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot)
        {
            if (completeCallback == null) return;
            if (databaseError != null) {
                completeCallback.onError(databaseError.toException());
            } else {
                completeCallback.onSuccess();
            }
        }
    });
    terminateOperation();
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:35,代码来源:Database.java


示例14: runCommentsCountTransition

import com.google.firebase.database.MutableData; //导入依赖的package包/类
/**
 * Decrement or increment commentsCount
 *
 * @param postRef   the Post reference to run transaction
 * @param increment if TRUE it wil increment, if FALSE it will decrement.
 */
public static void runCommentsCountTransition(DatabaseReference postRef, final boolean increment) {
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Post post = mutableData.getValue(Post.class);
            if (post == null) {
                return Transaction.success(mutableData);
            }

            int commentsCount = post.getCommentsCount();
            int data = increment ? commentsCount + 1 : commentsCount - 1;

            post.setCommentsCount(data);

            //update localy
            RepositoryManager.getInstance()
                    .getPostsRepository()
                    .updateLocaly(post);

            mutableData.setValue(post);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
            showLog("runCommentsCountTransition: " + (databaseError != null));
        }
    });
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:36,代码来源:Transations.java


示例15: onLikeClicked

import com.google.firebase.database.MutableData; //导入依赖的package包/类
private void onLikeClicked(final DatabaseReference likeRef) {
    likeRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Photo p = mutableData.getValue(Photo.class);
            if (p == null) {
                return Transaction.success(mutableData);
            }

            if (p.likes.containsKey(mUserId)) {
                // Unlike the photo and remove self from likes
                p.starCount = p.starCount - 1;
                p.likes.remove(mUserId);
                Log.d(TAG, "doTransaction: Unlike");
            } else {
                // Like the photo
                Log.d(TAG, "doTransaction: Like");
                p.starCount = p.starCount + 1;
                p.likes.put(mUserId, true);
            }
            // Set value and report transaction success
            mutableData.setValue(p);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Transaction completed
            Log.d(TAG, "postTransaction:onComplete:" + databaseError);
        }
    });
}
 
开发者ID:robertmathew,项目名称:KeralaAttractions,代码行数:34,代码来源:DetailActivity.java


示例16: incrementApkDownloads

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void incrementApkDownloads(Apk app) {
    databaseReference.child(app.getKey()).child("downloads").runTransaction(
            new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Long updatedViews = mutableData.getValue(Long.class) + 1;
            mutableData.setValue(updatedViews);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
        }
    });
}
 
开发者ID:ITVlab,项目名称:TvAppRepo,代码行数:16,代码来源:RepoDatabase.java


示例17: incrementApkViews

import com.google.firebase.database.MutableData; //导入依赖的package包/类
public void incrementApkViews(Apk app) {
    databaseReference.child(app.getKey()).child("views").runTransaction(
            new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Long updatedViews = mutableData.getValue(Long.class) + 1;
            mutableData.setValue(updatedViews);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
        }
    });
}
 
开发者ID:ITVlab,项目名称:TvAppRepo,代码行数:16,代码来源:RepoDatabase.java


示例18: onStarClicked

import com.google.firebase.database.MutableData; //导入依赖的package包/类
private void onStarClicked(DatabaseReference postRef) {
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Post p = mutableData.getValue(Post.class);
            if (p == null) {
                return Transaction.success(mutableData);
            }

            if (p.stars.containsKey(getUid())) {
                p.starCount = p.starCount - 1;
                p.stars.remove(getUid());
            } else {
                p.starCount = p.starCount + 1;
                p.stars.put(getUid(), true);
            }

            mutableData.setValue(p);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Transaction completed
            Log.d(TAG, "postTransaction:onComplete:" + databaseError);
        }
    });
}
 
开发者ID:imAKHILc,项目名称:IEEE_Malabar,代码行数:30,代码来源:PostListFragment.java


示例19: onStarClicked

import com.google.firebase.database.MutableData; //导入依赖的package包/类
private void onStarClicked(DatabaseReference postRef) {
    postRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            Post p = mutableData.getValue(Post.class);
            if (p == null) {
                return Transaction.success(mutableData);
            }

            if (p.stars.containsKey(getUid())) {
                // Unstar the post and remove self from stars
                p.starCount = p.starCount - 1;
                p.stars.remove(getUid());
            } else {
                // Star the post and add self to stars
                p.starCount = p.starCount + 1;
                p.stars.put(getUid(), true);
            }

            // Set value and report transaction success
            mutableData.setValue(p);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Transaction completed
            Log.d("PostAdapter", "postTransaction:onComplete:" + databaseError);
        }
    });
}
 
开发者ID:shivarajp,项目名称:LivePokemonFinder,代码行数:33,代码来源:PostsAdapter.java


示例20: sendTraceLikeToFirebase

import com.google.firebase.database.MutableData; //导入依赖的package包/类
private void sendTraceLikeToFirebase(final boolean isLikeClicked, final Trace trace) {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    final DatabaseReference myRef = database.getReference("building").child(trace.getLocationID()).child("trace").child(trace.getTraceID());

    myRef.runTransaction(new Transaction.Handler() {
        @Override
        public Transaction.Result doTransaction(MutableData mutableData) {
            MutableData likeNumData = mutableData.child("likeNum");
            MutableData likeUserListData = mutableData.child("likeUserList").child(User.getMyInstance().getUserId());
            Object likeNum = likeNumData.getValue();
            if(likeNum == null)
                return Transaction.success(mutableData);

            if(isLikeClicked) {
                likeNumData.setValue((long) likeNum + 1);
                likeUserListData.setValue(true);
            }
            else {
                likeNumData.setValue((long) likeNum - 1);
                likeUserListData.setValue(null);
            }

            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
            if(databaseError != null) {
            }
        }
    });
}
 
开发者ID:siosio34,项目名称:AR-Trace,代码行数:33,代码来源:FirebaseClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SmartTexture类代码示例发布时间:2022-05-21
下一篇:
Java SAMSequenceDictionary类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap