Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

SeojinSeojin
Copy link
Member

PR 개요

스샷

커스텀뷰를 쓴 이유

  • 뎁쓰가 얕아졌다는 장점!! 로딩도 빨라졌다는 장점!!
    • 원래는 캘린더액티비티(캘린더리사이클러뷰(캘린더알갱이리사이클러뷰)) 3겹이었지만
      • 이거 숨안쉬고 발음 가능하면 큰 칭찬 해드림
    • 지금은 캘린더액티비티(캘린더뷰) 이렇게 2겹이 됨!ㅎㅎ
  • 또한 캔버스로 그리면 렌더링을 안드가 하는게 아니구 skia라는 구글에서 만든 엔진이 대신 해준다고 주워들었음!
    • 웹 캔버스도 직접 렌더링하는게 아니라 더 빠르다..라는 걸 주워들었셈

궁금한 점

CalendarItemView.kt에서
클래스 컨스트럭터에서 받아오는 변수들은 그 클래스 안에서 다 접근 가능한건데
내가 그 변수들도 클래스 내부 함수에서 파라미터로 넘겨줬는데
굳이 넘겨줄 필요가 없지 않나?라는 생각이 드네..
어떻게 해야할까?

변수명들 구리지 않아?
너무 길거나 짧다면 가감없이 말씀해주십쇼..
(xml에 있는 id들은 어짜피 바꿀거라 대충 지었셈!)

후세에 남길 말

  • 짱치미 짱드로이드 여러분.. 이 레포에서 작업하려면 작업 쫌 해줘야 한다..
  • 서진아 .. height, font size는 대강 뒀지만, 우리 꺼에다가 심을 때는 유틸에 있는 함수 써서 DP로 써주어야 한단다..
  • 레이아웃 당연히 싹 갈아엎어야 하구..
  • 캐츄 드로어블 가져오는 로직도 다시 심어야 한단다..
  • 그리고 프라그먼트 띄우는 클릭리스너까지 뷰모델로 해보면 좋겠구나..
    • 굳이 캘린더 알갱이 하나하나에 리스너를 달지 말고,
    • 뷰모델에서 셀렉티드데이트쓰캐츄리스트라는 라이브데이터를 만들어서 거기다가 캐츄 배열만 넣어주어도 괜찮을 것 같구나..

참고자료

https://leveloper.tistory.com/174

@SeojinSeojin SeojinSeojin self-assigned this Oct 24, 2021
Copy link
Member

@l2hyunwoo l2hyunwoo left a 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'
Copy link
Member

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
Comment on lines 28 to 29
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
sourceCompatibility(JavaVersion.VERSION_11)
targetCompatibility(JavaVersion.VERSION_11)

버전 11로 올리기!

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jvmTarget = JavaVersion.VERSION_1_8
jvmTarget = JavaVersion.VERSION_11.toString()

Comment on lines +11 to +19
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
) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {

우선 생성자 형식은 저런데 뷰의 생성자에 저런 인자들이 들어가도 되나 나도 자세히 몰라서 확인해봐야할 듯

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

실제에서는 이건 dp로 맞춰줘야할 것 같습니다.

Comment on lines 60 to 63
if (date != null) {
if (catchuList.isNotEmpty()) drawDateWithCatchuRect(canvas, date, catchuList)
else drawDateRect(canvas, date)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
}

이런식으로 밀고갈 수 있을 것 같아

Comment on lines +23 to +24
val firstDayOfMonth = dateCalendar.get(Calendar.DAY_OF_WEEK) - 1
val lastDateOfMonth = dateCalendar.getActualMaximum(Calendar.DATE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명 굳

Comment on lines 28 to 30
for (blank in (lastDateOfLastMonth - firstDayOfMonth)..lastDateOfLastMonth) {
addView(CalendarItemView(context = context, date = blank, isPrevious = true))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프래그먼트 생성자는 무조건 빈 걸로 둬야한다고 하네요! 알아두시면 좋을 것 같습니다

그래서 정적 패토리 패턴을 쓰라고 했던거 ㅇㅇ

Comment on lines 9 to 23
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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 확장함수로 바꾸기
* 어딜 프라그먼트한테 인자를 넘겨! 팩토리 패턴 써보기
Copy link
Member

@l2hyunwoo l2hyunwoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

Comment on lines +20 to +22
val args = Bundle()
args.putLong(MILLS_ID, millsId)
fragment.arguments = args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val args = Bundle()
args.putLong(MILLS_ID, millsId)
fragment.arguments = args
fragment.arguments = Bundle().also { putLong(MILLS_ID, millsId) }

3줄을 1줄로

Comment on lines +38 to +40
arguments?.let {
millsId = it.getLong(MILLS_ID)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants