From 4893f197971c1985333214f10c807be16972a23c Mon Sep 17 00:00:00 2001 From: hyooosong Date: Fri, 1 Jan 2021 04:36:13 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=B0=94?= =?UTF-8?q?=EC=9D=B8=EB=94=A9=20Step.02=20=EC=8B=A4=EC=8A=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Step.02 dataBinding Use_DataClass Related to : #2, #6 --- .../practicegitanddatabinding/BindingAdapter.kt | 11 +++++++---- .../semina/practicegitanddatabinding/MainActivity.kt | 4 +++- app/src/main/res/layout/activity_main.xml | 9 +++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/sotp/semina/practicegitanddatabinding/BindingAdapter.kt b/app/src/main/java/sotp/semina/practicegitanddatabinding/BindingAdapter.kt index 9a688d7..128c77a 100644 --- a/app/src/main/java/sotp/semina/practicegitanddatabinding/BindingAdapter.kt +++ b/app/src/main/java/sotp/semina/practicegitanddatabinding/BindingAdapter.kt @@ -4,9 +4,12 @@ import android.widget.ImageView import androidx.databinding.BindingAdapter import com.bumptech.glide.Glide -/*TODO step2 바인딩 어뎁터 생성 -* Glide로 이미지를 띄워주는 바인딩 어뎁터를 만들어주세요 -* 뷰에서 사용할 어트리뷰트 이름은 image로 합니다.*/ object BindingAdapter { - + @BindingAdapter("image") + @JvmStatic + fun loadImage(imageView: ImageView, url: String) { + Glide.with(imageView.context) + .load(url) + .into(imageView) + } } \ No newline at end of file diff --git a/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt b/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt index e3366b3..739171d 100644 --- a/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt +++ b/app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt @@ -3,6 +3,7 @@ package sotp.semina.practicegitanddatabinding import android.os.Bundle import android.widget.EditText import androidx.appcompat.app.AppCompatActivity +import androidx.databinding.BindingAdapter import androidx.databinding.DataBindingUtil import sotp.semina.practicegitanddatabinding.databinding.ActivityMainBinding @@ -12,7 +13,8 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) val binding: ActivityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main) - /*TODO step3 유저 데이터를 binding 변수에 넣어서 뷰에서 사용할 수 있도록 합니다.*/ + + binding.userProfile = UserData(IMAGE_URL, DEFAULT_USER_NAME) addButtonClickEvent(binding) } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a8a9478..968095a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,10 +4,11 @@ xmlns:tools="http://schemas.android.com/tools"> - + - + app:image="@{userProfile.userImage}" /> + tools:text="@{userProfile.userName}" />