Я сделал RecyclerView
с CardViews
, который извлекает два TextViews
из облачного хранилища пожаров, и всякий раз, когда я нажимаю на карту, я хочу, чтобы на основе pdfUrl
, хранящейся в моей базе данных пожарного хранилища, было выполнено действиеоткрыть PDF или загрузить PDF на телефон.Но я не знаю, как этого добиться.
Вот моя структура пожарного депо
Мой код:
public class RecylerViewTestsActivity extends AppCompatActivity {
RecyclerView recyclerView;
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private FirestoreRecyclerAdapter<uploadTests, TestesViewHolder> adapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recyler_view_tests);
RecyclerView recyclerView = findViewById(R.id.recyclerViewTests);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
Query query = rootRef.collection("FilterPDFUploads");
FirestoreRecyclerOptions<uploadTests> options = new FirestoreRecyclerOptions.Builder<uploadTests>()
.setQuery(query, uploadTests.class)
.build();
adapter = new FirestoreRecyclerAdapter<uploadTests,TestesViewHolder >(options) {
@Override
protected void onBindViewHolder(@NonNull TestesViewHolder holder, int position, @NonNull uploadTests model) {
holder.setTestesDesc(model.getDescription());
holder.setTestesName(model.getUsername());
}
@NonNull
@Override
public TestesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pdf_tests_items, parent, false);
return new TestesViewHolder(view);
}
};
recyclerView.setAdapter(adapter);
}
//////////////////////////VIEW HOLDER////////////////////////////////////////////
private class TestesViewHolder extends RecyclerView.ViewHolder {
private View view;
private CardView itemsCard;
TestesViewHolder(final View itemView) {
super(itemView);
view = itemView;
}
void setTestesDesc (String descri) {
TextView desc = view.findViewById(R.id.teste_description);
desc.setText(descri);
}
void setTestesName (String username) {
TextView user = view.findViewById(R.id.name_id);
user.setText(username);
}
void setPdfUrl(final String url){
}
}
//////////////////////////VIEW HOLDER////////////////////////////////////////////
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
if (adapter != null) {
adapter.stopListening();
}
}
}