Skip to content

Commit

Permalink
Merge pull request #14 from DogusTeknoloji/feature/one_screen_ui
Browse files Browse the repository at this point in the history
OneScreen year and month ui added
  • Loading branch information
BerkkanB authored Sep 22, 2022
2 parents 2b041df + 55361aa commit cc8fa6e
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 123 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/com/dt/calendarwork/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.sp
import com.dt.calendarwork.ui.theme.CalendarWorkTheme
import com.dt.composedatepicker.CalendarType
import com.dt.composedatepicker.ComposeCalendar
import com.dt.composedatepicker.MonthViewType
import com.dt.composedatepicker.SelectDateListener
Expand All @@ -37,12 +38,12 @@ class MainActivity : ComponentActivity() {
@Composable
fun MainScreen() {
val calendar = Calendar.getInstance()
calendar.set(Calendar.YEAR, 2022)
calendar.set(Calendar.YEAR, 1999)
calendar.set(Calendar.MONTH, 1)
calendar.set(Calendar.DAY_OF_MONTH, 1)

val calendarMax = Calendar.getInstance()
calendarMax.set(Calendar.YEAR, 2023)
calendarMax.set(Calendar.YEAR, 2044)
calendarMax.set(Calendar.MONTH, 0)
calendarMax.set(Calendar.DAY_OF_MONTH, 1)

Expand Down Expand Up @@ -73,10 +74,11 @@ fun MainScreen() {
locale = Locale("en"),
title = "Select Date",
buttonTextSize = 15.sp,
calendarType = CalendarType.ONE_SCREEN_MONTH_AND_YEAR,
monthViewType = MonthViewType.ONLY_NUMBER_ONE_COLUMN,
listener = object : SelectDateListener {
override fun onDateSelected(date: Date) {
Log.i("DENEME", date.toString())
Log.i("Selected Date: ", date.toString())
}

override fun onCanceled() {
Expand Down
34 changes: 21 additions & 13 deletions library/src/main/java/com/dt/composedatepicker/CalendarHeader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ fun CalendarHeader(
showMonths: Boolean,
setShowMonths: (Boolean) -> Unit,
title: String,
showOnlyMonth: Boolean,
showOnlyYear: Boolean,
calendarType: CalendarType,
themeColor:Color,
monthViewType: MonthViewType?
monthViewType: MonthViewType?,
) {
val monthAsNumber = String.format("%02d",selectedMonth.index.plus(1))
val monthText = if (monthViewType==MonthViewType.ONLY_MONTH) selectedMonth.name.uppercase() else monthAsNumber

Column(modifier = Modifier
.fillMaxWidth()
.background(themeColor),
Expand All @@ -37,30 +37,38 @@ fun CalendarHeader(
modifier = Modifier.padding(top = 16.dp),
color = Color.White)
Row() {
if (!showOnlyYear) {
if (calendarType != CalendarType.ONLY_YEAR) {
Text(
text = monthText,
fontSize = 35.sp,
modifier = Modifier
.padding(bottom = 20.dp,
start = if (showOnlyMonth) 0.dp else 30.dp,
end = if (showOnlyMonth) 0.dp else 10.dp)
start = if (calendarType == CalendarType.ONLY_MONTH) 0.dp else 30.dp,
end = if (calendarType == CalendarType.ONLY_MONTH) 0.dp else 10.dp)
.clickable { setShowMonths(true) },
color = if (showMonths) Color.White else Color.LightGray)
color = if (calendarType == CalendarType.ONE_SCREEN_MONTH_AND_YEAR){
Color.White
} else {
if (showMonths) Color.White else Color.LightGray
})
}
if (!showOnlyMonth && !showOnlyYear){
if (calendarType != CalendarType.ONLY_MONTH && calendarType != CalendarType.ONLY_YEAR){
Text(text = "/",fontSize = 35.sp,color = Color.White)
}
if (!showOnlyMonth) {
if (calendarType != CalendarType.ONLY_MONTH ) {
Text(text = selectedYear.toString(),
fontSize = 35.sp,
modifier = Modifier
.padding(bottom = 20.dp,
start = if (showOnlyYear) 0.dp else 10.dp,
end = if (showOnlyYear) 0.dp else 30.dp)
start = if (calendarType == CalendarType.ONLY_YEAR) 0.dp else 10.dp,
end = if (calendarType == CalendarType.ONLY_YEAR) 0.dp else 30.dp)
.clickable { setShowMonths(false) },
color = if (showMonths) Color.LightGray else Color.White)
color = if (calendarType == CalendarType.ONE_SCREEN_MONTH_AND_YEAR){
Color.White
} else {
if (showMonths) Color.LightGray else Color.White
})
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ fun CalendarMonthViewOneColumn(
setShowMonths: (Boolean) -> Unit,
showOnlyMonth: Boolean,
themeColor: Color,
unselectedColor: Color
unselectedColor: Color,
modifier: Modifier = Modifier
.fillMaxHeight(0.85f)
.fillMaxWidth()
.padding(10.dp),
) {

LazyColumn(
modifier = Modifier
.fillMaxHeight(0.85f)
.fillMaxWidth()
.padding(10.dp),
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
) {
items(items = monthList) { item ->
Expand Down
Loading

0 comments on commit cc8fa6e

Please sign in to comment.