generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
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
Feat/#5 week2 xml 필수과제 구현 #7
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
119c260
feat/#5: 메뉴바 생성
hyeeum c872be5
feat/#5: 프래그먼트 생성
hyeeum 39cc771
feat/#5: 메뉴와 프래그먼트 연결
hyeeum 03a21c4
feat/#5: 리싸이클러뷰 연결
hyeeum 8f52e11
feat/#5: 유저의 상태메세지가 길거나 이름이 길때 말줄임표
hyeeum 131ba88
mod/#5: 마이페이지<->홈 변경
hyeeum 3205e16
del/#5 user 데이터 클래스 삭제
hyeeum 40c4f30
feat/#5: 멀티뷰 리싸이클러뷰 생성
hyeeum f6a8a70
fix/#5:공백 로그인 성공 오류 해결
hyeeum b379d72
fix/#5: 마이페이지 데이터 미전달 해결
hyeeum 69ccff0
mod/#5: 뷰홀더 분리 데이터 분리
hyeeum d712b65
mod/#5: 1주차 피드백 반영
hyeeum 5012ed1
mod/#5: 회원가입 조건 상수화
hyeeum b27970a
mod/#5: scope 함수 사용해보기
hyeeum 5bc08ee
rename/#5: 홈에 있는 rc 관련 파일 이름 변경
hyeeum 2420f0b
chore/#5: 리스트 데이터 추가
hyeeum 4dd9b1b
delete/#5: 주석 삭제
hyeeum 12e8ccc
chore/#5: 코드 정렬 및 함수명 변경
hyeeum b1a4e75
delete/#5: 쓸모없는 코드 삭제
hyeeum e2e4d11
Update README.md
hyeeum d8003c2
Merge branch 'main-xml' into feat/#5-week2_xml
hyeeum d0f0261
feat/#5: fragment notnull 처리
hyeeum 9169ea0
mod/#5: PR 적용 - getOrNull
hyeeum db71fd8
mod/#5: PR 적용 - with
hyeeum fa0ef19
mod/#5: PR 적용 - isBlank
hyeeum fd905d6
Merge branch 'feat/#5-week2_xml' of https://github.com/NOW-SOPT-ANDRO…
hyeeum 3d31950
mod/#5: PR 적용 - 숫자 대신 타입상수화
hyeeum ed096f8
mod/#5: PR 적용 - ViewHolder
hyeeum 480c147
mod/#5: PR 적용 - tools
hyeeum 3c26a27
mod/#5: PR 적용 - scope
hyeeum 9d4ddfb
feat/#5: RC 뷰모델 적용
hyeeum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Now Sopt Android | ||
feat/#5-week2_xml | ||
|
||
- **[FEAT]** : 새로운 기능 구현 | ||
- **[MOD]** : 코드 수정 및 내부 파일 수정 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.sopt.now | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.viewModels | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.sopt.now.databinding.FragmentHomeBinding | ||
|
||
class HomeFragment : Fragment() { | ||
private val binding:FragmentHomeBinding | ||
get()= requireNotNull(_binding){"_binding이 null이 아닌 경우만 _binding 반환"} | ||
private var _binding: FragmentHomeBinding ?= null | ||
private val viewModel by viewModels<HomeViewModel>() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentHomeBinding.inflate(inflater,container,false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val homeListAdapter = HomeListAdapter() | ||
binding.rvFriends.run { | ||
adapter = homeListAdapter | ||
layoutManager = LinearLayoutManager(requireContext()) | ||
} | ||
homeListAdapter.setHomeList(viewModel.homeListData) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sopt.now | ||
|
||
import androidx.annotation.DrawableRes | ||
|
||
data class HomeList( | ||
@DrawableRes val profileImage: Int, | ||
val name: String, | ||
val selfDescription: String, | ||
val viewType: Int | ||
) { | ||
companion object { | ||
const val VIEW_TYPE_USER = 0 | ||
const val VIEW_TYPE_FRIEND = 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.sopt.now | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopt.now.databinding.ItemFriendBinding | ||
import com.sopt.now.databinding.ItemUserBinding | ||
|
||
class HomeListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
private var homeListList: List<HomeList> = emptyList() | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val bindingUser = ItemUserBinding.inflate(inflater, parent, false) | ||
val bindingFriend = ItemFriendBinding.inflate(inflater, parent, false) | ||
return when(viewType){ | ||
HomeList.VIEW_TYPE_USER -> { | ||
UserViewHolder(bindingUser) | ||
} | ||
else -> { | ||
FriendViewHolder(bindingFriend) | ||
} | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
when(homeListList.getOrNull(position)?.viewType){ | ||
HomeList.VIEW_TYPE_USER -> { | ||
(holder as UserViewHolder).onBind(homeListList[position]) | ||
} | ||
else -> { | ||
(holder as FriendViewHolder).onBind(homeListList[position]) | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount() = homeListList.size | ||
override fun getItemViewType(position: Int): Int { | ||
return homeListList[position].viewType | ||
} | ||
fun setHomeList(homeListList: List<HomeList>) { | ||
this.homeListList = homeListList.toList() | ||
notifyDataSetChanged() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sopt.now | ||
|
||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopt.now.databinding.ItemFriendBinding | ||
import com.sopt.now.databinding.ItemUserBinding | ||
|
||
class FriendViewHolder(private val binding:ItemFriendBinding) : RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(friendData: HomeList) { | ||
binding.run { | ||
ivProfile.setImageResource(friendData.profileImage) | ||
tvName.text = friendData.name | ||
tvSelfDescription.text = friendData.selfDescription | ||
} | ||
} | ||
} | ||
|
||
class UserViewHolder(private val binding:ItemUserBinding) : RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(friendData: HomeList) { | ||
binding.run { | ||
ivProfile.setImageResource(friendData.profileImage) | ||
tvName.text = friendData.name | ||
tvSelfDescription.text = friendData.selfDescription | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.sopt.now | ||
|
||
import androidx.lifecycle.ViewModel | ||
|
||
class HomeViewModel : ViewModel() { | ||
val homeListData = listOf( | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "송혜음", | ||
selfDescription = "멀티 뷰 리싸이클러뷰!", | ||
HomeList.VIEW_TYPE_USER | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "박동민", | ||
selfDescription = "곽의진...얼굴 재치 실력 모든걸 다 가진 남자... 하지만 밀양박씨 36대손인 나 박동민은 가지지 못했지", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이석준", | ||
selfDescription = "죄송합니다 저 도핑했습니다... 안드-로이더 \uD83D\uDC89", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "박유진", | ||
selfDescription = "(ง˙∇˙)ว 에라 모르겠다", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이의경", | ||
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "우상욱", | ||
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "배지현", | ||
selfDescription = "표정 풀자 ^^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이의경", | ||
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "우상욱", | ||
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "배지현", | ||
selfDescription = "표정 풀자 ^^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이의경", | ||
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "우상욱", | ||
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "배지현", | ||
selfDescription = "표정 풀자 ^^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,57 +16,65 @@ class LoginActivity : AppCompatActivity() { | |
binding = ActivityLoginBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
//회원가입에서 사용자 정보 받아옴 | ||
getUser() | ||
getUserInfo() | ||
|
||
//회원가입 페이지로 넘어가기 | ||
moveToSignUp() | ||
|
||
} | ||
private fun getUser() { // 아쉬운 부분 | ||
private fun getUserInfo() { | ||
var id = "" | ||
var pw = "" | ||
var nick = "" | ||
resultLauncher = registerForActivityResult( | ||
ActivityResultContracts.StartActivityForResult() | ||
) { result -> | ||
if (result.resultCode == RESULT_OK) { | ||
id = result.data?.getStringExtra("id") ?: "" | ||
pw = result.data?.getStringExtra("pw") ?: "" | ||
nick = result.data?.getStringExtra("nick") ?: "" | ||
result.data?.let { data -> | ||
id = data.getStringExtra("id") ?: "" | ||
pw = data.getStringExtra("pw") ?: "" | ||
nick = data.getStringExtra("nick") ?: "" | ||
} | ||
} | ||
} | ||
binding.btnLogin.setOnClickListener { | ||
sendData(id,pw,nick) | ||
moveToMain(id,pw,nick) | ||
} | ||
} | ||
private fun moveToSignUp(){ | ||
binding.btnLoginSignIn.setOnClickListener { | ||
val intent = Intent(this, SignUpActivity::class.java) | ||
//회원가입 데이터를 받아오기 위해 startActivity가 아닌 resultLauncher사용 | ||
resultLauncher.launch(intent) | ||
} | ||
} | ||
private fun moveToMain(id:String,pw:String,nick:String){ | ||
if (isLoginAvailable(id, pw)) { | ||
val intent = Intent(this, MainActivity::class.java).apply { | ||
saveUserInfo(id, pw, nick) | ||
} | ||
Comment on lines
+50
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 객체를 생성하지 않고도 가능하답니당! |
||
startActivity(intent) | ||
} | ||
} | ||
private fun saveUserInfo(id:String,pw:String,nick:String) { | ||
val sharedPreferences = getSharedPreferences("userInfo", MODE_PRIVATE) | ||
val editor = sharedPreferences.edit() | ||
editor | ||
.putString("userId", id) | ||
.putString("userPw", pw) | ||
.putString("userNick", nick) | ||
.apply() | ||
} | ||
Comment on lines
+56
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 sharedPreference 너무 좋아요!! |
||
private fun isLoginAvailable(id: String, pw: String) :Boolean { | ||
var loginBool = false | ||
val userId = binding.etvLoginId.text.toString() | ||
val userPw = binding.etvLoginPw.text.toString() | ||
val message = when{ | ||
userId != id || userPw != pw -> "아이디 혹은 비밀번호가 일치하지 않습니다." | ||
userId.isBlank() || userPw.isBlank() -> getString(R.string.login_error_blank) | ||
userId != id || userPw != pw -> getString(R.string.login_error_different) | ||
else -> { | ||
loginBool = true | ||
"로그인에 성공했습니다." | ||
getString(R.string.login_success) | ||
} | ||
} | ||
Toast.makeText(this,message,Toast.LENGTH_SHORT).show() | ||
return loginBool | ||
} | ||
private fun sendData(id:String,pw:String,nick:String){ | ||
if (isLoginAvailable(id, pw)) { | ||
val intent = Intent(this, MainActivity::class.java) | ||
//메인 액티비티로 데이터를 보냄 | ||
intent.putExtra("id", id).putExtra("pw", pw).putExtra("nick", nick) | ||
startActivity(intent) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
구우우우웃!!!