shrikanth7698 / Collapsible-Calendar-View-Android

Collapsible CalendarView is a simple calendar view which can be collapsed to save space and can be expanded when needed
https://shrikanth7698.github.io/Collapsible-Calendar-View-Android/
MIT License
431 stars 122 forks source link

month view getting invisible on expanding #64

Open MihirLakhia opened 3 years ago

MihirLakhia commented 3 years ago

on expanding Calendar month view getting disable. please comment, if anyone have solution. thanks

ezgif com-video-to-gif

Zeeshan-The-Dev commented 3 years ago

@MihirLakhia

Change 301 line in CollapsibleCalendar.kt from

      view.layoutParams = TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)

to

      view.layoutParams = TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 
      ViewGroup.LayoutParams.MATCH_PARENT)
Gajendra479 commented 3 years ago

@Zeeshan-The-Dev not working out still facing same issue while expanding.

MihirLakhia commented 3 years ago

I was trying fixing this issue, but i reintegrate the library, and it works, try again.

forceporquillo commented 3 years ago

I was trying fixing this issue, but i reintegrate the library, and it works, try again.

I'm also facing the same issue. May I know how you come up with a solution or workaround on this? Thanks!

Gajendra479 commented 2 years ago

@MihirLakhia @Zeeshan-The-Dev @forceporquillo @tobiasschuerg

I debug the whole working of it and came up with the solution.

Solution:-

just write ( reload() method ) inside this condition in expand method

if (interpolatedTime == 1f) { state = STATE_EXPANDED

                    mBtnPrevMonth.isClickable = true
                    mBtnNextMonth.isClickable = true
                    reload()

}

Expand Method :-

fun expand(duration: Int) { if (state == STATE_COLLAPSED) { state = STATE_PROCESSING mLayoutBtnGroupMonth.visibility = View.VISIBLE mLayoutBtnGroupWeek.visibility = View.GONE mBtnPrevMonth.isClickable = false mBtnNextMonth.isClickable = false

        val currentHeight = mScrollViewBody.measuredHeight
        val targetHeight = mInitHeight

        val anim = object : Animation() {
            override fun applyTransformation(interpolatedTime: Float, t: Transformation) {

                mScrollViewBody.layoutParams.height = if (interpolatedTime == 1f)
                    LinearLayout.LayoutParams.WRAP_CONTENT
                else
                    currentHeight - ((currentHeight - targetHeight) * interpolatedTime).toInt()
                mScrollViewBody.requestLayout()

                if (interpolatedTime == 1f) {
                    state = STATE_EXPANDED

                    mBtnPrevMonth.isClickable = true
                    mBtnNextMonth.isClickable = true
                }
            }
        }
        anim.duration = duration.toLong()
        startAnimation(anim)
    }
    expandIconView.setState(ExpandIconView.LESS, true)
    reload()

}

developer-sunshine commented 2 years ago

Try this solution:

Change view.layoutParams = TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f) to view.layoutParams = TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT,1f) in reload() method of CollapsibleCalendar.kt class

Full reload() method

 override fun reload() {
        mAdapter?.let { mAdapter ->
            mAdapter.refresh()
            val calendar = Calendar.getInstance()
            val tempDatePattern: String
            if (calendar.get(Calendar.YEAR) != mAdapter.calendar.get(Calendar.YEAR)) {
                tempDatePattern = "MMMM yyyy"
            } else {
                tempDatePattern = datePattern
            }
            // reset UI
            val dateFormat = SimpleDateFormat(tempDatePattern, getCurrentLocale(context))
            dateFormat.timeZone = mAdapter.calendar.timeZone
            mTxtTitle.text = dateFormat.format(mAdapter.calendar.time)
            mTableHead.removeAllViews()
            mTableBody.removeAllViews()

            var rowCurrent: TableRow
            rowCurrent = TableRow(context)
            rowCurrent.layoutParams = TableLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT)
            for (i in 0..6) {
                val view = mInflater.inflate(R.layout.layout_day_of_week, null)
                val txtDayOfWeek = view.findViewById<View>(R.id.txt_day_of_week) as TextView
                txtDayOfWeek.setText(DateFormatSymbols().getShortWeekdays()[(i + firstDayOfWeek) % 7 + 1])
                view.layoutParams = TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT,1f)
                rowCurrent.addView(view)
            }
            mTableHead.addView(rowCurrent)

            // set day view
            for (i in 0 until mAdapter.count) {

                if (i % 7 == 0) {
                    rowCurrent = TableRow(context)
                    rowCurrent.layoutParams = TableLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f)
                    mTableBody.addView(rowCurrent)
                }
                val view = mAdapter.getView(i)
                view.layoutParams = TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f)
                params.let { params ->
                    if (params != null && (mAdapter.getItem(i).diff < params.prevDays || mAdapter.getItem(i).diff > params.nextDaysBlocked)) {
                        view.isClickable = false
                        view.alpha = 0.3f
                    } else {
                        view.setOnClickListener { v -> onItemClicked(v, mAdapter.getItem(i)) }
                    }
                }
                rowCurrent.addView(view)
            }

            redraw()
            mIsWaitingForUpdate = true
        }
    }