Inflate views using binding

This commit is contained in:
Naveen 2023-09-04 15:17:16 +05:30
parent 76b83a6a46
commit aac1d60baf
No known key found for this signature in database
GPG Key ID: 0E155DAD31671DA3
3 changed files with 10 additions and 12 deletions

View File

@ -17,10 +17,7 @@ import androidx.fragment.app.Fragment
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.databinding.AllDayEventsHolderLineBinding
import com.simplemobiletools.calendar.pro.databinding.FragmentWeekBinding
import com.simplemobiletools.calendar.pro.databinding.WeekAllDayEventMarkerBinding
import com.simplemobiletools.calendar.pro.databinding.WeekEventMarkerBinding
import com.simplemobiletools.calendar.pro.databinding.*
import com.simplemobiletools.calendar.pro.dialogs.EditRepeatingEventDialog
import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.*
@ -34,7 +31,6 @@ import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.MyTextView
import org.joda.time.DateTime
import org.joda.time.Days
import java.util.*
@ -196,7 +192,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private fun addDayColumns() {
binding.weekEventsColumnsHolder.removeAllViews()
(0 until config.weeklyViewDays).forEach {
val column = layoutInflater.inflate(R.layout.weekly_view_day_column, binding.weekEventsColumnsHolder, false) as RelativeLayout
val column = WeeklyViewDayColumnBinding.inflate(layoutInflater, binding.weekEventsColumnsHolder, false).root
column.tag = Formatter.getDayCodeFromTS(weekTimestamp + it * DAY_SECONDS)
binding.weekEventsColumnsHolder.addView(column)
dayColumns.add(column)
@ -232,7 +228,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
requireContext().getProperTextColor()
}
val label = layoutInflater.inflate(R.layout.weekly_view_day_letter, binding.weekLettersHolder, false) as MyTextView
val label = WeeklyViewDayLetterBinding.inflate(layoutInflater, binding.weekLettersHolder, false).root
label.text = "$dayLetter\n${curDay.dayOfMonth}"
label.setTextColor(textColor)
if (todayCode == dayCode) {
@ -359,7 +355,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
selectedGrid?.beGone()
val hour = (event.y / rowHeight).toInt()
selectedGrid = (layoutInflater.inflate(R.layout.week_grid_item, null, false) as ImageView).apply {
selectedGrid = WeekGridItemBinding.inflate(layoutInflater).root.apply {
view.addView(this)
background = ColorDrawable(primaryColor)
layoutParams.width = view.width
@ -726,7 +722,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
}
val weeklyViewDays = config.weeklyViewDays
currentTimeView = (layoutInflater.inflate(R.layout.week_now_marker, null, false) as ImageView).apply {
currentTimeView = WeekNowMarkerBinding.inflate(layoutInflater).root.apply {
applyColorFilter(primaryColor)
binding.weekEventsHolder.addView(this, 0)
val extraWidth = res.getDimension(R.dimen.activity_margin).toInt()

View File

@ -15,6 +15,7 @@ import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity
import com.simplemobiletools.calendar.pro.adapters.MyWeekPagerAdapter
import com.simplemobiletools.calendar.pro.databinding.FragmentWeekHolderBinding
import com.simplemobiletools.calendar.pro.databinding.WeeklyViewHourTextviewBinding
import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.helpers.WEEKLY_VIEW
@ -135,7 +136,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
val hourDateTime = DateTime().withDate(2000, 1, 1).withTime(0, 0, 0, 0)
for (i in 1..23) {
val formattedHours = Formatter.getTime(requireContext(), hourDateTime.withHourOfDay(i))
(layoutInflater.inflate(R.layout.weekly_view_hour_textview, null, false) as TextView).apply {
WeeklyViewHourTextviewBinding.inflate(layoutInflater).root.apply {
text = formattedHours
setTextColor(textColor)
height = itemHeight

View File

@ -5,6 +5,7 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.databinding.MonthViewBackgroundBinding
import com.simplemobiletools.calendar.pro.databinding.MonthViewBinding
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.helpers.COLUMN_COUNT
@ -126,7 +127,7 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
val xPos = viewX * dayWidth + horizontalOffset
val yPos = viewY * dayHeight + weekDaysLetterHeight
inflater.inflate(R.layout.month_view_background, this, false).apply {
MonthViewBackgroundBinding.inflate(inflater, this, false).apply {
if (isMonthDayView) {
background = null
}
@ -142,7 +143,7 @@ class MonthViewWrapper(context: Context, attrs: AttributeSet, defStyle: Int) : F
binding.monthView.updateCurrentlySelectedDay(viewX, viewY)
}
}
addView(this)
addView(root)
}
}