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


Java Query.keepSynced方法代码示例

本文整理汇总了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);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:23,代码来源:KeepSyncedTestIT.java

示例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());
        }
    });
}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:26,代码来源:MainActivity.java

示例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()));
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:20,代码来源:DatabaseHelper.java

示例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);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:KeepSyncedTestIT.java

示例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());
        }
    });

}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:29,代码来源:NotificationActivity.java

示例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) {

        }
    });
}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:32,代码来源:CouncilDetailsFragment.java

示例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));
        }
    });
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:31,代码来源:DatabaseHelper.java


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