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

leesc0839 week 2 commit #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

leesc0839 week 2 commit #5

wants to merge 1 commit into from

Conversation

tmdcheol
Copy link
Collaborator

@tmdcheol tmdcheol commented Aug 2, 2022

! 유료 강의가 있어 해당 강의를 듣고 이해한 후, 강의의 코드를 참고하여 짠 코드임을 미리 알려 드립니다.!

saf 기능(잘 모릅니다) 을 통해서, content provider (처음 써 봤습니다.) 즉, 내장 데이터에 접근해 사진을 가져왔습니다.
그리고 해당 사진을 첫 화면에 띄워준 후(최대 6장, 초과할 시에 alertDialog를 띄워서 사진을 교체합니다.)
alertDialog .create()에서 끝나는 게 아니라 .show()도 해야함을 까먹지 말자..

사진이 선택되면, 다음 액티비티로 넘어가서 사진을 슬라이드 쇼로 보여 줍니다.

넘어간 레이아웃 에서는, imageView 두 개를 겹친 후, 투명도 조절을 통해 사진이 바뀌게 하였습니다.
timer, animate를 처음 써 보았습니다.

사진은 Uri로 오고 간다는 것을 알았습니다. 각 activity 파일마다, mutableArrayList를 통해 사진의 Uri를 관리하였고,
이때 ArrayList 사용법을 배웠습니다. 편리하기도 하지만, 공부해서 잘 써야겠다고 생각했습니다. forEachIndex를 써 보았습니다.

액티비티 간 데이터를 주고 받을 때, startActivityForResult를 쓰는 대신,
Launcher를 이용해서 데이터를 주고 받는 방법을 처음으로 해 보았습니다. requestcode를 따로 쓰지 않아도, 데이터를 받을 수 있는 것이 사실 잘 이해가 가지 않습니다.

그렇게 해보고 싶었던, viewBinding을 처음 써 보았습니다. 사용법이 크게 어렵지 않았지만,
액티비티 또는 xml 파일 이름에 오타가 생기거나 하면, viewbinding으로 가져온 모든 뷰들에 빨간 줄이 생기는
곤란한 상황이 생기기 때문에 조심해야한다고 생각했습니다. - 처음에 이거로 고생을 좀 했습니다 ㅎ

범위 지정 함수 (scope 함수)를 공부해 보았습니다. 금방 까먹을 것 같아서 다시 해야겠습니다.
해당 코드에서는 let, apply, run를 써 보았습니다.
let은 null일 때 실행시키지 않는 용도,
apply는 초기화 목적
run은 진짜 run의 의미와 비슷한데, apply로 초기화된 뷰바인딩 객체 뒤에 .run{}을 써서 binding에 속해있는 뷰들을 실행시키는 코드들을 작성했습니다.

<궁금한 점>
Leesc0893Week2Activity - 53번째 줄

  1. 저는 Launcher를 통해 ActivityResult가 람다로 반환되면 requestcode 없이, 그냥 it.data 이런식으로 접근하였습니다.
    만약 다양한 액티비티에서 데이터들을 보내게 된다면, 이때는 어떻게 해결해야 하나요?
    startActivityForResult를 쓸 때는, when문을 통해 requestCode로 판단해서 어디에서 온 인텐트인지 구분을 해주었는데, Launcher는 어떻게 해결해야 하는지 궁금합니다.

Leesc0893Week2Activity - 111, 24번째 줄
2. "imageView$i" (i에 숫자가 들어갑니다) -> 이런식으로 하면 imageView1 , imageView2 이렇게 인식을 하는데 (111번 째 줄)
"binding.imageView{$i}"이거는 인식이 안됩니다.(24번 째줄) ' . ' 이 들어간 상황에서는 해결을 못하나요?

긴 글 읽어주셔서 감사합니다.

@tmdcheol tmdcheol self-assigned this Aug 2, 2022
}

private fun initActivityResultLauncher(){
activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){ result ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

result.resultCode를 when으로 분기하면 어디서 온건지 구분 가능합니다. 이게 1번 질문 답변

private var imageUriList: MutableList<Uri> = mutableListOf<Uri>()
private val imageList: List<AppCompatImageView> by lazy {
mutableListOf<AppCompatImageView>().apply {
add(binding.imageView1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기서 "binding.imageView$i" 를 쓰려고 한거면 당연히 안되지 "" 요걸로 넣으면 AppCompatImageView를 넣는게 아니라 String을 넣게되는거니까

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