我想获得特定用户的所有任务(约束数为1), 但只有可用的用户(约束数为2)。
我知道我可以通过'顺序克服一个约束。并且'等于'功能, 但我没有克服第二个问题。
这是我的firebase db:
这是我在应用程序中的当前结果(完成任务就在那里!我不想要它!):
这是我的相关代码:
public class PendingFragmentUser extends Fragment {
private String TAG = "dDEBUG";
private RecyclerView mPendingList;
private DatabaseReference mMissionsDb;
private FirebaseAuth mAuth;
private String mCurrent_user_id;
private View mMainView;
Query queries;
public PendingFragmentUser() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mMainView = inflater.inflate(R.layout.fragment_pending_user, container, false);
mPendingList = (RecyclerView)mMainView.findViewById(R.id.pending_recycler_user);
mAuth = FirebaseAuth.getInstance();
mCurrent_user_id = mAuth.getCurrentUser().getUid();
mMissionsDb = FirebaseDatabase.getInstance().getReference().child("Missions");
queries = mMissionsDb.orderByChild("user_uid").equalTo(mCurrent_user_id);
mMissionsDb.keepSynced(true);
mPendingList.setHasFixedSize(true);
mPendingList.setLayoutManager(new LinearLayoutManager(getContext()));
// Inflate the layout for this fragment
return mMainView;
}
@Override
public void onStart() {
super.onStart();
final FirebaseRecyclerAdapter<Mission, PendingFragmentUser.MissionsViewHolder> firebaseMissionsUserRecyclerAdapter = new FirebaseRecyclerAdapter<Mission, PendingFragmentUser.MissionsViewHolder>(
Mission.class,
R.layout.missions_single_layout,
PendingFragmentUser.MissionsViewHolder.class,
queries
) {
@Override
protected void populateViewHolder(PendingFragmentUser.MissionsViewHolder missionViewHolder, final Mission missionModel, final int missionPosition) {
// Log.d(TAG, "inside populateViewHolder" + missionModel.getType() + " , " + missionModel.getDescription());
missionViewHolder.setMissionName(missionModel.getType());
missionViewHolder.setMissionDescription(missionModel.getDescription());
missionViewHolder.setMissionStatus(missionModel.getStatus());
}
};
mPendingList.setAdapter(firebaseMissionsUserRecyclerAdapter);
}
public static class MissionsViewHolder extends RecyclerView.ViewHolder {
View mView;
Button button ;
public MissionsViewHolder(View itemView) {
super(itemView);
mView = itemView;
button = (Button)mView.findViewById(R.id.pending_single_button);
}
public void setMissionName(String name){
TextView mMissionNameView = mView.findViewById(R.id.mission_single_name);
mMissionNameView.setText(name);
}
public void setMissionStatus(String status){
TextView mMissionStatusView = mView.findViewById(R.id.mission_single_status);
mMissionStatusView.setText(status);
if (status.equals("Available")){
mMissionStatusView.setTextColor(Color.parseColor("#008000"));;
} else {
mMissionStatusView.setTextColor(Color.parseColor("#FF0000"));;
}
}
public void setMissionDescription(String description){
TextView mMissionDescriptionView = mView.findViewById(R.id.mission_single_description);
mMissionDescriptionView.setText(description);
}
}
}
如何克服这种火力基础限制?
过滤特定用户的所有任务:
queries = mMissionsDb.orderByChild("user_uid").equalTo(mCurrent_user_id);
现在我想做:
queries = mMissionsDb.orderByChild("user_uid").equalTo(mCurrent_user_id).orderByChild("status").equalTo("Available");
但它在firebase中是不可能的。
此外,我必须使用实时适配器,因为它的关键是我的UI准确显示数据库中DB的更改延迟最小。感谢