-
Notifications
You must be signed in to change notification settings - Fork 30
전남대 android_신혜서 1주차 과제 (Step2) #20
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
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 8b9b2f4.
결국 Sharedpre로 갔습니다...
|
[수정 후 기능 변화]
|
bigstark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰가 늦어 죄송합니다! 전반적으로 함수의 분리와, 사용하지 않는 코드를 제거하는 부분에 대해 조금 더 신경써주셔서 작성해주시면 좋을 것 같아요!
일단 SharedPreferences 를 사용하고 있는 부분은 존재하고 있지 않은 것 같아요. 추가를 하더라도 리스트에 표현이 되고 있지 않은데, 어떻게 처리하면 좋을지 고민해보시면 좋을 것 같아요 :)
| messageTextView = findViewById(R.id.message) | ||
| recyclerView = findViewById(R.id.recyclerView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewBinding 을 통해서 findViewById 를 사용하지 않을 수 있습니다!
| addButton.setOnClickListener { | ||
| val intent = Intent(this, MainActivity::class.java) | ||
| startActivity(intent) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setOnClickListener 나 layoutMangager 를 설정하는 부분은 초기화의 영역으로 보여요. 초기화를 하는 메소드로 따로 처리해두는건 어떨까요?
| val contacts = getContacts() | ||
| contactAdapter = ContactAdapter(contacts) | ||
| recyclerView.adapter = contactAdapter |
There was a problem hiding this comment.
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 할 수 있는 메소드를 추가하는 편이 조금 더 좋은 방향으로 보여요.
| 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) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전역변수는 상단에 정의해주시는 편이 좋습니다.
| rgfemale.isChecked -> ContactsContract.CommonDataKinds.StructuredName.DATA1 | ||
| rgmale.isChecked -> ContactsContract.CommonDataKinds.StructuredName.DATA2 | ||
| else -> ContactsContract.CommonDataKinds.StructuredName.DATA3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContactsContract 의 사용은 의도된 것이 아닌 것으로 보입니다.
| private fun writeContactsToXml(allContacts: List<Contact?>) { | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용하지 않는 함수는 제거해주시는 편이 좋을 것 같아요.
| 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) | ||
| } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
serializable 보다는 parcelable 로 정의해서 받는 것이 어떨까요?
| 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) | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inner class 로 ViewHolder 를 선언하기 보다는 name 을 설정할 수 있는 메소드를 따로 선언하는 편이 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
또한 ViewHolder 라는 이름보다는 조금 더 명확한 용도의 클래스 이름을 지어보는 것이 좋을 것 같아요.
| 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) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 ContactData 는 사용되지 않는 것으로 보여요. Contact 대신에 요걸 사용해보는건 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
또한 kotlin-pareclize 를 통해 parcelabe 을 조금 더 쉽게 선언할 수 있습니다!
[이전의 오류는 해결했습니다]
Room을 이용하여 데이터베이스를 구현하였고,
RecyclerView를 이용하여 연락처를 나타낼 수 있도록 하였습니다. itemview를 클릭하면 activity_whoami로 이동해 자세한 정보가 표시될 수 있도록 하였습니다.
하지만 collection.kt에서 오류가 발생합니다.
putExtra와 122줄에 있는 contacts, Contact.ContactData에서 오류가 발생합니다.