Skip to content

Commit

Permalink
[Fix] rebase... 급하게 하는 커밋이라 참고하지 마셈
Browse files Browse the repository at this point in the history
  • Loading branch information
jinsu4755 committed Dec 31, 2020
1 parent c82f10c commit 6c7b732
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 79 deletions.
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
/*TODO step1 kotlin kapt 추가하기
* 코틀린 어노테이션을 사용하기 위함*/
}

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

buildFeatures{
dataBinding = true
}
/*TODO step2 DataBinding 활성화 하기*/
}

dependencies {
Expand Down
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"
}
}
100 changes: 50 additions & 50 deletions app/src/main/res/layout/activity_main.xml
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>

0 comments on commit 6c7b732

Please sign in to comment.