-
Notifications
You must be signed in to change notification settings - Fork 0
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
PR : 실습 3주차 필수과제 #11
PR : 실습 3주차 필수과제 #11
Conversation
친구 추가 다이어로그 UI material3 적용하기 - TextField 사용 (닉네임, 상태메시지) - CustomView(NumberPicker 사용) 생일 설정
SharedPreference 모듈화 - 클래스로 만들어 캡슐화 진행 - object 아니고 class 로 한 이유는 객체로 사용함으로써 범용성있게 사용하기 위함. (추가로 생성자로 context를 전달하기 위함)
로그인 확인 오류 개선 (빈 아이디, 빈 패스워드 시 로컬 데이터베이스에서 불러오는 값이 빈 값일 때, 로그인 되는 오류 개선)
M3 Swtich 구현 - 자동 로그인 기능 추가(on/off)
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.
진자...완벽하다 이남자
import org.sopt.dosopttemplate.databinding.CustomNumberPickerBinding | ||
import java.text.SimpleDateFormat | ||
|
||
class SoptNumberPicker @JvmOverloads constructor( |
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.
이 부분에서 @jvmoverloads는 무슨 용도인가요?
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.
커스텀뷰에는 3가지 생성자를 default로 구현하게 되는데 하나의 생성자 내에서 처리 가능하게 끔 하는 어노테이션입니다
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.
어노테이션을 굳이 안사용해도 무리없이 잘 작동하겠지만, 생성자를 오버로딩하고 싶지 않아서 그만..
@@ -0,0 +1,26 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
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.
아웅 야무지네요 셀렉터
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.
엄청나고 굉장한 코드 잘보구 갑니다!!
class Preference(val context: Context) { | ||
fun getId(): String = context.getSharedPreferences().getString(ID, "") ?: "" | ||
fun getPassword(): String = context.getSharedPreferences().getString(PWD, "") ?: "" | ||
fun getNickname(): String = context.getSharedPreferences().getString(NICKNAME, "") ?: "" | ||
fun getMBTI(): String = context.getSharedPreferences().getString(MBTI, "") ?: "" | ||
fun getAutoLogin(): Boolean = context.getSharedPreferences().getBoolean(AUTO_LOGIN, false) | ||
|
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.
?:"" 도 좋지만 .orEmpty() 라는 것도 있습니다 참고한번 해보세욥!
fun setAutoLogin(auto: Boolean) { | ||
context.getSharedPreferences().edit(commit = true) { | ||
putBoolean(AUTO_LOGIN, auto) | ||
} | ||
} | ||
|
||
fun setUser(user: User?) { | ||
context.getSharedPreferences().edit(commit = true) { | ||
user?.let { | ||
putString(ID, it.id) | ||
putString(PWD, it.password) | ||
putString(NICKNAME, it.nickname) | ||
putString(MBTI, it.mbti.toString()) | ||
} | ||
} | ||
} | ||
|
||
private fun Context.getSharedPreferences(): SharedPreferences = | ||
getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE) |
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 객체를 선언하시는 것 같은데요, 혹시 더 좋은 방법 없을까요?
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 val preference: Preference by lazy { | ||
Preference(this) | ||
} |
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.
lazy하게 초기화 하시는 이유가 있을까요?!!?
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.
불변의 객체 (읽기 전용)으로 선언하기 위함과 adapater 와 같은 경우에는 말씀해주신대로 view 를 가지고 컨트롤할 수 있어서 지연 초기화(lateinit)가 좋아보이지만 해당 클래스에서는 지연 초기화의 필요성을 못느꼈습니다! (주저리주저리 말씀드렸지만.. 맞나용? ㅎㅎ..)
import org.sopt.dosopttemplate.databinding.CustomNumberPickerBinding | ||
import java.text.SimpleDateFormat | ||
|
||
class SoptNumberPicker @JvmOverloads constructor( |
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.
커스텀뷰에는 3가지 생성자를 default로 구현하게 되는데 하나의 생성자 내에서 처리 가능하게 끔 하는 어노테이션입니다
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.
항상 완벽하게 구현하셔서 ㅎㅎ 오늘도 많이 배우고 갑니다! 친구추가 하기 기능으로 저도 추가해주세요 ㅋㅋㅋ
fun getAutoLogin(): Boolean = context.getSharedPreferences().getBoolean(AUTO_LOGIN, false) | ||
|
||
fun setAutoLogin(auto: Boolean) { | ||
context.getSharedPreferences().edit(commit = true) { |
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.
apply함수가 아니라 commit 함수를 사용하신 이유가 있을까요?
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.
edit 내부 인자로 commit = true 인자를 사용한 것에 대한 질문이 맞으시다면,
context.getSharedPreferences().edit().apply()
일반적으로 사용하겠지만, SharedPreference KTX 를 사용하게된다면, 제가 작성한 코드처럼 작성할 수 있습니다.
여기서 KTX 가 궁금하실텐데, 간단하게 코틀린스럽게 라이브러리를 확장해서 사용할 수 있는 방법입니다.
https://developer.android.com/kotlin/ktx?hl=ko 해당 링크를 참조해보시면 좋을 것 같아요!
SharedPreference 객체 선언 시 생성을 싱글톤 패턴으로 구현하기
엘비스 연산자 대신 사용하는 orEmpty 함수 사용햅괴
진짜 싱글톤패턴 적용
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.
수고했어!! 담부터는 코리 빨리 할께 ㅎㅎ
|
||
@Synchronized | ||
private fun getInstance(context: Context) { | ||
if (::sharedPreferencesInstance.isInitialized) { |
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.
저번에 같이 봤던 부분이네여 저는 좀 더 공부해봐야 할 듯요ㅎㅎ
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.
같이 화이팅합시다~
|
||
<com.google.android.material.textfield.TextInputLayout | ||
android:id="@+id/text_field_description" | ||
style="@style/TextFieldCounterAndEndClear" |
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.
오 style까지 따로 지정해주셨군요..!
📌𝘐𝘴𝘴𝘶𝘦𝘴
📎𝘞𝘰𝘳𝘬 𝘋𝘦𝘴𝘤𝘳𝘪𝘱𝘵𝘪𝘰𝘯
Use Material3
Do Refactoring
📷𝘚𝘤𝘳𝘦𝘦𝘯𝘴𝘩𝘰𝘵
자동로그인 (Switch)
default.mp4
친구추가 (TextField)
default.mp4
💬𝘛𝘰 𝘙𝘦𝘷𝘪𝘦𝘸𝘦𝘳𝘴
심화 과제 + 도전 과제 내용이 조금 들어간 것 같지만, 수정이 필요해보입니다.. 나중에 심화, 도전 과제 진행 시 수정하겠습니다.
리뷰 감사합니다!