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


Java Query.addListenerForSingleValueEvent方法代码示例

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


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

示例1: getFollowingList

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void getFollowingList(String userId, final OnCompleteGetUserFollowingListener listener)
{
    RemoteDatabaseManager rdm = new RemoteDatabaseManager();

    Query recentPostsQuery = rdm.getUsersReference().child(userId).child("following")
            .limitToFirst(3000);
    recentPostsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ArrayList<String> arrayList = new ArrayList<String>();

            for (DataSnapshot messageSnapshot: dataSnapshot.getChildren()) {
                String name = (String) messageSnapshot.getKey();
                Log.e("UserManager", "Name : "+ name);
                arrayList.add(name);
            }

            listener.onComplete(arrayList);
            followingListCache = arrayList;
        }

        @Override
        public void onCancelled(DatabaseError databaseError) { }
    });
}
 
开发者ID:icaynia,项目名称:pracler,代码行数:26,代码来源:UserManager.java

示例2: 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

示例3: updateOwnerCollection

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void updateOwnerCollection(final String BookReference) {
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    Query query = mCurrentUser.orderByChild("email").equalTo(user.getEmail());

    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String value = dataSnapshot.getValue().toString();
            String userRef = value.substring(1, value.indexOf('='));
            dataSnapshot.child(userRef).child("owns").child(bookRef).getRef().setValue(1);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e(TAG, "Failed to reach the server");
        }
    });
}
 
开发者ID:Hank-TNguyen,项目名称:BookJobs,代码行数:20,代码来源:BookController.java

示例4: addOnceValueEventListener

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void addOnceValueEventListener(final ReadableArray modifiers,
                                      final Callback callback) {
  final FirestackDBReference self = this;

  mOnceValueListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
      WritableMap data = FirestackUtils.dataSnapshotToMap("value", mPath, dataSnapshot);
      callback.invoke(null, data);
    }

    @Override
    public void onCancelled(DatabaseError error) {
      WritableMap err = Arguments.createMap();
      err.putInt("errorCode", error.getCode());
      err.putString("errorDetails", error.getDetails());
      err.putString("description", error.getMessage());
      callback.invoke(err);
    }
  };

  Query ref = this.getDatabaseQueryAtPathAndModifiers(modifiers);
  ref.addListenerForSingleValueEvent(mOnceValueListener);
}
 
开发者ID:fullstackreact,项目名称:react-native-firestack,代码行数:25,代码来源:FirestackDatabase.java

示例5: getUserList

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void getUserList(final String findname, int limit, final OnCompleteGetUserListListener listener)
{

    RemoteDatabaseManager rdm = new RemoteDatabaseManager();
    // 여기서 검색이 잘 동작하는지 모르겠음.
    Query get = rdm.getUsersReference().orderByChild("profile/name").startAt(findname);

    get.addListenerForSingleValueEvent(new ValueEventListener()
    {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot)
        {
            ArrayList<User> arrayList = new ArrayList<>();

            Iterator<DataSnapshot> i = dataSnapshot.getChildren().iterator();

            while (i.hasNext())
            {
                Log.e("UserManaer", "get");
                DataSnapshot d = i.next();
                User user = (User) d.child("profile").getValue(User.class);

                if (user != null)
                if (user.name.contains(findname))
                    arrayList.add(user);

                Log.e("UserManaer", user.name);
            }

            listener.onComplete(arrayList);
        }

        @Override
        public void onCancelled(DatabaseError databaseError)
        {

        }
    });
}
 
开发者ID:icaynia,项目名称:pracler,代码行数:40,代码来源:UserManager.java

示例6: loadDataFromId

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void loadDataFromId(final String idx) {
    Query query = References.getInstance().chatsRef.child(idx);
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.getValue() != null) {
                Map<String, Object> messageData = (Map<String, Object>) dataSnapshot.getValue();
                Message message = new Message(mUser.getIdx(), messageData);
                Map<String, Object> phones = getMapDataFromData("phones", messageData);
                if (message.getChatType() == ChatType.PERSONAL) {
                    String key = dataSnapshot.getKey();
                    String[] userIds = Util.getUserIdsFrom(key);
                    String contactId = null;
                    for (String userId : userIds) {
                        if (!userId.equals(mUser.getIdx())) {
                            contactId = userId;
                        }
                    }

                    mPhoneContactNumber = (String) phones.get(contactId);
                    updateContactName(mPhoneContactNumber);

                    updateData(message, contactId);

                } else {

                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e("ChatListAdapter", databaseError.toString());
        }
    });

    updateUnreadCount(0);
}
 
开发者ID:AppHero2,项目名称:Raffler-Android,代码行数:39,代码来源:ChatListRecyclerViewAdapter.java

示例7: getUser

import com.google.firebase.database.Query; //导入方法依赖的package包/类
/**
 * This function is used to get user data from firebase database
 * @param userId : registered user id to get
 * @param listener : callback to get event
 */
public static void getUser(String userId, final UserValueListener listener) {
    if (userId != null) {
        Query query = References.getInstance().usersRef.child(userId);
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.getValue() != null){
                    Map<String, Object> userData = (Map<String, Object>) dataSnapshot.getValue();
                    User user = new User(userData);
                    if (listener != null) {
                        listener.onLoadedUser(user);
                    }
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.d("TrackUser", databaseError.toString());
            }
        });
    } else {
        if (listener != null) {
            listener.onLoadedUser(null);
        }
    }
}
 
开发者ID:AppHero2,项目名称:Raffler-Android,代码行数:32,代码来源:AppManager.java

示例8: 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

示例9: onQueryTextChange

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
public boolean onQueryTextChange(String s) {
    currentSearchRequest = s;
    if (s.length() == 0) {
        clearList();
        searchAdapter.notifyDataSetChanged();
    } else {
        Query query = databaseReference
                .child("users")
                .orderByChild("caseFoldedName")
                .startAt(s.toLowerCase()).endAt(s.toLowerCase() + "~")
                .limitToFirst(20);
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                clearList();
                for (DataSnapshot ds : dataSnapshot.getChildren()) {
                    if (!ds.getKey().equals(uid)) {
                        addUsersToView(ds);
                    }
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
    return false;
}
 
开发者ID:STUDIO-apps,项目名称:GeoShare_Android,代码行数:32,代码来源:FriendSearchActivity.java

示例10: updateUsers

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void updateUsers(Query query) {

        query.addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        // Get user value
                        // Toast.makeText(getActivity(), "count = " + dataSnapshot.getChildrenCount(), Toast.LENGTH_SHORT).show();
                        List<User> users = new ArrayList<>();
                        for (DataSnapshot ds : dataSnapshot.getChildren()) {
                            User user = ds.getValue(User.class);
                            user.setUid(ds.getKey());
                            users.add(user);

                        }

                        mAdapter.setUsers(users);
                        mAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.w(TAG, "getUser:onCancelled", databaseError.toException());
                        // ...
                    }
                });
    }
 
开发者ID:shawara,项目名称:ChatUp,代码行数:28,代码来源:SearchUsersFragment.java

示例11: isFavourite

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void isFavourite(Context context, final String placeId) {
    /*String URL = PlacesProvider.URL;
    Uri places = Uri.parse(URL);
    Cursor cursor = null;
    cursor = context.getContentResolver().query(places, null, PlacesSQLiteHelper.ID +" = '"+ placeId +"'", null, PlacesSQLiteHelper.ROW_ID);
    if (cursor != null&&cursor.moveToNext()) {
        return true;
    } else {
        return false;
    }*/
    isFavPlace = false;
    Query placeQuery = mFavsDbRef.orderByChild(Constants.title_node_place_id).equalTo(placeId);
    placeQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                if (snapshot.exists()) {
                    isFavPlace = true;
                    fabFav.setImageResource(R.drawable.ic_favorite_white_24px);
                }
            }

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e(TAG, "onCancelled " + databaseError.toException());
        }
    });

}
 
开发者ID:thesabareesh,项目名称:protrip,代码行数:32,代码来源:PlaceDetailActivity.java

示例12: updateDatabase

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void updateDatabase() {

        if(currentBookIndex!=-1)
        {

            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            final Book book = bookArrayList.get(currentBookIndex);
            Query query = mCurrentUserReference.orderByChild("email").equalTo(user.getEmail());

            query.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    String value = dataSnapshot.getValue().toString();
                    String userRef = value.substring(1, value.indexOf('='));
                    if(book!=null)
                    {

                        dataSnapshot.child(userRef).child("wants").child(book.getmISBN()).getRef().setValue(1);
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    Log.e("BooksFragment", "Failed to reach the server");
                }
            });

        }
        else
        {
            Toast.makeText(getContext(),"No More Books To Show", Toast.LENGTH_SHORT).show();
        }



    }
 
开发者ID:Hank-TNguyen,项目名称:BookJobs,代码行数:37,代码来源:BooksFragment.java

示例13: createIco

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void createIco(Company savecompany) {

    mDatabase = FirebaseDatabase.getInstance().getReference();
    Query myTopPostsQuery = mDatabase.child("companies").child(savecompany.cmico);
    myTopPostsQuery.addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
        // the initial data has been loaded, hide the progress bar

        Company result = dataSnapshot.getValue(Company.class);
          if( result != null ) {
            String texttoast = getString(R.string.companyexist, savecompany.cmico);
            //String texttoast = "New Company did not create. Company " + savecompany.cmico + " already exist.";
            Toast.makeText(CompanyChooseBaseSearchActivity.this, texttoast, Toast.LENGTH_LONG).show();
          }else{
            //Log.d("callsaveIco ", savecompany.cmico + " " + savecompany.cmname + " " + savecompany.cmcity + " " + savecompany.cmakt + " " + savecompany.cmdom + " " + savecompany.cmfir);
            saveNewCompany(savecompany);
          }
       }

      @Override
      public void onCancelled(DatabaseError firebaseError) {

      }
    });

  }
 
开发者ID:eurosecom,项目名称:Attendance,代码行数:28,代码来源:CompanyChooseBaseSearchActivity.java

示例14: addMember

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
public void addMember(final String chatId, String username) {
    final FirebaseDatabase db = FirebaseDatabase.getInstance();

    // create references
    final DatabaseReference usersRef = db.getReference().child("users");
    final DatabaseReference membersRef = db.getReference().child("members");

    final Long timestamp = System.currentTimeMillis();

    // get partner's id
    Query query = usersRef.orderByChild("username").startAt(username).endAt(username);
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.getChildrenCount() != 1) {
                Log.d("CHAT", "User not found!");
                return;
            }

            String partnerId = dataSnapshot.getChildren().iterator().next().getKey();

            membersRef.child(chatId).child(partnerId).setValue(timestamp);

            // create chat entry in users
            usersRef.child(partnerId).child("chats").child(chatId).setValue(true);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:feberhard,项目名称:LLAMA,代码行数:35,代码来源:ChatService.java

示例15: updateCurrentUserName

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
public void updateCurrentUserName(final String username, final Runnable alreadyTakenAction) {
    final DatabaseReference usersRef = FirebaseDatabase.getInstance().getReference().child("users");

    Query query = usersRef.orderByChild("username").startAt(username).endAt(username);
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.getChildrenCount() == 1) {
                Log.d("SETTINGS", "Username already existed!");
                alreadyTakenAction.run();
                return;
            }

            String userId = getCurrentUserId();

            usersRef.child(userId)
                    .child("username")
                    .setValue(username);

            User user = userCache.get(userId);
            if (user != null)
                user.setUsername(username);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:feberhard,项目名称:LLAMA,代码行数:32,代码来源:UserService.java


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