Hallo
This commit is contained in:
parent
72b110af36
commit
8450a791d5
@ -51,6 +51,10 @@ class AppNavigation(private val context: Context) {
|
|||||||
onEditWorkout = { workout ->
|
onEditWorkout = { workout ->
|
||||||
showEditWorkout(workout)
|
showEditWorkout(workout)
|
||||||
},
|
},
|
||||||
|
onDeleteWorkout = { workout ->
|
||||||
|
viewModel.deleteWorkout(workout.id)
|
||||||
|
showSavedWorkouts()
|
||||||
|
},
|
||||||
onBack = { showHome() }
|
onBack = { showHome() }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.example.workouttimer.ui.screens
|
package com.example.workouttimer.ui.screens
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.CountDownTimer
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
@ -18,6 +19,8 @@ class RunningWorkoutScreen(
|
|||||||
onPause: () -> Unit
|
onPause: () -> Unit
|
||||||
) : LinearLayout(context) {
|
) : LinearLayout(context) {
|
||||||
|
|
||||||
|
private var countDownTimer: CountDownTimer? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
orientation = VERTICAL
|
orientation = VERTICAL
|
||||||
gravity = Gravity.CENTER
|
gravity = Gravity.CENTER
|
||||||
@ -38,6 +41,10 @@ class RunningWorkoutScreen(
|
|||||||
targetText.textSize = 24f
|
targetText.textSize = 24f
|
||||||
targetText.gravity = Gravity.CENTER
|
targetText.gravity = Gravity.CENTER
|
||||||
|
|
||||||
|
val timerText = TextView(context)
|
||||||
|
timerText.textSize = 36f
|
||||||
|
timerText.gravity = Gravity.CENTER
|
||||||
|
|
||||||
val infoText = TextView(context)
|
val infoText = TextView(context)
|
||||||
infoText.text = exercise?.info ?: ""
|
infoText.text = exercise?.info ?: ""
|
||||||
infoText.textSize = 16f
|
infoText.textSize = 16f
|
||||||
@ -46,21 +53,62 @@ class RunningWorkoutScreen(
|
|||||||
val nextButton = Button(context)
|
val nextButton = Button(context)
|
||||||
nextButton.text = "Übung geschafft / Weiter"
|
nextButton.text = "Übung geschafft / Weiter"
|
||||||
nextButton.setOnClickListener {
|
nextButton.setOnClickListener {
|
||||||
|
countDownTimer?.cancel()
|
||||||
onNextExercise()
|
onNextExercise()
|
||||||
}
|
}
|
||||||
|
|
||||||
val pauseButton = Button(context)
|
val pauseButton = Button(context)
|
||||||
pauseButton.text = "Pause"
|
pauseButton.text = "Pause"
|
||||||
pauseButton.setOnClickListener {
|
pauseButton.setOnClickListener {
|
||||||
|
countDownTimer?.cancel()
|
||||||
onPause()
|
onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
addView(workoutTitle)
|
addView(workoutTitle)
|
||||||
addView(exerciseTitle)
|
addView(exerciseTitle)
|
||||||
addView(targetText)
|
addView(targetText)
|
||||||
|
addView(timerText)
|
||||||
addView(infoText)
|
addView(infoText)
|
||||||
addView(nextButton)
|
addView(nextButton)
|
||||||
addView(pauseButton)
|
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 {
|
private fun formatTarget(target: ExerciseTarget): String {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class SavedWorkoutsScreen(
|
|||||||
onWorkoutSelected: (Workout) -> Unit,
|
onWorkoutSelected: (Workout) -> Unit,
|
||||||
onCreateWorkout: () -> Unit,
|
onCreateWorkout: () -> Unit,
|
||||||
onEditWorkout: (Workout) -> Unit,
|
onEditWorkout: (Workout) -> Unit,
|
||||||
|
onDeleteWorkout: (Workout) -> Unit,
|
||||||
onBack: () -> Unit
|
onBack: () -> Unit
|
||||||
) : LinearLayout(context) {
|
) : LinearLayout(context) {
|
||||||
|
|
||||||
@ -53,8 +54,15 @@ class SavedWorkoutsScreen(
|
|||||||
onEditWorkout(workout)
|
onEditWorkout(workout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deleteButton = Button(context)
|
||||||
|
deleteButton.text = "Löschen"
|
||||||
|
deleteButton.setOnClickListener {
|
||||||
|
onDeleteWorkout(workout)
|
||||||
|
}
|
||||||
|
|
||||||
workoutRow.addView(workoutButton)
|
workoutRow.addView(workoutButton)
|
||||||
workoutRow.addView(editButton)
|
workoutRow.addView(editButton)
|
||||||
|
workoutRow.addView(deleteButton)
|
||||||
|
|
||||||
addView(workoutRow)
|
addView(workoutRow)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,11 @@ class WorkoutEditorScreen(
|
|||||||
) : ScrollView(context) {
|
) : ScrollView(context) {
|
||||||
|
|
||||||
private val exercises = mutableListOf<Exercise>()
|
private val exercises = mutableListOf<Exercise>()
|
||||||
private val exerciseListText = TextView(context)
|
private val exerciseListContainer = LinearLayout(context)
|
||||||
|
|
||||||
|
init {
|
||||||
|
exerciseListContainer.orientation = LinearLayout.VERTICAL
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val content = LinearLayout(context)
|
val content = LinearLayout(context)
|
||||||
@ -149,7 +153,8 @@ class WorkoutEditorScreen(
|
|||||||
listTitle.textSize = 22f
|
listTitle.textSize = 22f
|
||||||
|
|
||||||
content.addView(listTitle)
|
content.addView(listTitle)
|
||||||
content.addView(exerciseListText)
|
exerciseListContainer.orientation = LinearLayout.VERTICAL
|
||||||
|
content.addView(exerciseListContainer)
|
||||||
|
|
||||||
content.addView(saveButton)
|
content.addView(saveButton)
|
||||||
content.addView(cancelButton)
|
content.addView(cancelButton)
|
||||||
@ -158,14 +163,47 @@ class WorkoutEditorScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateExerciseList() {
|
private fun updateExerciseList() {
|
||||||
|
exerciseListContainer.removeAllViews()
|
||||||
|
|
||||||
if (exercises.isEmpty()) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exerciseListText.text = exercises.mapIndexed { index, exercise ->
|
exercises.forEachIndexed { index, exercise ->
|
||||||
"${index + 1}. ${exercise.name} - ${formatTarget(exercise.target)}"
|
|
||||||
}.joinToString("\n")
|
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 {
|
private fun formatTarget(target: ExerciseTarget): String {
|
||||||
|
|||||||
@ -72,6 +72,18 @@ class WorkoutViewModel(context: Context) {
|
|||||||
storage.saveWorkouts(workoutList)
|
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() {
|
fun startWorkout() {
|
||||||
workoutState = WorkoutState.RUNNING
|
workoutState = WorkoutState.RUNNING
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user