-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature/calendar2] 커스텀뷰 캘린더 #7
base: develop
Are you sure you want to change the base?
Conversation
* 버전 많이 바꿔두었습니다..
* 눌렀을 때 프라그먼트 뿅 튀어나오는 부분, * height랑 폰트사이즈 조정 은 우리 찐 레포에서 해야할듯!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굳!! 나도 커스텀뷰 잘 몰라서 이번 기회에 코드 보게된 것 같네용! 퍼포먼스 문제만 없으면 주어진 코드 기반으로 만들 수 있을 것 같습니다.
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0" | ||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-rc01' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 벌써 rc 나왔구나 코루틴 사용하기 더 편해지겠누
app/build.gradle
Outdated
sourceCompatibility(JavaVersion.VERSION_1_8) | ||
targetCompatibility(JavaVersion.VERSION_1_8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sourceCompatibility(JavaVersion.VERSION_1_8) | |
targetCompatibility(JavaVersion.VERSION_1_8) | |
sourceCompatibility(JavaVersion.VERSION_11) | |
targetCompatibility(JavaVersion.VERSION_11) |
버전 11로 올리기!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
왁 큰일날뻔!! 감사형광등~
app/build.gradle
Outdated
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
jvmTarget = JavaVersion.VERSION_1_8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jvmTarget = JavaVersion.VERSION_1_8 | |
jvmTarget = JavaVersion.VERSION_11.toString() |
class CalendarItemView @JvmOverloads | ||
constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0, | ||
private val date: Int? = null, | ||
private val catchuList: Array<Int> = arrayOf(), | ||
private val isPrevious: Boolean = false | ||
) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class CalendarItemView @JvmOverloads | |
constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0, | |
private val date: Int? = null, | |
private val catchuList: Array<Int> = arrayOf(), | |
private val isPrevious: Boolean = false | |
) : | |
class CalendarItemView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyleAttr: Int = 0, | |
private val date: Int? = null, | |
private val catchuList: Array<Int> = arrayOf(), | |
private val isPrevious: Boolean = false | |
) : View(context, attrs, defStyleAttr) { |
우선 생성자 형식은 저런데 뷰의 생성자에 저런 인자들이 들어가도 되나 나도 자세히 몰라서 확인해봐야할 듯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오키 일단 해보고 우리 리얼 레포에 PR날리기 전까지 나도 확인해보겠음!!
안 돌아가진 않는데 위험할 수는 있을 것 같아
private var paint: Paint = Paint() | ||
|
||
private fun drawDateRect(canvas: Canvas, date: Int) { | ||
paint.textSize = 36f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실제에서는 이건 dp로 맞춰줘야할 것 같습니다.
if (date != null) { | ||
if (catchuList.isNotEmpty()) drawDateWithCatchuRect(canvas, date, catchuList) | ||
else drawDateRect(canvas, date) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (date != null) { | |
if (catchuList.isNotEmpty()) drawDateWithCatchuRect(canvas, date, catchuList) | |
else drawDateRect(canvas, date) | |
} | |
date?.run { | |
if (catchuList.isNotEmpty()) drawDateWithCatchuRect(canvas, it, catchuList) | |
else drawDateRect(canvas, it) | |
} |
이런식으로 밀고갈 수 있을 것 같아
val firstDayOfMonth = dateCalendar.get(Calendar.DAY_OF_WEEK) - 1 | ||
val lastDateOfMonth = dateCalendar.getActualMaximum(Calendar.DATE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
변수명 굳
for (blank in (lastDateOfLastMonth - firstDayOfMonth)..lastDateOfLastMonth) { | ||
addView(CalendarItemView(context = context, date = blank, isPrevious = true)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (blank in (lastDateOfLastMonth - firstDayOfMonth)..lastDateOfLastMonth) { | |
addView(CalendarItemView(context = context, date = blank, isPrevious = true)) | |
} | |
((lastDateOfLastMonth - firstDayOfMonth)..lastDateOfLastMonth).forEach { blank -> | |
addView(CalendarItemView(context = context, date = blank, isPrevious = true)) | |
} |
import com.teamcatchme.catchmesample.databinding.FragmentCustomCalendarBinding | ||
import java.util.* | ||
|
||
class CustomCalendarFragment(private val millsId: Long) : Fragment() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프래그먼트 생성자는 무조건 빈 걸로 둬야한다고 하네요! 알아두시면 좋을 것 같습니다
그래서 정적 패토리 패턴을 쓰라고 했던거 ㅇㅇ
fun drawableToBitmap(drawable: Drawable): Bitmap? { | ||
if (drawable is BitmapDrawable) { | ||
return drawable.bitmap | ||
} | ||
val bitmap = | ||
Bitmap.createBitmap( | ||
drawable.intrinsicWidth, | ||
drawable.intrinsicHeight, | ||
Bitmap.Config.ARGB_8888 | ||
) | ||
val canvas = Canvas(bitmap) | ||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()) | ||
drawable.draw(canvas) | ||
return bitmap | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun drawableToBitmap(drawable: Drawable): Bitmap? { | |
if (drawable is BitmapDrawable) { | |
return drawable.bitmap | |
} | |
val bitmap = | |
Bitmap.createBitmap( | |
drawable.intrinsicWidth, | |
drawable.intrinsicHeight, | |
Bitmap.Config.ARGB_8888 | |
) | |
val canvas = Canvas(bitmap) | |
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()) | |
drawable.draw(canvas) | |
return bitmap | |
} | |
fun Drawable.ToBitmap(): Bitmap? { | |
if (this is BitmapDrawable) { | |
return bitmap | |
} | |
val bitmap = | |
Bitmap.createBitmap( | |
intrinsicWidth, | |
intrinsicHeight, | |
Bitmap.Config.ARGB_8888 | |
) | |
val canvas = Canvas(bitmap) | |
setBounds(0, 0, canvas.getWidth(), canvas.getHeight()) | |
draw(canvas) | |
return bitmap | |
} |
이런식으로도 변형 가능(이건 그냥 내 스타일이어서 취사 선택 해주시길 바람!)
- for -> forEach - null처리 바꾸기
- Drawable 확장함수로 바꾸기
* 어딜 프라그먼트한테 인자를 넘겨! 팩토리 패턴 써보기
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍🏻
val args = Bundle() | ||
args.putLong(MILLS_ID, millsId) | ||
fragment.arguments = args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val args = Bundle() | |
args.putLong(MILLS_ID, millsId) | |
fragment.arguments = args | |
fragment.arguments = Bundle().also { putLong(MILLS_ID, millsId) } |
3줄을 1줄로
arguments?.let { | ||
millsId = it.getLong(MILLS_ID) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
PR 개요
스샷
커스텀뷰를 쓴 이유
궁금한 점
CalendarItemView.kt에서
클래스 컨스트럭터에서 받아오는 변수들은 그 클래스 안에서 다 접근 가능한건데
내가 그 변수들도 클래스 내부 함수에서 파라미터로 넘겨줬는데
굳이 넘겨줄 필요가 없지 않나?라는 생각이 드네..
어떻게 해야할까?
변수명들 구리지 않아?
너무 길거나 짧다면 가감없이 말씀해주십쇼..
(xml에 있는 id들은 어짜피 바꿀거라 대충 지었셈!)
후세에 남길 말
참고자료
https://leveloper.tistory.com/174