HijriDatePickerPlus is an advanced Android date picker built using Jetpack Compose, designed for selecting dates in the Hijri (Islamic) calendar. The picker now uses the widely supported IslamicCalendar
class, offering flexibility and compatibility across various regions, with support for the “umalqura”, “civil”, or “islamic” calendar types.
While the Umm Al-Qura calendar is specific to Saudi Arabia and suitable for regional use, the IslamicCalendar provides broader support globally. It offers flexibility for international users with support for various calendar types, including Islamic Civil and General Islamic calendars.
git clone https://github.com/YourUsername/HijriDatePickerPlus.git
To use HijriDatePickerPlus in your Android project, follow these steps:
First, add the dependency to your project’s build.gradle
file. Make sure your project is set up to use JitPack by adding the JitPack repository in your settings.gradle
or build.gradle
(for Gradle version catalog users, include this in your version catalog file):
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Then, add the following to your app-level build.gradle
file under dependencies
:
dependencies {
implementation 'com.github.mohamedma872:HijriDatePickerPlus:Tag'
}
Replace Tag
with the latest version, which you can find here.
To use the date picker, simply call the HijriDatePickerPlus component in your Composable function. Here’s an example of how to integrate it into your app:
@Composable
fun ShowHijriDatePicker() {
// Example of how to trigger the date picker using different calendar types
HijriDatePickerButton()
OR
showHijriDatePicker(
initialYear = 1446, // Pass the initial year, e.g., current Hijri year
initialMonth = 1, // Initial month
initialDay = 10, // Initial day
onDateSelected = { year, month, day ->
// Handle date selected (year, month, day)
println("Selected Date: $day-${getHijriMonthName(month)}-$year")
},
onConfirm = { year, month, day ->
// Handle the final confirmed date
println("Confirmed Date: $day-${getHijriMonthName(month)}-$year")
},
onDismissRequest = {
// Handle the dismiss action
println("Date Picker Dismissed")
},
calendarType = "umalqura" // Use "umalqura", "civil", or "islamic"
)
}
You can modify the picker to suit your design needs by adjusting properties such as:
HeaderSection
, YearSelectionScreen
, and FooterSection
components.IslamicCalendar
class for date calculations. You can directly interact with this class for customization or region-specific adjustments.You can easily get the current date based on the Umm Al-Qura, Islamic Civil, or General Islamic calendar using the following function:
For example, to get the current date for the selected calendar type:
// Get the current Hijri date using the desired calendar type
val currentHijriCalendar = getIslamicCalendar("umalqura")
val currentHijriYear = currentHijriCalendar.get(Calendar.YEAR)
val currentHijriMonth = currentHijriCalendar.get(Calendar.MONTH)
val currentHijriDay = currentHijriCalendar.get(Calendar.DAY_OF_MONTH)
println("Current Hijri Date: $currentHijriDay-${getHijriMonthName(currentHijriMonth)}-$currentHijriYear")
You can modify the picker to suit your design needs by adjusting properties such as:
HeaderSection
, YearSelectionScreen
, and FooterSection
components.IslamicCalendar
class for date calculations. You can directly interact with this class if you need further customization or region-specific adjustments.HijriDatePickerPlus implements a critical fix for date validation in the Hijri calendar, ensuring that selecting a day beyond the valid number of days in a month (e.g., selecting the 30th day in a month with only 29 days) doesn’t cause the app to crash. The picker automatically adjusts the selected day to the correct number of days in each month.
To install and use HijriDatePickerPlus in your project:
You can customize the appearance and behavior of the HijriDatePickerPlus by adjusting the following:
IslamicCalendar
class directly for further custom functionality or region-specific adaptations.If you’d like to contribute to HijriDatePickerPlus, feel free to submit a pull request or open an issue for any bugs or features you’d like to suggest.
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions or support regarding this project, you can contact the project maintainer at: mohamed.ma872@gmail.com
This updated README includes the mention of the getIslamicCalendar
function and an example of how to use it to get the current Hijri date. Let me know if you need any further adjustments!