diff --git a/app/src/main/kotlin/de/hbch/traewelling/api/ApiService.kt b/app/src/main/kotlin/de/hbch/traewelling/api/ApiService.kt index d31c8271..bcfb0465 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/api/ApiService.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/api/ApiService.kt @@ -171,8 +171,11 @@ interface CheckInService { @Path("statusId") statusId: Int ): Call - @GET("activeEvents") - fun getActiveEvents(): Call>> + @GET("events") + suspend fun getEvents( + @Query("timestamp") timestamp: ZonedDateTime = ZonedDateTime.now(), + @Query("upcoming") upcoming: Boolean = false + ): Data> } interface TravelService { diff --git a/app/src/main/kotlin/de/hbch/traewelling/api/models/status/Status.kt b/app/src/main/kotlin/de/hbch/traewelling/api/models/status/Status.kt index ad33488f..93f1b247 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/api/models/status/Status.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/api/models/status/Status.kt @@ -7,6 +7,7 @@ import androidx.compose.ui.text.font.FontWeight import com.google.gson.annotations.SerializedName import de.hbch.traewelling.R import de.hbch.traewelling.api.models.event.Event +import de.hbch.traewelling.api.models.user.LightUser import de.hbch.traewelling.util.extractUsernames import java.time.ZonedDateTime @@ -14,9 +15,6 @@ data class Status( val id: Int, val body: String?, val createdAt: ZonedDateTime, - val profilePicture: String?, - @SerializedName("user") val userId: Int, - val username: String, val visibility: StatusVisibility, val business: StatusBusiness, var likes: Int?, @@ -25,12 +23,13 @@ data class Status( @SerializedName("train") val journey: Journey, val event: Event?, val client: ApiClient?, - @SerializedName("bodyMentions") val mentions: List + @SerializedName("bodyMentions") val mentions: List, + @SerializedName("userDetails") val user: LightUser ) { fun getStatusText(): String { var statusBody = body ?: "" - if (username == "ErikUden") { + if (user.username == "ErikUden") { statusBody += "\nšŸ‘" } diff --git a/app/src/main/kotlin/de/hbch/traewelling/api/models/user/User.kt b/app/src/main/kotlin/de/hbch/traewelling/api/models/user/User.kt index 4b35ec0e..08f3903b 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/api/models/user/User.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/api/models/user/User.kt @@ -9,8 +9,8 @@ data class User( @SerializedName("displayName") val name: String, @SerializedName("username") val username: String, @SerializedName("profilePicture") val avatarUrl: String, - @SerializedName("trainDistance") val distance: Int, - @SerializedName("trainDuration") val duration: Int, + @SerializedName("totalDistance") val distance: Int, + @SerializedName("totalDuration") val duration: Int, @SerializedName("points") val points: Int, @SerializedName("mastodonUrl") val mastodonUrl: String?, @SerializedName("privateProfile") val privateProfile: Boolean, @@ -23,3 +23,11 @@ data class User( ) { val averageSpeed: Double get() = (distance / 1000.0) / (duration / 60.0) } + +data class LightUser( + @SerializedName("id") val id: Int, + @SerializedName("displayName") val name: String, + @SerializedName("username") val username: String, + @SerializedName("profilePicture") val avatarUrl: String, + @SerializedName("mastodonUrl") val mastodonUrl: String? +) diff --git a/app/src/main/kotlin/de/hbch/traewelling/navigation/NavHost.kt b/app/src/main/kotlin/de/hbch/traewelling/navigation/NavHost.kt index c3e9214a..8b223779 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/navigation/NavHost.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/navigation/NavHost.kt @@ -304,7 +304,7 @@ fun TraewelldroidNavHost( statusLoaded = { status -> val menuItems = mutableListOf() if (loggedInUserViewModel.loggedInUser.value != null) { - if (status.userId == loggedInUserViewModel.loggedInUser.value?.id) { + if (status.user.id == loggedInUserViewModel.loggedInUser.value?.id) { menuItems.add( ComposeMenuItem( R.string.title_share, diff --git a/app/src/main/kotlin/de/hbch/traewelling/shared/EventViewModel.kt b/app/src/main/kotlin/de/hbch/traewelling/shared/EventViewModel.kt index c234d9cc..bdd65be4 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/shared/EventViewModel.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/shared/EventViewModel.kt @@ -14,25 +14,16 @@ class EventViewModel : ViewModel() { val activeEvents: MutableLiveData> = MutableLiveData(listOf()) - fun activeEvents() { - TraewellingApi - .checkInService - .getActiveEvents() - .enqueue(object : Callback>> { - override fun onResponse( - call: Call>>, - response: Response>> - ) { - if (response.isSuccessful) { - val data = response.body()?.data ?: return - activeEvents.postValue(data) - return - } - } - - override fun onFailure(call: Call>>, t: Throwable) { - Logger.captureException(t) - } - }) + suspend fun activeEvents() { + activeEvents.postValue( + try { + TraewellingApi + .checkInService + .getEvents() + .data + } catch (_: Exception) { + listOf() + } + ) } } diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/checkInResult/CheckInResult.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/checkInResult/CheckInResult.kt index 2dbd86dd..0ddc9917 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/checkInResult/CheckInResult.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/checkInResult/CheckInResult.kt @@ -249,15 +249,15 @@ private fun CoTraveller( horizontalArrangement = Arrangement.spacedBy(8.dp) ) { ProfilePicture( - name = status.username, - url = status.profilePicture ?: "", + name = status.user.username, + url = status.user.avatarUrl, modifier = Modifier .width(32.dp) .height(32.dp) ) Column { Text( - text = "@${status.username}", + text = "@${status.user.username}", fontWeight = FontWeight.ExtraBold ) Text( diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/include/status/CheckInCard.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/include/status/CheckInCard.kt index 13c12d99..c7e49db9 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/include/status/CheckInCard.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/include/status/CheckInCard.kt @@ -214,7 +214,7 @@ fun CheckInCard( modifier = Modifier.fillMaxWidth(), status = status, isOwnStatus = - (loggedInUserViewModel?.loggedInUser?.value?.id ?: -1) == status.userId, + (loggedInUserViewModel?.loggedInUser?.value?.id ?: -1) == status.user.id, displayLongDate = displayLongDate, checkInCardViewModel = checkInCardViewModel, userSelected = userSelected, @@ -503,8 +503,8 @@ private fun CheckInCardFooter( else getLocalTimeString(date = status.createdAt) ProfilePicture( - name = status.username, - url = status.profilePicture ?: "", + name = status.user.username, + url = status.user.avatarUrl, modifier = Modifier .height(24.dp) .width(24.dp) @@ -512,11 +512,11 @@ private fun CheckInCardFooter( ) Text( modifier = alignmentModifier - .clickable { userSelected(status.username) } + .clickable { userSelected(status.user.username) } .padding(2.dp), text = stringResource( id = R.string.check_in_user_time, - status.username, + status.user.username, dateString ), textAlign = TextAlign.End, diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/main/MainActivity.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/main/MainActivity.kt index f88a0c7b..3691d433 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/main/MainActivity.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/main/MainActivity.kt @@ -83,6 +83,10 @@ import de.hbch.traewelling.util.publishStationShortcuts import io.getunleash.UnleashClient import io.getunleash.UnleashConfig import io.getunleash.polling.PollingModes +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode @@ -121,7 +125,11 @@ class MainActivity : ComponentActivity() emojiPackItemAdapter = EmojiPackItemAdapter.get(this) TraewellingApi.jwt = secureStorage.getObject(SharedValues.SS_JWT, String::class.java)!! SharedValues.TRAVELYNX_TOKEN = secureStorage.getObject(SharedValues.SS_TRAVELYNX_TOKEN, String::class.java) ?: "" - eventViewModel.activeEvents() + + val coroutineScope = CoroutineScope(Dispatchers.IO) + coroutineScope.launch { + eventViewModel.activeEvents() + } enableEdgeToEdge() WindowCompat.setDecorFitsSystemWindows(window, false) diff --git a/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt b/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt index babd1317..377e3817 100644 --- a/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt +++ b/app/src/main/kotlin/de/hbch/traewelling/ui/statusDetail/StatusDetail.kt @@ -144,7 +144,7 @@ fun StatusDetail( StatusTags( statusId = statusId, modifier = Modifier.fillMaxWidth(), - isOwnStatus = (loggedInUserViewModel?.loggedInUser?.value?.id ?: -1) == status?.userId, + isOwnStatus = (loggedInUserViewModel?.loggedInUser?.value?.id ?: -1) == status?.user?.id, defaultVisibility = loggedInUserViewModel?.defaultStatusVisibility ?: StatusVisibility.PUBLIC ) status?.likes?.let {