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

타이머관련 리팩토링 및 최근앱에서 제거 해도 다시 반영되게 변경 #156

Merged
merged 17 commits into from
Dec 12, 2024

Conversation

no1msh
Copy link
Contributor

@no1msh no1msh commented Dec 11, 2024

resolved #137
resolved #138

AS-IS

  • 타이머에서 뷰로직포함
  • 홈뷰모델에서 타이머관련 로직 포함
  • 최근앱에서 제거하면 서비스는 돌아도 뷰는 복구되지 않았음

TO-BE

  • 타이머에서 뷰로직 제거
  • 홈뷰모델에서 타이머관련 로직 제거
  • 최근 앱에서 제거해도 뷰 복구 되게 변경

KEY-POINT

  • 홈에서 각종 다이얼로그들이 떠있는지에 대한 상태까지 UIState로 다루는 것을 분리하였습니다.

  • 프로모션 다이얼로그는 프로모션에 대한 데이터에 따라 다이얼로그를 표시할지 말지를 정함으로 뷰모델에서 관리하는게 맞지만, 다른 다이얼로그들은 HomeScreen 딴에서 자체적으로 처리가 가능하다 판단하여 분리하였습니다.

  • 상태 호이스팅은 필요한 곳 까지만 올리는 것이 유리합니다.

  • QA용 앱은 메일로 보내드렸습니다 :)

@no1msh no1msh requested a review from librarywon December 11, 2024 06:45
@no1msh no1msh self-assigned this Dec 11, 2024
Copy link
Contributor

@librarywon librarywon left a comment

Choose a reason for hiding this comment

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

힘들고 험난한 작업 진행해주셔서 너무 감사합니다. 보내주신 apk 테스트를 진행 해보았고 궁금한점이나 코멘트를 남겼으니 확인해주시면 감사드리겠습니다!
상태 호이스팅은 어디까지 올려야 필요한 곳까지 올린 것인지 저에게는 아직 헷갈리는 순간들이 있어 공부를 진행 해보겠습니다.

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

data class Time(
Copy link
Contributor

Choose a reason for hiding this comment

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

Time이라는 이름은 너무 일반적이고 추상적인 느낌이 강한 것 같습니다. 더 목적을 분명하게 TimerTime으로 변경하는 것은 어떠실까요?

Comment on lines 11 to 12
val hourAndMinute: String
get() = "$hour:$minute"
Copy link
Contributor

Choose a reason for hiding this comment

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

hourAndMinute 변수도 formattedTimerTime이라고 변경하는 것은 어떠할까요?

fun create(endTime: LocalDateTime): LeftTime {
val now = LocalDateTime.now()
if (now.isAfter(endTime)) {
val timeOver = String.format(Locale.KOREA, LEFT_TIME_FORMAT, 0, 0, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

이 timeOver 값 자체도 상수화 가능해 보입니다

Comment on lines 29 to 30
while (isTimeOver().not()) {
val leftSeconds: Long = leftTime.seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

val leftSeconds: Long = leftTime.seconds
while(leftSeconds > Duration.ZERO){
}

이렇게 아래 로직과 통합하시는건 어떤가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

함수 사용처가 여기뿐이라 isNotTimeOver로 변경하였습니다.

val durationMillis: Long = intent?.getLongExtra(EXTRA_TIME, 0L) ?: 0L
intent.getLongExtra(EXTRA_START_TIME, System.currentTimeMillis())
val endTimeMillis: Long =
intent.getLongExtra(EXTRA_END_TIME, System.currentTimeMillis() + 1000 * 60 * 60 * 4)
Copy link
Contributor

Choose a reason for hiding this comment

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

1000 * 60 * 60 * 4 상수 자체는 난해한 감이 있는 것 같습니다. 적절한 상수화가 필요해 보입니다

timerJob =
serviceScope.launch {
while (true) {
val remainingTime: Long = endTime - System.currentTimeMillis()
val leftTime =
Copy link
Contributor

Choose a reason for hiding this comment

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

자료형 명시 부탁드립니다!

appContext.startForegroundService(startIntent)
}

override fun stopService() {
val stopIntent = Intent(context, TimerForegroundService::class.java)
runBlocking {
withTimeout(4000L) {
Copy link
Contributor

Choose a reason for hiding this comment

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

withTimeout(4000L)에서 4초를 기준으로 잡으신 이유가 뭔가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

runBlocking을 사용한 이유부터 말씀드리자면, 서비스가 stop될 때, 공부시간을 저장하는 로직이 완료되지 않은 상태에서 종료되는걸 경계해서 사용하였습니다. (물론 서비스 스코프에서도 잘 돌아가기는 합니다. 혹시모를 상황을 대비하여 사용하였습니다.)

스레드를 블로킹함으로 ANR(5초동안 메인스레드 블락)의 위험성이 있기에 아무리 블로킹을 오래 하더라도 4초를 못넘기게 한 것입니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

ANR을 염두하고 한 것이 맞았군요 답변 감사합니다.

@no1msh no1msh requested a review from librarywon December 12, 2024 01:38
Copy link
Contributor

@librarywon librarywon left a comment

Choose a reason for hiding this comment

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

리뷰 반영 고생하셨습니다 다시 꼼꼼히 봤는데 정말 수고많으셨습니다!

@no1msh no1msh merged commit ee347f1 into develop Dec 12, 2024
1 check passed
@librarywon librarywon deleted the Feature/#137-timer-continue branch December 13, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants