GithubHelp home page GithubHelp logo

Comments (9)

kizitonwose avatar kizitonwose commented on May 29, 2024

Are you using the compose library or view?

from calendar.

V41ER avatar V41ER commented on May 29, 2024

i use view 👍

from calendar.

kizitonwose avatar kizitonwose commented on May 29, 2024

Unfortunately, this is not possible at the moment and I do not think it is worth adding to the core library as the use case is too specific. However, you can fork the library and add these changes for personal use. I tried to see if I could add it but found myself rewriting more things than I wanted.

Here's what it looks like just by changing this and this from dayHolders.count() to 5 and setting the views with Saturday and Sunday to View.GONE (of course you would need to update the weekday header too):

from calendar.

kizitonwose avatar kizitonwose commented on May 29, 2024

Closing this as there is no plan to implement it in the library

from calendar.

V41ER avatar V41ER commented on May 29, 2024

Hey ! I tested your solution look at my code it doesn't really work from my fork :
If I take Example2Fragment :

calendarView.dayBinder = object : MonthDayBinder<DayViewContainer> {
            override fun create(view: View) = DayViewContainer(view)

            override fun bind(container: DayViewContainer, data: CalendarDay) {
                container.day = data
                val textView = container.textView

                if (isWeekend(data.date)) {
                    // Masquer la vue du jour si c'est un week-end
                    textView.makeInVisible()
                } else {
                    textView.makeVisible()
                    textView.text = data.date.dayOfMonth.toString()

                    if (data.position == DayPosition.MonthDate) {
                        when (data.date) {
                            selectedDate -> {
                                textView.setTextColorRes(R.color.example_2_white)
                                textView.setBackgroundResource(R.drawable.example_2_selected_bg)
                            }
                            today -> {
                                textView.setTextColorRes(R.color.example_2_red)
                                textView.background = null
                            }
                            else -> {
                                textView.setTextColorRes(R.color.example_2_black)
                                textView.background = null
                            }
                        }
                    } else {
                        textView.makeInVisible()
                    }
                }
            }

            // Fonction pour vérifier si une date est un jour de week-end
            private fun isWeekend(date: LocalDate): Boolean {
                val dayOfWeek = date.dayOfWeek
                return dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY
            }
        }

This modification allows me to hide weekends.

and I've also modified the WeekHolder code:

    fun inflateWeekView(parent: LinearLayout): View {
       return WidthDivisorLinearLayout(parent.context).apply {
           weekContainer = this
           val width = if (daySize.parentDecidesWidth) MATCH_PARENT else WRAP_CONTENT
           val height = if (daySize.parentDecidesHeight) MATCH_PARENT else WRAP_CONTENT
           val weight = if (daySize.parentDecidesHeight) 1f else 0f
           layoutParams = LinearLayout.LayoutParams(width, height, weight)
           orientation = LinearLayout.HORIZONTAL
           weightSum = 5.toFloat()
           widthDivisorForHeight = if (daySize == DaySize.Square) 5 else 0
           for (holder in dayHolders) {
               addView(holder.inflateDayView(this))
           }
       }
   }

But with these changes I've got an empty page!

from calendar.

kizitonwose avatar kizitonwose commented on May 29, 2024
 widthDivisorForHeight = if (daySize == DaySize.Square) 5 else 0
   for (holder in dayHolders) { // This is a loop of 7 items, you need to add 5 items
       addView(holder.inflateDayView(this))
   }

from calendar.

V41ER avatar V41ER commented on May 29, 2024

Screenshot_20231219-133556_Calendar Sample

It was the same problem look the screenshot

from calendar.

V41ER avatar V41ER commented on May 29, 2024

And I did modify the code though :

    fun inflateWeekView(parent: LinearLayout): View {
        return WidthDivisorLinearLayout(parent.context).apply {
            weekContainer = this
            val width = if (daySize.parentDecidesWidth) MATCH_PARENT else WRAP_CONTENT
            val height = if (daySize.parentDecidesHeight) MATCH_PARENT else WRAP_CONTENT
            val weight = if (daySize.parentDecidesHeight) 1f else 0f
            layoutParams = LinearLayout.LayoutParams(width, height, weight)
            orientation = LinearLayout.HORIZONTAL
            weightSum = 5.toFloat()
            widthDivisorForHeight = if (daySize == DaySize.Square) 5 else 0
            for (holder in dayHolders) { // This is a loop of 7 items, you need to add 5 items
                addView(holder.inflateDayView(this))
            }
        }
    }

from calendar.

V41ER avatar V41ER commented on May 29, 2024

The worst thing is when I put the code like this I get one result out of 4 which is really good! but for 5 impossible ...

    fun inflateWeekView(parent: LinearLayout): View {
        return WidthDivisorLinearLayout(parent.context).apply {
            weekContainer = this
            val width = if (daySize.parentDecidesWidth) MATCH_PARENT else WRAP_CONTENT
            val height = if (daySize.parentDecidesHeight) MATCH_PARENT else WRAP_CONTENT
            val weight = if (daySize.parentDecidesHeight) 1f else 0f
            layoutParams = LinearLayout.LayoutParams(width, height, weight)
            orientation = LinearLayout.HORIZONTAL
            weightSum = 8.toFloat()
            widthDivisorForHeight = if (daySize == DaySize.Square) 4 else 0
            for (holder in dayHolders) {
                addView(holder.inflateDayView(this))
            }
        }
    }

Screenshot_20231219-143844_Calendar Sample

from calendar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.