This commit is contained in:
KJG
2024-11-29 17:52:58 +09:00
parent 29d47c1162
commit fb444ee292
9 changed files with 227 additions and 72 deletions
@@ -72,7 +72,7 @@ class DayView : BaseCustomViews {
}
fun displayDayNumber() {
numOfDayView?.text = dayInfo?.getDayOfNum()?.toString() ?: "TEST"
numOfDayView?.text = dayInfo?.getNumOfDay()?.toString() ?: "TEST"
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
}
@@ -1,11 +1,18 @@
package com.example.calrendarview
import android.content.Context
import android.content.res.TypedArray
import android.os.Build
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.example.calrendarview.model.CalendarFactory
import com.example.calrendarview.model.DayInfo
@RequiresApi(Build.VERSION_CODES.O)
class MonthView : BaseCustomViews {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
@@ -23,8 +30,42 @@ class MonthView : BaseCustomViews {
initChildViews()
}
fun initChildViews() {
var dayInfo: DayInfo? = null
set(value) {
field = value
displayDayNumber()
}
var numberOfday : Int = -1
set(value) {
field = value
numOfDayView = findViewById<TextView>(field)
}
var numOfDayView : TextView? = null
override fun onTypedArray(context: Context, typedArray: TypedArray) {
super.onTypedArray(context, typedArray)
numberOfday = typedArray.getResourceId(R.styleable.BaseCustomViews_numOfDayId, R.id.day_num)
displayDayNumber()
}
fun initChildViews(): Array<DayView?> {
//todo : 7 * numberOfRow 의 차일드 뷰를 만든다.
val infos = CalendarFactory().getBeansOfThisWeek()
val childrens = Array<DayView?>(numberOfRow) {
val dayView = inflate(context, R.layout.item_day, this) as? DayView
dayView?.dayInfo = infos[it]
addView(dayView)
return@Array dayView
}
return childrens
}
fun displayDayNumber() {
numOfDayView?.text = dayInfo?.getNumOfDay()?.toString() ?: "TEST"
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
}
fun displyMonthOfNumber() {
@@ -0,0 +1,39 @@
package com.example.calrendarview.model
import android.os.Build
import androidx.annotation.RequiresApi
import java.time.LocalDate
@RequiresApi(Build.VERSION_CODES.O)
class CalendarBean: DayInfo {
constructor(date: LocalDate) {
this.day = date
}
constructor(y: Int, m: Int, d: Int) {
this.day = LocalDate.of(y, m , d)
}
private val today: LocalDate = LocalDate.now()
private val day: LocalDate
override fun getNumOfDay(): Int = this.day.dayOfMonth
override fun getMonth(): Int = this.day.monthValue
override fun getYear(): Int = this.day.year
override fun getDayOfWeek(): String = this.day.dayOfWeek.toString()
override fun isToday(): Boolean = day.isEqual(today)
fun getNumOfToday(): Int = this.today.dayOfMonth
fun getMonthOfToday(): Int = this.today.monthValue
fun getYearOfToday(): Int = this.today.year
fun getTodayOfWeek(): String = this.today.dayOfWeek.toString()
}
@@ -0,0 +1,27 @@
package com.example.calrendarview.model
import android.os.Build
import androidx.annotation.RequiresApi
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.YearMonth
import java.time.temporal.TemporalAdjuster
import java.time.temporal.TemporalAdjusters
@RequiresApi(Build.VERSION_CODES.O)
class CalendarFactory {
fun getBeansOfWeek(date: LocalDate): Array<CalendarBean> {
val startDate = date.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY))
return Array<CalendarBean>(7) {
CalendarBean(startDate.plusDays(it.toLong()))
}
}
fun getBeansOfThisWeek(): Array<CalendarBean> = getBeansOfWeek(LocalDate.now())
fun getBeansOfMonth(y: Int, m:Int): Array<CalendarBean> {
val daysInMonth = YearMonth.of(y, m).lengthOfMonth()
return Array<CalendarBean>(daysInMonth) {
CalendarBean(y, m, it + 1)
}
}
}
@@ -2,7 +2,9 @@ package com.example.calrendarview.model
interface DayInfo {
fun getDayOfNum() : Int
fun getDayOfWeek() : Int
fun getNumOfDay() : Int
fun getMonth(): Int
fun getYear(): Int
fun getDayOfWeek() : String
fun isToday() : Boolean
}
+3 -3
View File
@@ -10,11 +10,11 @@
</declare-styleable>
<declare-styleable name="DayView">
<attr name="item_layout"/>
<attr name="numOfDayId"/>
<!-- <attr name="item_layout"/>-->
<!-- <attr name="numOfDayId"/>-->
</declare-styleable>
<declare-styleable name="MonthView">
<attr name="item_layout"/>
<!-- <attr name="item_layout"/>-->
</declare-styleable>
</resources>