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

[feat] 네트워크 연결 상태 확인 (로딩,에러 뷰) #103

Merged
merged 17 commits into from
Mar 2, 2024

Conversation

l2zh
Copy link
Contributor

@l2zh l2zh commented Feb 26, 2024

📌 관련 이슈

📷 screenshot

default.mp4

📝 Work Desciption

  • 네트워크 연결 끊겼을 때 다이얼로그 띄우기 (앱 사용 불가)
  • 인터셉터에서 500번대 에러 감지 시 에러 뷰로 이동
  • 로딩 상태일 경우 로딩 뷰로 화면 이동

📚 Reference 혹은 궁금한 사항들

평소에 안하던 방법으로 해서 문제가 있는것 같으면 바로 알려주세요...!

@l2zh l2zh added feat 구현 및 개선 Pull Request 🔥 pr 날릴때 준희 👻 막내온탑 labels Feb 26, 2024
@l2zh l2zh added this to the 2차 스프린트 milestone Feb 26, 2024
@l2zh l2zh self-assigned this Feb 26, 2024
@gatttto
Copy link

gatttto commented Feb 26, 2024

코드 쌉꿀마 🍠 수고하셨습니다

val request = chain.request()
var response = chain.proceed(chain.request())

when (response.code) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

현재는 if문을 써도 될 것 같은데 확장성 고려하신 건가요 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵! 에러코드가 아직 정리가 안된것 같아서 우선 500번대만 처리해 두었습니다!


when (response.code) {

in SERVER_ERROR_START..SERVER_ERROR_END -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 상수화가 필요한 상수화인지 생각해봐도 좋을 것 같아요! 물론 나쁘다는 의미는 아니지만, HTTP 코드 정도는 어느정도 상식으로 알고 계시는 분도 많다보니 오히려 어색한 느낌이 들기도 하네요 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오...그런 부분은 생각 못해봤네요! 좋은 피드백 감사합니다!

Comment on lines +5 to +19
class NetworkErrorListenerImpl @Inject constructor() : NetworkErrorListener {
private var onApiCallFailedCallback: (() -> Unit)? = null

override fun onApiCallFailed() {
onApiCallFailedCallback?.invoke()
}

override fun setOnApiCallFailedCallback(callback: () -> Unit) {
onApiCallFailedCallback = callback
}

override fun clearOnApiCallFailedCallback() {
onApiCallFailedCallback = null
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 너무 좋은 설계인 것 같은데요 ?? 👍

import android.net.NetworkCapabilities
import androidx.lifecycle.LiveData

class NetworkStateLiveData(context: Context) : LiveData<Boolean>() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 클래스를 싱글톤으로 만드는건 어떨까요 ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

해당 클래스는 이미 힐트 모듈로 정의해주어서 애플리케이션의 전역범위에서 동일한 인스턴스를 제공하는 것 같은데 혹시 잘못된 부분이 있을까요??

Copy link
Collaborator

Choose a reason for hiding this comment

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

아 그러네요 ㅋㅋㅋㅎ 확인했습니다 !

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

backPressed()
Copy link
Collaborator

Choose a reason for hiding this comment

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

조금 더 명확한 함수명을 사용해도 좋을 것 같아요!

Suggested change
backPressed()
overrideOnBackPressed()

@@ -28,7 +28,7 @@ class SplashFragment : BindingFragment<FragmentSplashBinding>(R.layout.fragment_

private fun showSplash() {
lifecycleScope.launch {
delay(2000)
delay(SPLASH_DISPLAY_LENGTH)
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 이건 너무 좋은 상수화네요! 상수화함으로서 이름이 생겨 delay의 의미까지 명확해진 좋은 코드인 것 같습니다 👍

Copy link
Collaborator

@giovannijunseokim giovannijunseokim left a comment

Choose a reason for hiding this comment

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

그만 잘해주세요 ~

Copy link
Collaborator

@Jokwanhee Jokwanhee left a comment

Choose a reason for hiding this comment

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

코드 작성하느라 고생하셨습니다! 🔥

말씀하신것처럼 로딩 뷰로 이어지는 플로우가 별로네욤.. context change 로 비용도 늘고 안티패턴인 것 같네여..! 나중에 회의해서 어떻게 할지 고민해보면 좋을 것 같습이다요!

Comment on lines +16 to +17
override fun clearOnTokenRefreshFailedCallback() {
onTokenRefreshFailedCallback = null
Copy link
Collaborator

Choose a reason for hiding this comment

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

😎 나이스 코드네요!

Comment on lines 7 to 8
val networkStateLiveData: LiveData<Boolean>
val isLoading: LiveData<Boolean>
Copy link
Collaborator

Choose a reason for hiding this comment

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

LiveData 를 사용하신 이유가 궁금합니다!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

엇 기존에 베이스 뷰모델로 하려던게 인스턴스 문제 때문에 repository로 옴겼는데 그 과정에서 놓친 부분이네요ㅠㅠ
도메인 레이어와 데이터 레이어에서는 순수 코틀린 코드로만 이루어져야 안드로이드 프레임워크와 결합이 생기지 않는데 지금 코드는 아키텍쳐에 위배되는 코드인 것 같네요..!
짚어주셔서 감삼당~

navController.popBackStack(R.id.loginFragment, false)
navController.navigate(R.id.loginFragment)
authTokenRefreshListener.setOnTokenRefreshFailedCallback {
CoroutineScope(Dispatchers.Main).launch {
Copy link
Collaborator

Choose a reason for hiding this comment

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

코루틴 디스패처를 외부 주입으로 하시는 건 어떠신가요~?

https://june0122.tistory.com/22

Copy link
Contributor Author

Choose a reason for hiding this comment

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

공식문서 따르겠습니다..ㅎㅎ

Copy link
Collaborator

@Jokwanhee Jokwanhee left a comment

Choose a reason for hiding this comment

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

고생하셨습니다요~ 🍡

@l2zh l2zh merged commit 740cba2 into develop Mar 2, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 구현 및 개선 Pull Request 🔥 pr 날릴때 준희 👻 막내온탑
Projects
Development

Successfully merging this pull request may close these issues.

4 participants