Second Commit:
Version 1.5 [Partialy Optimized Version] [UI Fixes And Improvment] Todo: Optimized the Code Add String Theolgy
This commit is contained in:
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -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"
|
||||
|
||||
@ -106,10 +109,9 @@ class DetailJournalActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
binding.btnDeleteHistory.setOnClickListener() {
|
||||
deleteHistory()
|
||||
}
|
||||
private fun setupListener() {
|
||||
binding.btnDeleteHistory.setOnClickListener() {
|
||||
deleteHistory()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user