Skip to content
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

전남대 Android_이가현_1주차 과제 #31

Open
wants to merge 34 commits into
base: leeghy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4abfea5
readme
leeghy Jun 25, 2024
8254ab1
UI작성(더보기 버튼 시 입력폼 확장은 미구현)
leeghy Jun 25, 2024
6d17319
모든 요소 받아오기
leeghy Jun 26, 2024
dce38cc
더보기 기능 구현
leeghy Jun 26, 2024
19a21e2
취소, 저장 버튼에 토스트 붙여줌
leeghy Jun 26, 2024
f21e03c
전화번호는 숫자만 입력/기본 키패드 숫자
leeghy Jun 26, 2024
e7dd2cf
리드미 수정
leeghy Jun 26, 2024
9ed9f61
더보기 옆 화살표 추가
leeghy Jun 27, 2024
e2ba8bf
키보드 올라올 때 저장,취소 버튼 함께 올라오기/이름,전화번호 미입력시 토스트 보내기
leeghy Jun 27, 2024
14ad72f
생일 누르면 캘린더 띄우기
leeghy Jun 27, 2024
1fa7c63
Revert "생일 누르면 캘린더 띄우기"
leeghy Jun 27, 2024
c6773b0
뷰가 스크롤 되게 설정
leeghy Jun 27, 2024
a8cc882
revert 잘못 한거 되돌림(캘린더 띄우는 부분)
leeghy Jun 27, 2024
a0ee0bc
리드미 수정
leeghy Jun 27, 2024
10aebb7
연락처 추가 뷰 구성/플러스 버튼 누르면 화면 넘어가는 것 구현
leeghy Jun 28, 2024
e333b16
저장 버튼 누르면 데이터 보내기
leeghy Jun 28, 2024
f99583a
Revert "저장 버튼 누르면 데이터 보내기"
leeghy Jun 28, 2024
611e320
되돌림
leeghy Jun 28, 2024
3d9aafd
contact z클래스, adapter
leeghy Jun 28, 2024
a926350
contact item 추가
leeghy Jun 30, 2024
130a35e
취소 시 경고 메시지 보내기
leeghy Jun 30, 2024
128f905
info 화면 그리기
leeghy Jun 30, 2024
4533d62
initial 함수, 리스너 세팅
leeghy Jun 30, 2024
b1430b9
리사이클러 뷰 세팅
leeghy Jun 30, 2024
c9f77a1
detail 화면 그리기
leeghy Jun 30, 2024
5fc5229
디테일 액티비티 이니셜라이즈
leeghy Jun 30, 2024
f48ea10
info 화면에서 디테일 화면으로 넘어가는 것 구현
leeghy Jun 30, 2024
06f938d
setDetail 함수 구현
leeghy Jun 30, 2024
cfb5624
레이아웃을 보여줄지 말지 정하는 함수 구현
leeghy Jun 30, 2024
40eb7dc
리스트의 값 여부에 따라 텍스트 보일지 말지 정하는 함수 구현
leeghy Jun 30, 2024
4a32d51
인풋텍스트 라운드 처리
leeghy Jun 30, 2024
886d4d0
리드미 수정
leeghy Jul 1, 2024
99c9bdc
리드미 수정
leeghy Jul 1, 2024
b7d8ec6
fix: 피드백 수정
leeghy Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# android-contacts

### 구현할 기능 목록
- 얼굴 사진 ✅
- 입력란
- 이름(필수값) ✅
- 전화번호(필수, 숫자만 입력) ✅
- 메일 ✅
- 더보기 ✅
- 생일(캘린더로 선택 가능하게끔) ✅
- 성별(라디오 버튼) ✅
- 메모 ✅
- 저장 -> 완료시 토스트 전송 ✅
- 취소 -> 토스트 전송 ✅

- 스크롤뷰 ✅
- 저장, 취소 버튼 키보드와 함께 올리기 ✅

- 저장 버튼 누르면 Info 액티비티로 데이터 보내기 ✅
- 데이터 받아서 화면 띄우기 ✅
- 데이터 아이템을 누르면 디테일 화면으로 이동시키기 ✅
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("kotlin-parcelize")
}

android {
Expand Down Expand Up @@ -41,6 +42,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.9.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
android:theme="@style/Theme.Contacts"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
android:name=".ContactDetail"
android:exported="false" />
<activity
android:name=".AddInfo"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="false" />
</application>

</manifest>
</manifest>
124 changes: 124 additions & 0 deletions app/src/main/java/campus/tech/kakao/contacts/AddInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package campus.tech.kakao.contacts

import android.app.Activity
import android.content.Context
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.Button
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlin.collections.ArrayList

class AddInfo : AppCompatActivity() {
leeghy marked this conversation as resolved.
Show resolved Hide resolved
private lateinit var addBtn: Button
private lateinit var recyclerView: RecyclerView
private lateinit var infoText: TextView
leeghy marked this conversation as resolved.
Show resolved Hide resolved
private var contactList = ArrayList<Contact>()
leeghy marked this conversation as resolved.
Show resolved Hide resolved

private lateinit var resultLauncher: ActivityResultLauncher<Intent>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_add_info)

initialize()
setUpListeners()
setRecyclerView()
setupResultLauncher()

}

private fun initialize() {
addBtn = findViewById(R.id.addBtn)
recyclerView = findViewById(R.id.recyclerView)
infoText = findViewById(R.id.infoText)

}

private fun setUpListeners() {
addBtn.setOnClickListener {
val intent = Intent(this@AddInfo, MainActivity::class.java)
resultLauncher.launch(intent)
}
}


private fun setRecyclerView() {
recyclerView.adapter = RecyclerViewAdapter(contactList, LayoutInflater.from(this),this)
recyclerView.layoutManager = LinearLayoutManager(this)
}

private fun setupResultLauncher() {
resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val data: Intent? = result.data
val contact = data?.getParcelableExtra<Contact>("CONTACT_RESULT")
leeghy marked this conversation as resolved.
Show resolved Hide resolved
contact?.let {
contactList.add(it)
recyclerView.adapter?.notifyItemInserted(contactList.size - 1)
Log.d("AddInfo", "New contact added: ${it.name}")
isShowText()
}
}
}
}

private fun isShowText() {
if (contactList.isEmpty()) {
infoText.visibility = View.VISIBLE
}
else {
infoText.visibility = View.GONE
}
}


class RecyclerViewAdapter(
var contactList: ArrayList<Contact>,
var inflater: LayoutInflater,
private val context: Context
leeghy marked this conversation as resolved.
Show resolved Hide resolved
): RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() {

inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
leeghy marked this conversation as resolved.
Show resolved Hide resolved
val faceImg: ImageView
val name_text_view: TextView
leeghy marked this conversation as resolved.
Show resolved Hide resolved

init {
faceImg = itemView.findViewById(R.id.faceImg)
name_text_view = itemView.findViewById(R.id.name_text_view)
}

}
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) {
val contact = contactList[position]
holder.name_text_view.text = contact.name

holder.itemView.setOnClickListener {
val intent = Intent(context, ContactDetail::class.java).apply {
putExtra("CONTACT", contact)
}
context.startActivity(intent)
}
}

override fun getItemCount(): Int {
return contactList.size
}
}
}

14 changes: 14 additions & 0 deletions app/src/main/java/campus/tech/kakao/contacts/Contact.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package campus.tech.kakao.contacts

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Contact(
val name: String,
val tel: String,
val mail: String,
val birth: String,
val gender: String,
leeghy marked this conversation as resolved.
Show resolved Hide resolved
val memo: String
): Parcelable
leeghy marked this conversation as resolved.
Show resolved Hide resolved
72 changes: 72 additions & 0 deletions app/src/main/java/campus/tech/kakao/contacts/ContactDetail.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package campus.tech.kakao.contacts

import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout

class ContactDetail : AppCompatActivity() {
lateinit var detailName: TextView
lateinit var detailTel: TextView
lateinit var detailMail: TextView
lateinit var detailBirth: TextView
lateinit var detailGender: TextView
lateinit var detailMemo: TextView

lateinit var detailMailLayout: ConstraintLayout
lateinit var detailBirthLayout: ConstraintLayout
lateinit var detailGenderLayout: ConstraintLayout
lateinit var detailMemoLayout: ConstraintLayout

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_contact_detail)

initialize()
setContactDetail()
}
private fun initialize() {
detailName = findViewById(R.id.detailName)
detailTel = findViewById(R.id.detailTel)
detailMail = findViewById(R.id.detailMail)
detailBirth = findViewById(R.id.detailBirth)
detailGender = findViewById(R.id.detailGender)
detailMemo = findViewById(R.id.detailMemo)

detailMailLayout = findViewById(R.id.detailMail_layout)
detailBirthLayout = findViewById(R.id.detailBirth_layout)
detailGenderLayout = findViewById(R.id.detailGender_layout)
detailMemoLayout = findViewById(R.id.detailMemo_layout)
}

private fun setContactDetail() {
val contact: Contact? =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra("CONTACT", Contact::class.java)
} else {
intent.getParcelableExtra("CONTACT")
}
leeghy marked this conversation as resolved.
Show resolved Hide resolved

contact?.let {
setDetail(it)
setDetailLayoutVisibility(it)
}
}
private fun setDetail(contact: Contact) {
detailName.text = contact.name
detailTel.text = contact.tel
detailMail.text = contact.mail ?: ""
detailBirth.text = contact.birth ?: ""
detailGender.text = contact.gender
detailMemo.text = contact.memo ?: ""
}

private fun setDetailLayoutVisibility(contact: Contact) {
detailMailLayout.visibility = if (contact.mail.isEmpty()) View.GONE else View.VISIBLE
detailBirthLayout.visibility = if (contact.birth.isEmpty()) View.GONE else View.VISIBLE
detailGenderLayout.visibility = if (contact.gender == "null") View.GONE else View.VISIBLE
detailMemoLayout.visibility = if (contact.memo.isEmpty()) View.GONE else View.VISIBLE
leeghy marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading