-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from amardeshbd/develop
Release 1.4
- Loading branch information
Showing
13 changed files
with
96 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...c/main/java/com/blacklivesmatter/policebrutality/ui/util/IncidentAvailabilityValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.blacklivesmatter.policebrutality.ui.util | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import com.google.android.material.datepicker.CalendarConstraints | ||
import org.threeten.bp.Instant | ||
import org.threeten.bp.OffsetDateTime | ||
import org.threeten.bp.ZoneId | ||
import org.threeten.bp.format.DateTimeFormatter | ||
import timber.log.Timber | ||
import java.util.Locale | ||
|
||
/** | ||
* Validates if given date has incident records. | ||
*/ | ||
class IncidentAvailabilityValidator( | ||
/** | ||
* List of date that has available incident records | ||
*/ | ||
private val datesIncidentHappened: List<String> | ||
) : CalendarConstraints.DateValidator { | ||
private val dateFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.US) | ||
override fun isValid(date: Long): Boolean { | ||
if (datesIncidentHappened.isEmpty()) { | ||
return true // Don't block all the dates in case we don't have dates data | ||
} | ||
|
||
val instant = Instant.ofEpochMilli(date) | ||
val offsetDateTime: OffsetDateTime = OffsetDateTime.ofInstant(instant, ZoneId.of("UTC")) | ||
val formattedDate = offsetDateTime.format(dateFormat) | ||
|
||
val didIncidentHappenOnThisDay = datesIncidentHappened.contains(formattedDate) | ||
Timber.d("Did incident happen on $formattedDate : $didIncidentHappenOnThisDay") | ||
return didIncidentHappenOnThisDay | ||
} | ||
|
||
/** Part of [android.os.Parcelable] requirements. Do not use. */ | ||
override fun describeContents(): Int = 0 | ||
override fun writeToParcel(dest: Parcel?, flags: Int) { | ||
dest?.writeList(datesIncidentHappened) | ||
} | ||
|
||
companion object CREATOR : Parcelable.Creator<IncidentAvailabilityValidator> { | ||
override fun createFromParcel(parcel: Parcel): IncidentAvailabilityValidator { | ||
return IncidentAvailabilityValidator(emptyList()) | ||
} | ||
|
||
override fun newArray(size: Int): Array<IncidentAvailabilityValidator?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.