Second Commit:

Version 1.5 [Partialy Optimized Version] [UI Fixes And Improvment]
Todo:
Optimized the Code
Add String Theolgy
This commit is contained in:
Diassdp
2025-02-10 10:23:19 +07:00
parent d8cb493832
commit d96b96bf42
10 changed files with 75 additions and 82 deletions

View File

@ -41,16 +41,14 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
// Create notification channel
NotificationUtils.createNotificationChannel(this)
// Schedule reminders
scheduleHealthReminders(this)
setContentView(binding.root)
user = FirebaseAuth.getInstance()
database = FirebaseDatabase.getInstance()
userCheck()
setupListener()
populateHistory()
navigationBottomBar()
}
@ -141,33 +139,12 @@ class MainActivity : AppCompatActivity() {
}
}
private fun addJournal(){
if (dailyReport != false){
Toast.makeText(this, "Daily Report Already Created", Toast.LENGTH_SHORT).show()
} else {
startActivity(Intent(this, JournalInputActivity::class.java))
}
}
private fun home(){
}
private fun profile(){
intent = Intent(this, ProfileActivity::class.java)
startActivity(intent)
}
private fun setupListener(){
binding.btnRecomendation.setOnClickListener {
startActivity(Intent(this, RecommendationActivity::class.java))
finish()
}
binding.btnInputData.setOnClickListener {
startActivity(Intent(this, JournalInputActivity::class.java))
finish()
}
}
@ -213,19 +190,18 @@ class MainActivity : AppCompatActivity() {
}
private fun userCheck() {
val user = FirebaseAuth.getInstance().currentUser
if (user == null) {
Toast.makeText(this, "Please Login to an account", Toast.LENGTH_SHORT).show()
user = FirebaseAuth.getInstance()
// Redirect to LoginActivity
if (user.currentUser == null) {
Toast.makeText(this, "Please Login to an account", Toast.LENGTH_SHORT).show()
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
finish()
} else {
Toast.makeText(this, "Welcome back!", Toast.LENGTH_SHORT).show()
dailycheck()
getWeekCount()
populateHistory()
}
}
@ -250,7 +226,7 @@ class MainActivity : AppCompatActivity() {
val systolicBP = snapshot.child("bloodPressureSYS").value.toString().toIntOrNull() ?: 0
val BMI = snapshot.child("bmi").value.toString().toFloatOrNull() ?: 0f
val date = snapshot.child("date").value.toString()
val task = snapshot.child("recommendation").child("task").value as? List<Map<String, Any>> ?: emptyList()
val task = snapshot.child("recommendation").child("tasks").value as? List<Map<String, Any>> ?: emptyList()
val resultData = ResultData(journalID, bloodSugar, diastolicBP, systolicBP, BMI, date, task)
healthDataList.add(resultData)
@ -264,21 +240,27 @@ class MainActivity : AppCompatActivity() {
}
private fun populateTodayReport(referencePath: String){
val userID = user.currentUser!!.uid
database.getReference("users").child(userID).child("journal").child(referencePath).get().addOnCompleteListener {
if (it.isSuccessful) {
binding.tvBloodsugarLevel.text = it.result.child("bloodSugar").value.toString()+" mg/dL"
binding.tvBloodsugarDesc.text = it.result.child("recommendation").child("bloodSugarAnalysis").value.toString()
binding.tvBloodpressureLevel.text = it.result.child("bloodPressureDIA").value.toString()+"/"+it.result.child("bloodPressureSYS").value.toString()+" mm Hg"
binding.tvBloodpressureDesc.text = it.result.child("recommendation").child("bloodPressureAnalysis").value.toString()
binding.tvBmiLevel.text = it.result.child("BMI").value.toString() +" BMI"
binding.tvBmiDesc.text = it.result.child("recommendation").child("BMIAnalysis").value.toString()
} else {
Log.d("error", it.exception!!.message.toString())
Toast.makeText(this, it.exception!!.message, Toast.LENGTH_SHORT).show()
}
}
private fun populateTodayReport(referencePath: String) {
if (!::user.isInitialized || user.currentUser == null) {
Log.e("MainActivity", "User not logged in, cannot fetch today's report")
return
}
val userID = user.currentUser!!.uid
database.getReference("users").child(userID).child("journal").child(referencePath)
.get().addOnCompleteListener {
if (it.isSuccessful) {
val bmiValue = it.result.child("BMI").value.toString().toDoubleOrNull() ?: 0.0
binding.tvBloodsugarLevel.text = it.result.child("bloodSugar").value.toString() + " mg/dL"
binding.tvBloodsugarDesc.text = it.result.child("recommendation").child("bloodSugarAnalysis").value.toString()
binding.tvBloodpressureLevel.text = it.result.child("bloodPressureDIA").value.toString() + "/" + it.result.child("bloodPressureSYS").value.toString() + " mm Hg"
binding.tvBloodpressureDesc.text = it.result.child("recommendation").child("bloodPressureAnalysis").value.toString()
binding.tvBmiLevel.text = String.format(Locale.getDefault(), "%.2f BMI", bmiValue)
binding.tvBmiDesc.text = it.result.child("recommendation").child("BMIAnalysis").value.toString()
} else {
Log.e("MainActivity", "Error fetching today's report: ${it.exception?.message}")
Toast.makeText(this, it.exception?.message, Toast.LENGTH_SHORT).show()
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.healthjournal.ui.dashboard
import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -49,19 +50,23 @@ class MainAdapter(private val healthDataList: MutableList<ResultData>) : Recycle
}
}
private fun countGoals (list: List<Map<String, Any>>): String {
private fun countGoals(taskList: List<Map<String, Any>>): String {
Log.d("debug", taskList.toString())
var completedGoals = 0
var goalsCount = 0
for (item in list) {
if (item["completed"] == true) {
val totalGoals = taskList.size
for (task in taskList) {
val isCompleted = task["completed"] as? Boolean ?: false
if (isCompleted) {
completedGoals++
}
goalsCount++
}
if (completedGoals == 0) {
return "No goals completed"
return when {
totalGoals == 0 -> "No goals available"
completedGoals == 0 -> "No goals completed"
else -> "$completedGoals/$totalGoals goals completed"
}
return "$completedGoals/$goalsCount goals completed"
}
override fun onBindViewHolder(holder: HealthViewHolder, position: Int) {

View File

@ -55,11 +55,14 @@ class DetailJournalActivity : AppCompatActivity() {
if (task.isSuccessful) {
val result = task.result
if (result.exists()) {
val bmiValue = result.child("BMI").value.toString().toFloatOrNull() ?: 0f
Log.d("debug", bmiValue.toString())
binding.tvBloodsugarLevel2.text = "${result.child("bloodSugar").value ?: "N/A"} mg/dL"
binding.tvBloodsugarDesc.text = result.child("recommendation").child("bloodSugarAnalysis").value?.toString() ?: "No data"
binding.tvBloodpressureLevel2.text = "${result.child("bloodPressureDIA").value ?: "N/A"}/${result.child("bloodPressureSYS").value ?: "N/A"} mm Hg"
binding.tvBloodpressureDesc.text = result.child("recommendation").child("bloodPressureAnalysis").value?.toString() ?: "No data"
binding.tvBMILevel2.text = "${result.child("BMI").value ?: "N/A"} BMI"
binding.tvBMILevel2.text = String.format("%.2f BMI", bmiValue)
binding.tvBMIDesc.text = result.child("recommendation").child("BMIAnalysis").value?.toString() ?: "No data"
binding.tvJournalNote.text = result.child("note").value?.toString() ?: "No notes available"
@ -111,5 +114,4 @@ class DetailJournalActivity : AppCompatActivity() {
deleteHistory()
}
}
}

View File

@ -14,7 +14,7 @@ class RecommendationAdapter(
) : RecyclerView.Adapter<RecommendationAdapter.RecommendationViewHolder>() {
inner class RecommendationViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val tvGoalName: TextView = view.findViewById(R.id.tv_goal_name)
val tvGoal: TextView = view.findViewById(R.id.tv_goal)
val checkBox: CheckBox = view.findViewById(R.id.toggle)
}
@ -26,7 +26,7 @@ class RecommendationAdapter(
override fun onBindViewHolder(holder: RecommendationViewHolder, position: Int) {
val (task, isCompleted) = recommendationList[position]
holder.tvGoalName.text = task
holder.tvGoal.text = task
holder.checkBox.isChecked = isCompleted
holder.checkBox.setOnCheckedChangeListener { _, isChecked ->
onCheckedChange(position, isChecked)

View File

@ -39,11 +39,13 @@ class RecommendationActivity : AppCompatActivity() {
if (task.isSuccessful) {
task.result.children.forEach {
if (it.child("date").value.toString() == today) {
val bmiValue = it.child("BMI").value.toString().toDoubleOrNull() ?: 0.0
binding.tvBloodsugarLevel2.text = "${it.child("bloodSugar").value} mg/dL"
binding.tvBloodsugarDesc.text = it.child("recommendation").child("bloodSugarAnalysis").value.toString()
binding.tvBloodpressureLevel2.text = "${it.child("bloodPressureDIA").value}/${it.child("bloodPressureSYS").value} mm Hg"
binding.tvBloodpressureDesc.text = it.child("recommendation").child("bloodPressureAnalysis").value.toString()
binding.tvBMILevel2.text = "${it.child("BMI").value} BMI"
binding.tvBMILevel2.text = "${bmiValue} BMI"
binding.tvBMIDesc.text = it.child("recommendation").child("BMIAnalysis").value.toString()
val tasks = it.child("recommendation").child("tasks").value

View File

@ -22,6 +22,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
tools:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@ -198,6 +199,7 @@ z
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
tools:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@ -210,7 +212,7 @@ z
android:text="TODAY HEALTH REPORT"
android:textAlignment="center"
android:textColor="@color/Primary_Dark"
android:textSize="20sp"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -225,6 +227,7 @@ z
android:textAlignment="center"
android:textColor="@color/Primary_Light"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_title_2" />
@ -256,10 +259,10 @@ z
<TextView
android:id="@+id/tv_bloodsugar_desc"
android:layout_width="190dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Your blood sugar level is within the normal range. Maintain a balanced diet and regular exercise."
android:textSize="8sp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/tv_bloodsugar_level"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_sub_title_BSL"
@ -291,10 +294,10 @@ z
<TextView
android:id="@+id/tv_bloodpressure_desc"
android:layout_width="190dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Your blood pressure is within the normal range. Continue a heart-healthy lifestyle."
android:textSize="8sp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_sub_title_BPL"
@ -330,10 +333,10 @@ z
<TextView
android:id="@+id/tv_bmi_desc"
android:layout_width="190dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="This is still considered an acceptable range, and is associated with good health."
android:textSize="8sp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_sub_title_BMI"

View File

@ -10,9 +10,8 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginTop="4dp"
android:background="@color/Accent_Dark_Gray"
android:layout_height="255dp"
android:background="@drawable/bg_dashboard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
@ -64,7 +63,7 @@
android:id="@+id/tv_bloodsugar_desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="8sp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/tv_bloodsugar_level2"
app:layout_constraintStart_toStartOf="@+id/tv_bloodsugar_level1"
app:layout_constraintTop_toBottomOf="@id/tv_bloodsugar_level1"
@ -74,7 +73,7 @@
android:id="@+id/tv_bloodpressure_level1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:text="Blood Pressure Level :"
android:textColor="@color/Primary_Dark"
android:textSize="16sp"
@ -102,7 +101,7 @@
android:id="@+id/tv_bloodpressure_desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="8sp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/tv_bloodpressure_level2"
app:layout_constraintStart_toStartOf="@+id/tv_bloodpressure_level1"
app:layout_constraintTop_toBottomOf="@id/tv_bloodpressure_level1"
@ -112,7 +111,7 @@
android:id="@+id/tv_BMI_level1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginTop="5dp"
android:text="BMI(Body Mass Index) :"
android:textColor="@color/Primary_Dark"
android:textSize="16sp"
@ -140,7 +139,7 @@
android:id="@+id/tv_BMI_desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="8sp"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/tv_BMI_level2"
app:layout_constraintStart_toStartOf="@+id/tv_BMI_level1"
app:layout_constraintTop_toBottomOf="@id/tv_BMI_level1"

View File

@ -170,7 +170,7 @@
android:layout_height="39dp"
android:layout_marginTop="40dp"
android:background="@drawable/bg_button"
android:text="REGISTER"
android:text="Register"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="14sp"

View File

@ -2,7 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="320dp"
android:layout_height="70dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:background="@drawable/bg_profile">
@ -20,9 +20,9 @@
<TextView
android:id="@+id/tv_goal"
android:layout_width="wrap_content"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="2"
android:layout_marginLeft="8dp"
android:text="Exercise for 40 Minutes "
android:textSize="16sp"

View File

@ -58,7 +58,7 @@
android:text="Blood Sugar Level : "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.21"
app:layout_constraintHorizontal_bias="0.176"
app:layout_constraintStart_toEndOf="@+id/iv_user"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.346" />