Firestore-添加.whereEqualTo数据后不会实时刷新

时间:2018-12-06 18:47:33

标签: android firebase google-cloud-firestore

添加方法.whereEquals后,此数据不会实时刷新。我需要切换到其他屏幕,然后返回以进行刷新。有谁知道为什么会这样?

代码如下:

        Query query = dailyGoalsRef.whereEqualTo("isNotToDisplay", false).orderBy("date", Query.Direction.ASCENDING);
    FirestoreRecyclerOptions<DailyGoalsModel> firestoreRecyclerOptions = new FirestoreRecyclerOptions.Builder<DailyGoalsModel>()
            .setQuery(query, DailyGoalsModel.class)
            .build();

    firestoreRecyclerAdapter =
            new FirestoreRecyclerAdapter<DailyGoalsModel, DailyGoalsHolder>(firestoreRecyclerOptions) {
                @Override
                protected void onBindViewHolder(@NonNull DailyGoalsHolder holder, int position, @NonNull DailyGoalsModel model) {
                    String fragmentName = "dailyGoals";
                    holder.setGoalsList(context, userEmail, model, fragmentName);
                }

                @NonNull
                @Override
                public DailyGoalsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.daily_goals_list, parent, false);
                    return new DailyGoalsHolder(view);
                }

                @Override
                public void onDataChanged() {
                    if (progressBar != null) {
                        progressBar.setVisibility(View.GONE);
                    }
                    if (getItemCount() == 0) {
                        recyclerView.setVisibility((View.GONE));
                        emptyView.setVisibility((View.VISIBLE));
                    } else {
                        recyclerView.setVisibility(View.VISIBLE);
                        emptyView.setVisibility(View.GONE);
                    }
                }

                @Override
                public int getItemCount() {
                    return super.getItemCount();
                }
            };
    recyclerView.setAdapter(firestoreRecyclerAdapter);
    return layout;

Firestore: enter image description here

值“ isNotToDispaly”的更改

if ((date.getTime()) < (todayDate.getTime() - 2*24*60*60*1000)) {
            rootRef.collection("goalsData").document(userEmail).collection(fragmentName).document(goalsId).update("isNotToDisplay", true);
        }

它位于

public void setGoalsList(final Context context, String userEmail, DailyGoalsModel goalsModel, String fragmentName)

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。这很不寻常,因为它与在Firebase平台中不添加索引有关。