本文整理汇总了Java中com.google.firebase.database.Query.keepSynced方法的典型用法代码示例。如果您正苦于以下问题:Java Query.keepSynced方法的具体用法?Java Query.keepSynced怎么用?Java Query.keepSynced使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.database.Query
的用法示例。
在下文中一共展示了Query.keepSynced方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDifferentIndependentQueries
import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Test
public void testDifferentIndependentQueries() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
Query query1 = ref.limitToFirst(1);
Query query2 = ref.limitToFirst(2);
query1.keepSynced(true);
assertIsKeptSynced(query1);
assertNotKeptSynced(query2);
query2.keepSynced(true);
assertIsKeptSynced(query1);
assertIsKeptSynced(query2);
query1.keepSynced(false);
assertIsKeptSynced(query2);
assertNotKeptSynced(query1);
query2.keepSynced(false);
assertNotKeptSynced(query1);
assertNotKeptSynced(query2);
}
示例2: onResume
import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
Query listenNewNotif = FirebaseDatabase
.getInstance()
.getReference(getString(R.string.firebase_key_last_notif))
.child(getString(R.string.firebase_key_notif_id));
listenNewNotif.keepSynced(true);
final DatabaseHelper dbHelper = new DatabaseHelper(this);
listenNewNotif.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dbHelper.getUnreadCount()>0 && notifMenu!=null){
notifMenu.setIcon(getResources().getDrawable(R.drawable.ic_notification_new));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG,databaseError.getMessage());
}
});
}
示例3: getPostListByUser
import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void getPostListByUser(final OnDataChangedListener<Post> onDataChangedListener, String userId) {
DatabaseReference databaseReference = database.getReference("posts");
Query postsQuery;
postsQuery = databaseReference.orderByChild("authorId").equalTo(userId);
postsQuery.keepSynced(true);
postsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
PostListResult result = parsePostList((Map<String, Object>) dataSnapshot.getValue());
onDataChangedListener.onListChanged(result.getPosts());
}
@Override
public void onCancelled(DatabaseError databaseError) {
LogUtil.logError(TAG, "getPostListByUser(), onCancelled", new Exception(databaseError.getMessage()));
}
});
}
示例4: testKeepSyncedAffectOnQueries
import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Test
public void testKeepSyncedAffectOnQueries() throws Exception {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ref.keepSynced(true);
Query query = ref.limitToFirst(5);
query.keepSynced(true);
assertIsKeptSynced(ref);
ref.keepSynced(false);
assertNotKeptSynced(ref);
// currently, setting false on the default query affects all queries at that location
assertNotKeptSynced(query);
}
示例5: onResume
import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
final DatabaseHelper dbHelper = new DatabaseHelper(this);
Query listenNewNotif = FirebaseDatabase
.getInstance()
.getReference(getString(R.string.firebase_key_last_notif))
.child(getString(R.string.firebase_key_notif_id));
listenNewNotif.keepSynced(true);
listenNewNotif.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
notifications.clear();
notifications.addAll(dbHelper.selectAllNotifications());
notifAdapter.notifyDataSetChanged();
// Scroll to top
((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(0,0);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG,databaseError.getMessage());
}
});
}
示例6: onActivityCreated
import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.d(TAG,"In onActivityCreated");
list = new ArrayList<>();
adapter = new CouncilMemberAdapter(getContext(), list);
listingsView = view.findViewById(R.id.council_members_listingsview);
listingsView.setLayoutManager(new LinearLayoutManager(getContext()));
listingsView.setAdapter(adapter);
final Query cmDb = FirebaseDatabase.getInstance()
.getReference(getString(R.string.firebase_key_council_member))
.orderByChild(getString(R.string.firebase_key_member_id));
cmDb.keepSynced(true);
cmDb.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot data : dataSnapshot.getChildren()){
CouncilMember member = data.getValue(CouncilMember.class);
list.add(member);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例7: getPostList
import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void getPostList(final OnPostListChangedListener<Post> onDataChangedListener, long date) {
DatabaseReference databaseReference = database.getReference("posts");
Query postsQuery;
if (date == 0) {
postsQuery = databaseReference.limitToLast(Constants.Post.POST_AMOUNT_ON_PAGE).orderByChild("createdDate");
} else {
postsQuery = databaseReference.limitToLast(Constants.Post.POST_AMOUNT_ON_PAGE).endAt(date).orderByChild("createdDate");
}
postsQuery.keepSynced(true);
postsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Map<String, Object> objectMap = (Map<String, Object>) dataSnapshot.getValue();
PostListResult result = parsePostList(objectMap);
if (result.getPosts().isEmpty() && result.isMoreDataAvailable()) {
getPostList(onDataChangedListener, result.getLastItemCreatedDate() - 1);
} else {
onDataChangedListener.onListChanged(parsePostList(objectMap));
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
LogUtil.logError(TAG, "getPostList(), onCancelled", new Exception(databaseError.getMessage()));
onDataChangedListener.onCanceled(context.getString(R.string.permission_denied_error));
}
});
}