Fix date range selection issue.
- The issue was that the MaterialDatePicker uses the UTC time zone internally. We had to account for that to avoid showing an off by one wrong selection on the Filter Options date range and the Date Range picker (MaterialDatePicker).
This commit is contained in:
parent
7e12224795
commit
0ad0f7c911
3 changed files with 17 additions and 3 deletions
|
@ -99,6 +99,8 @@ class FilterOptionsDialog : DialogFragment() {
|
|||
|
||||
binding.tvEndDate.setOnClickListener { showDateRangePicker() }
|
||||
|
||||
dateFormat.timeZone = TimeZone.getTimeZone("UTC")
|
||||
|
||||
updateDateTextViews()
|
||||
|
||||
// Initialize Asset
|
||||
|
|
|
@ -2,6 +2,7 @@ package cy.agorise.bitsybitshareswallet.viewmodels
|
|||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.*
|
||||
import com.google.android.material.datepicker.MaterialDatePicker
|
||||
import cy.agorise.bitsybitshareswallet.database.joins.TransferDetail
|
||||
import cy.agorise.bitsybitshareswallet.models.FilterOptions
|
||||
import cy.agorise.bitsybitshareswallet.repositories.TransferDetailRepository
|
||||
|
@ -11,6 +12,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
|
||||
|
||||
class TransactionsViewModel(application: Application) : AndroidViewModel(application) {
|
||||
companion object {
|
||||
const val TAG = "TransactionsViewModel"
|
||||
|
@ -32,12 +34,19 @@ class TransactionsViewModel(application: Application) : AndroidViewModel(applica
|
|||
|
||||
init {
|
||||
// Initialize the start and end dates for the FilterOptions
|
||||
val calendar = Calendar.getInstance()
|
||||
val calendar = getClearedUtc()
|
||||
calendar.timeInMillis = MaterialDatePicker.todayInUtcMilliseconds()
|
||||
mFilterOptions.endDate = calendar.timeInMillis
|
||||
calendar.add(Calendar.MONTH, -2)
|
||||
calendar.roll(Calendar.MONTH, -2)
|
||||
mFilterOptions.startDate = calendar.timeInMillis
|
||||
}
|
||||
|
||||
private fun getClearedUtc(): Calendar {
|
||||
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||
utc.clear()
|
||||
return utc
|
||||
}
|
||||
|
||||
internal fun getFilteredTransactions(userId: String): LiveData<List<TransferDetail>> {
|
||||
val currencyCode = Helper.getCoingeckoSupportedCurrency(Locale.getDefault())
|
||||
transactions = mRepository.getAll(userId, currencyCode)
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
android:text="@string/text__date_range"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintTop_toTopOf="@id/cbDateRange"
|
||||
app:layout_constraintBottom_toBottomOf="@id/cbDateRange"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<CheckBox
|
||||
|
@ -118,6 +119,7 @@
|
|||
android:text="@string/text__asset"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintTop_toTopOf="@id/cbAsset"
|
||||
app:layout_constraintBottom_toBottomOf="@id/cbAsset"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<CheckBox
|
||||
|
@ -158,6 +160,7 @@
|
|||
android:text="@string/text__equivalent_value"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintTop_toTopOf="@id/cbEquivalentValue"
|
||||
app:layout_constraintBottom_toBottomOf="@id/cbEquivalentValue"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
|
||||
<CheckBox
|
||||
|
@ -238,4 +241,4 @@
|
|||
app:layout_constraintEnd_toStartOf="@id/btnFilter"
|
||||
android:textColor="@color/colorPrimary"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
Loading…
Reference in a new issue