diff --git a/api/src/main/kotlin/com/lhwdev/selfTestMacro/api/registerServey.kt b/api/src/main/kotlin/com/lhwdev/selfTestMacro/api/registerServey.kt index 613af886..ce049e0f 100644 --- a/api/src/main/kotlin/com/lhwdev/selfTestMacro/api/registerServey.kt +++ b/api/src/main/kotlin/com/lhwdev/selfTestMacro/api/registerServey.kt @@ -52,7 +52,8 @@ data class SurveyData( val rspns14: String? = null, val rspns15: String? = null, @SerialName("upperToken") val userToken: UserToken, - @SerialName("upperUserNameEncpt") val upperUserName: String + @SerialName("upperUserNameEncpt") val upperUserName: String, + val clientVersion: String ) @Serializable diff --git a/app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt b/app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt index b4613723..7fa2d5fd 100644 --- a/app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt +++ b/app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt @@ -40,7 +40,7 @@ suspend fun Context.singleOfUserGroup(list: List) = if(list.size == 1) lis null } -fun Context.surveyData(user: User, usersIdentifier: UserIdentifier): SurveyData { +suspend fun Context.surveyData(user: User, usersIdentifier: UserIdentifier): SurveyData { val pref = preferenceState val quickTestNegative = pref.quickTest?.let { @@ -53,6 +53,7 @@ fun Context.surveyData(user: User, usersIdentifier: UserIdentifier): SurveyData } ?: false val isIsolated = pref.isIsolated + val clientVersion = pref.appMeta().hcsVersion return SurveyData( userToken = user.token, @@ -60,7 +61,9 @@ fun Context.surveyData(user: User, usersIdentifier: UserIdentifier): SurveyData rspns03 = if(quickTestNegative) null else "1", rspns07 = if(quickTestNegative) "0" else null, // rspns09 = if(isIsolated) "1" else "0", - rspns00 = !(isIsolated) // true = okay, false = problem + // rspns00 = !(isIsolated) // true = okay, false = problem + rspns00 = true, + clientVersion = clientVersion ) } @@ -126,7 +129,7 @@ fun Context.updateTime(intent: PendingIntent) { private val random = Random -private fun millisToDaysCumulative(millis: Long) = +fun millisToDaysCumulative(millis: Long) = // ms sec min hour day millis / 1000 / 60 / 60 / 24 @@ -161,6 +164,10 @@ fun Context.scheduleNextAlarm( return } + if(nextDay && lastDay == millisToDaysCumulative(new.timeInMillis)) { + new.add(Calendar.DAY_OF_YEAR, 1) + } + var iteration = 0 while(iteration < 10) { val days = millisToDaysCumulative(new.timeInMillis) @@ -168,7 +175,6 @@ fun Context.scheduleNextAlarm( when { !pref.includeWeekend && (day == Calendar.SATURDAY || day == Calendar.SUNDAY) -> Unit - nextDay || lastDay == days || targetMin < currentMin - 5 -> Unit quick != null && quick.behavior == QuickTestInfo.Behavior.doNotSubmit && day in quick.days -> Unit else -> break } diff --git a/app/src/main/java/com/lhwdev/selfTestMacro/utils.kt b/app/src/main/java/com/lhwdev/selfTestMacro/utils.kt index 95b53273..1138644d 100644 --- a/app/src/main/java/com/lhwdev/selfTestMacro/utils.kt +++ b/app/src/main/java/com/lhwdev/selfTestMacro/utils.kt @@ -20,6 +20,7 @@ import androidx.core.view.doOnPreDraw import androidx.core.view.setPadding import com.google.android.material.snackbar.Snackbar import com.lhwdev.fetch.http.Session +import com.lhwdev.fetch.http.fetch import com.lhwdev.selfTestMacro.api.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.suspendCancellableCoroutine @@ -28,6 +29,7 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json +import java.net.URL import java.util.WeakHashMap import kotlin.coroutines.resume import kotlin.properties.ReadWriteProperty @@ -153,6 +155,8 @@ class PreferenceState(val pref: SharedPreferences) { putLong("lastSubmit", value) } + var appMeta: AppMeta? by pref.preferenceSerialized("appMeta", AppMeta.serializer()) + var lastQuestion: String? by pref.preferenceString("lastQuestion") var shownNotices: Set @@ -167,6 +171,25 @@ class PreferenceState(val pref: SharedPreferences) { } } +suspend fun PreferenceState.appMeta(): AppMeta.Data { + val day = millisToDaysCumulative(System.currentTimeMillis()) + val last = appMeta + if(last != null && last.at == day) return last.data + + val data = fetch(URL("https://raw.githubusercontent.com/wiki/lhwdev/covid-selftest-macro/app_meta.json")) + .toJsonLoose(AppMeta.Data.serializer()) + appMeta = AppMeta(data, at = day) + return data +} + +@Serializable +class AppMeta(val data: Data, val at: Long) { + @Serializable + class Data( + val hcsVersion: String + ) +} + @Serializable data class QuickTestInfo( val days: Set,