fix: fix wrong url for sending finished trainings
This commit is contained in:
parent
cfbd2a313b
commit
6241efca58
4 changed files with 12 additions and 12 deletions
|
|
@ -24,6 +24,7 @@ import de.patani.kettlebelltracker.viewmodels.*
|
|||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.util.UUID
|
||||
import androidx.core.content.edit
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ class MainActivity : ComponentActivity() {
|
|||
var uuid = prefs.getString("app_uuid", null)
|
||||
if (uuid == null) {
|
||||
uuid = UUID.randomUUID().toString()
|
||||
prefs.edit().putString("app_uuid", uuid).apply()
|
||||
prefs.edit { putString("app_uuid", uuid) }
|
||||
}
|
||||
uuid
|
||||
}
|
||||
|
|
@ -72,11 +73,9 @@ class MainActivity : ComponentActivity() {
|
|||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return when {
|
||||
modelClass.isAssignableFrom(TrainingViewModel::class.java) ->
|
||||
appUUID?.let {
|
||||
TrainingViewModel(db.trainingSessionDao(), settingsDataStore, apiRepository,
|
||||
it
|
||||
)
|
||||
} as T
|
||||
appUUID
|
||||
) as T
|
||||
modelClass.isAssignableFrom(HomeViewModel::class.java) ->
|
||||
HomeViewModel(db.trainingSessionDao(), trainingViewModel) as T
|
||||
modelClass.isAssignableFrom(HistoryViewModel::class.java) ->
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import retrofit2.http.Body
|
|||
import retrofit2.http.POST
|
||||
|
||||
interface ApiService {
|
||||
@POST("trainings/")
|
||||
@POST("trainings")
|
||||
suspend fun sendTrainingData(@Body payload: TrainingPayload): Response<Unit>
|
||||
|
||||
@POST("trainings/recommend-rest")
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class ApiRepository(private val apiService: ApiService) {
|
|||
)
|
||||
val response = apiService.sendTrainingData(payload)
|
||||
if (response.isSuccessful) {
|
||||
Log.d("ApiRepository", "Training successfully sent to backend.")
|
||||
Log.i("ApiRepository", "Training successfully sent to backend.")
|
||||
} else {
|
||||
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 response = apiService.getRecommendedRest(request)
|
||||
if (response.isSuccessful) {
|
||||
Log.i("ApiRepository", "Got Rest Recommendation:")
|
||||
val body = response.body()?.data
|
||||
Log.i("ApiRepository", body.toString())
|
||||
response.body()?.data
|
||||
} else {
|
||||
null
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ data class TrainingState(
|
|||
val currentBlockDay: Int = 1,
|
||||
val currentReps: Int = 5,
|
||||
val totalTrainingDays: Int = 0,
|
||||
// Neue Rundentimer-Eigenschaften
|
||||
val isRoundActive: Boolean = false,
|
||||
val currentRoundTime: Int = 0,
|
||||
val totalRoundTime: Int = 0
|
||||
|
|
@ -131,10 +130,8 @@ class TrainingViewModel(
|
|||
|
||||
stopRoundTimer()
|
||||
|
||||
if (newSetsDone < currentState.goalSets) {
|
||||
startNextRound()
|
||||
}
|
||||
}
|
||||
|
||||
private fun startNextRound() {
|
||||
startRoundTimer(recommendedRestSeconds)
|
||||
|
|
@ -208,6 +205,7 @@ class TrainingViewModel(
|
|||
)
|
||||
|
||||
dao.insert(session)
|
||||
Log.d("Training", "Sending Trainingsession to backend: $appUUID")
|
||||
apiRepository.sendTrainingData(session, appUUID)
|
||||
resetTraining()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue