當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。