Skip to content

Commit

Permalink
Major resets
Browse files Browse the repository at this point in the history
  • Loading branch information
ForceTower committed Nov 6, 2024
1 parent 59cf629 commit 763a298
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface EdgeService {
@GET("account/me")
suspend fun me(): ServiceResponseWrapper<ServiceAccountDTO>

@GET("account/session/start")
@POST("account/session/start")
suspend fun sessionStart(@Body data: EdgeLoginBody)

@POST("account/register/start")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
package com.forcetower.uefs.core.storage.repository

import android.content.SharedPreferences
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringSetPreferencesKey
import androidx.lifecycle.LiveData
import androidx.lifecycle.liveData
import com.forcetower.sagres.SagresNavigator
Expand Down Expand Up @@ -49,9 +53,12 @@ class SagresDataRepository @Inject constructor(
private val preferences: SharedPreferences,
private val client: OkHttpClient,
@Named("webViewUA") private val agent: String,
@Named("internalConfig") private val config: DataStore<Preferences>,
private val cookies: CookieSessionRepository,
private val service: UService
) {
private val missingSemestersKey = stringSetPreferencesKey("missing_semesters_run")

fun getMessages() = database.messageDao().getAllMessages()

fun logout() {
Expand All @@ -77,6 +84,9 @@ class SagresDataRepository @Inject constructor(
database.edgeAccessToken.deleteAll()
database.edgeServiceAccount.deleteAll()
database.studentServiceDao().markNoOneAsMe()
config.edit {
it[missingSemestersKey] = emptySet()
}
}

fun getFlags() = database.flagsDao().getFlags()
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/forcetower/uefs/core/util/ObjectUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.google.gson.JsonDeserializer
import com.google.gson.JsonParseException
import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializer
import timber.log.Timber
import java.time.Instant
import java.time.OffsetDateTime
import java.time.ZoneId
Expand All @@ -43,23 +44,24 @@ object ObjectUtils {
val patterns = arrayOf(
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd'T'HH:mmX",
"yyyy-MM-dd'T'HH:mm:ssX",
"yyyy-MM-dd'T'HH:mmZ",
"yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"
"yyyy-MM-dd'T'HH:mm:ssX"
)
for (pattern in patterns) {
try {
val parser = DateTimeFormatter.ofPattern(pattern).withZone(ZoneId.of(BuildConfig.SIECOMP_TIMEZONE))
return@JsonDeserializer ZonedDateTime.parse(jsonPrimitive.asString, parser)
} catch (_: Throwable) { }
}

return@JsonDeserializer ZonedDateTime.parse(jsonPrimitive.asString)
}

// if provided as Long
if (jsonPrimitive.isNumber) {
return@JsonDeserializer ZonedDateTime.ofInstant(Instant.ofEpochMilli(jsonPrimitive.asLong), ZoneId.systemDefault())
}

// Timber.e("JSON Primitive: $jsonPrimitive")
} catch (e: RuntimeException) {
throw JsonParseException("Unable to parse ZonedDateTime", e)
}
Expand Down

0 comments on commit 763a298

Please sign in to comment.