From e15f6d077ddd6ac45728c08d3b07f5ec58718288 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Mon, 24 Jun 2024 19:49:33 +0900 Subject: [PATCH 01/21] docs : Update README.md --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc0acc5a..cf825e22 100644 --- a/README.md +++ b/README.md @@ -1 +1,18 @@ -# android-contacts +# android-contacts - 간단한 연락처 구현(1주차) +## 구현할 기능 목록 + +**지정된 형식의 데이터를 입력하는 기능** +- [ ] 문자열을 입력할 수 있는 기능 +- [ ] 숫자만 입력할 수 있는 기능 +- [ ] 날짜 선택 기능 +- [ ] 성별 선택 기능 + +**더보기 기능** +- [ ] 더보기를 클릭하면 숨겨져 있던 입력 폼을 드러낼 수 있는 기능 + +**저장 기능** +- [ ] 저장 버튼을 클릭하면 토스트 메세지를 출력 +- [ ] 이름, 전화번호의 칸이 채워져 있지 않으면 저장이 되지 않으면 그에 맞는 토스트 메세지를 출력 + +**취소 기능** +- [ ] 취소 버튼을 클릭하면 토스트 메세지를 출력 \ No newline at end of file From 83f72d57f3f9e5e6d5df70a25ad40af6e7d1c20f Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Tue, 25 Jun 2024 15:08:43 +0900 Subject: [PATCH 02/21] feat : Add string input feature --- README.md | 4 +- app/src/main/res/drawable/input_form.xml | 6 + app/src/main/res/layout/activity_main.xml | 166 ++++++++++++++++++++-- 3 files changed, 166 insertions(+), 10 deletions(-) create mode 100644 app/src/main/res/drawable/input_form.xml diff --git a/README.md b/README.md index cf825e22..40ebf374 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ ## 구현할 기능 목록 **지정된 형식의 데이터를 입력하는 기능** -- [ ] 문자열을 입력할 수 있는 기능 -- [ ] 숫자만 입력할 수 있는 기능 +- [x] 문자열을 입력할 수 있는 기능 +- [x] 숫자만 입력할 수 있는 기능 - [ ] 날짜 선택 기능 - [ ] 성별 선택 기능 diff --git a/app/src/main/res/drawable/input_form.xml b/app/src/main/res/drawable/input_form.xml new file mode 100644 index 00000000..2abf3180 --- /dev/null +++ b/app/src/main/res/drawable/input_form.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 24d17df2..7eedae27 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,13 +7,163 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + + + + + + + + + + + + + + + + + + + + + + + + From 38f158a62ca537c7313c9b0f73d701eef90523cd Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Tue, 25 Jun 2024 15:49:57 +0900 Subject: [PATCH 03/21] feat : Add feature that display Toast Message when cancel button is clicked --- .../tech/kakao/contacts/MainActivity.kt | 17 +++++++++++++ app/src/main/res/layout/activity_main.xml | 24 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 7aae79fe..0fdc698b 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -1,11 +1,28 @@ package campus.tech.kakao.contacts +import android.content.Context import android.os.Bundle +import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + cancelButtonSetOnClickListner(this) } + + fun cancelButtonSetOnClickListner(context : Context){ + findViewById(R.id.button_cancel).setOnClickListener(){ + displayCancelMessage(context) + } + } + + fun displayCancelMessage(context: Context){ + val cancelMessage = Toast.makeText(context, "취소 되었습니다", Toast.LENGTH_SHORT) + cancelMessage.show() + } + } + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7eedae27..9beb2643 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,8 +13,10 @@ android:layout_height="0dp" android:fillViewport="true" android:scrollbars="vertical" + app:layout_constraintBottom_toTopOf="@+id/button_cancel" app:layout_constraintTop_toTopOf="parent" > + + + From bbd28cf10f0ee2d9ffa74862b1f4bb258d8458cc Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Tue, 25 Jun 2024 18:23:35 +0900 Subject: [PATCH 04/21] feat : Add feature that display toast message when save clicked --- README.md | 4 ++-- .../java/campus/tech/kakao/contacts/MainActivity.kt | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40ebf374..bfcf29d6 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ - [ ] 더보기를 클릭하면 숨겨져 있던 입력 폼을 드러낼 수 있는 기능 **저장 기능** -- [ ] 저장 버튼을 클릭하면 토스트 메세지를 출력 +- [x] 저장 버튼을 클릭하면 토스트 메세지를 출력 - [ ] 이름, 전화번호의 칸이 채워져 있지 않으면 저장이 되지 않으면 그에 맞는 토스트 메세지를 출력 **취소 기능** -- [ ] 취소 버튼을 클릭하면 토스트 메세지를 출력 \ No newline at end of file +- [x] 취소 버튼을 클릭하면 토스트 메세지를 출력 \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 0fdc698b..ca70bac4 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -10,6 +10,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + saveButtonSetOnClickListner(this) cancelButtonSetOnClickListner(this) } @@ -24,5 +25,15 @@ class MainActivity : AppCompatActivity() { cancelMessage.show() } + fun saveButtonSetOnClickListner(context : Context){ + findViewById(R.id.button_save).setOnClickListener(){ + displaySaveMessage(context) + } + } + + fun displaySaveMessage(context: Context){ + val saveMessage = Toast.makeText(context, "저장이 완료 되었습니다.", Toast.LENGTH_SHORT) + saveMessage.show() + } } From 4cb00caba8e91248cd7d3d7d6aaddbe52604c99e Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Tue, 25 Jun 2024 20:09:10 +0900 Subject: [PATCH 05/21] feat : Add feature that display toast message if name, number field is not fill --- .../tech/kakao/contacts/MainActivity.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index ca70bac4..5b289170 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -2,14 +2,22 @@ package campus.tech.kakao.contacts import android.content.Context import android.os.Bundle +import android.util.Log +import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import kotlin.math.log class MainActivity : AppCompatActivity() { + lateinit var name : EditText + lateinit var phoneNumber : EditText + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + name = findViewById(R.id.input_name) + phoneNumber = findViewById(R.id.input_phone_number) saveButtonSetOnClickListner(this) cancelButtonSetOnClickListner(this) } @@ -32,8 +40,24 @@ class MainActivity : AppCompatActivity() { } fun displaySaveMessage(context: Context){ - val saveMessage = Toast.makeText(context, "저장이 완료 되었습니다.", Toast.LENGTH_SHORT) + Log.d("phone", "" + name.text) + val text = checkNameAndPhoneNum() + val saveMessage = Toast.makeText(context, text, Toast.LENGTH_SHORT) saveMessage.show() } + + fun checkNameAndPhoneNum() : String{ + if (name.text.toString() == ""){ + name.requestFocus() + return "이름을 입력해야만 합니다" + } + else if(phoneNumber.text.toString() == ""){ + phoneNumber.requestFocus() + return "번호를 입력해야만 합니다" + } + else{ + return "저장이 완료 되었습니다" + } + } } From 6cb51ac70b2f617f7e6b274354281f1b443fb9e9 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Wed, 26 Jun 2024 14:51:07 +0900 Subject: [PATCH 06/21] feat : Add feature that display more input field when button is clicked --- README.md | 4 +-- .../tech/kakao/contacts/MainActivity.kt | 25 ++++++++++++++++++- app/src/main/res/layout/activity_main.xml | 11 ++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bfcf29d6..9a05af8e 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ - [ ] 성별 선택 기능 **더보기 기능** -- [ ] 더보기를 클릭하면 숨겨져 있던 입력 폼을 드러낼 수 있는 기능 +- [x] 더보기를 클릭하면 숨겨져 있던 입력 폼을 드러낼 수 있는 기능 **저장 기능** - [x] 저장 버튼을 클릭하면 토스트 메세지를 출력 -- [ ] 이름, 전화번호의 칸이 채워져 있지 않으면 저장이 되지 않으면 그에 맞는 토스트 메세지를 출력 +- [x] 이름, 전화번호의 칸이 채워져 있지 않으면 저장이 되지 않으면 그에 맞는 토스트 메세지를 출력 **취소 기능** - [x] 취소 버튼을 클릭하면 토스트 메세지를 출력 \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 5b289170..77349afc 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -3,7 +3,9 @@ package campus.tech.kakao.contacts import android.content.Context import android.os.Bundle import android.util.Log +import android.view.View import android.widget.EditText +import android.widget.RadioGroup import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity @@ -12,14 +14,36 @@ import kotlin.math.log class MainActivity : AppCompatActivity() { lateinit var name : EditText lateinit var phoneNumber : EditText + lateinit var mail : EditText + lateinit var gender : EditText + lateinit var genderRadioGroup : RadioGroup + lateinit var memo : EditText + lateinit var birthday : EditText + lateinit var moreInfoButton : TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) name = findViewById(R.id.input_name) phoneNumber = findViewById(R.id.input_phone_number) + mail = findViewById(R.id.input_mail) + birthday = findViewById(R.id.input_birthday) + gender = findViewById(R.id.input_gender) + genderRadioGroup = findViewById(R.id.gender_radio_group) + memo = findViewById(R.id.input_memo) + moreInfoButton = findViewById(R.id.more_info_button) + saveButtonSetOnClickListner(this) cancelButtonSetOnClickListner(this) + moreInfoButton.setOnClickListener(){ + birthday.visibility = View.VISIBLE + gender.visibility = View.VISIBLE + genderRadioGroup.visibility = View.VISIBLE + memo.visibility = View.VISIBLE + moreInfoButton.visibility = View.GONE + + } + } fun cancelButtonSetOnClickListner(context : Context){ @@ -40,7 +64,6 @@ class MainActivity : AppCompatActivity() { } fun displaySaveMessage(context: Context){ - Log.d("phone", "" + name.text) val text = checkNameAndPhoneNum() val saveMessage = Toast.makeText(context, text, Toast.LENGTH_SHORT) saveMessage.show() diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9beb2643..89f1f73e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -97,6 +97,7 @@ android:layout_marginEnd="20dp" android:layout_marginTop="15dp" android:background="@drawable/input_form" + android:visibility="gone" /> + app:layout_constraintTop_toTopOf="@id/input_gender" + android:visibility="gone" + > Date: Wed, 26 Jun 2024 15:03:39 +0900 Subject: [PATCH 07/21] refactor : refactoring about feature that display more info field --- .../tech/kakao/contacts/MainActivity.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 77349afc..ba54f836 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -33,20 +33,13 @@ class MainActivity : AppCompatActivity() { memo = findViewById(R.id.input_memo) moreInfoButton = findViewById(R.id.more_info_button) - saveButtonSetOnClickListner(this) - cancelButtonSetOnClickListner(this) - moreInfoButton.setOnClickListener(){ - birthday.visibility = View.VISIBLE - gender.visibility = View.VISIBLE - genderRadioGroup.visibility = View.VISIBLE - memo.visibility = View.VISIBLE - moreInfoButton.visibility = View.GONE - - } + saveButtonSetOnClickListener(this) + cancelButtonSetOnClickListener(this) + moreButtonSetOnClickListener() } - fun cancelButtonSetOnClickListner(context : Context){ + fun cancelButtonSetOnClickListener(context : Context){ findViewById(R.id.button_cancel).setOnClickListener(){ displayCancelMessage(context) } @@ -57,7 +50,7 @@ class MainActivity : AppCompatActivity() { cancelMessage.show() } - fun saveButtonSetOnClickListner(context : Context){ + fun saveButtonSetOnClickListener(context : Context){ findViewById(R.id.button_save).setOnClickListener(){ displaySaveMessage(context) } @@ -82,5 +75,19 @@ class MainActivity : AppCompatActivity() { return "저장이 완료 되었습니다" } } + + fun moreButtonSetOnClickListener(){ + moreInfoButton.setOnClickListener(){ + setInputFieldVisible() + } + } + + fun setInputFieldVisible(){ + birthday.visibility = View.VISIBLE + gender.visibility = View.VISIBLE + genderRadioGroup.visibility = View.VISIBLE + memo.visibility = View.VISIBLE + moreInfoButton.visibility = View.GONE + } } From b3bf8d9facc8afd2ed456d1f20ad6be7d4043f5f Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Wed, 26 Jun 2024 15:43:58 +0900 Subject: [PATCH 08/21] feat : Add feature that input birthday field --- README.md | 2 +- .../tech/kakao/contacts/MainActivity.kt | 20 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a05af8e..8d57ed87 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **지정된 형식의 데이터를 입력하는 기능** - [x] 문자열을 입력할 수 있는 기능 - [x] 숫자만 입력할 수 있는 기능 -- [ ] 날짜 선택 기능 +- [x] 날짜 선택 기능 - [ ] 성별 선택 기능 **더보기 기능** diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index ba54f836..ebf63e1b 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -1,14 +1,17 @@ package campus.tech.kakao.contacts +import android.app.DatePickerDialog import android.content.Context import android.os.Bundle import android.util.Log import android.view.View +import android.widget.DatePicker import android.widget.EditText import android.widget.RadioGroup import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import java.util.Calendar import kotlin.math.log class MainActivity : AppCompatActivity() { @@ -36,6 +39,8 @@ class MainActivity : AppCompatActivity() { saveButtonSetOnClickListener(this) cancelButtonSetOnClickListener(this) moreButtonSetOnClickListener() + birthdayFieldSetOnclickListener() + } @@ -89,5 +94,20 @@ class MainActivity : AppCompatActivity() { memo.visibility = View.VISIBLE moreInfoButton.visibility = View.GONE } + + fun birthdayFieldSetOnclickListener(){ + birthday.setOnClickListener(){ + setBirthday() + } + } + + fun setBirthday(){ + val datePicker = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { + view : DatePicker?, year, month, day -> + birthday.setText("${year}/${month}/${day}") + }, 2000, 1, 1).show() + } + + } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 89f1f73e..f73d1e58 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -89,6 +89,7 @@ android:layout_height="55dp" android:paddingLeft="10dp" android:hint="생일" + android:focusable="false" app:layout_constraintTop_toBottomOf="@id/input_mail" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" From 1e6b013b39b94315f105db0fa3cf21717039a07a Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Wed, 26 Jun 2024 17:35:18 +0900 Subject: [PATCH 09/21] feat : Add feature that select gender field --- README.md | 2 +- .../campus/tech/kakao/contacts/MainActivity.kt | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8d57ed87..15be09e7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - [x] 문자열을 입력할 수 있는 기능 - [x] 숫자만 입력할 수 있는 기능 - [x] 날짜 선택 기능 -- [ ] 성별 선택 기능 +- [x] 성별 선택 기능 **더보기 기능** - [x] 더보기를 클릭하면 숨겨져 있던 입력 폼을 드러낼 수 있는 기능 diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index ebf63e1b..a9f97987 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -40,7 +40,7 @@ class MainActivity : AppCompatActivity() { cancelButtonSetOnClickListener(this) moreButtonSetOnClickListener() birthdayFieldSetOnclickListener() - + genderFieldSetOnChangeListener() } @@ -103,11 +103,23 @@ class MainActivity : AppCompatActivity() { fun setBirthday(){ val datePicker = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { - view : DatePicker?, year, month, day -> + view, year, month, day -> birthday.setText("${year}/${month}/${day}") }, 2000, 1, 1).show() } + fun genderFieldSetOnChangeListener(){ + genderRadioGroup.setOnCheckedChangeListener { it, id -> + fillGenderField(id) + } + } + fun fillGenderField(id : Int){ + when(id){ + R.id.button_woman -> gender.setText("여성") + R.id.button_man -> gender.setText("남성") + else -> gender.setText("") + } + } } From 35ac9daa2936c3a3f1c45a3e79bb821a646c5c2d Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Wed, 26 Jun 2024 18:08:35 +0900 Subject: [PATCH 10/21] refactor : refector initializing variable code and listener code --- .../tech/kakao/contacts/MainActivity.kt | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index a9f97987..1164cf12 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -27,21 +27,16 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - name = findViewById(R.id.input_name) - phoneNumber = findViewById(R.id.input_phone_number) - mail = findViewById(R.id.input_mail) - birthday = findViewById(R.id.input_birthday) - gender = findViewById(R.id.input_gender) - genderRadioGroup = findViewById(R.id.gender_radio_group) - memo = findViewById(R.id.input_memo) - moreInfoButton = findViewById(R.id.more_info_button) + initVar() + initListener() + } + fun initListener(){ saveButtonSetOnClickListener(this) cancelButtonSetOnClickListener(this) moreButtonSetOnClickListener() birthdayFieldSetOnclickListener() genderFieldSetOnChangeListener() - } fun cancelButtonSetOnClickListener(context : Context){ @@ -103,13 +98,13 @@ class MainActivity : AppCompatActivity() { fun setBirthday(){ val datePicker = DatePickerDialog(this, DatePickerDialog.OnDateSetListener { - view, year, month, day -> + _, year, month, day -> birthday.setText("${year}/${month}/${day}") }, 2000, 1, 1).show() } fun genderFieldSetOnChangeListener(){ - genderRadioGroup.setOnCheckedChangeListener { it, id -> + genderRadioGroup.setOnCheckedChangeListener { _, id -> fillGenderField(id) } } @@ -121,5 +116,16 @@ class MainActivity : AppCompatActivity() { } } + fun initVar(){ + name = findViewById(R.id.input_name) + phoneNumber = findViewById(R.id.input_phone_number) + mail = findViewById(R.id.input_mail) + birthday = findViewById(R.id.input_birthday) + gender = findViewById(R.id.input_gender) + genderRadioGroup = findViewById(R.id.gender_radio_group) + memo = findViewById(R.id.input_memo) + moreInfoButton = findViewById(R.id.more_info_button) + } + } From 847e50d161b60bafc088b45eabce06170efb452b Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 13:29:47 +0900 Subject: [PATCH 11/21] docs : Update README.md --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15be09e7..09543bf7 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,19 @@ - [x] 이름, 전화번호의 칸이 채워져 있지 않으면 저장이 되지 않으면 그에 맞는 토스트 메세지를 출력 **취소 기능** -- [x] 취소 버튼을 클릭하면 토스트 메세지를 출력 \ No newline at end of file +- [x] 취소 버튼을 클릭하면 토스트 메세지를 출력 + +## step2 구현할 기능 목록 + +**연락처 추가 기능** +- [ ] + 버튼을 통해 연락처를 추가하는 창을 띄우는 기능 + +**연락처 출력 기능** +- [ ] 저장된 연락처들을 간단하게 이름만 띄워주는 기능 +- [ ] 각 연락처를 클릭하면 상세 화면을 띄워주는 기능 +- [ ] 상세화면에서 적힌 내용만 출력하는 기능 + +**연락처 저장 기능** +- [ ] 저장 버튼을 누르면 연락처를 저장할 수 있는 기능 +- [ ] 뒤로가기 버튼을 누를 때 만약 작성된 내용이 있다면 확인 팝업이 나타나는 기능 +- [ ] 취소 버튼을 누를 때 만약 작성된 내용이 있다면 확인 팝업이 나타나는 기능 \ No newline at end of file From ff5a8b451dc19984fb299c26af8bc6bfe3c1c793 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 13:36:12 +0900 Subject: [PATCH 12/21] style : Add xml file that list page and detail page --- app/build.gradle.kts | 1 + app/src/main/AndroidManifest.xml | 8 +- .../tech/kakao/contacts/DetailActivity.kt | 14 ++ .../tech/kakao/contacts/ListActivity.kt | 14 ++ app/src/main/res/drawable/item.xml | 7 + app/src/main/res/drawable/yellow_box.xml | 6 + app/src/main/res/drawable/yellow_circle.xml | 6 + app/src/main/res/layout/activity_detail.xml | 205 ++++++++++++++++++ app/src/main/res/layout/activity_list.xml | 46 ++++ app/src/main/res/layout/contact_item.xml | 44 ++++ 10 files changed, 350 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt create mode 100644 app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt create mode 100644 app/src/main/res/drawable/item.xml create mode 100644 app/src/main/res/drawable/yellow_box.xml create mode 100644 app/src/main/res/drawable/yellow_circle.xml create mode 100644 app/src/main/res/layout/activity_detail.xml create mode 100644 app/src/main/res/layout/activity_list.xml create mode 100644 app/src/main/res/layout/contact_item.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c5add08f..12f60dcb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -41,6 +41,7 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.11.0") implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("androidx.activity:activity:1.8.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 89dc9d8b..1793994b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,8 +12,14 @@ android:supportsRtl="true" android:theme="@style/Theme.Contacts" tools:targetApi="31"> + + @@ -23,4 +29,4 @@ - + \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt new file mode 100644 index 00000000..f0f43479 --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt @@ -0,0 +1,14 @@ +package campus.tech.kakao.contacts + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +class DetailActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_detail) + } +} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt new file mode 100644 index 00000000..40939cbb --- /dev/null +++ b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt @@ -0,0 +1,14 @@ +package campus.tech.kakao.contacts + +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat + +class ListActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_list) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/item.xml b/app/src/main/res/drawable/item.xml new file mode 100644 index 00000000..766b434e --- /dev/null +++ b/app/src/main/res/drawable/item.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/yellow_box.xml b/app/src/main/res/drawable/yellow_box.xml new file mode 100644 index 00000000..2a670c65 --- /dev/null +++ b/app/src/main/res/drawable/yellow_box.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/yellow_circle.xml b/app/src/main/res/drawable/yellow_circle.xml new file mode 100644 index 00000000..29375f91 --- /dev/null +++ b/app/src/main/res/drawable/yellow_circle.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml new file mode 100644 index 00000000..ad84b28e --- /dev/null +++ b/app/src/main/res/layout/activity_detail.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_list.xml b/app/src/main/res/layout/activity_list.xml new file mode 100644 index 00000000..0e9527c2 --- /dev/null +++ b/app/src/main/res/layout/activity_list.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/contact_item.xml b/app/src/main/res/layout/contact_item.xml new file mode 100644 index 00000000..1c3abce6 --- /dev/null +++ b/app/src/main/res/layout/contact_item.xml @@ -0,0 +1,44 @@ + + + + + + + + \ No newline at end of file From a33025b7922c3423d4e8d073ce69b797f527dd8b Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 14:28:22 +0900 Subject: [PATCH 13/21] feat : Add feature that save contact --- .../tech/kakao/contacts/ListActivity.kt | 28 ++++++++++ .../tech/kakao/contacts/MainActivity.kt | 53 +++++++++++++++---- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt index 40939cbb..d0fd094d 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt @@ -10,5 +10,33 @@ class ListActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_list) + val intent = getIntent() + val contactList = mutableListOf() + val contact = Contact( + intent.getStringExtra("name").toString(), + intent.getStringExtra("phoneNumber").toString(), + intent.getStringExtra("mail").toString(), + intent.getStringExtra("birthday").toString(), + intent.getStringExtra("gender").toString(), + intent.getStringExtra("memo").toString()) + contactList.add(contact) + } +} + +class Contact(var name : String, var phoneNumber : String, var mail : String, var birthday : String, var gender : String, var memo : String){ + fun existsMail(): Boolean { + return mail != "" + } + + fun existsBirthday(): Boolean { + return birthday != "" + } + + fun existsGender(): Boolean { + return gender != "" + } + + fun existsMemo(): Boolean { + return memo != "" } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 1164cf12..1cd23cac 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -2,6 +2,7 @@ package campus.tech.kakao.contacts import android.app.DatePickerDialog import android.content.Context +import android.content.Intent import android.os.Bundle import android.util.Log import android.view.View @@ -52,27 +53,60 @@ class MainActivity : AppCompatActivity() { fun saveButtonSetOnClickListener(context : Context){ findViewById(R.id.button_save).setOnClickListener(){ + saveContact(context) + } + } + + fun existNameAndPhoneNum() : Boolean{ + val checkNum = checkNameAndPhoneNum() + return if(checkNum == 2 || checkNum == 3) false + else true + } + + fun saveContact(context:Context){ + val intent = Intent(this, ListActivity::class.java) + if (existNameAndPhoneNum()){ + displaySaveMessage(context) + intent.putExtra("name", name.text.toString()) + intent.putExtra("phoneNumber", phoneNumber.text.toString()) + intent.putExtra("mail", mail.text.toString()) + intent.putExtra("birthday", birthday.text.toString()) + intent.putExtra("gender", gender.text.toString()) + intent.putExtra("memo", memo.text.toString()) + startActivity(intent) + } + else { displaySaveMessage(context) } + } fun displaySaveMessage(context: Context){ - val text = checkNameAndPhoneNum() + val text = getToastMessageToNameAndPhoneNum() val saveMessage = Toast.makeText(context, text, Toast.LENGTH_SHORT) saveMessage.show() } - fun checkNameAndPhoneNum() : String{ - if (name.text.toString() == ""){ + + fun checkNameAndPhoneNum() : Int{ + return if (name.text.toString() == ""){ name.requestFocus() - return "이름을 입력해야만 합니다" - } - else if(phoneNumber.text.toString() == ""){ + 2 + } else if(phoneNumber.text.toString() == ""){ phoneNumber.requestFocus() - return "번호를 입력해야만 합니다" + 3 + } else{ + 1 } - else{ - return "저장이 완료 되었습니다" + } + + fun getToastMessageToNameAndPhoneNum() : String{ + val checkNum = checkNameAndPhoneNum() + return when(checkNum){ + 1 -> "저장이 완료되었습니다" + 2 -> "이름을 입력해 주세요" + 3 -> "전화번호를 입력해 주세요" + else -> "오류" } } @@ -126,6 +160,5 @@ class MainActivity : AppCompatActivity() { memo = findViewById(R.id.input_memo) moreInfoButton = findViewById(R.id.more_info_button) } - } From a082d6089fcd1d091dbdb9d5c45aa1615df201d6 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 14:35:32 +0900 Subject: [PATCH 14/21] feat : Add feature that move to adding contact Activity when plus is clicked --- .../java/campus/tech/kakao/contacts/ListActivity.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt index d0fd094d..9a5b5c5d 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt @@ -1,12 +1,15 @@ package campus.tech.kakao.contacts +import android.content.Intent import android.os.Bundle +import android.widget.TextView import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat class ListActivity : AppCompatActivity() { + lateinit var plusButton : TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_list) @@ -20,6 +23,16 @@ class ListActivity : AppCompatActivity() { intent.getStringExtra("gender").toString(), intent.getStringExtra("memo").toString()) contactList.add(contact) + + val plusButton = findViewById(R.id.plus_item_button) + plusButton.setOnClickListener{ + moveToAddContact() + } + } + + fun moveToAddContact(){ + val intent = Intent(this@ListActivity, MainActivity::class.java) + startActivity(intent) } } From 8ded020ee1b7bc277b5b8f82b7154f270f00391d Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 15:56:14 +0900 Subject: [PATCH 15/21] feat : Add feature that display contact list --- .../tech/kakao/contacts/ListActivity.kt | 93 ++++++++++++++++--- .../tech/kakao/contacts/MainActivity.kt | 4 +- app/src/main/res/layout/activity_list.xml | 4 +- app/src/main/res/layout/contact_item.xml | 1 + 4 files changed, 87 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt index 9a5b5c5d..0179de56 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt @@ -2,40 +2,109 @@ package campus.tech.kakao.contacts import android.content.Intent import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import android.widget.TextView import androidx.activity.enableEdgeToEdge +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView class ListActivity : AppCompatActivity() { + lateinit var resultLauncher : ActivityResultLauncher + lateinit var descriptionText : TextView lateinit var plusButton : TextView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_list) - val intent = getIntent() + + val contactList = mutableListOf() - val contact = Contact( - intent.getStringExtra("name").toString(), - intent.getStringExtra("phoneNumber").toString(), - intent.getStringExtra("mail").toString(), - intent.getStringExtra("birthday").toString(), - intent.getStringExtra("gender").toString(), - intent.getStringExtra("memo").toString()) - contactList.add(contact) - - val plusButton = findViewById(R.id.plus_item_button) + + plusButton = findViewById(R.id.plus_item_button) + descriptionText = findViewById(R.id.description_text) plusButton.setOnClickListener{ moveToAddContact() } + Log.d("contact2", contactList.toString()) + val recyclerView = findViewById(R.id.recyclerView) + val adapter = RecyclerViewAdapter(contactList, LayoutInflater.from(this)) + recyclerView.adapter = adapter + // 리사이클러 뷰에 레이아웃 매니저 장착 + recyclerView.layoutManager= LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) + // 리사이클러 뷰에 어답터 장착 + resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == RESULT_OK) { + // 전달 받은 String 데이터를 출력 + val contact = Contact( + result.data?.getStringExtra("name") ?: "", + result.data?.getStringExtra("phoneNumber") ?: "", + result.data?.getStringExtra("mail") ?: "", + result.data?.getStringExtra("birthday") ?: "", + result.data?.getStringExtra("gender") ?: "", + result.data?.getStringExtra("memo") ?: "", + ) + Log.d("contact2", contact.name) + contactList.add(contact) + setDescriptionTextVisibilityGone() + adapter.notifyItemInserted(contactList.size) + } + } } fun moveToAddContact(){ val intent = Intent(this@ListActivity, MainActivity::class.java) - startActivity(intent) + resultLauncher.launch(intent) + } + + fun setDescriptionTextVisibilityGone(){ + descriptionText.visibility = View.GONE } } +class RecyclerViewAdapter( + //outer class + var contactList : MutableList, + var inflater : LayoutInflater +) : RecyclerView.Adapter(){ // 어떤 뷰홀더를 쓸건지 알려줘야함 ViewHolder는 클래스 안쪽에 만든다.(inner class) + + inner class ViewHolder(itemView: View ): RecyclerView.ViewHolder(itemView){ + //RecyclerView의 뷰 홀더를 상속받아야만 개선된 ViewHolder를 사용할 수 있다. + // 아이템뷰 컴포넌트를 구체적으로 찾는(홀드하는) 역할 + val userTitle : TextView + val userName : TextView + init{ + userTitle = itemView.findViewById(R.id.user_title) + userName = itemView.findViewById(R.id.user_name) + + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + // 인플레이트 시켜서 뷰 홀더에게 넘겨준다. + val view = inflater.inflate(R.layout.contact_item, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + //데이터를 아이템뷰의 뷰컴포넌트와 묶는다.(뷰를 채운다) + holder.userTitle.text = contactList.get(position).name[0].toString() + holder.userName.text = contactList.get(position).name + } + + override fun getItemCount(): Int { + // 전체 데이터의 크기 리턴 + return contactList.size + } +} + + class Contact(var name : String, var phoneNumber : String, var mail : String, var birthday : String, var gender : String, var memo : String){ fun existsMail(): Boolean { return mail != "" diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 1cd23cac..3d8dd0b7 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -64,7 +64,6 @@ class MainActivity : AppCompatActivity() { } fun saveContact(context:Context){ - val intent = Intent(this, ListActivity::class.java) if (existNameAndPhoneNum()){ displaySaveMessage(context) intent.putExtra("name", name.text.toString()) @@ -73,7 +72,8 @@ class MainActivity : AppCompatActivity() { intent.putExtra("birthday", birthday.text.toString()) intent.putExtra("gender", gender.text.toString()) intent.putExtra("memo", memo.text.toString()) - startActivity(intent) + setResult(RESULT_OK, intent) + finish() } else { displaySaveMessage(context) diff --git a/app/src/main/res/layout/activity_list.xml b/app/src/main/res/layout/activity_list.xml index 0e9527c2..8892367e 100644 --- a/app/src/main/res/layout/activity_list.xml +++ b/app/src/main/res/layout/activity_list.xml @@ -8,12 +8,13 @@ tools:context=".ListActivity"> @@ -31,6 +32,7 @@ app:layout_constraintRight_toRightOf="parent" /> Date: Fri, 28 Jun 2024 16:32:18 +0900 Subject: [PATCH 16/21] feat : Add feature that move to detail page --- .../tech/kakao/contacts/DetailActivity.kt | 36 +++++++++++++++++++ .../tech/kakao/contacts/ListActivity.kt | 36 +++++++++---------- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt index f0f43479..59a15018 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt @@ -1,14 +1,50 @@ package campus.tech.kakao.contacts import android.os.Bundle +import android.widget.TextView import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat class DetailActivity : AppCompatActivity() { + lateinit var name: TextView + lateinit var phoneNumber: TextView + lateinit var mail: TextView + lateinit var birthday: TextView + lateinit var gender: TextView + lateinit var memo: TextView + lateinit var nameInputField: TextView + lateinit var phoneNumberInputField: TextView + lateinit var mailInputField: TextView + lateinit var birthdayInputField: TextView + lateinit var genderInputField: TextView + lateinit var memoInputField: TextView + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail) + + name = findViewById(R.id.name) + phoneNumber = findViewById(R.id.phone_number) + mail = findViewById(R.id.mail) + birthday = findViewById(R.id.birthday) + gender = findViewById(R.id.gender) + memo = findViewById(R.id.memo) + nameInputField = findViewById(R.id.input_name_field) + phoneNumberInputField = findViewById(R.id.input_phone_number_field) + mailInputField = findViewById(R.id.input_mail_field) + birthdayInputField = findViewById(R.id.input_birthday_field) + genderInputField = findViewById(R.id.input_gender_field) + memoInputField = findViewById(R.id.input_memo_field) + + val intent = intent + nameInputField.setText(intent.getStringExtra("name")) + phoneNumberInputField.setText(intent.getStringExtra("phoneNumber")) + mailInputField.setText(intent.getStringExtra("mail")) + birthdayInputField.setText(intent.getStringExtra("birthday")) + genderInputField.setText(intent.getStringExtra("gender")) + memoInputField.setText(intent.getStringExtra("memo")) + } } \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt index 0179de56..d3ba3ba9 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt @@ -1,5 +1,6 @@ package campus.tech.kakao.contacts +import android.content.Context import android.content.Intent import android.os.Bundle import android.util.Log @@ -34,7 +35,7 @@ class ListActivity : AppCompatActivity() { } Log.d("contact2", contactList.toString()) val recyclerView = findViewById(R.id.recyclerView) - val adapter = RecyclerViewAdapter(contactList, LayoutInflater.from(this)) + val adapter = RecyclerViewAdapter(contactList, LayoutInflater.from(this), this) recyclerView.adapter = adapter // 리사이클러 뷰에 레이아웃 매니저 장착 recyclerView.layoutManager= LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) @@ -71,7 +72,8 @@ class ListActivity : AppCompatActivity() { class RecyclerViewAdapter( //outer class var contactList : MutableList, - var inflater : LayoutInflater + var inflater : LayoutInflater, + var context : Context ) : RecyclerView.Adapter(){ // 어떤 뷰홀더를 쓸건지 알려줘야함 ViewHolder는 클래스 안쪽에 만든다.(inner class) inner class ViewHolder(itemView: View ): RecyclerView.ViewHolder(itemView){ @@ -82,6 +84,18 @@ class RecyclerViewAdapter( init{ userTitle = itemView.findViewById(R.id.user_title) userName = itemView.findViewById(R.id.user_name) + itemView.setOnClickListener{ + val position : Int = adapterPosition + val intent = Intent(context, DetailActivity::class.java) + val sendContact = contactList.get(position) + intent.putExtra("name", sendContact.name) + intent.putExtra("phoneNumber", sendContact.phoneNumber) + intent.putExtra("mail", sendContact.mail) + intent.putExtra("birthday", sendContact.birthday) + intent.putExtra("gender", sendContact.gender) + intent.putExtra("memo", sendContact.memo) + context.startActivity(intent) + } } } @@ -105,20 +119,4 @@ class RecyclerViewAdapter( } -class Contact(var name : String, var phoneNumber : String, var mail : String, var birthday : String, var gender : String, var memo : String){ - fun existsMail(): Boolean { - return mail != "" - } - - fun existsBirthday(): Boolean { - return birthday != "" - } - - fun existsGender(): Boolean { - return gender != "" - } - - fun existsMemo(): Boolean { - return memo != "" - } -} \ No newline at end of file +class Contact(var name : String, var phoneNumber : String, var mail : String, var birthday : String, var gender : String, var memo : String){} \ No newline at end of file From d3218c05d497a567addf9dd6a945f3070ce4f630 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 16:45:42 +0900 Subject: [PATCH 17/21] feat : Add feature that display only completed field at detail page --- .../tech/kakao/contacts/DetailActivity.kt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt index 59a15018..5e8098d6 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt @@ -1,6 +1,7 @@ package campus.tech.kakao.contacts import android.os.Bundle +import android.view.View import android.widget.TextView import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity @@ -45,6 +46,42 @@ class DetailActivity : AppCompatActivity() { birthdayInputField.setText(intent.getStringExtra("birthday")) genderInputField.setText(intent.getStringExtra("gender")) memoInputField.setText(intent.getStringExtra("memo")) + setVisibleCompletedFields() + } + + fun setVisibleCompletedFields() { + if(ExistMail()){ + mail.visibility = View.VISIBLE + mailInputField.visibility = View.VISIBLE + } + if(ExistBirthday()){ + birthday.visibility = View.VISIBLE + birthdayInputField.visibility = View.VISIBLE + } + if(ExistGender()){ + gender.visibility = View.VISIBLE + genderInputField.visibility = View.VISIBLE + } + if(ExistMemo()){ + memo.visibility = View.VISIBLE + memoInputField.visibility = View.VISIBLE + } + + } + + fun ExistMail(): Boolean { + return mailInputField.text.toString() != "" + } + + fun ExistBirthday(): Boolean { + return birthdayInputField.text.toString() != "" + } + + fun ExistGender(): Boolean { + return genderInputField.text.toString() != "" + } + fun ExistMemo(): Boolean { + return memoInputField.text.toString() != "" } } \ No newline at end of file From 7bc6c79dfb35b59107c649ad82f1ce0b71ee8e95 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 17:17:35 +0900 Subject: [PATCH 18/21] feat : Add feature that display cancel dialog when back pressed --- .../tech/kakao/contacts/MainActivity.kt | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 3d8dd0b7..6e39db17 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -2,6 +2,7 @@ package campus.tech.kakao.contacts import android.app.DatePickerDialog import android.content.Context +import android.content.DialogInterface import android.content.Intent import android.os.Bundle import android.util.Log @@ -11,6 +12,8 @@ import android.widget.EditText import android.widget.RadioGroup import android.widget.TextView import android.widget.Toast +import androidx.activity.OnBackPressedCallback +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import java.util.Calendar import kotlin.math.log @@ -30,6 +33,40 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) initVar() initListener() + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) + } + + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + finishContactAdding(this@MainActivity) + } + } + + fun finishContactAdding(context: Context){ + if(isNowWritting()) + displayCancelDialog(context) + else + finish() + } + + + fun displayCancelDialog(context: Context){ + val alert = AlertDialog.Builder(this@MainActivity) + alert.setTitle("") + alert.setMessage("작성중인 내용이 있습니다. 정말 나가시겠습니까?") + alert.setPositiveButton("작성하기", DialogInterface.OnClickListener{ dialog, which -> + }) + alert.setNegativeButton("나가기", DialogInterface.OnClickListener { dialog, which -> + displayCancelToastMessage(context) + finish() + }) + alert.show() + } + + fun isNowWritting() : Boolean{ + return if(name.text.toString() != "" || phoneNumber.text.toString() != "" || mail.text.toString() != "" || birthday.text.toString() != "" || gender.text.toString() != "" || memo.text.toString() != "") + true + else false } fun initListener(){ @@ -42,11 +79,11 @@ class MainActivity : AppCompatActivity() { fun cancelButtonSetOnClickListener(context : Context){ findViewById(R.id.button_cancel).setOnClickListener(){ - displayCancelMessage(context) + displayCancelToastMessage(context) } } - fun displayCancelMessage(context: Context){ + fun displayCancelToastMessage(context: Context){ val cancelMessage = Toast.makeText(context, "취소 되었습니다", Toast.LENGTH_SHORT) cancelMessage.show() } From a22f786079234f499f4863db8d90eda57e434f0f Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 17:19:25 +0900 Subject: [PATCH 19/21] feat : Add feature that display dialog when cancel button is clicked --- app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 6e39db17..9886a3f5 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -79,7 +79,7 @@ class MainActivity : AppCompatActivity() { fun cancelButtonSetOnClickListener(context : Context){ findViewById(R.id.button_cancel).setOnClickListener(){ - displayCancelToastMessage(context) + finishContactAdding(context) } } From 98604026e712c740ab85a9a84c3f3db539f54413 Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 17:39:22 +0900 Subject: [PATCH 20/21] refactor : refactor MainActivity, ListActivity, DetailActivity code --- .../tech/kakao/contacts/DetailActivity.kt | 11 +- .../tech/kakao/contacts/ListActivity.kt | 116 ++++++++++-------- .../tech/kakao/contacts/MainActivity.kt | 40 +++--- 3 files changed, 95 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt index 5e8098d6..8a7bdd91 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/DetailActivity.kt @@ -26,6 +26,12 @@ class DetailActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail) + initVar() + bindField() + setVisibleCompletedFields() + } + + fun initVar(){ name = findViewById(R.id.name) phoneNumber = findViewById(R.id.phone_number) mail = findViewById(R.id.mail) @@ -38,7 +44,9 @@ class DetailActivity : AppCompatActivity() { birthdayInputField = findViewById(R.id.input_birthday_field) genderInputField = findViewById(R.id.input_gender_field) memoInputField = findViewById(R.id.input_memo_field) + } + fun bindField(){ val intent = intent nameInputField.setText(intent.getStringExtra("name")) phoneNumberInputField.setText(intent.getStringExtra("phoneNumber")) @@ -46,7 +54,6 @@ class DetailActivity : AppCompatActivity() { birthdayInputField.setText(intent.getStringExtra("birthday")) genderInputField.setText(intent.getStringExtra("gender")) memoInputField.setText(intent.getStringExtra("memo")) - setVisibleCompletedFields() } fun setVisibleCompletedFields() { @@ -69,6 +76,8 @@ class DetailActivity : AppCompatActivity() { } + + fun ExistMail(): Boolean { return mailInputField.text.toString() != "" } diff --git a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt index d3ba3ba9..ac1a7ca4 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/ListActivity.kt @@ -18,74 +18,86 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class ListActivity : AppCompatActivity() { - lateinit var resultLauncher : ActivityResultLauncher - lateinit var descriptionText : TextView - lateinit var plusButton : TextView + lateinit var resultLauncher: ActivityResultLauncher + lateinit var descriptionText: TextView + lateinit var plusButton: TextView + lateinit var recyclerView: RecyclerView + lateinit var contactList: MutableList + lateinit var adapter: RecyclerViewAdapter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_list) + initVar() + initListener() - val contactList = mutableListOf() + } + fun initVar(){ + contactList = mutableListOf() + adapter = RecyclerViewAdapter(contactList, LayoutInflater.from(this), this) plusButton = findViewById(R.id.plus_item_button) descriptionText = findViewById(R.id.description_text) - plusButton.setOnClickListener{ - moveToAddContact() - } - Log.d("contact2", contactList.toString()) - val recyclerView = findViewById(R.id.recyclerView) - val adapter = RecyclerViewAdapter(contactList, LayoutInflater.from(this), this) + initRecyclerView() + initResultLauncher() + } + + fun initRecyclerView() { + recyclerView = findViewById(R.id.recyclerView) recyclerView.adapter = adapter - // 리사이클러 뷰에 레이아웃 매니저 장착 - recyclerView.layoutManager= LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) - // 리사이클러 뷰에 어답터 장착 - resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - if (result.resultCode == RESULT_OK) { - // 전달 받은 String 데이터를 출력 - val contact = Contact( - result.data?.getStringExtra("name") ?: "", - result.data?.getStringExtra("phoneNumber") ?: "", - result.data?.getStringExtra("mail") ?: "", - result.data?.getStringExtra("birthday") ?: "", - result.data?.getStringExtra("gender") ?: "", - result.data?.getStringExtra("memo") ?: "", - ) - Log.d("contact2", contact.name) - contactList.add(contact) - setDescriptionTextVisibilityGone() - adapter.notifyItemInserted(contactList.size) + recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) + } + + fun initResultLauncher() { + resultLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == RESULT_OK) { + val contact = Contact( + result.data?.getStringExtra("name") ?: "", + result.data?.getStringExtra("phoneNumber") ?: "", + result.data?.getStringExtra("mail") ?: "", + result.data?.getStringExtra("birthday") ?: "", + result.data?.getStringExtra("gender") ?: "", + result.data?.getStringExtra("memo") ?: "", + ) + Log.d("contact2", contact.name) + contactList.add(contact) + setDescriptionTextVisibilityGone() + adapter.notifyItemInserted(contactList.size) + } } + } + fun initListener(){ + plusButton.setOnClickListener { + moveToAddContact() } } - - fun moveToAddContact(){ + fun moveToAddContact() { val intent = Intent(this@ListActivity, MainActivity::class.java) resultLauncher.launch(intent) } - fun setDescriptionTextVisibilityGone(){ + fun setDescriptionTextVisibilityGone() { descriptionText.visibility = View.GONE } + } class RecyclerViewAdapter( - //outer class - var contactList : MutableList, - var inflater : LayoutInflater, - var context : Context -) : RecyclerView.Adapter(){ // 어떤 뷰홀더를 쓸건지 알려줘야함 ViewHolder는 클래스 안쪽에 만든다.(inner class) - - inner class ViewHolder(itemView: View ): RecyclerView.ViewHolder(itemView){ - //RecyclerView의 뷰 홀더를 상속받아야만 개선된 ViewHolder를 사용할 수 있다. - // 아이템뷰 컴포넌트를 구체적으로 찾는(홀드하는) 역할 - val userTitle : TextView - val userName : TextView - init{ + var contactList: MutableList, + var inflater: LayoutInflater, + var context: Context +) : RecyclerView.Adapter() { + + inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val userTitle: TextView + val userName: TextView + + init { userTitle = itemView.findViewById(R.id.user_title) userName = itemView.findViewById(R.id.user_name) - itemView.setOnClickListener{ - val position : Int = adapterPosition + itemView.setOnClickListener { + val position: Int = adapterPosition val intent = Intent(context, DetailActivity::class.java) val sendContact = contactList.get(position) intent.putExtra("name", sendContact.name) @@ -96,27 +108,29 @@ class RecyclerViewAdapter( intent.putExtra("memo", sendContact.memo) context.startActivity(intent) } - } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - // 인플레이트 시켜서 뷰 홀더에게 넘겨준다. val view = inflater.inflate(R.layout.contact_item, parent, false) return ViewHolder(view) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { - //데이터를 아이템뷰의 뷰컴포넌트와 묶는다.(뷰를 채운다) holder.userTitle.text = contactList.get(position).name[0].toString() holder.userName.text = contactList.get(position).name } override fun getItemCount(): Int { - // 전체 데이터의 크기 리턴 return contactList.size } } - -class Contact(var name : String, var phoneNumber : String, var mail : String, var birthday : String, var gender : String, var memo : String){} \ No newline at end of file +class Contact( + var name: String, + var phoneNumber: String, + var mail: String, + var birthday: String, + var gender: String, + var memo: String +) {} \ No newline at end of file diff --git a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt index 9886a3f5..03f9c44a 100644 --- a/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt +++ b/app/src/main/java/campus/tech/kakao/contacts/MainActivity.kt @@ -3,11 +3,8 @@ package campus.tech.kakao.contacts import android.app.DatePickerDialog import android.content.Context import android.content.DialogInterface -import android.content.Intent import android.os.Bundle -import android.util.Log import android.view.View -import android.widget.DatePicker import android.widget.EditText import android.widget.RadioGroup import android.widget.TextView @@ -15,8 +12,10 @@ import android.widget.Toast import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity -import java.util.Calendar -import kotlin.math.log + +const val EXIST_NAME_AND_PHONE_NUMBER = 1 +const val NOT_EXIST_NAME = 2 +const val NOT_EXIST_PHONE_NUMBER = 3 class MainActivity : AppCompatActivity() { lateinit var name : EditText @@ -28,6 +27,7 @@ class MainActivity : AppCompatActivity() { lateinit var birthday : EditText lateinit var moreInfoButton : TextView + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -42,6 +42,14 @@ class MainActivity : AppCompatActivity() { } } + fun initListener(){ + saveButtonSetOnClickListener(this) + cancelButtonSetOnClickListener(this) + moreButtonSetOnClickListener() + birthdayFieldSetOnclickListener() + genderFieldSetOnChangeListener() + } + fun finishContactAdding(context: Context){ if(isNowWritting()) displayCancelDialog(context) @@ -69,14 +77,6 @@ class MainActivity : AppCompatActivity() { else false } - fun initListener(){ - saveButtonSetOnClickListener(this) - cancelButtonSetOnClickListener(this) - moreButtonSetOnClickListener() - birthdayFieldSetOnclickListener() - genderFieldSetOnChangeListener() - } - fun cancelButtonSetOnClickListener(context : Context){ findViewById(R.id.button_cancel).setOnClickListener(){ finishContactAdding(context) @@ -96,7 +96,7 @@ class MainActivity : AppCompatActivity() { fun existNameAndPhoneNum() : Boolean{ val checkNum = checkNameAndPhoneNum() - return if(checkNum == 2 || checkNum == 3) false + return if(checkNum == NOT_EXIST_NAME || checkNum == NOT_EXIST_PHONE_NUMBER) false else true } @@ -128,21 +128,21 @@ class MainActivity : AppCompatActivity() { fun checkNameAndPhoneNum() : Int{ return if (name.text.toString() == ""){ name.requestFocus() - 2 + NOT_EXIST_NAME } else if(phoneNumber.text.toString() == ""){ phoneNumber.requestFocus() - 3 + NOT_EXIST_PHONE_NUMBER } else{ - 1 + EXIST_NAME_AND_PHONE_NUMBER } } fun getToastMessageToNameAndPhoneNum() : String{ val checkNum = checkNameAndPhoneNum() return when(checkNum){ - 1 -> "저장이 완료되었습니다" - 2 -> "이름을 입력해 주세요" - 3 -> "전화번호를 입력해 주세요" + EXIST_NAME_AND_PHONE_NUMBER -> "저장이 완료되었습니다" + NOT_EXIST_NAME -> "이름을 입력해 주세요" + NOT_EXIST_PHONE_NUMBER -> "전화번호를 입력해 주세요" else -> "오류" } } From 9f22f833ad12a80585dfb10fec3894b038c561af Mon Sep 17 00:00:00 2001 From: fiveJinw Date: Fri, 28 Jun 2024 17:44:00 +0900 Subject: [PATCH 21/21] docs : Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 09543bf7..f61ce0a0 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,14 @@ ## step2 구현할 기능 목록 **연락처 추가 기능** -- [ ] + 버튼을 통해 연락처를 추가하는 창을 띄우는 기능 +- [x] + 버튼을 통해 연락처를 추가하는 창을 띄우는 기능 **연락처 출력 기능** -- [ ] 저장된 연락처들을 간단하게 이름만 띄워주는 기능 -- [ ] 각 연락처를 클릭하면 상세 화면을 띄워주는 기능 -- [ ] 상세화면에서 적힌 내용만 출력하는 기능 +- [x] 저장된 연락처들을 간단하게 이름만 띄워주는 기능 +- [x] 각 연락처를 클릭하면 상세 화면을 띄워주는 기능 +- [x] 상세화면에서 적힌 내용만 출력하는 기능 **연락처 저장 기능** -- [ ] 저장 버튼을 누르면 연락처를 저장할 수 있는 기능 -- [ ] 뒤로가기 버튼을 누를 때 만약 작성된 내용이 있다면 확인 팝업이 나타나는 기능 -- [ ] 취소 버튼을 누를 때 만약 작성된 내용이 있다면 확인 팝업이 나타나는 기능 \ No newline at end of file +- [x] 저장 버튼을 누르면 연락처를 저장할 수 있는 기능 +- [x] 뒤로가기 버튼을 누를 때 만약 작성된 내용이 있다면 확인 팝업이 나타나는 기능 +- [x] 취소 버튼을 누를 때 만약 작성된 내용이 있다면 확인 팝업이 나타나는 기능 \ No newline at end of file