Week Calendar with Starting Day as "Sunday"
See original GitHub issueI am working on app, where I need to show a Week Calendar with the starting Day of the Week Calendar as Sunday. I tried to use Sample code and also tried to figure it out, but didn’t work. My code is given below, kindly guide me who I can show Weekly Calendar as “Sun, Mon, Tue, Wed, Thur, Fri, Sat”. One more thing I am trying to put custom Drawable with Red Dot, that also not showing there. I followed Sample from the Library.
class AppointmentWeekFragment : BaseFragment(R.layout.appointment_week_fragment), HasToolbar,
HasBackButton {
override val titleRes: Int = R.string.appointment_weekly
override val toolbar: Toolbar?
get() = binding.exSevenToolbar
private var selectedDate = LocalDate.now()
private val dateFormatter = DateTimeFormatter.ofPattern("dd")
private val dayFormatter = DateTimeFormatter.ofPattern("EEE")
private val monthFormatter = DateTimeFormatter.ofPattern("MMM")
private lateinit var binding: Example7FragmentBinding
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = Example7FragmentBinding.bind(view)
val dm = DisplayMetrics()
val wm = requireContext().getSystemService(Context.WINDOW_SERVICE) as WindowManager
wm.defaultDisplay.getMetrics(dm)
binding.exSevenCalendar.apply {
val dayWidth = dm.widthPixels / 7
val dayHeight = (dayWidth * 2)
daySize = Size(dayWidth, dayHeight)
}
class DayViewContainer(view: View) : ViewContainer(view) {
val bind = AppointmentCalendarDayBinding.bind(view)
lateinit var day: CalendarDay
fun bind(day: CalendarDay) {
this.day = day
bind.exSevenDateText.text = dateFormatter.format(day.date)
bind.exSevenDayText.text = dayFormatter.format(day.date)
bind.exSevenMonthText.text = monthFormatter.format(day.date)
bind.dotImg.visibility = View.VISIBLE
bind.exSevenDateText.setTextColor(view.context.getColorCompat(if (day.date == selectedDate) R.color.example_4_grey else R.color.example_4_grey))
// bind.exSevenSelectedView.isVisible = day.date == selectedDate
}
}
binding.exSevenCalendar.dayBinder = object : DayBinder<DayViewContainer> {
override fun create(view: View) = DayViewContainer(view)
override fun bind(container: DayViewContainer, day: CalendarDay) = container.bind(day)
}
val currentMonth = YearMonth.now()
binding.exSevenCalendar.setup(
currentMonth,
currentMonth.plusMonths(1),
DayOfWeek.values().random()
)
binding.exSevenCalendar.scrollToDate(LocalDate.of(2021, 1, 23))
// Showing exact Date as 23rd of Jan 2021.
// Need to start my Weekly Calendar from Sun.
binding.exSevenCalendar.suppressLayout(true)
}
}
My Fragment XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
tools:context=".Example7Fragment">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/exSevenToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@color/white" />
</com.google.android.material.appbar.AppBarLayout>
<com.kizitonwose.calendarview.CalendarView
android:id="@+id/exSevenCalendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cv_dayViewResource="@layout/appointment_calendar_day"
app:cv_hasBoundaries="false"
app:cv_inDateStyle="none"
app:cv_outDateStyle="none"
app:cv_maxRowCount="1"
app:cv_orientation="horizontal" />
</LinearLayout>
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
What is the First Day of the Week? - Calendarr
Sunday has always been regarded as the first day of the week for ... calendar has 52 or 53 7-day weeks, and it...
Read more >Which Day is the Beginning of the Week?
The Gregorian calendar, currently used in most countries, is derived from the Hebrew calendar, where Sunday is considered the beginning of the week....
Read more >What Is the First Day of the Week? - Time and Date
Whether the Gregorian calendar shows Sunday or Monday as the first day of the week depends on where you live. Most countries start...
Read more >Why does the week start on Sunday in some calendars and on ...
Calendars that keep the weekend days together and begin with the first day of the workweek aim to make planning a little more...
Read more >Set the first day of the calendar week and change calendar ...
By default, the work week is defined as Monday through Friday with a work day of 9 A.M. to 5 P.M. The first...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Of course, then you have to also call
setup()
with the desired day:Replace this:
with:
Thank you @kizitonwose for this. It is working fine now. Really love your work and highly appreciate your response.