Skip to content

Conversation

@tlsgptj
Copy link

@tlsgptj tlsgptj commented Jun 28, 2024

[이전의 오류는 해결했습니다]

  1. MainActivity.xml으로 연락처를 입력하면 collection.xml에 저장이 이루어지도록 하였습니다.
    Room을 이용하여 데이터베이스를 구현하였고,
    RecyclerView를 이용하여 연락처를 나타낼 수 있도록 하였습니다. itemview를 클릭하면 activity_whoami로 이동해 자세한 정보가 표시될 수 있도록 하였습니다.
    하지만 collection.kt에서 오류가 발생합니다.
    putExtra와 122줄에 있는 contacts, Contact.ContactData에서 오류가 발생합니다.
  2. contact.kt로 분리해보기도 했습니다. 하지만 오류가 해결되지 않았습니다. 어떻게 하면 좋을까요?
  3. 그러고 안드로이드 에뮬레이터 실행도 되지 않는 문제도 발생했습니다. 어떻게 해결하면 좋을까여?

@tlsgptj tlsgptj changed the title 전남대 android_신혜서 Step2 전남대 android_신혜서 1주차 과제 (Step2) Jun 28, 2024
@tlsgptj
Copy link
Author

tlsgptj commented Jul 3, 2024

[수정 후 기능 변화]

  1. 우선 RoomDB에서 오류가 많이 나서 일단 삭제하고 SharedPreference로 구현을 했습니다.
  2. collection_xml의 내용을 멘토님의 조언을 받아 FrameLayout에서 ConstraintLayout으로 변경하여
    RecyclerView로 구현을 해보았습니다.
  3. collection.kt의 오류를 수정하였습니다.
  4. recyclerView와 ItemView가 collection.xml에 표시되게끔 만들었습니다.

Copy link

@bigstark bigstark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰가 늦어 죄송합니다! 전반적으로 함수의 분리와, 사용하지 않는 코드를 제거하는 부분에 대해 조금 더 신경써주셔서 작성해주시면 좋을 것 같아요!

일단 SharedPreferences 를 사용하고 있는 부분은 존재하고 있지 않은 것 같아요. 추가를 하더라도 리스트에 표현이 되고 있지 않은데, 어떻게 처리하면 좋을지 고민해보시면 좋을 것 같아요 :)

Comment on lines +26 to +27
messageTextView = findViewById(R.id.message)
recyclerView = findViewById(R.id.recyclerView)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewBinding 을 통해서 findViewById 를 사용하지 않을 수 있습니다!

Comment on lines +32 to +35
addButton.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setOnClickListener 나 layoutMangager 를 설정하는 부분은 초기화의 영역으로 보여요. 초기화를 하는 메소드로 따로 처리해두는건 어떨까요?

Comment on lines +43 to +45
val contacts = getContacts()
contactAdapter = ContactAdapter(contacts)
recyclerView.adapter = contactAdapter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadContacts 내부에서 adapter 를 매번 생성하고 할당하는 것보다는, Adapter 에 contacts set / add / remove 할 수 있는 메소드를 추가하는 편이 조금 더 좋은 방향으로 보여요.

Comment on lines +67 to +73
private val etName: EditText by lazy { findViewById(R.id.name) }
private val etPhone: EditText by lazy { findViewById(R.id.phone) }
private val etmail: EditText by lazy { findViewById(R.id.email) }
private val etmessage: EditText by lazy { findViewById(R.id.message) }
val btnbirthday: Button by lazy { findViewById(R.id.birthday) }
private val rgfemale: RadioButton by lazy { findViewById(R.id.female) }
private val rgmale: RadioButton by lazy { findViewById(R.id.male) }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전역변수는 상단에 정의해주시는 편이 좋습니다.

Comment on lines +81 to +83
rgfemale.isChecked -> ContactsContract.CommonDataKinds.StructuredName.DATA1
rgmale.isChecked -> ContactsContract.CommonDataKinds.StructuredName.DATA2
else -> ContactsContract.CommonDataKinds.StructuredName.DATA3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContactsContract 의 사용은 의도된 것이 아닌 것으로 보입니다.

Comment on lines +151 to +153
private fun writeContactsToXml(allContacts: List<Contact?>) {

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 함수는 제거해주시는 편이 좋을 것 같아요.

Comment on lines +172 to +184
private fun setupPhoneNumberInput() {
etPhone.inputType = InputType.TYPE_CLASS_PHONE

val phoneNumberFilter = InputFilter { source, start, end, dest, dstart, dend ->
val phoneNumberRegex = Regex("^\\+?\\d{0,13}\$")
if (phoneNumberRegex.matches(source.toString())) {
null
} else {
""
}
}
etPhone.filters = arrayOf(phoneNumberFilter)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 메소드로 보입니다.

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_who_am_iactivity)

val contact = intent.getSerializableExtra("contact") as? Contact
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializable 보다는 parcelable 로 정의해서 받는 것이 어떨까요?

Comment on lines +21 to +32
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val nameTextView: TextView = itemView.findViewById(R.id.namelist)

init {
itemView.setOnClickListener {
contacts[adapterPosition]?.let { contact ->
val intent = Intent(itemView.context, WhoAmIActivity::class.java)
itemView.context.startActivity(intent)
}
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inner class 로 ViewHolder 를 선언하기 보다는 name 을 설정할 수 있는 메소드를 따로 선언하는 편이 어떨까요?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

또한 ViewHolder 라는 이름보다는 조금 더 명확한 용도의 클래스 이름을 지어보는 것이 좋을 것 같아요.

Comment on lines +6 to +45
data class ContactData(
val name: String,
val phone: String,
val gender: String,
val email: String,
val message: String,
val birthday: String
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readString().toString(),
parcel.readString().toString()
)

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(name)
parcel.writeString(phone)
parcel.writeString(gender)
parcel.writeString(email)
parcel.writeString(message)
parcel.writeString(birthday)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<ContactData> {
override fun createFromParcel(parcel: Parcel): ContactData {
return ContactData(parcel)
}

override fun newArray(size: Int): Array<ContactData?> {
return arrayOfNulls(size)
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 ContactData 는 사용되지 않는 것으로 보여요. Contact 대신에 요걸 사용해보는건 어떨까요?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

또한 kotlin-pareclize 를 통해 parcelabe 을 조금 더 쉽게 선언할 수 있습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants