Skip to content

Commit

Permalink
working on report page
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelford24 authored and Samuelford24 committed Apr 14, 2021
1 parent 9b8288e commit ff4457c
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 68 deletions.
18 changes: 17 additions & 1 deletion app/src/main/java/com/sf/stormwaterutilityandroid/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

if (firebaseAuth.getCurrentUser() != null && auth.getCurrentUser().isEmailVerified()) {
// fetchAgencyID();
startActivity(new Intent(Login.this, WaterWayNav.class));
finish();
}
Expand All @@ -54,14 +55,17 @@ public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
};



setContentView(R.layout.activity_login);
inputEmail = findViewById(R.id.email);
inputPassword = findViewById(R.id.password);
progressBar = findViewById(R.id.progressBar3);
btnSignup = findViewById(R.id.btn_signup);
btnLogin = findViewById(R.id.btn_login);
btnReset = findViewById(R.id.btn_reset_password);

if (auth.getCurrentUser() != null) {
fetchAgencyID();
}
//Get Firebase auth instance
auth = FirebaseAuth.getInstance();

Expand Down Expand Up @@ -166,4 +170,16 @@ public void onClick(DialogInterface dialog, int id) {

}

private void fetchAgencyID() {
System.out.println("Execute 171");
FirebaseFirestore.getInstance().collection("Users").document(auth.getUid()).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
System.out.println("Execute 174");
User.agid = task.getResult().toObject(User.class).getAgencyID();
System.out.println(User.agid);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ public ReportAdapter.MyHolder onCreateViewHolder(ViewGroup parent, int viewType)

public void onBindViewHolder(ReportAdapter.MyHolder holder, final int position) {

// final Report data = listdata.get(position);
// holder.inspectorName.setText(data.getInspectorName());
// holder.site.setText(data.getSite());
// holder.date.setText((CharSequence) data.getDate());
final WaterWayReport data = listdata.get(position);
holder.inspectorName.setText(data.getH_inspector_name());
holder.site.setText(data.getH_site_name());
holder.date.setText(data.getH_date());


}

@Override
public int getItemCount() {
return 0;
if (listdata == null) {
return 0;
}
return listdata.size();
}

// @Override
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/sf/stormwaterutilityandroid/User.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.sf.stormwaterutilityandroid;

class User {
public class User {
String name, email, uid,agencyID;
public static String agid;

public User() {
}

public User(String name, String email, String uid, String agencyID) {
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class WaterWayReport {
Map<String, Double> doubleFields = new HashMap<>();
Map<String,String> stringFields = new HashMap<>();

public WaterWayReport() {
}

public WaterWayReport(String h_date, String h_inspector_name, String h_site_name, Timestamp sortTimeStamp, GeoPoint location, Map<String, Boolean> boolFields, Map<String, Double> doubleFields, Map<String, String> stringFields) {
H_date = h_date;
H_inspector_name = h_inspector_name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sf.stormwaterutilityandroid.WaterWay;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
Expand All @@ -22,28 +24,36 @@
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.android.material.bottomnavigation.BottomNavigationView;
import com.google.firebase.auth.FirebaseAuth;
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.ConstructionReportAdapter;
import com.sf.stormwaterutilityandroid.R;

import com.sf.stormwaterutilityandroid.ReportAdapter;
import com.sf.stormwaterutilityandroid.User;

import org.w3c.dom.Document;

import java.util.ArrayList;
import java.util.List;


public class WaterWayReportFragment extends Fragment {

private SearchView searchBar;//TODO: Make a search bar later?
private EditText searchBar;//TODO: Make a search bar later?
private RecyclerView recyclerView;
private Button btnSiteName, btnDate, btnInspectorName;
List<WaterWayReport> reportList;
ReportAdapter reportAdapter;
//TODO: Need vars for formdata

//TODO: Need a var for tvReports: UITableView!
Expand All @@ -55,8 +65,9 @@ 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 ReportAdapter(reportList);


btnSiteName = view.findViewById(R.id.btn_site_name);
Expand All @@ -66,26 +77,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,"H_site_name");

}
});

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,"H_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,"H_inspector_name");
}
});

Expand All @@ -94,21 +140,40 @@ public void onClick(View v) {


}

private void fetchFilteredDate(String txt, String searchField) {
FirebaseFirestore.getInstance().collection("Forms").document(User.agid).collection("Waterway").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(WaterWayReport.class));
}
reportAdapter.notifyDataSetChanged();
}
}
});


}

public void fetchData() {
List<WaterWayReport> reportList = new ArrayList<>();
final ReportAdapter reportAdapter = new ReportAdapter(reportList);
FirebaseFirestore.getInstance().collection("AquaSourceForms").orderBy("SortTimeStamp", Query.Direction.DESCENDING).addSnapshotListener(new EventListener<QuerySnapshot>() {

FirebaseFirestore.getInstance().collection("Forms").document(User.agid).collection("Waterway").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(WaterWayReport.class));
}
System.out.println(reportList.size());

reportAdapter.notifyDataSetChanged();
}
Expand Down
77 changes: 25 additions & 52 deletions app/src/main/res/layout/activity_reports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,91 +6,64 @@

android:layout_height="match_parent">

<RelativeLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/design_default_color_background"
android:gravity="center"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchView">


<!-- Login Button -->

<!-- Link to Login Screen android:translationX="-105.0dp"
android:translationY="-260.0dp"
android:translationX="110.0dp"
android:translationY="-260dp"
android:translationX="15.0dp"
android:translationY="-260dp"-->

</RelativeLayout>

<SearchView
<EditText
android:id="@+id/searchView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
android:hint="Date,name,or site" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/navigation"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_site_name" />
app:layout_constraintTop_toBottomOf="@+id/btn_inspector_name" />

<Button
android:id="@+id/btn_site_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="16dp"
android:text="SN"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchView" />
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toStartOf="@+id/btn_inspector_name"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/btn_inspector_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="9dp"
android:text="IN"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toStartOf="@+id/btn_date"
app:layout_constraintStart_toEndOf="@+id/btn_site_name"
app:layout_constraintTop_toBottomOf="@+id/searchView" />
app:layout_constraintStart_toEndOf="@+id/btn_site_name" />

<Button
android:id="@+id/btn_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:layout_marginEnd="6dp"
android:text="D"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchView" />
app:layout_constraintStart_toEndOf="@+id/btn_inspector_name" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="119dp" />


</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit ff4457c

Please sign in to comment.