Skip to content

working on reports #21

Merged
merged 1 commit into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

recyclerView = root.findViewById(R.id.recyclerView2);

recyclerView.addView(submitButton);
// recyclerView.addView(submitButton);

return root;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sf.stormwaterutilityandroid.Construction;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -17,16 +19,22 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;

import com.sf.stormwaterutilityandroid.ConstructionFormData;
import com.sf.stormwaterutilityandroid.ConstructionReportAdapter;
import com.sf.stormwaterutilityandroid.R;
import com.sf.stormwaterutilityandroid.ReportAdapter;
import com.sf.stormwaterutilityandroid.User;
import com.sf.stormwaterutilityandroid.WaterWay.WaterWayReport;


import java.util.ArrayList;
Expand All @@ -42,13 +50,22 @@ public class ConstructionReportsFragment extends Fragment {
List<ConstructionFormData> reportList = new ArrayList<>();
//TODO: LayoutInflator inflater, ViewGroup container,Might not be needed
//This was a public void

ConstructionReportAdapter reportAdapter;
//TODO: Need vars for formdata

//TODO: Need a var for tvReports: UITableView!
// List<Report> reportList = new ArrayList<>();
//TODO: LayoutInflator inflater, ViewGroup container,Might not be needed
//This was a public void
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.activity_reports, container, false);
recyclerView = view.findViewById(R.id.recyclerView);

// recyclerView = view.findViewById(R.id.recyclerView);
reportList = new ArrayList<>();
reportAdapter = new ConstructionReportAdapter(reportList);


btnSiteName = view.findViewById(R.id.btn_site_name);
Expand All @@ -58,26 +75,61 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
recyclerView = view.findViewById(R.id.recyclerView);

fetchData();
searchBar.addTextChangedListener(new TextWatcher() {


@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().length() == 0) {
fetchData();
}
}

@Override
public void afterTextChanged(Editable s) {

}


});

btnSiteName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//startActivity(new Intent(Reports.this, Site_name.class));
String txt = searchBar.getText().toString().trim();
if (txt.isEmpty() || txt ==null) {
return;
}
fetchFilteredDate(txt,"location");

}
});

btnDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//startActivity(new Intent(Reports.this, Date.class));
String txt = searchBar.getText().toString().trim();
if (txt.isEmpty() || txt ==null) {
return;
}
fetchFilteredDate(txt,"date");
}
});

btnInspectorName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//startActivity(new Intent(Reports.this, Inspector_name.class));
String txt = searchBar.getText().toString().trim();
if (txt.isEmpty() || txt ==null) {
return;
}
fetchFilteredDate(txt,"inspector");
}
});

Expand All @@ -86,27 +138,48 @@ public void onClick(View v) {


}

private void fetchFilteredDate(String txt, String searchField) {
FirebaseFirestore.getInstance().collection("Forms").document(User.agid).collection("Construction").whereEqualTo(searchField,txt).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
reportList.clear();
if (task.isSuccessful() && task != null) {
for(QueryDocumentSnapshot document:task.getResult()) {
reportList.add(document.toObject(ConstructionFormData.class));
}
reportAdapter.notifyDataSetChanged();
}
}
});


}

public void fetchData() {
final ConstructionReportAdapter reporter = new ConstructionReportAdapter(reportList);
FirebaseFirestore.getInstance().collection("ConstructionForms").orderBy("SortTimeStamp", Query.Direction.DESCENDING).addSnapshotListener(new EventListener<QuerySnapshot>() {

FirebaseFirestore.getInstance().collection("Forms").document(User.agid).collection("Construction").orderBy("SortTimeStamp", Query.Direction.DESCENDING).addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@javax.annotation.Nullable QuerySnapshot queryDocumentSnapshots, @javax.annotation.Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.i("Error", "No data");
}
reportList.clear();
System.out.println("108:" +queryDocumentSnapshots.size());
for (DocumentSnapshot d:queryDocumentSnapshots){
//needs to be changed to waterway data type

reportList.add( d.toObject(ConstructionFormData.class));
}
System.out.println(reportList.size());

reporter.notifyDataSetChanged();
reportAdapter.notifyDataSetChanged();
}
});
RecyclerView.LayoutManager layoutmanager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutmanager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(reporter);
recyclerView.setAdapter(reportAdapter);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,124 @@
package com.sf.stormwaterutilityandroid;

import com.google.firebase.firestore.GeoPoint;
import com.google.firebase.firestore.ServerTimestamp;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ConstructionFormData {
public class ConstructionFormData implements Serializable {
private Map<String, Object> data;
// String contact
// String date
// String inspector
// String location
String contact;
String date;
String inspector;
String location;
GeoPoint geoPoint;
@ServerTimestamp Date timeStamp;

// (they are lists because firebase doesn't serialize arrays)
// List<String> answers
// List<String> imgLink
List<String> answers;
List<String> imgLink;

public ConstructionFormData(String contact, String date, String inspector,
String location, List<String> answers, List<String> imgLink) {
public ConstructionFormData(String contact, String date, String inspector, Date timestamp, String location,
GeoPoint geoPoint, List<String> answers, List<String> imgLinks) {
this.contact = contact;
this.date = date;
this.inspector = inspector;
this.timeStamp = timestamp;
data = new HashMap<>();
this.location = location;
this.geoPoint = geoPoint;
this.answers = answers;
this.imgLink = imgLinks;
}
public ConstructionFormData(String contact, String date, String inspector, Date timestamp, String location,
List<String> answers, List<String> imgLinks) {
this.contact = contact;
this.date = date;
this.inspector = inspector;
this.timeStamp = timestamp;
data = new HashMap<>();
data.put("contact", contact);
data.put("date", date);
data.put("inspector", inspector);
data.put("location", location);
data.put("answers", answers);
data.put("imgLink", imgLink);
this.location = location;
this.answers = answers;
this.imgLink = imgLinks;
}

public ConstructionFormData() {
}

public Map<String, Object> getData() {
return data;
}

public void setData(Map<String, Object> data) {
this.data = data;
}

public String getContact() {
return contact;
}

public void setContact(String contact) {
this.contact = contact;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public String getInspector() {
return inspector;
}

public void setInspector(String inspector) {
this.inspector = inspector;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

public GeoPoint getGeoPoint() {
return geoPoint;
}

public void setGeoPoint(GeoPoint geoPoint) {
this.geoPoint = geoPoint;
}

public Date getTimeStamp() {
return timeStamp;
}

public void setTimeStamp(Date timeStamp) {
this.timeStamp = timeStamp;
}

public List<String> getAnswers() {
return answers;
}

public void setAnswers(List<String> answers) {
this.answers = answers;
}

public List<String> getImgLink() {
return imgLink;
}

public void setImgLink(List<String> imgLink) {
this.imgLink = imgLink;
}

public Map<String, Object> getMap() {
Expand All @@ -37,4 +132,4 @@ public String toString() {
'}';
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public ConstructionReportAdapter.MyHolder onCreateViewHolder(ViewGroup parent, i
public void onBindViewHolder(ConstructionReportAdapter.MyHolder holder, final int position) {

final ConstructionFormData data = listdata.get(position);
//holder.inspectorName.setText(data.getInspectorName());
// holder.site.setText(data.getSite());
// holder.date.setText((CharSequence) data.getDate());
holder.inspectorName.setText(data.getInspector());
holder.site.setText(data.getLocation());
holder.date.setText((data.getDate()));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ private void setupForm() {
List<String> imgLink = new ArrayList<>();
imgLink.add(evidenceTextField.getValue());

ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink);
// ConstructionFormData constructionFormData = new ConstructionFormData(contact, date, inspector, location, answersList, imgLink);


// submit data to firestore
uploadToFirestore(constructionFormData);
// uploadToFirestore(constructionFormData);
});


Expand Down