Skip to content

Commit

Permalink
Fix bugggg
Browse files Browse the repository at this point in the history
  • Loading branch information
lhwdev committed Mar 3, 2022
1 parent f2ef78f commit ae793fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/lhwdev/selfTestMacro/selfTestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ suspend fun Context.singleOfUserGroup(list: List<User>) = 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 {
Expand All @@ -53,14 +53,17 @@ fun Context.surveyData(user: User, usersIdentifier: UserIdentifier): SurveyData
} ?: false
val isIsolated = pref.isIsolated

val clientVersion = pref.appMeta().hcsVersion

return SurveyData(
userToken = user.token,
upperUserName = usersIdentifier.mainUserName,
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
)
}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -161,14 +164,17 @@ 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)
val day = new[Calendar.DAY_OF_WEEK]

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
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/lhwdev/selfTestMacro/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<String>
Expand All @@ -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<Int>,
Expand Down

0 comments on commit ae793fa

Please sign in to comment.