Hallo
This commit is contained in:
parent
72b110af36
commit
8450a791d5
@ -51,6 +51,10 @@ class AppNavigation(private val context: Context) {
|
||||
onEditWorkout = { workout ->
|
||||
showEditWorkout(workout)
|
||||
},
|
||||
onDeleteWorkout = { workout ->
|
||||
viewModel.deleteWorkout(workout.id)
|
||||
showSavedWorkouts()
|
||||
},
|
||||
onBack = { showHome() }
|
||||
)
|
||||
)
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.example.workouttimer.ui.screens
|
||||
|
||||
import android.content.Context
|
||||
import android.os.CountDownTimer
|
||||
import android.view.Gravity
|
||||
import android.widget.Button
|
||||
import android.widget.LinearLayout
|
||||
@ -18,6 +19,8 @@ class RunningWorkoutScreen(
|
||||
onPause: () -> Unit
|
||||
) : LinearLayout(context) {
|
||||
|
||||
private var countDownTimer: CountDownTimer? = null
|
||||
|
||||
init {
|
||||
orientation = VERTICAL
|
||||
gravity = Gravity.CENTER
|
||||
@ -38,6 +41,10 @@ class RunningWorkoutScreen(
|
||||
targetText.textSize = 24f
|
||||
targetText.gravity = Gravity.CENTER
|
||||
|
||||
val timerText = TextView(context)
|
||||
timerText.textSize = 36f
|
||||
timerText.gravity = Gravity.CENTER
|
||||
|
||||
val infoText = TextView(context)
|
||||
infoText.text = exercise?.info ?: ""
|
||||
infoText.textSize = 16f
|
||||
@ -46,21 +53,62 @@ class RunningWorkoutScreen(
|
||||
val nextButton = Button(context)
|
||||
nextButton.text = "Übung geschafft / Weiter"
|
||||
nextButton.setOnClickListener {
|
||||
countDownTimer?.cancel()
|
||||
onNextExercise()
|
||||
}
|
||||
|
||||
val pauseButton = Button(context)
|
||||
pauseButton.text = "Pause"
|
||||
pauseButton.setOnClickListener {
|
||||
countDownTimer?.cancel()
|
||||
onPause()
|
||||
}
|
||||
|
||||
addView(workoutTitle)
|
||||
addView(exerciseTitle)
|
||||
addView(targetText)
|
||||
addView(timerText)
|
||||
addView(infoText)
|
||||
addView(nextButton)
|
||||
addView(pauseButton)
|
||||
|
||||
if (exercise?.target is ExerciseTarget.Duration) {
|
||||
nextButton.text = "Überspringen"
|
||||
startCountdown(
|
||||
seconds = exercise.target.seconds,
|
||||
timerText = timerText,
|
||||
onFinished = onNextExercise
|
||||
)
|
||||
} else {
|
||||
timerText.text = ""
|
||||
}
|
||||
}
|
||||
|
||||
private fun startCountdown(
|
||||
seconds: Int,
|
||||
timerText: TextView,
|
||||
onFinished: () -> Unit
|
||||
) {
|
||||
timerText.text = "$seconds"
|
||||
|
||||
countDownTimer = object : CountDownTimer(seconds * 1000L, 1000L) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
val remainingSeconds = (millisUntilFinished / 1000L).toInt()
|
||||
timerText.text = remainingSeconds.toString()
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
timerText.text = "0"
|
||||
onFinished()
|
||||
}
|
||||
}
|
||||
|
||||
countDownTimer?.start()
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
countDownTimer?.cancel()
|
||||
}
|
||||
|
||||
private fun formatTarget(target: ExerciseTarget): String {
|
||||
|
||||
@ -13,6 +13,7 @@ class SavedWorkoutsScreen(
|
||||
onWorkoutSelected: (Workout) -> Unit,
|
||||
onCreateWorkout: () -> Unit,
|
||||
onEditWorkout: (Workout) -> Unit,
|
||||
onDeleteWorkout: (Workout) -> Unit,
|
||||
onBack: () -> Unit
|
||||
) : LinearLayout(context) {
|
||||
|
||||
@ -53,8 +54,15 @@ class SavedWorkoutsScreen(
|
||||
onEditWorkout(workout)
|
||||
}
|
||||
|
||||
val deleteButton = Button(context)
|
||||
deleteButton.text = "Löschen"
|
||||
deleteButton.setOnClickListener {
|
||||
onDeleteWorkout(workout)
|
||||
}
|
||||
|
||||
workoutRow.addView(workoutButton)
|
||||
workoutRow.addView(editButton)
|
||||
workoutRow.addView(deleteButton)
|
||||
|
||||
addView(workoutRow)
|
||||
}
|
||||
|
||||
@ -24,7 +24,11 @@ class WorkoutEditorScreen(
|
||||
) : ScrollView(context) {
|
||||
|
||||
private val exercises = mutableListOf<Exercise>()
|
||||
private val exerciseListText = TextView(context)
|
||||
private val exerciseListContainer = LinearLayout(context)
|
||||
|
||||
init {
|
||||
exerciseListContainer.orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
|
||||
init {
|
||||
val content = LinearLayout(context)
|
||||
@ -149,7 +153,8 @@ class WorkoutEditorScreen(
|
||||
listTitle.textSize = 22f
|
||||
|
||||
content.addView(listTitle)
|
||||
content.addView(exerciseListText)
|
||||
exerciseListContainer.orientation = LinearLayout.VERTICAL
|
||||
content.addView(exerciseListContainer)
|
||||
|
||||
content.addView(saveButton)
|
||||
content.addView(cancelButton)
|
||||
@ -158,14 +163,47 @@ class WorkoutEditorScreen(
|
||||
}
|
||||
|
||||
private fun updateExerciseList() {
|
||||
exerciseListContainer.removeAllViews()
|
||||
|
||||
if (exercises.isEmpty()) {
|
||||
exerciseListText.text = "Noch keine Übungen hinzugefügt."
|
||||
val emptyText = TextView(context)
|
||||
emptyText.text = "Noch keine Übungen hinzugefügt."
|
||||
exerciseListContainer.addView(emptyText)
|
||||
return
|
||||
}
|
||||
|
||||
exerciseListText.text = exercises.mapIndexed { index, exercise ->
|
||||
"${index + 1}. ${exercise.name} - ${formatTarget(exercise.target)}"
|
||||
}.joinToString("\n")
|
||||
exercises.forEachIndexed { index, exercise ->
|
||||
|
||||
val row = LinearLayout(context)
|
||||
row.orientation = LinearLayout.HORIZONTAL
|
||||
row.gravity = Gravity.CENTER_VERTICAL
|
||||
|
||||
val exerciseText = TextView(context)
|
||||
exerciseText.text = "${index + 1}. ${exercise.name} - ${formatTarget(exercise.target)}"
|
||||
exerciseText.textSize = 16f
|
||||
|
||||
val deleteButton = Button(context)
|
||||
deleteButton.text = "Löschen"
|
||||
deleteButton.setOnClickListener {
|
||||
exercises.removeAt(index)
|
||||
updateExerciseIds()
|
||||
updateExerciseList()
|
||||
}
|
||||
|
||||
row.addView(exerciseText)
|
||||
row.addView(deleteButton)
|
||||
|
||||
exerciseListContainer.addView(row)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateExerciseIds() {
|
||||
val updatedExercises = exercises.mapIndexed { index, exercise ->
|
||||
exercise.copy(id = index + 1)
|
||||
}
|
||||
|
||||
exercises.clear()
|
||||
exercises.addAll(updatedExercises)
|
||||
}
|
||||
|
||||
private fun formatTarget(target: ExerciseTarget): String {
|
||||
|
||||
@ -72,6 +72,18 @@ class WorkoutViewModel(context: Context) {
|
||||
storage.saveWorkouts(workoutList)
|
||||
}
|
||||
|
||||
fun deleteWorkout(workoutId: Int) {
|
||||
workoutList.removeAll { it.id == workoutId }
|
||||
|
||||
if (currentWorkout?.id == workoutId) {
|
||||
currentWorkout = null
|
||||
currentExerciseIndex = 0
|
||||
workoutState = WorkoutState.READY
|
||||
}
|
||||
|
||||
storage.saveWorkouts(workoutList)
|
||||
}
|
||||
|
||||
fun startWorkout() {
|
||||
workoutState = WorkoutState.RUNNING
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user