From 8e7491a9ba38a3cb06973d681f0dc28f6208b0f6 Mon Sep 17 00:00:00 2001
From: John Mark Peroche <92581738+Java-rice@users.noreply.github.com>
Date: Tue, 13 Feb 2024 00:03:14 +0800
Subject: [PATCH 1/9] phone call
---
.../mobile/komyusagip/EmergencyContacts.kt | 50 ++++++++++---
.../mobile/komyusagip/EmergencyFragment.kt | 1 -
.../com/mobile/komyusagip/EmergencyHotline.kt | 74 ++++++++++++++++---
3 files changed, 103 insertions(+), 22 deletions(-)
diff --git a/app/src/main/java/com/mobile/komyusagip/EmergencyContacts.kt b/app/src/main/java/com/mobile/komyusagip/EmergencyContacts.kt
index 942b09f..d7de37e 100644
--- a/app/src/main/java/com/mobile/komyusagip/EmergencyContacts.kt
+++ b/app/src/main/java/com/mobile/komyusagip/EmergencyContacts.kt
@@ -1,12 +1,12 @@
package com.mobile.komyusagip
-import android.content.Intent
+
import android.os.Bundle
-import android.widget.Button
import android.widget.ImageButton
import android.widget.LinearLayout
+import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
-class EmergencyContacts : AppCompatActivity() {
+class EmergencyContacts : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.page_emergency_contacts)
@@ -16,7 +16,6 @@ class EmergencyContacts : AppCompatActivity() {
finish()
}
-
// Reference the LinearLayout where you want to add the contact containers
val contactContainerLayout = findViewById(R.id.contactCont)
@@ -31,18 +30,51 @@ class EmergencyContacts : AppCompatActivity() {
R.layout.contact_components,
R.layout.contact_components,
R.layout.contact_components,
- R.layout.contact_components,
- R.layout.contact_components,
- R.layout.contact_components,
R.layout.contact_components
+ // Add more layout IDs as needed
)
- for (contactContainerId in contactContainerIds) {
+ val contactNames = arrayOf(
+ "John Doe",
+ "Jane Doe",
+ "Bob Smith",
+ "Alice Johnson",
+ "David Lee",
+ "Ella Martinez",
+ "Michael Cruz",
+ "Sophia Reyes",
+ "William Garcia",
+ "Olivia Rodriguez"
+ // Add more contact names as needed
+ )
+
+ val contactNumbers = arrayOf(
+ "+639123456789",
+ "+639987654321",
+ "+639555123456",
+ "+639876543210",
+ "+639111223344",
+ "+639876543210",
+ "+639222334455",
+ "+639333445566",
+ "+639444556677",
+ "+639555667788"
+ // Add more valid Philippine phone numbers as needed
+ )
+
+ for (i in contactContainerIds.indices) {
val inflater = layoutInflater
- val contactContainer = inflater.inflate(contactContainerId, null)
+ val contactContainer = inflater.inflate(contactContainerIds[i], null)
// You can customize the contact container programmatically if needed
+ // Set contact details
+ val contactName = contactContainer.findViewById(R.id.contactName)
+ contactName.text = contactNames[i]
+
+ val contactNumber = contactContainer.findViewById(R.id.contactNumber)
+ contactNumber.text = contactNumbers[i]
+
// Add the contact container to the LinearLayout
contactContainerLayout.addView(contactContainer)
}
diff --git a/app/src/main/java/com/mobile/komyusagip/EmergencyFragment.kt b/app/src/main/java/com/mobile/komyusagip/EmergencyFragment.kt
index 0f535e5..cab2442 100644
--- a/app/src/main/java/com/mobile/komyusagip/EmergencyFragment.kt
+++ b/app/src/main/java/com/mobile/komyusagip/EmergencyFragment.kt
@@ -61,7 +61,6 @@ class EmergencyFragment : Fragment() {
val proceedButton = view.findViewById
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2c61ff9..12aee14 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -83,4 +83,7 @@
"Community Watch"
try
+ "Like"
+ "Comment"
+
\ No newline at end of file
From 5fbf00bd29c30f22fb3776b67b5a7278266a253f Mon Sep 17 00:00:00 2001
From: John Patrick Lagatuz
Date: Tue, 13 Feb 2024 22:16:13 +0800
Subject: [PATCH 6/9] added validation for type of crime and description in
activity_createpost.xml
---
app/src/main/java/com/mobile/komyusagip/CreatePost.kt | 11 ++++++++++-
.../main/java/com/mobile/komyusagip/HomeFragment.kt | 4 ++++
app/src/main/res/layout/activity_createpost.xml | 3 ++-
app/src/main/res/values/strings.xml | 2 ++
4 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/com/mobile/komyusagip/CreatePost.kt b/app/src/main/java/com/mobile/komyusagip/CreatePost.kt
index b3e7c48..2cee2c5 100644
--- a/app/src/main/java/com/mobile/komyusagip/CreatePost.kt
+++ b/app/src/main/java/com/mobile/komyusagip/CreatePost.kt
@@ -130,11 +130,20 @@ class CreatePost : AppCompatActivity() {
val description = addDescription.text?.toString()?.trim()
val typeOfCrime = spinnerSelectedValueTextView.text.toString()
- if (description.isNullOrEmpty()) {
+ if (typeOfCrime.isNullOrEmpty() && description.isNullOrEmpty()) {
+ spinnerSelectedValueTextView.error = "Please select the type of crime"
+ addDescription.error = "Add description"
+ return
+ } else if (typeOfCrime.isNullOrEmpty()) {
+ spinnerSelectedValueTextView.error = "Please select the type of crime"
+ return
+ } else if (description.isNullOrEmpty()) {
addDescription.error = "Add description"
return
}
+
+
// Get current user ID
val userId = auth.currentUser?.uid
userId?.let { uid ->
diff --git a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
index 5a838d8..51aea24 100644
--- a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
+++ b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
@@ -72,6 +72,10 @@ class HomeFragment : Fragment() {
val mostRecentCrimeReports = listOf(
CrimeReport("Theft", "Description of theft incident"),
CrimeReport("Assault", "Description of assault incident"),
+ CrimeReport("Assault", "Description of assault incident"),
+ CrimeReport("Assault", "Description of assault incident"),
+ CrimeReport("Assault", "Description of assault incident"),
+ CrimeReport("Assault", "Description of assault incident"),
CrimeReport("Pur", "Description of pur incident")
// Add more crime reports as needed
)
diff --git a/app/src/main/res/layout/activity_createpost.xml b/app/src/main/res/layout/activity_createpost.xml
index b51d91d..817b21a 100644
--- a/app/src/main/res/layout/activity_createpost.xml
+++ b/app/src/main/res/layout/activity_createpost.xml
@@ -257,7 +257,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.491"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/TypeOfCrime" />
+ app:layout_constraintTop_toBottomOf="@+id/TypeOfCrime"
+ android:dropDownVerticalOffset="39dp"/>
"Like"
"Comment"
+ The incident occurred at %1$s on %2$s at %3$s.
+
\ No newline at end of file
From ac96ba7f24268f4e775cf3f2ef3e8baca15f7e7e Mon Sep 17 00:00:00 2001
From: John Patrick Lagatuz
Date: Tue, 13 Feb 2024 23:12:56 +0800
Subject: [PATCH 7/9] added post feature for loadInYourAreaCrimeReports in
HomeFragment.kt
---
.../com/mobile/komyusagip/HomeFragment.kt | 70 ++++++++++++++-----
1 file changed, 53 insertions(+), 17 deletions(-)
diff --git a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
index 51aea24..71d2c21 100644
--- a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
+++ b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
@@ -2,19 +2,27 @@ package com.mobile.komyusagip
import CrimeReport
import CrimeReportAdapter
+import android.content.ContentValues.TAG
+
import android.os.Bundle
+import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import com.google.firebase.auth.FirebaseAuth
+import com.google.firebase.firestore.FirebaseFirestore
class HomeFragment : Fragment() {
private lateinit var recyclerView: RecyclerView
private lateinit var adapter: CrimeReportAdapter
+ private val auth = FirebaseAuth.getInstance()
+ private val db = FirebaseFirestore.getInstance()
+
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@@ -83,22 +91,50 @@ class HomeFragment : Fragment() {
}
private fun loadInYourAreaCrimeReports() {
- // Implement logic to load crime reports in user's area
- val inYourAreaCrimeReports = listOf(
- CrimeReport("Vandalism", "Description of vandalism incident"),
- CrimeReport("Burglary", "Description of burglary incident")
- // Add more crime reports as needed
- )
- adapter.setData(inYourAreaCrimeReports)
- }
+ // Get the current user's ID
+ val userId = auth.currentUser?.uid
+
+ // Check if the user is authenticated
+ userId?.let { uid ->
+ // Reference to the user's "post" subcollection
+ val userPostRef = db.collection("user").document(uid).collection("post")
+
+ // Query Firestore to fetch crime reports in the user's area
+ userPostRef
+ .get()
+ .addOnSuccessListener { documents ->
+ val crimeReports = mutableListOf()
+
+ for (document in documents) {
+ val typeOfCrime = document.getString("typeOfCrime")
+ val description = document.getString("description")
+
+ typeOfCrime?.let { crimeType ->
+ description?.let { desc ->
+ val crimeReport = CrimeReport(crimeType, desc)
+ crimeReports.add(crimeReport)
+ }
+ }
+ }
+
+ // Set data to the adapter after populating the crimeReports list
+ adapter.setData(crimeReports)
+ }
+ .addOnFailureListener { exception ->
+ // Handle any errors
+ Log.e(TAG, "Error fetching crime reports: $exception")
+ }
+ }
+ }
- private fun loadCommunityWatchCrimeReports() {
- // Implement logic to load crime reports for community watch
- val communityWatchCrimeReports = listOf(
- CrimeReport("Drug Trafficking", "Description of drug trafficking incident"),
- CrimeReport("Hit and Run", "Description of hit and run incident")
- // Add more crime reports as needed
- )
- adapter.setData(communityWatchCrimeReports)
+
+ private fun loadCommunityWatchCrimeReports() {
+ // Implement logic to load crime reports for community watch
+ val communityWatchCrimeReports = listOf(
+ CrimeReport("Drug Trafficking", "Description of drug trafficking incident"),
+ CrimeReport("Hit and Run", "Description of hit and run incident")
+ // Add more crime reports as needed
+ )
+ adapter.setData(communityWatchCrimeReports)
+ }
}
-}
From 887aabffa153139a4952115e6c1792a0a7a58347 Mon Sep 17 00:00:00 2001
From: John Patrick Lagatuz
Date: Tue, 13 Feb 2024 23:27:44 +0800
Subject: [PATCH 8/9] added post feature for loadMostRecentCrimeReport in
HomeFragment.kt
---
.../com/mobile/komyusagip/HomeFragment.kt | 47 ++++++++++++++-----
app/src/main/res/layout/item_crime_report.xml | 2 +-
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
index 71d2c21..a0ea4a4 100644
--- a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
+++ b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
@@ -75,19 +75,42 @@ class HomeFragment : Fragment() {
recyclerView.adapter = adapter
}
+
private fun loadMostRecentCrimeReports() {
- // Implement logic to load most recent crime reports
- val mostRecentCrimeReports = listOf(
- CrimeReport("Theft", "Description of theft incident"),
- CrimeReport("Assault", "Description of assault incident"),
- CrimeReport("Assault", "Description of assault incident"),
- CrimeReport("Assault", "Description of assault incident"),
- CrimeReport("Assault", "Description of assault incident"),
- CrimeReport("Assault", "Description of assault incident"),
- CrimeReport("Pur", "Description of pur incident")
- // Add more crime reports as needed
- )
- adapter.setData(mostRecentCrimeReports)
+ // Get the current user's ID
+ val userId = auth.currentUser?.uid
+
+ // Check if the user is authenticated
+ userId?.let { uid ->
+ // Reference to the user's "post" subcollection
+ val userPostRef = db.collection("user").document(uid).collection("post")
+
+ // Query Firestore to fetch crime reports in the user's area
+ userPostRef
+ .get()
+ .addOnSuccessListener { documents ->
+ val crimeReports = mutableListOf()
+
+ for (document in documents) {
+ val typeOfCrime = document.getString("typeOfCrime")
+ val description = document.getString("description")
+
+ typeOfCrime?.let { crimeType ->
+ description?.let { desc ->
+ val crimeReport = CrimeReport(crimeType, desc)
+ crimeReports.add(crimeReport)
+ }
+ }
+ }
+
+ // Set data to the adapter after populating the crimeReports list
+ adapter.setData(crimeReports)
+ }
+ .addOnFailureListener { exception ->
+ // Handle any errors
+ Log.e(TAG, "Error fetching crime reports: $exception")
+ }
+ }
}
private fun loadInYourAreaCrimeReports() {
diff --git a/app/src/main/res/layout/item_crime_report.xml b/app/src/main/res/layout/item_crime_report.xml
index c6293fd..7b10382 100644
--- a/app/src/main/res/layout/item_crime_report.xml
+++ b/app/src/main/res/layout/item_crime_report.xml
@@ -36,7 +36,7 @@
Date: Tue, 13 Feb 2024 23:55:15 +0800
Subject: [PATCH 9/9] added profile picture and username for
loadInYourAreaCrimeReport in HomeFragment.kt
---
.../com/mobile/komyusagip/HomeFragment.kt | 74 ++++++++++++++-----
1 file changed, 54 insertions(+), 20 deletions(-)
diff --git a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
index a0ea4a4..7bde748 100644
--- a/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
+++ b/app/src/main/java/com/mobile/komyusagip/HomeFragment.kt
@@ -10,10 +10,13 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.ImageView
+import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.FirebaseFirestore
+import com.squareup.picasso.Picasso
class HomeFragment : Fragment() {
@@ -123,35 +126,66 @@ class HomeFragment : Fragment() {
val userPostRef = db.collection("user").document(uid).collection("post")
// Query Firestore to fetch crime reports in the user's area
- userPostRef
- .get()
- .addOnSuccessListener { documents ->
- val crimeReports = mutableListOf()
-
- for (document in documents) {
- val typeOfCrime = document.getString("typeOfCrime")
- val description = document.getString("description")
-
- typeOfCrime?.let { crimeType ->
- description?.let { desc ->
- val crimeReport = CrimeReport(crimeType, desc)
- crimeReports.add(crimeReport)
+ userPostRef.get().addOnSuccessListener { documents ->
+ val crimeReports = mutableListOf()
+
+ // Fetch user profile data
+ val profileRef = db.collection("user").document(uid).collection("profiles")
+ profileRef.get().addOnSuccessListener { profileQuerySnapshot ->
+ if (!profileQuerySnapshot.isEmpty) {
+ val profileDocument = profileQuerySnapshot.documents[0]
+ // Fetch data from the profile document
+ val imageUrl = profileDocument.getString("imageUrl")
+ val username = profileDocument.getString("username")
+
+ // Process each crime report document
+ for (document in documents) {
+ val typeOfCrime = document.getString("typeOfCrime")
+ val description = document.getString("description")
+
+ typeOfCrime?.let { crimeType ->
+ description?.let { desc ->
+ val crimeReport = CrimeReport(crimeType, desc)
+ crimeReports.add(crimeReport)
+ }
}
}
- }
- // Set data to the adapter after populating the crimeReports list
- adapter.setData(crimeReports)
- }
- .addOnFailureListener { exception ->
+ // Update profile UI
+ updateProfileUI(requireView(), username, imageUrl)
+
+ // Set data to the adapter after populating the crimeReports list
+ adapter.setData(crimeReports)
+ }
+ }.addOnFailureListener { exception ->
// Handle any errors
- Log.e(TAG, "Error fetching crime reports: $exception")
+ Log.e(TAG, "Error fetching profile data: $exception")
}
+ }.addOnFailureListener { exception ->
+ // Handle any errors
+ Log.e(TAG, "Error fetching crime reports: $exception")
}
}
+ }
+
+ private fun updateProfileUI(view: View, username: String?, imageUrl: String?) {
+ // Update profile picture
+ val profilePicture = view.findViewById(R.id.ProfilePicture)
+ val profileUsername = view.findViewById(R.id.ProfileUsername)
+
+ imageUrl?.let {
+ Picasso.get().load(it).into(profilePicture)
+ }
+ // Update username
+ val userWithAtSymbol = "@$username"
+ profileUsername?.text = userWithAtSymbol
+ }
+
+
+
- private fun loadCommunityWatchCrimeReports() {
+ private fun loadCommunityWatchCrimeReports() {
// Implement logic to load crime reports for community watch
val communityWatchCrimeReports = listOf(
CrimeReport("Drug Trafficking", "Description of drug trafficking incident"),