fix: fix wrong url for sending finished trainings

This commit is contained in:
Patryk Hegenberg 2025-10-08 21:54:05 +02:00
parent cfbd2a313b
commit 6241efca58
4 changed files with 12 additions and 12 deletions

View file

@ -24,6 +24,7 @@ import de.patani.kettlebelltracker.viewmodels.*
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import java.util.UUID import java.util.UUID
import androidx.core.content.edit
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@ -47,7 +48,7 @@ class MainActivity : ComponentActivity() {
var uuid = prefs.getString("app_uuid", null) var uuid = prefs.getString("app_uuid", null)
if (uuid == null) { if (uuid == null) {
uuid = UUID.randomUUID().toString() uuid = UUID.randomUUID().toString()
prefs.edit().putString("app_uuid", uuid).apply() prefs.edit { putString("app_uuid", uuid) }
} }
uuid uuid
} }
@ -72,11 +73,9 @@ class MainActivity : ComponentActivity() {
override fun <T : ViewModel> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
return when { return when {
modelClass.isAssignableFrom(TrainingViewModel::class.java) -> modelClass.isAssignableFrom(TrainingViewModel::class.java) ->
appUUID?.let { TrainingViewModel(db.trainingSessionDao(), settingsDataStore, apiRepository,
TrainingViewModel(db.trainingSessionDao(), settingsDataStore, apiRepository, appUUID
it ) as T
)
} as T
modelClass.isAssignableFrom(HomeViewModel::class.java) -> modelClass.isAssignableFrom(HomeViewModel::class.java) ->
HomeViewModel(db.trainingSessionDao(), trainingViewModel) as T HomeViewModel(db.trainingSessionDao(), trainingViewModel) as T
modelClass.isAssignableFrom(HistoryViewModel::class.java) -> modelClass.isAssignableFrom(HistoryViewModel::class.java) ->

View file

@ -5,7 +5,7 @@ import retrofit2.http.Body
import retrofit2.http.POST import retrofit2.http.POST
interface ApiService { interface ApiService {
@POST("trainings/") @POST("trainings")
suspend fun sendTrainingData(@Body payload: TrainingPayload): Response<Unit> suspend fun sendTrainingData(@Body payload: TrainingPayload): Response<Unit>
@POST("trainings/recommend-rest") @POST("trainings/recommend-rest")

View file

@ -25,7 +25,7 @@ class ApiRepository(private val apiService: ApiService) {
) )
val response = apiService.sendTrainingData(payload) val response = apiService.sendTrainingData(payload)
if (response.isSuccessful) { if (response.isSuccessful) {
Log.d("ApiRepository", "Training successfully sent to backend.") Log.i("ApiRepository", "Training successfully sent to backend.")
} else { } else {
Log.e("ApiRepository", "API Error: Unexpected status code: ${response.code()}") Log.e("ApiRepository", "API Error: Unexpected status code: ${response.code()}")
} }
@ -39,6 +39,9 @@ class ApiRepository(private val apiService: ApiService) {
val request = RestRecommendationRequest(uuid, repsPerSet, currentSets) val request = RestRecommendationRequest(uuid, repsPerSet, currentSets)
val response = apiService.getRecommendedRest(request) val response = apiService.getRecommendedRest(request)
if (response.isSuccessful) { if (response.isSuccessful) {
Log.i("ApiRepository", "Got Rest Recommendation:")
val body = response.body()?.data
Log.i("ApiRepository", body.toString())
response.body()?.data response.body()?.data
} else { } else {
null null

View file

@ -30,7 +30,6 @@ data class TrainingState(
val currentBlockDay: Int = 1, val currentBlockDay: Int = 1,
val currentReps: Int = 5, val currentReps: Int = 5,
val totalTrainingDays: Int = 0, val totalTrainingDays: Int = 0,
// Neue Rundentimer-Eigenschaften
val isRoundActive: Boolean = false, val isRoundActive: Boolean = false,
val currentRoundTime: Int = 0, val currentRoundTime: Int = 0,
val totalRoundTime: Int = 0 val totalRoundTime: Int = 0
@ -131,9 +130,7 @@ class TrainingViewModel(
stopRoundTimer() stopRoundTimer()
if (newSetsDone < currentState.goalSets) { startNextRound()
startNextRound()
}
} }
private fun startNextRound() { private fun startNextRound() {
@ -208,6 +205,7 @@ class TrainingViewModel(
) )
dao.insert(session) dao.insert(session)
Log.d("Training", "Sending Trainingsession to backend: $appUUID")
apiRepository.sendTrainingData(session, appUUID) apiRepository.sendTrainingData(session, appUUID)
resetTraining() resetTraining()
} }