FragmentSimulators.java
public class FragmentSimulators extends Fragment implements View.OnClickListener {
RecyclerView RVSimulators;
ArrayList<Simulators> simulators = new ArrayList<>();
FirebaseFirestore db = FirebaseFirestore.getInstance();
FloatingActionButton floatingActionButton;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_simulators, container, false);
RVSimulators = (RecyclerView) view.findViewById(R.id.simulators_recycler);
floatingActionButton = (FloatingActionButton) view.findViewById(R.id.fab);
floatingActionButton.setOnClickListener(this);
RVSimulators.setLayoutManager(new LinearLayoutManager(this.getActivity()));
final DataAdapterSimulators adapter = new DataAdapterSimulators(this.getActivity(), simulators);
RVSimulators.setAdapter(adapter);
db.collection("simulators")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Simulators simulatorsClass = document.toObject(Simulators.class);
simulators.add(new Simulators(simulatorsClass.name, simulatorsClass.description, simulatorsClass.photoID));
}
Log.d("logmy", "прогрузились документы");
} else {
Log.w("logmy", "Error getting documents.", task.getException());
}
}
});
return view;
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.fab:
Intent intent = new Intent(FragmentSimulators.this.getContext(), AddSimulator.class);
startActivity(intent);
break;
}
}
}