-
Notifications
You must be signed in to change notification settings - Fork 0
Lee hyungjun/step.01 #5
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
base: Step.01-Solution-Databinding-Start_use_local_value
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저같은 경우는 전역변수로 binding을 선언했고, 함수의 매개변수가 다른 것 말고는 진행 상황은 같았습니다
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아주 좋아! 이 부분은 크게 정해진건 없으니 옳다고 생각하는 부분으로, 또는 Activity마다 유동적으로 적어주면 되는 부분이야~
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 아마 Gradle 빌드 돌리면 아마 워닝으로 뜰탠데 자세히 읽어보면
다음과 같이 변경되었으니 적어달라고 뜰꺼야