material-components / material-components/material-components-android
[MaterialDatePicker] Support for selecting multiple dates
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 17.4k
- Fork
- 3.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Is your feature request related to a problem? Please describe.
Currently there is no way to use the date picker to select multiple dates.
Only a single date or a date range is possible.
Describe the solution you'd like
I would like to see an date picker to select multiple dates which are not a range.
Additional context
We need an calendar which where users can select multiple (independend) dates.
Like
I want to use this service on 2022-08-04 2022-08-10 and 2022-08-12
I found out that this is somewhat possible to implement already.
Checkout this one:
(Ugly!) Kotlin source code
@SuppressLint("RestrictedApi")
class MultipleDatesSelector() : SingleDateSelector() {
private var dates = mutableListOf<Long>()
override fun select(selection: Long) {
if (dates.contains(selection)) dates.remove(selection)
else dates.add(selection)
}
override fun isSelectionComplete(): Boolean {
return dates.isNotEmpty()
}
override fun getSelectedDays(): MutableCollection<Long> {
return dates.toCollection(arrayListOf())
}
override fun getSelectionDisplayString(context: Context): String {
return "" // TODO: A nice string for multiple dates
}
override fun getDefaultTitleResId(): Int {
return R.string.select_multiple_dates_title
}
/* Parcelable interface */
// TODO: Is this correcty implemented?!
@JvmField
val CREATOR: Parcelable.Creator<SingleDateSelector> = object : Parcelable.Creator<SingleDateSelector> {
override fun createFromParcel(source: Parcel): SingleDateSelector {
val singleDateSelector = X()
singleDateSelector.dates = source.readValue(List::class.java.classLoader) as MutableList<Long>
return singleDateSelector
}
override fun newArray(size: Int): Array<SingleDateSelector> {
return arrayOf(X())
}
}
}
This is possible because there exist already an method to add a custom selector.
https://github.com/material-components/material-components-android/blob/a6df2545efb84e7bca37fdf987ec35c6846e5025/lib/java/com/google/android/material/datepicker/MaterialDatePicker.java#L623-L627
Unfortunately, the method above as well as the DateSelector is restricted to the Scope.LibraryGroup, which is odd.
https://github.com/material-components/material-components-android/blob/a6df2545efb84e7bca37fdf987ec35c6846e5025/lib/java/com/google/android/material/datepicker/DateSelector.java#L50-L51
It would be great if to consider to either:
- Remove the restriction
- Support a multiple dates picker via this library
As my code shows the implementation isn't that hard.
Would you interested in support such an picker? I could also help by creating a pull request for it...
I would also help to cleanup the DateSelector interface instead and to remove the restriction (because I think it is restricted because the DateSelector isn't a great abstraction yeat 😁 )
Thank you.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da MaterialDatePicker.java, intorno al punto di ingresso dei selettori personalizzati, e da DateSelector.java, in particolare dalle relative restrizioni Scope.LibraryGroup. Determina se la modifica debba esporre selettori personalizzati o aggiungere un selettore integrato indipendente per più date; il lavoro è completato quando le date selezionate possono essere scelte indipendentemente e restituite tramite l’API pubblica del picker.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, java, kotlin
- Ambito
- mobile
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100