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

[MOD] 상세페이지 / 보관함으로 뒤로가기 및 코스 삭제 시 애니메이션 통일 #277

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.runnect.runnect.presentation.mydrawdetail
import android.content.ContentValues
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import androidx.activity.viewModels
import androidx.core.net.toUri
import com.bumptech.glide.Glide
Expand Down Expand Up @@ -42,6 +43,11 @@ class MyDrawDetailActivity :
deleteButton()
}

private fun finishViewAnimLeftRight() {
finish()
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right)
}

private fun deletingDialog() {
val (dialog, dialogLayout) = setActivityDialog(
layoutInflater = layoutInflater,
Expand All @@ -57,6 +63,7 @@ class MyDrawDetailActivity :
putExtra(EXTRA_FRAGMENT_REPLACEMENT_DIRECTION, "fromDeleteMyDrawDetail")
}
startActivity(intent)
finishViewAnimLeftRight()
}
this.btn_delete_no.setOnClickListener {
dialog.dismiss()
Expand All @@ -73,17 +80,17 @@ class MyDrawDetailActivity :

private fun backButton() { //png가 imgBtn으로 하면 잘리길래 어차피 임시로 해놓는 거니까 imgView로 component를 추가해줬음
binding.imgBtnBack.setOnClickListener {
finish()
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right)
finishViewAnimLeftRight()
}
}

override fun onBackPressed() {
finish()
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right)
private val backPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finishViewAnimLeftRight()
}
Copy link
Member

Choose a reason for hiding this comment

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

반복되는 코드를 함수화 하는 게 어떨까요??

finish()
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right)

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
Member

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.

확장함수로 만들었고 반영했습니다!

}

fun getMyDrawDetail() {
private fun getMyDrawDetail() {
val courseId = intent.getIntExtra(EXTRA_COURSE_ID, 0)
Timber.tag(ContentValues.TAG).d("courseId from Storage : $courseId")

Expand All @@ -101,6 +108,8 @@ class MyDrawDetailActivity :

fun addObserver() {
observeGetResult()

onBackPressedDispatcher.addCallback(this, backPressedCallback)
Copy link
Member

Choose a reason for hiding this comment

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

코드 스타일의 차이일 수 있지만, 아래처럼 관련있는 코드를 함수로 묶어두면 나중에 볼 때 편하더라구요!

private fun registerBackPressedCallback() { // 이 함수를 addObserver에서 호출 
  val callback = object : OnBackPressedCallback(true) {
    override fun handleOnBackPressed() {
      naviagteToPreviousScreen() 
    }
  }
  onBackPressedDispatcher.addCallback(this, callback)
}

private fun naviagteToPreviousScreen() {
  finish()
  overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right)
}

Copy link
Contributor Author

@unam98 unam98 Nov 10, 2023

Choose a reason for hiding this comment

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

finishViewAnimLeftRight()라는 네이밍으로 함수화해서 커밋 올렸는데 혹시 위의 코드에서 알려주신 navigateToPreviousScreen()이라는 함수가 다른 파일에서도 쓰이고 있는 것인가요? 그렇다면 이름을 navigateToPreviousScreen()으로 맞추겠습니다

Copy link
Member

Choose a reason for hiding this comment

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

저는 다른 코드에서 navigateToPreviousScreen 이라는 함수명을 사용하긴 했습니다!
현재 액티비티에서 뒤로가기 버튼을 누르면 이전 액티비티로 돌아간다는 걸 표현하고 싶어서 그렇게 작성했던 걸로 기억합니다!

Copy link
Member

Choose a reason for hiding this comment

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

addObserver 함수에서 onBackPressedDispatcher에 콜백 등록하는 코드도
registerBackPressedCallback 이라는 함수를 따로 만들어서 그 안에서 작성하는 게 어떨까 싶습니다!

backPressedCallback 이라는 변수를 굳이 전역 변수로 만들 필요가 없을 거 같아서요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!

}

private fun setImage(src: ResponseGetMyDrawDetailDTO) {
Expand Down
Loading