Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'

}

android {
Expand Down Expand Up @@ -31,9 +32,8 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}

buildFeatures{
dataBinding = true
dataBinding{
enabled = true
}
Comment on lines +35 to 37
Copy link
Member

Choose a reason for hiding this comment

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

이 부분은 아마 Gradle 빌드 돌리면 아마 워닝으로 뜰탠데 자세히 읽어보면

Suggested change
dataBinding{
enabled = true
}
buildFeatures{
dataBinding = true
}

다음과 같이 변경되었으니 적어달라고 뜰꺼야

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
package sotp.semina.practicegitanddatabinding

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.bumptech.glide.Glide
import sotp.semina.practicegitanddatabinding.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding: ActivityMainBinding =
DataBindingUtil.setContentView(this, R.layout.activity_main)
initProfileImage(binding.imageProfileImage)
setProfileName(binding.textProfileName, DEFAULT_USER_NAME)
Copy link
Author

Choose a reason for hiding this comment

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

저같은 경우는 전역변수로 binding을 선언했고, 함수의 매개변수가 다른 것 말고는 진행 상황은 같았습니다

Copy link
Member

Choose a reason for hiding this comment

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

아주 좋아!
이건 내 개인적인 생각이었는데 binding value를 전역으로 선언할 필요가 있을까? 생각했었어.
Activity는 뷰에서 일어날 어떤 활동들? 그중에서도 생명주기와 연결이 강한 활동들이 일어나는 책임이라고 생각했기에
결국 binding value는 내가 뷰를 컨트롤 하면서 생기는 일이라 전역으로 쓰기보다는 범위를 줄여서 뷰에 관련된 일만 할 수 있도록 해야겠다 생각하고 각 뷰로 binding value를 쏴준거야

이 부분은 크게 정해진건 없으니 옳다고 생각하는 부분으로, 또는 Activity마다 유동적으로 적어주면 되는 부분이야~

Copy link
Author

Choose a reason for hiding this comment

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

무슨말인지 이해했어!! 사실 그렇게 까지 생각하지 않고, 전역변수로 쓰는 것이 더 편하다고만 생각했어서 먼저 전역변수로
선언해놓고 코드를 진행했던것 같아!! 참고할게~

addButtonClickEvent(binding)
setContentView(R.layout.activity_main)

binding = DataBindingUtil.setContentView(this,R.layout.activity_main)
binding.main = this

initView()

}

private fun initView() {
initProfileImage()
setProfileName(DEFAULT_USER_NAME)
addButtonClickEvent()
}

private fun initProfileImage(profileImage: ImageView) {
private fun initProfileImage() {
Glide.with(this)
.load(IMAGE_URL)
.into(profileImage)
.into(binding.imageProfileImage)
}

private fun setProfileName(profileName: TextView, content: String) {
profileName.text = content
private fun setProfileName(content:String) {
binding.textProfileName.text = content
}

private fun addButtonClickEvent(binding: ActivityMainBinding) {
private fun addButtonClickEvent() {
binding.buttonProfileChangeButton.setOnClickListener {
setProfileName(
binding.textProfileName,
getEditTextToString(binding.inputChangedProfile)
)
setProfileName(getEditTextToString(binding.inputChangedProfile))
}
}

private fun getEditTextToString(content: EditText): String = content.text.toString()
private fun getEditTextToString(content:EditText):String = content.text.toString()


companion object {
private const val IMAGE_URL =
"https://avatars3.githubusercontent.com/u/45380072?s=460&u=b9fc82996ec2cc568a7dfcbf8846944dc16a7ccd&v=4"
private const val IMAGE_URL = "https://avatars3.githubusercontent.com/u/45380072?s=460&u=b9fc82996ec2cc568a7dfcbf8846944dc16a7ccd&v=4"
private const val DEFAULT_USER_NAME = "Default User Name"
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>
<variable
name="main"
type="sotp.semina.practicegitanddatabinding.MainActivity" />
</data>
Comment on lines +6 to +10
Copy link
Member

Choose a reason for hiding this comment

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

이건 변수명에 관한건데 main이란 이름은 뭔가 개인적인 생각으로 많이 축약이다 생각이 들어!

바로 아래 타입이 적혀있어 큰 문제는 없지만 뷰가 복잡해지고 길어지고, variable이 많아지면 main이 엑티비티인지, 뷰모델인지, data class인지 판별하기 힘들 것 같다 생각했기 때문이야


<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down