-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 20 additions & 24 deletions
44
app/src/main/java/sotp/semina/practicegitanddatabinding/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,46 @@ | ||
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 | ||
|
||
/*TODO step4 데이터 바인딩 직접 적용해보기.*/ | ||
class MainActivity : AppCompatActivity() { | ||
|
||
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) | ||
addButtonClickEvent(binding) | ||
setContentView(R.layout.activity_main) | ||
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(findViewById(R.id.image_profile_image)) | ||
} | ||
|
||
private fun setProfileName(profileName: TextView, content: String) { | ||
profileName.text = content | ||
private fun setProfileName(content:String) { | ||
findViewById<TextView>(R.id.text_profile_name).text = content | ||
} | ||
|
||
private fun addButtonClickEvent(binding: ActivityMainBinding) { | ||
binding.buttonProfileChangeButton.setOnClickListener { | ||
setProfileName( | ||
binding.textProfileName, | ||
getEditTextToString(binding.inputChangedProfile) | ||
) | ||
private fun addButtonClickEvent() { | ||
findViewById<Button>(R.id.button_profile_change_button).setOnClickListener { | ||
setProfileName(getEditTextToString(findViewById(R.id.input_changed_profile))) | ||
} | ||
} | ||
|
||
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<!--TODO step3 데이터 바인딩을 위한 레이아웃으로 감싸기--> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/image_profile_image" | ||
android:layout_width="200dp" | ||
android:layout_height="200dp" | ||
android:layout_marginTop="100dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:src="@mipmap/ic_launcher" /> | ||
<ImageView | ||
android:id="@+id/image_profile_image" | ||
android:layout_width="200dp" | ||
android:layout_height="200dp" | ||
android:layout_marginTop="100dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:src = "@mipmap/ic_launcher" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/text_profile_name" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="16dp" | ||
android:textColor="@color/black" | ||
android:textSize="20sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/image_profile_image" | ||
tools:text="profile name" /> | ||
<TextView | ||
android:id="@+id/text_profile_name" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="16dp" | ||
android:textColor="@color/black" | ||
android:textSize="20sp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/image_profile_image" | ||
tools:text="profile name" /> | ||
|
||
<EditText | ||
android:id="@+id/input_changed_profile" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/text_profile_name" /> | ||
<EditText | ||
android:id="@+id/input_changed_profile" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/text_profile_name" /> | ||
|
||
<Button | ||
android:id="@+id/button_profile_change_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
android:text="Change" | ||
app:layout_constraintTop_toBottomOf="@+id/input_changed_profile" /> | ||
<Button | ||
android:id="@+id/button_profile_change_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="16dp" | ||
android:layout_marginTop="16dp" | ||
android:layout_marginEnd="16dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
android:text="Change" | ||
app:layout_constraintTop_toBottomOf="@+id/input_changed_profile" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |