Skip to content
This repository was archived by the owner on Sep 22, 2025. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.5.1'
classpath 'com.android.tools.build:gradle:8.11.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.9.20"
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@
<activity
android:name=".view.general.PatientDetailsActivity"
android:exported="false" />
<activity
android:name=".view.general.AssignDoctorActivity"
android:exported="false" />
<activity
android:name=".view.general.AddPatientLogActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,39 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.cardview.widget.CardView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import deakin.gopher.guardian.adapter.ExerciseAdapter
import deakin.gopher.guardian.model.ExerciseItem

/**
* Fragment that handles both the exercise portal and detail views
*/
class PatientExercisePortalFragment : Fragment() {
private var currentExerciseType: String? = null
private var currentTabState: TabState = TabState.TO_DO
private lateinit var adapter: ExerciseAdapter
private lateinit var recyclerView: RecyclerView

enum class TabState {
TO_DO,
IN_PROGRESS,
COMPLETED,
}

private val allExercises =
listOf(
ExerciseItem("flexibility", "Flexibility", R.drawable.stretching),
ExerciseItem("strength", "Strength", R.drawable.walking2),
ExerciseItem("breathing", "Breathing", R.drawable.breathing),
ExerciseItem("balance", "Balance", R.drawable.balance),
ExerciseItem("cardio", "Cardio", R.drawable.walking2),
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

arguments?.let {
currentExerciseType = it.getString("exercise_type")
}
currentExerciseType = arguments?.getString("exercise_type")
}

override fun onCreateView(
Expand All @@ -45,9 +56,9 @@ class PatientExercisePortalFragment : Fragment() {
when (currentExerciseType) {
"flexibility" -> R.layout.activity_exercise_flexibility_module
"strength" -> R.layout.activity_exercise_strength_module
// "breathing" -> R.layout.activity_exercise_breathing_module //PR not yet approved
// "balance" -> R.layout.activity_exercise_balance_module //PR not yet approved
"cardio" -> R.layout.activity_exercise_cardio_module
// "breathing" -> R.layout.activity_exercise_breathing //PR not yet approved
// "balance" -> R.layout.activity_exercise_balance //PR not yet approved
else -> R.layout.activity_exercise_flexibility_module
}
val view = inflater.inflate(layoutResId, container, false)
Expand All @@ -56,142 +67,80 @@ class PatientExercisePortalFragment : Fragment() {
}
}

override fun onResume() {
super.onResume()

if (currentExerciseType == null) {
view?.let { updateExerciseVisibility(it, currentTabState) }
}
}

private fun setupPortalView(view: View) {
try {
currentTabState = TabState.TO_DO

view.findViewById<CardView>(R.id.flexibilityCard)?.setOnClickListener {
navigateToExercise("flexibility")
}

view.findViewById<CardView>(R.id.strengthCard)?.setOnClickListener {
navigateToExercise("strength")
}

view.findViewById<CardView>(R.id.breathingCard)?.setOnClickListener {
navigateToExercise("breathing")
}

view.findViewById<CardView>(R.id.balanceCard)?.setOnClickListener {
navigateToExercise("balance")
}

view.findViewById<CardView>(R.id.cardioCard)?.setOnClickListener {
navigateToExercise("cardio")
}
recyclerView = view.findViewById(R.id.exerciseRecyclerView)
recyclerView.layoutManager = GridLayoutManager(context, 2)

view.findViewById<TextView>(R.id.tabToDo)?.setOnClickListener {
setActiveTab(view, it as TextView)
currentTabState = TabState.TO_DO
updateExerciseVisibility(view, TabState.TO_DO)
adapter =
ExerciseAdapter(emptyList()) { item ->
navigateToExercise(item.type)
}
recyclerView.adapter = adapter

view.findViewById<TextView>(R.id.tabInProgress)?.setOnClickListener {
setActiveTab(view, it as TextView)
currentTabState = TabState.IN_PROGRESS
updateExerciseVisibility(view, TabState.IN_PROGRESS)
}

view.findViewById<TextView>(R.id.tabCompleted)?.setOnClickListener {
setActiveTab(view, it as TextView)
currentTabState = TabState.COMPLETED
updateExerciseVisibility(view, TabState.COMPLETED)
}
view.findViewById<TextView>(R.id.tabToDo)?.setOnClickListener {
setActiveTab(view, it as TextView)
currentTabState = TabState.TO_DO
updateRecyclerView()
}

view.findViewById<Button>(R.id.backButton)?.setOnClickListener {
activity?.finish()
}
view.findViewById<TextView>(R.id.tabInProgress)?.setOnClickListener {
setActiveTab(view, it as TextView)
currentTabState = TabState.IN_PROGRESS
updateRecyclerView()
}

setActiveTab(view, view.findViewById(R.id.tabToDo)!!)
updateExerciseVisibility(view, TabState.TO_DO)
} catch (e: Exception) {
e.printStackTrace()
view.findViewById<TextView>(R.id.tabCompleted)?.setOnClickListener {
setActiveTab(view, it as TextView)
currentTabState = TabState.COMPLETED
updateRecyclerView()
}
}

private fun updateExerciseVisibility(
view: View,
tabState: TabState,
) {
val sharedPreferences = requireActivity().getSharedPreferences("exercise_prefs", 0)

val flexibilityCard = view.findViewById<CardView>(R.id.flexibilityCard)
val strengthCard = view.findViewById<CardView>(R.id.strengthCard)
val breathingCard = view.findViewById<CardView>(R.id.breathingCard)
val balanceCard = view.findViewById<CardView>(R.id.balanceCard)
val cardioCard = view.findViewById<CardView>(R.id.cardioCard)

fun updateCardVisibility(
card: CardView?,
exerciseType: String,
) {
val isCompleted = sharedPreferences.getBoolean("completed_$exerciseType", false)
val isSaved = sharedPreferences.getBoolean("saved_$exerciseType", false)

card?.visibility =
when (tabState) {
TabState.TO_DO -> if (!isCompleted && !isSaved) View.VISIBLE else View.GONE
TabState.IN_PROGRESS -> if (isSaved && !isCompleted) View.VISIBLE else View.GONE
TabState.COMPLETED -> if (isCompleted) View.VISIBLE else View.GONE
}
view.findViewById<Button>(R.id.backButton)?.setOnClickListener {
activity?.finish()
}

updateCardVisibility(flexibilityCard, "flexibility")
updateCardVisibility(strengthCard, "strength")
updateCardVisibility(breathingCard, "breathing")
updateCardVisibility(balanceCard, "balance")
updateCardVisibility(cardioCard, "cardio")
setActiveTab(view, view.findViewById(R.id.tabToDo))
updateRecyclerView()
}

private fun setupExerciseDetailView(view: View) {
try {
view.findViewById<Button>(R.id.saveForLaterButton)?.setOnClickListener {
val exerciseName = view.findViewById<TextView>(R.id.benefits_exercising)?.text.toString() ?: ""

val exerciseName =
view.findViewById<TextView>(R.id.benefits_exercising)?.text.toString()
Toast.makeText(
requireContext(),
"$exerciseName saved for later",
Toast.LENGTH_SHORT,
).show()
)
.show()

val sharedPreferences =
requireActivity().getSharedPreferences(
"exercise_prefs",
0,
)
val sharedPreferences = requireActivity().getSharedPreferences("exercise_prefs", 0)
sharedPreferences.edit()
.putBoolean("saved_$currentExerciseType", true)
.putBoolean("completed_$currentExerciseType", false) // Ensure it's not marked as completed
.putBoolean("completed_$currentExerciseType", false)
.apply()

navigateBackToPortal()
}

view.findViewById<Button>(R.id.markCompleteButton)?.setOnClickListener {
val exerciseName = view.findViewById<TextView>(R.id.benefits_exercising)?.text.toString() ?: ""

val exerciseName =
view.findViewById<TextView>(R.id.benefits_exercising)?.text.toString()
Toast.makeText(
requireContext(),
"$exerciseName marked as complete",
Toast.LENGTH_SHORT,
).show()
)
.show()

val sharedPreferences =
requireActivity().getSharedPreferences(
"exercise_prefs",
0,
)
val sharedPreferences = requireActivity().getSharedPreferences("exercise_prefs", 0)
sharedPreferences.edit()
.putBoolean("completed_$currentExerciseType", true)
.putBoolean("saved_$currentExerciseType", false)
.putBoolean(
"saved_$currentExerciseType",
false,
) // Ensure it's not marked as completed
.apply()

// Go back to portal
Expand All @@ -200,11 +149,7 @@ class PatientExercisePortalFragment : Fragment() {

view.findViewById<Button>(R.id.backButton)?.setOnClickListener {
// Reset the exercise to "To Do" when back button is pressed
val sharedPreferences =
requireActivity().getSharedPreferences(
"exercise_prefs",
0,
)
val sharedPreferences = requireActivity().getSharedPreferences("exercise_prefs", 0)
sharedPreferences.edit()
.putBoolean("saved_$currentExerciseType", false)
.putBoolean("completed_$currentExerciseType", false)
Expand All @@ -217,22 +162,55 @@ class PatientExercisePortalFragment : Fragment() {
}
}

private fun navigateToExercise(exerciseType: String) {
override fun onResume() {
super.onResume()
if (currentExerciseType == null && view != null) {
// force reset to currentTabState
when (currentTabState) {
TabState.TO_DO -> {
setActiveTab(requireView(), requireView().findViewById(R.id.tabToDo))
}

TabState.IN_PROGRESS -> {
setActiveTab(requireView(), requireView().findViewById(R.id.tabInProgress))
}

TabState.COMPLETED -> {
setActiveTab(requireView(), requireView().findViewById(R.id.tabCompleted))
}
}
updateRecyclerView()
}
}

private fun updateRecyclerView() {
val prefs = requireActivity().getSharedPreferences("exercise_prefs", 0)
val filtered =
allExercises.filter { item ->
val isCompleted = prefs.getBoolean("completed_${item.type}", false)
val isSaved = prefs.getBoolean("saved_${item.type}", false)
when (currentTabState) {
TabState.TO_DO -> !isCompleted && !isSaved
TabState.IN_PROGRESS -> isSaved && !isCompleted
TabState.COMPLETED -> isCompleted
}
}
adapter.updateList(filtered)
}

private fun navigateToExercise(type: String) {
val fragment =
PatientExercisePortalFragment().apply {
arguments =
Bundle().apply {
putString("exercise_type", exerciseType)
}
arguments = Bundle().apply { putString("exercise_type", type) }
}

requireActivity().supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment)
.addToBackStack(null)
.commit()
}

private fun navigateBackToPortal() {
currentTabState = TabState.TO_DO
requireActivity().supportFragmentManager.popBackStack()
}

Expand Down
Loading