-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 #6294 from grzesiek2010/COLLECT-5866_1
Added Buddhist calendar
- Loading branch information
Showing
39 changed files
with
613 additions
and
92 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
2 changes: 1 addition & 1 deletion
2
...lect/android/utilities/DateTimeUtils.java → ...droid/widgets/datetime/DateTimeUtils.java
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
90 changes: 90 additions & 0 deletions
90
...rc/main/java/org/odk/collect/android/widgets/datetime/pickers/BuddhistDatePickerDialog.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,90 @@ | ||
package org.odk.collect.android.widgets.datetime.pickers | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import org.joda.time.LocalDateTime | ||
import org.joda.time.chrono.BuddhistChronology | ||
import org.odk.collect.android.R | ||
import org.odk.collect.android.widgets.datetime.DateTimeUtils | ||
|
||
class BuddhistDatePickerDialog : CustomDatePickerDialog() { | ||
private lateinit var monthsArray: Array<String> | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
monthsArray = resources.getStringArray(R.array.buddhist_months) | ||
return super.onCreateView(inflater, container, savedInstanceState) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
setUpValues() | ||
} | ||
|
||
override fun updateDays() { | ||
val localDateTime = getCurrentBuddhistDate() | ||
setUpDayPicker(localDateTime.dayOfMonth, localDateTime.dayOfMonth().maximumValue) | ||
} | ||
|
||
override fun getOriginalDate(): LocalDateTime { | ||
return getCurrentBuddhistDate() | ||
} | ||
|
||
private fun setUpDatePicker() { | ||
val buddhistDate = DateTimeUtils | ||
.skipDaylightSavingGapIfExists(date) | ||
.toDateTime() | ||
.withChronology(BuddhistChronology.getInstance()) | ||
.toLocalDateTime() | ||
|
||
setUpDayPicker(buddhistDate.dayOfMonth, buddhistDate.dayOfMonth().maximumValue) | ||
setUpMonthPicker(buddhistDate.monthOfYear, monthsArray) | ||
setUpYearPicker(buddhistDate.year, MIN_SUPPORTED_YEAR, MAX_SUPPORTED_YEAR) | ||
} | ||
|
||
private fun setUpValues() { | ||
setUpDatePicker() | ||
updateGregorianDateLabel() | ||
} | ||
|
||
private fun getCurrentBuddhistDate(): LocalDateTime { | ||
var buddhistDay = day | ||
val buddhistMonth = monthsArray.indexOf(month) | ||
val buddhistYear = year | ||
|
||
val buddhistDate = LocalDateTime( | ||
buddhistYear, | ||
buddhistMonth + 1, | ||
1, | ||
0, | ||
0, | ||
0, | ||
0, | ||
BuddhistChronology.getInstance() | ||
) | ||
if (buddhistDay > buddhistDate.dayOfMonth().maximumValue) { | ||
buddhistDay = buddhistDate.dayOfMonth().maximumValue | ||
} | ||
|
||
return LocalDateTime( | ||
buddhistYear, | ||
buddhistMonth + 1, | ||
buddhistDay, | ||
0, | ||
0, | ||
0, | ||
0, | ||
BuddhistChronology.getInstance() | ||
) | ||
} | ||
|
||
companion object { | ||
const val MIN_SUPPORTED_YEAR = 2443 // 1900 in Gregorian calendar | ||
const val MAX_SUPPORTED_YEAR = 2643 // 2100 in Gregorian calendar | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...ments/dialogs/CustomTimePickerDialog.java → ...etime/pickers/CustomTimePickerDialog.java
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
Oops, something went wrong.