Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #22

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4b090e6
add utils file
mohamedma872 Sep 5, 2024
2fe0f2e
add function to show picker and make it more simple
mohamedma872 Sep 6, 2024
019cff7
Merge branch 'master' into Development
mohamedma872 Sep 6, 2024
3e7374a
add function to show picker
mohamedma872 Sep 6, 2024
1f62a20
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 6, 2024
eb2581b
Merge branch 'master' into Development
mohamedma872 Sep 6, 2024
1105a6c
add library files
mohamedma872 Sep 6, 2024
b713221
add library files
mohamedma872 Sep 6, 2024
05c966d
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 6, 2024
6436d53
build lib
mohamedma872 Sep 6, 2024
824e598
Update README.md
mohamedma872 Sep 6, 2024
04df34e
add some file to gradle
mohamedma872 Sep 6, 2024
e9b6d13
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 6, 2024
2b1e590
add maven publish
mohamedma872 Sep 7, 2024
367a94a
add some updates to maven and gradle
mohamedma872 Sep 7, 2024
a74832e
add library as project to main app
mohamedma872 Sep 7, 2024
5adb318
add MavenPublication to lib
mohamedma872 Sep 7, 2024
5b43cae
Merge branch 'master' into Development
mohamedma872 Sep 7, 2024
0eec7de
update groupId , artifactId
mohamedma872 Sep 7, 2024
f48d950
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 7, 2024
1f9422b
update groupId , artifactId
mohamedma872 Sep 7, 2024
98e814d
update gradle
mohamedma872 Sep 7, 2024
53abfa8
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 7, 2024
43e5ecd
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 7, 2024
5c79784
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 7, 2024
9bb763e
Merge remote-tracking branch 'origin/Development' into Development
mohamedma872 Sep 7, 2024
b2ff613
stable release
mohamedma872 Sep 7, 2024
0d82f0f
Merge branch 'master' into Development
mohamedma872 Sep 7, 2024
15608e3
Update README.md
mohamedma872 Sep 7, 2024
7dd3b53
Update README.md
mohamedma872 Sep 8, 2024
b9b7974
Merge branch 'master' into Development
mohamedma872 Sep 8, 2024
40dc98f
add preview for each function
mohamedma872 Sep 8, 2024
1884918
change min sdk from 28 to 26
mohamedma872 Sep 26, 2024
fa88ead
delete the library of live cycle data
mohamedma872 Sep 26, 2024
96f86b9
fix some issues
mohamedma872 Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions HijriDatePickerLib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
compileSdk = 34

defaultConfig {
minSdk = 28
minSdk = 26

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down Expand Up @@ -44,7 +44,7 @@ android {
dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
// implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
Expand All @@ -54,7 +54,7 @@ dependencies {
debugImplementation(libs.androidx.ui.test.manifest)
implementation( libs.material3)
implementation (libs.material)
implementation (libs.androidx.lifecycle.runtime.ktx.v231)
// implementation (libs.androidx.lifecycle.runtime.ktx.v231)
implementation (libs.androidx.foundation)
implementation (libs.android.joda)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -38,3 +39,13 @@ fun FooterSection(nextMonthName: String, onConfirm: () -> Unit, onCancel: () ->
}
}
}

@Preview(showBackground = true)
@Composable
fun PreviewFooterSection() {
FooterSection(
nextMonthName = "Safar",
onConfirm = { /* Handle confirm action in preview */ },
onCancel = { /* Handle cancel action in preview */ }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -44,3 +45,19 @@ fun HeaderSection(calendar: Calendar, onYearClick: () -> Unit) {
)
}
}

@Preview(showBackground = true)
@Composable
fun PreviewHeaderSection() {
// Creating an instance of IslamicCalendar for preview purposes
val calendar = IslamicCalendar().apply {
set(Calendar.YEAR, 1445)
set(Calendar.MONTH, 1) // Safar
set(Calendar.DAY_OF_MONTH, 5)
}

// Preview the HeaderSection with a mock IslamicCalendar and a simple onYearClick action
HeaderSection(calendar = calendar, onYearClick = {
// Handle year click in preview
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -75,7 +76,7 @@ fun HijriDatePickerButton(
preselectedMonth.value = month
preselectedDay.value = day
},
onConfirm = {
onConfirm = { year, month, day ->
showDialog = false // Close the dialog when Confirm is clicked
},
onDismissRequest = {
Expand All @@ -85,4 +86,11 @@ fun HijriDatePickerButton(
"umalqura" // "umalqura", "civil", or "islamic"
)
}
}

@Preview(showBackground = true)
@Composable
fun PreviewHijriDatePickerButton() {
// Preview the HijriDatePickerButton with "umalqura" as calendar type
HijriDatePickerButton(calendarType = "umalqura")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog

Expand All @@ -26,8 +27,8 @@ fun HijriDatePickerDialogWithThreeSections(
initialYear: Int,
initialMonth: Int,
initialDay: Int,
onDateSelected: (Int, Int, Int) -> Unit,
onConfirm: () -> Unit,
onDateSelected: (Int, Int, Int) -> Unit, // Call this when date is selected
onConfirm: (Int, Int, Int) -> Unit, // Pass the selected year, month, day
onDismissRequest: () -> Unit,
initialShowYearSelection: Boolean = true, // Always show year selection when opening the dialog
calendarType: String
Expand All @@ -38,25 +39,30 @@ fun HijriDatePickerDialogWithThreeSections(
var showYearSelection by remember { mutableStateOf(initialShowYearSelection) }

// Ensure selected day is valid for the selected month
val daysInMonth = getHijriDaysInMonth(selectedYear, selectedMonth,calendarType)
val daysInMonth = getHijriDaysInMonth(selectedYear, selectedMonth, calendarType)
if (selectedDay > daysInMonth) {
selectedDay = daysInMonth
}

Dialog(onDismissRequest = onDismissRequest) {
Surface(
modifier = Modifier.fillMaxWidth().heightIn(min = 400.dp, max = 500.dp).padding(16.dp),
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 400.dp, max = 500.dp)
.padding(16.dp),
shape = MaterialTheme.shapes.medium
) {
Column(
modifier = Modifier.fillMaxWidth().background(Color.White)
modifier = Modifier
.fillMaxWidth()
.background(Color.White)
) {
// Header section with the selected date
val calendar = getIslamicCalendar(calendarType)
// Set the specific year, month, and day on the calendar instance
calendar.set(Calendar.YEAR, selectedYear)
calendar.set(Calendar.MONTH, selectedMonth)
calendar.set(Calendar.DAY_OF_MONTH, selectedDay)

// Pass the callback to trigger year selection
HeaderSection(calendar = calendar) {
showYearSelection = true // Toggle to show year selection when the year is clicked
Expand All @@ -77,15 +83,17 @@ fun HijriDatePickerDialogWithThreeSections(
} else {
// Month Grid with Days Section
Box(
modifier = Modifier.weight(1f).fillMaxWidth()
modifier = Modifier
.weight(1f)
.fillMaxWidth()
) {
MonthGridWithDays(
selectedYear = selectedYear,
onDaySelected = { year, month, day ->
selectedYear = year
selectedMonth = month
selectedDay = day
onDateSelected(year, month, day)
onDateSelected(year, month, day) // Update selected date
},
preselectedMonth = selectedMonth, // Pass the preselected month
preselectedDay = selectedDay, // Pass the preselected day
Expand All @@ -99,11 +107,36 @@ fun HijriDatePickerDialogWithThreeSections(
// Footer with Confirm and Cancel buttons
FooterSection(
nextMonthName = getHijriMonthName(selectedMonth),
onConfirm = onConfirm,
onCancel = onDismissRequest
onConfirm = {
onConfirm(selectedYear, selectedMonth, selectedDay) // Pass the selected date when confirmed
},
onCancel = onDismissRequest // Handle dismissal when cancel is clicked
)
}
}
}
}


@Preview(showBackground = true)
@Composable
fun PreviewHijriDatePickerDialogWithThreeSections() {
HijriDatePickerDialogWithThreeSections(
initialYear = 1445, // Initial Hijri year
initialMonth = 1, // Safar (month index starts at 0)
initialDay = 5, // 5th day of Safar
onDateSelected = { year, month, day ->
// Simulate the date selection in the preview (just log or print)
println("Date Selected in Preview: $day-${getHijriMonthName(month)}-$year")
},
onConfirm = { year, month, day ->
// Simulate confirmation action in the preview
println("Date Confirmed in Preview: $day-${getHijriMonthName(month)}-$year")
},
onDismissRequest = {
// Simulate dismiss action in the preview
println("Dialog Dismissed in Preview")
},
calendarType = "umalqura" // Simulate the "umalqura" calendar type for preview
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -79,4 +80,18 @@ fun MonthGridWithDays(
}
}
}
}

@Preview(showBackground = true)
@Composable
fun PreviewMonthGridWithDays() {
MonthGridWithDays(
selectedYear = 1445, // Example year
onDaySelected = { year, month, day ->
// Handle day selection (preview action)
},
preselectedMonth = 1, // Safar (0-indexed month)
preselectedDay = 5, // Preselected day
calendarType = "umalqura" // Calendar type for preview
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -57,4 +58,16 @@ fun YearSelectionScreen(
)
}
}
}

@Preview(showBackground = true)
@Composable
fun PreviewYearSelectionScreen() {
YearSelectionScreen(
selectedYear = 1445, // Preselected year
onYearSelected = { year ->
// Handle year selection (preview action)
},
currentYear = 1445 // Scroll to this year by default
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.tooling.preview.Preview

// Example of how you can trigger the date picker from anywhere
/* showHijriDatePicker(
Expand Down Expand Up @@ -36,37 +37,51 @@ fun showHijriDatePicker(
onDismissRequest: () -> Unit,
calendarType: String
) {
// State for preselected date
val preselectedYear = remember { mutableStateOf(initialYear) }
val preselectedMonth = remember { mutableStateOf(initialMonth) }
val preselectedDay = remember { mutableStateOf(initialDay) }

// Dialog visibility is controlled outside (no button, it will be triggered by external events)
// The showDialog state is controlled outside, as this Composable doesn't have buttons.
var showDialog by remember { mutableStateOf(true) }

if (showDialog) {
HijriDatePickerDialogWithThreeSections(
initialYear = preselectedYear.value,
initialMonth = preselectedMonth.value,
initialDay = preselectedDay.value,
initialYear = initialYear, // Preselected year from the lifted state
initialMonth = initialMonth, // Preselected month from the lifted state
initialDay = initialDay, // Preselected day from the lifted state
onDateSelected = { year, month, day ->
// Update the preselected date for the next opening
preselectedYear.value = year
preselectedMonth.value = month
preselectedDay.value = day
onDateSelected(year, month, day) // Call the provided callback
// Update the selected date in the parent
onDateSelected(year, month, day)
},
onConfirm = {
showDialog = false // Close the dialog when Confirm is clicked
onConfirm = { year, month, day ->
showDialog = false // Close the dialog when Confirm is clicked
// Pass the selected date to the confirm callback
onConfirm(preselectedYear.value, preselectedMonth.value, preselectedDay.value)
onConfirm(year, month, day)
},
onDismissRequest = {
showDialog = false // Close the dialog when dismissed
onDismissRequest() // Call the dismiss callback
showDialog = false // Close the dialog when dismissed
onDismissRequest() // Call the dismiss callback
},
initialShowYearSelection = true, // Always show year selection first
calendarType = calendarType // "umalqura", "civil", or "islamic"
calendarType = calendarType // Calendar type ("umalqura", "civil", or "islamic")
)
}
}


@Preview(showBackground = true)
@Composable
fun PreviewHijriDatePicker() {
// Preview the Hijri Date Picker with some predefined values
showHijriDatePicker(
initialYear = 1445, // Initial year in Hijri calendar
initialMonth = 1, // Safar (0-indexed month)
initialDay = 1, // 1st day of Safar
onDateSelected = { year, month, day ->
// Handle date selection (preview action)
},
onConfirm = { year, month, day ->
// Handle confirmation (preview action)
},
onDismissRequest = {
// Handle dismissal (preview action)
},
calendarType = "umalqura" // Calendar type for preview
)
}
Loading