-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integrate kronos-android ntp clock library into project #150
base: develop
Are you sure you want to change the base?
Changes from 7 commits
fe9df02
bcc9950
c7f3c82
d04e542
385e199
fdff161
2f31082
1a90ab6
f2f9b99
e626be8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,10 @@ dependencies { | |
testImplementation "io.mockk:mockk:1.10.0" | ||
// Koin | ||
testImplementation "org.koin:koin-test:$koin_version" | ||
|
||
// Kronos ntp clock | ||
def kronos_latest_version = "0.0.1-alpha09" | ||
implementation "com.lyft.kronos:kronos-android:$kronos_latest_version" | ||
} | ||
|
||
apply plugin: 'com.google.gms.google-services' | ||
apply plugin: 'com.google.gms.google-services' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the same formatter from AS in the future to avoid this kind of changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.covidwatch.android.data | ||
|
||
import android.content.Context | ||
import com.lyft.kronos.AndroidClockFactory | ||
import com.lyft.kronos.KronosClock | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
import java.time.ZoneId | ||
|
||
class NtpTime (context : Context) { | ||
private val kronosClock : KronosClock = AndroidClockFactory.createKronosClock(context) | ||
|
||
private fun currentTimeMillis() : Long = kronosClock.getCurrentTimeMs() | ||
|
||
fun syncInBackground() = kronosClock.syncInBackground() | ||
|
||
fun nowAsLocalDate() : LocalDate = | ||
Instant.ofEpochMilli(currentTimeMillis()).atZone(ZoneId.systemDefault()).toLocalDate() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
One way to resolve is just to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed notion of LocalDate from NtpTime to avoid confusion / simplify the code. Sticking to returning Instants instead |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,19 +14,21 @@ import com.google.android.material.datepicker.CalendarConstraints | |
import com.google.android.material.datepicker.MaterialDatePicker | ||
import com.google.android.material.textfield.TextInputLayout | ||
import org.covidwatch.android.R | ||
import org.covidwatch.android.data.NtpTime | ||
import org.covidwatch.android.databinding.FragmentVerifyPositiveDiagnosisBinding | ||
import org.covidwatch.android.extension.observe | ||
import org.covidwatch.android.extension.observeEvent | ||
import org.covidwatch.android.extension.observeNullableEvent | ||
import org.covidwatch.android.extension.toInstant | ||
import org.covidwatch.android.ui.BaseViewModelFragment | ||
import org.koin.android.ext.android.inject | ||
import org.koin.androidx.viewmodel.ext.android.stateViewModel | ||
import java.time.LocalDate | ||
|
||
class VerifyPositiveDiagnosisFragment : | ||
BaseViewModelFragment<FragmentVerifyPositiveDiagnosisBinding, VerifyPositiveDiagnosisViewModel>() { | ||
|
||
override val viewModel: VerifyPositiveDiagnosisViewModel by stateViewModel() | ||
private val ntpTime: NtpTime by inject() | ||
|
||
override fun bind( | ||
inflater: LayoutInflater, | ||
|
@@ -119,13 +121,13 @@ class VerifyPositiveDiagnosisFragment : | |
val builder = MaterialDatePicker.Builder.datePicker() | ||
val constraints = CalendarConstraints.Builder() | ||
|
||
val twoWeeksAgo = LocalDate.now().plusDays(-14).toInstant() | ||
val twoWeeksAgo = ntpTime.nowAsLocalDate().plusDays(-14).toInstant() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a problem with this solution. I tried to use selection to current day when we open the dialog but it doesn't help. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding a setOpenAt() to the date picker constraints fixes this |
||
.toEpochMilli() | ||
|
||
// Day in the past or 14 days back | ||
val fromWhen = dayInPast ?: twoWeeksAgo | ||
|
||
val untilNow = LocalDate.now().toInstant().toEpochMilli() | ||
val untilNow = ntpTime.nowAsLocalDate().toInstant().toEpochMilli() | ||
|
||
constraints.setValidator(BaseDateValidator { it in fromWhen..untilNow }) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last dependencies are preserved for the test flavored so let's move this before the test dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dependency line moved