From 975a3316695690b4da3a6bbc1f1d7cd1d6d82ec1 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 21:59:58 +0900 Subject: [PATCH 01/25] =?UTF-8?q?[Del]=20:=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/Friend/FriendAdapter.kt | 27 ------ .../com/sopt/now/Friend/FriendViewHolder.kt | 17 ---- .../java/com/sopt/now/Home/HomeFragment.kt | 52 ------------ .../java/com/sopt/now/Home/HomeViewModel.kt | 82 ------------------- .../java/com/sopt/now/Home/MyPageFragment.kt | 78 ------------------ .../java/com/sopt/now/Home/SearchFragment.kt | 20 ----- .../main/java/com/sopt/now/LoginActivity.kt | 64 --------------- .../main/java/com/sopt/now/LoginViewModel.kt | 40 --------- .../main/java/com/sopt/now/MainActivity.kt | 68 --------------- .../main/java/com/sopt/now/SignUpViewModel.kt | 42 ---------- .../main/java/com/sopt/now/User/UserData.kt | 10 --- .../java/com/sopt/now/User/UserDataInput.kt | 20 ----- .../main/java/com/sopt/now/api/ApiFactory.kt | 24 ------ .../sopt/now/dto/LoginDto/ResponseLogInDto.kt | 12 --- .../com/sopt/now/dto/ResponseUserProfile.kt | 24 ------ 15 files changed, 580 deletions(-) delete mode 100644 app/src/main/java/com/sopt/now/Friend/FriendAdapter.kt delete mode 100644 app/src/main/java/com/sopt/now/Friend/FriendViewHolder.kt delete mode 100644 app/src/main/java/com/sopt/now/Home/HomeFragment.kt delete mode 100644 app/src/main/java/com/sopt/now/Home/HomeViewModel.kt delete mode 100644 app/src/main/java/com/sopt/now/Home/MyPageFragment.kt delete mode 100644 app/src/main/java/com/sopt/now/Home/SearchFragment.kt delete mode 100644 app/src/main/java/com/sopt/now/LoginActivity.kt delete mode 100644 app/src/main/java/com/sopt/now/LoginViewModel.kt delete mode 100644 app/src/main/java/com/sopt/now/MainActivity.kt delete mode 100644 app/src/main/java/com/sopt/now/SignUpViewModel.kt delete mode 100644 app/src/main/java/com/sopt/now/User/UserData.kt delete mode 100644 app/src/main/java/com/sopt/now/User/UserDataInput.kt delete mode 100644 app/src/main/java/com/sopt/now/api/ApiFactory.kt delete mode 100644 app/src/main/java/com/sopt/now/dto/LoginDto/ResponseLogInDto.kt delete mode 100644 app/src/main/java/com/sopt/now/dto/ResponseUserProfile.kt diff --git a/app/src/main/java/com/sopt/now/Friend/FriendAdapter.kt b/app/src/main/java/com/sopt/now/Friend/FriendAdapter.kt deleted file mode 100644 index fad461d..0000000 --- a/app/src/main/java/com/sopt/now/Friend/FriendAdapter.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.sopt.now.Friend - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import com.sopt.now.databinding.ItemFriendBinding - -class FriendAdapter() : RecyclerView.Adapter() { - private var friendList: List = emptyList() - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FriendViewHolder { - val inflater = LayoutInflater.from(parent.context) - val binding = ItemFriendBinding.inflate(inflater, parent, false) - return FriendViewHolder(binding) - } - - override fun onBindViewHolder(holder: FriendViewHolder, position: Int) { - holder.onBind(friendList[position]) - } - - override fun getItemCount() = friendList.size - - fun setFriendList(friendList: List) { - this.friendList = friendList.toList() - notifyDataSetChanged() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/Friend/FriendViewHolder.kt b/app/src/main/java/com/sopt/now/Friend/FriendViewHolder.kt deleted file mode 100644 index 2d6586c..0000000 --- a/app/src/main/java/com/sopt/now/Friend/FriendViewHolder.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.sopt.now.Friend - -import androidx.recyclerview.widget.RecyclerView -import com.sopt.now.databinding.ItemFriendBinding - - -class FriendViewHolder(private val binding: ItemFriendBinding) : - RecyclerView.ViewHolder(binding.root) { - - fun onBind(friendData: FriendData) { - binding.run { - ivProfile.setImageResource(friendData.profileImage) - tvName.text = friendData.name - tvSelfDescription.text = friendData.selfDescription - } - } -} diff --git a/app/src/main/java/com/sopt/now/Home/HomeFragment.kt b/app/src/main/java/com/sopt/now/Home/HomeFragment.kt deleted file mode 100644 index 7dc89c7..0000000 --- a/app/src/main/java/com/sopt/now/Home/HomeFragment.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.sopt.now.Home - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.fragment.app.viewModels -import androidx.recyclerview.widget.ConcatAdapter -import androidx.recyclerview.widget.LinearLayoutManager -import com.sopt.now.Friend.FriendAdapter -import com.sopt.now.User.UserAdapter -import com.sopt.now.databinding.FragmentHomeBinding - - - -class HomeFragment: Fragment() { - private var _binding: FragmentHomeBinding? = null - private val binding: FragmentHomeBinding - get() = requireNotNull(_binding) - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - _binding = FragmentHomeBinding.inflate(inflater, container, false) - return binding.root - } - private val viewModel by viewModels() - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - val friendAdapter = FriendAdapter() - val userAdapter = UserAdapter() - - friendAdapter.setFriendList(viewModel.mockFriendList) - userAdapter.setUserList(viewModel.mockUserList) - val concatAdapter = ConcatAdapter(userAdapter, friendAdapter) - - binding.rvFriends.run { - adapter = concatAdapter - layoutManager = LinearLayoutManager(requireContext()) - } - - - } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/Home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/Home/HomeViewModel.kt deleted file mode 100644 index aa9e757..0000000 --- a/app/src/main/java/com/sopt/now/Home/HomeViewModel.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.sopt.now.Home - -import androidx.lifecycle.ViewModel -import com.sopt.now.Friend.FriendData -import com.sopt.now.R -import com.sopt.now.User.UserData - -class HomeViewModel : ViewModel() { - - val mockFriendList = listOf( - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "이의경", - selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "우상욱", - selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "배지현", - selfDescription = "표정 풀자 ^^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "이의경", - selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "우상욱", - selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "배지현", - selfDescription = "표정 풀자 ^^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "이의경", - selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "우상욱", - selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "배지현", - selfDescription = "표정 풀자 ^^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "이의경", - selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "우상욱", - selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", - ), - FriendData( - profileImage = R.drawable.ic_person_black_24, - name = "배지현", - selfDescription = "표정 풀자 ^^", - ), - - - ) - - val mockUserList = listOf( - UserData( - profileImage = R.drawable.pic, - name = "주효은", - selfDescription = "34기 YB입니다!!", - ), - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/Home/MyPageFragment.kt b/app/src/main/java/com/sopt/now/Home/MyPageFragment.kt deleted file mode 100644 index 3556c3d..0000000 --- a/app/src/main/java/com/sopt/now/Home/MyPageFragment.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.sopt.now.Home - -import android.os.Bundle -import android.util.Log -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.Toast -import androidx.fragment.app.Fragment -import com.sopt.now.api.ServicePool -import com.sopt.now.databinding.FragmentMyPageBinding -import com.sopt.now.dto.ResponseUserProfile -import retrofit2.Call -import retrofit2.Callback -import retrofit2.Response - - -class MyPageFragment : Fragment() { - private var _binding: FragmentMyPageBinding? = null - private val binding: FragmentMyPageBinding - get() = requireNotNull(_binding) - - private var userId: String? = null - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View? { - _binding = FragmentMyPageBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - userId = arguments?.getString("userId") - Log.d("MyPageFragment", "userId: $userId") - userId?.let { getUserInfo(it) } - } - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - - private fun getUserInfo(userId: String) { - ServicePool.authService.getUserInfo(userId.toInt()) - .enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response, - ) { - if (response.isSuccessful) { - val userProfile = response.body() - Log.d("MyPageFragment", "User profile: $userProfile") - - userProfile?.let { - with(binding) { - tvUserId.text = "ID: ${it.data.authenticationId}" - tvUserName.text = "Name: ${it.data.nickname}" - tvPhone.text = "Phone: ${it.data.phone}" - - } - } - } else { - onFailure(call, Throwable("Fail: ${response.code()}")) - } - } - - override fun onFailure(call: Call, t: Throwable) { - Toast.makeText(requireContext(), t.message.toString(), Toast.LENGTH_SHORT) - .show() - } - - }) - } -} diff --git a/app/src/main/java/com/sopt/now/Home/SearchFragment.kt b/app/src/main/java/com/sopt/now/Home/SearchFragment.kt deleted file mode 100644 index 91cb9ab..0000000 --- a/app/src/main/java/com/sopt/now/Home/SearchFragment.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.sopt.now.Home - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.Fragment -import com.sopt.now.R - -class SearchFragment : Fragment() { - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_search, container, false) - } - -} diff --git a/app/src/main/java/com/sopt/now/LoginActivity.kt b/app/src/main/java/com/sopt/now/LoginActivity.kt deleted file mode 100644 index becd510..0000000 --- a/app/src/main/java/com/sopt/now/LoginActivity.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.sopt.now - -import android.content.Intent -import android.os.Bundle -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProvider -import com.sopt.now.databinding.ActivityLoginBinding -import com.sopt.now.dto.LoginDto.RequestLogInDto - - -class LoginActivity : AppCompatActivity() { - private lateinit var binding: ActivityLoginBinding - private lateinit var viewModel: LoginViewModel - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - binding = ActivityLoginBinding.inflate(layoutInflater) - setContentView(binding.root) - - viewModel = ViewModelProvider(this).get(LoginViewModel::class.java) - initViews() - observeLoginViewModel() - - } - - private fun initViews() { - binding.btnLogin.setOnClickListener { - val loginRequest = getLogInRequestDto() - viewModel.logIn(loginRequest) - } - binding.btnSignup.setOnClickListener { - val intent = Intent(this@LoginActivity, SignUpActivity::class.java) - startActivity(intent) - } - } - - private fun observeLoginViewModel() { - viewModel.loginResult.observe(this, Observer { success -> - if (success) { - viewModel.userId.value?.let { userId -> - val intent = Intent(this@LoginActivity, MainActivity::class.java) - intent.putExtra("userId", userId) - startActivity(intent) - finish() - } - } - }) - - viewModel.errorMessage.observe(this, Observer { errorMessage -> - Toast.makeText(this@LoginActivity, errorMessage, Toast.LENGTH_SHORT).show() - }) - } - - private fun getLogInRequestDto(): RequestLogInDto { - val id = binding.etId.text.toString() - val password = binding.pw2.text.toString() - return RequestLogInDto( - authenticationId = id, - password = password - ) - } -} - diff --git a/app/src/main/java/com/sopt/now/LoginViewModel.kt b/app/src/main/java/com/sopt/now/LoginViewModel.kt deleted file mode 100644 index 3f7df6a..0000000 --- a/app/src/main/java/com/sopt/now/LoginViewModel.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.sopt.now - - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.sopt.now.api.ServicePool -import com.sopt.now.dto.LoginDto.RequestLogInDto -import com.sopt.now.dto.LoginDto.ResponseLogInDto -import retrofit2.Call -import retrofit2.Callback -import retrofit2.Response - -class LoginViewModel : ViewModel() { - val loginResult: MutableLiveData = MutableLiveData() - val errorMessage: MutableLiveData = MutableLiveData() - val userId: MutableLiveData = MutableLiveData() - fun logIn(loginRequest: RequestLogInDto) { - ServicePool.authService.logIn(loginRequest).enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response, - ) { - if (response.isSuccessful) { - val userId = response.headers()["location"] - userId?.let { - this@LoginViewModel.userId.postValue(it) - loginResult.postValue(true) - } - } else { - val error = response.message() - errorMessage.postValue("$error") - } - } - - override fun onFailure(call: Call, t: Throwable) { - errorMessage.postValue("서버 에러 발생") - } - }) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/MainActivity.kt b/app/src/main/java/com/sopt/now/MainActivity.kt deleted file mode 100644 index d54f931..0000000 --- a/app/src/main/java/com/sopt/now/MainActivity.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.sopt.now - -import android.os.Bundle -import android.util.Log -import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment -import com.sopt.now.Home.HomeFragment -import com.sopt.now.Home.MyPageFragment -import com.sopt.now.Home.SearchFragment -import com.sopt.now.User.UserDataInput -import com.sopt.now.databinding.ActivityMainBinding - -class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - binding = ActivityMainBinding.inflate(layoutInflater) - setContentView(binding.root) - val userId = intent.getStringExtra("userId") - Log.d("main","$userId") - - val currentFragment = supportFragmentManager.findFragmentById(binding.fcvHome.id) - if (currentFragment == null) { - supportFragmentManager.beginTransaction() - .add(binding.fcvHome.id, HomeFragment()) - .commit() - } - clickBottomNavigation() - } - - private fun clickBottomNavigation() { - binding.bnvHome.setOnItemSelectedListener { - when (it.itemId) { - R.id.menu_home -> { - replaceFragment(HomeFragment()) - true - } - R.id.menu_search -> { - replaceFragment(SearchFragment()) - true - } - R.id.menu_mypage -> { - val userId = intent.getStringExtra("userId") - - userId?.let { - val myPageFragment = MyPageFragment() - val bundle = Bundle().apply { - putString("userId", it) - } - myPageFragment.arguments = bundle - replaceFragment(myPageFragment) - } - true - } - else -> false - } - } - } - - private fun replaceFragment(fragment: Fragment) { - supportFragmentManager.beginTransaction() - .replace(R.id.fcv_home, fragment) - .commit() - } - -} - - diff --git a/app/src/main/java/com/sopt/now/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/SignUpViewModel.kt deleted file mode 100644 index 777a567..0000000 --- a/app/src/main/java/com/sopt/now/SignUpViewModel.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.sopt.now - - -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.sopt.now.api.ServicePool -import com.sopt.now.dto.SignUp.RequestSignUpDto -import com.sopt.now.dto.SignUp.ResponseSignUpDto -import org.json.JSONObject -import retrofit2.Call -import retrofit2.Callback -import retrofit2.Response - -class SignUpViewModel : ViewModel() { - val signUpResult: MutableLiveData = MutableLiveData() - val errorMessage: MutableLiveData = MutableLiveData() - val userId: MutableLiveData = MutableLiveData() - fun signUp(signUpRequest: RequestSignUpDto) { - ServicePool.authService.signUp(signUpRequest).enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response, - ) { - if (response.isSuccessful) { - val userId = response.headers()["location"] - userId?.let { - this@SignUpViewModel.userId.postValue(it) - signUpResult.postValue(true) - } - } else { - val errorBody = response.errorBody()?.string() ?: "No error message" - val errorMessage = JSONObject(errorBody).getString("message") - this@SignUpViewModel.errorMessage.postValue(errorMessage) - } - } - - override fun onFailure(call: Call, t: Throwable) { - errorMessage.postValue("서버 에러 발생") - } - }) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/User/UserData.kt b/app/src/main/java/com/sopt/now/User/UserData.kt deleted file mode 100644 index cd5df17..0000000 --- a/app/src/main/java/com/sopt/now/User/UserData.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.sopt.now.User - -import androidx.annotation.DrawableRes - -data class UserData( - @DrawableRes val profileImage: Int, - val name: String, - val selfDescription: String, - - ) diff --git a/app/src/main/java/com/sopt/now/User/UserDataInput.kt b/app/src/main/java/com/sopt/now/User/UserDataInput.kt deleted file mode 100644 index 960cc9b..0000000 --- a/app/src/main/java/com/sopt/now/User/UserDataInput.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.sopt.now.User - -import android.os.Parcelable -import android.provider.ContactsContract.CommonDataKinds.Nickname -import android.provider.ContactsContract.CommonDataKinds.Phone -import android.security.identity.AccessControlProfileId -import kotlinx.parcelize.Parcelize -import java.net.Authenticator -import java.sql.Struct - - -@Parcelize -data class UserDataInput( - val userId: String, - val userPW: String, - val userNickName: String, - val userMbti: String, -) : Parcelable { - -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/api/ApiFactory.kt b/app/src/main/java/com/sopt/now/api/ApiFactory.kt deleted file mode 100644 index 034998d..0000000 --- a/app/src/main/java/com/sopt/now/api/ApiFactory.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.sopt.now.api - -import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory -import com.sopt.now.BuildConfig -import kotlinx.serialization.json.Json -import okhttp3.MediaType.Companion.toMediaType -import retrofit2.Retrofit - -object ApiFactory { - private const val BASE_URL: String = BuildConfig.AUTH_BASE_URL - - val retrofit: Retrofit by lazy { - Retrofit.Builder() - .baseUrl(BASE_URL) - .addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) - .build() - } - - inline fun create(): T = retrofit.create(T::class.java) -} - -object ServicePool { - val authService = ApiFactory.create() -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/dto/LoginDto/ResponseLogInDto.kt b/app/src/main/java/com/sopt/now/dto/LoginDto/ResponseLogInDto.kt deleted file mode 100644 index 95672fe..0000000 --- a/app/src/main/java/com/sopt/now/dto/LoginDto/ResponseLogInDto.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.sopt.now.dto.LoginDto - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class ResponseLogInDto ( - @SerialName("code") - val code: Int, - @SerialName("message") - val message: String, -) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/dto/ResponseUserProfile.kt b/app/src/main/java/com/sopt/now/dto/ResponseUserProfile.kt deleted file mode 100644 index 4ae730d..0000000 --- a/app/src/main/java/com/sopt/now/dto/ResponseUserProfile.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.sopt.now.dto - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class ResponseUserProfile( - @SerialName("code") - val code: Int, - @SerialName("message") - val message: String, - @SerialName("data") - val data: UserData, -) { - @Serializable - data class UserData( - @SerialName("authenticationId") - val authenticationId: String, - @SerialName("nickname") - val nickname: String, - @SerialName("phone") - val phone: String, - ) -} \ No newline at end of file From 505b66967e7c157ca73db9d2258a86cf004a5f28 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:00:32 +0900 Subject: [PATCH 02/25] =?UTF-8?q?[feat]=20:=20=EB=8D=B0=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 8 ++--- .../java/com/sopt/now/data/AuthRepoImpl.kt | 33 +++++++++++++++++ .../java/com/sopt/now/data/api/ApiFactory.kt | 35 +++++++++++++++++++ .../java/com/sopt/now/data/api/AuthService.kt | 30 ++++++++++++++++ .../com/sopt/now/domain/AuthRepository.kt | 9 +++++ .../com/sopt/now/domain/model/AuthData.kt | 10 ++++++ 6 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt create mode 100644 app/src/main/java/com/sopt/now/data/api/ApiFactory.kt create mode 100644 app/src/main/java/com/sopt/now/data/api/AuthService.kt create mode 100644 app/src/main/java/com/sopt/now/domain/AuthRepository.kt create mode 100644 app/src/main/java/com/sopt/now/domain/model/AuthData.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 67c4108..bfe69bf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ tools:targetApi="31" android:usesCleartextTraffic="true"> @@ -26,10 +26,10 @@ + android:name=".presentation.MainActivity" + android:exported="false"/> diff --git a/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt b/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt new file mode 100644 index 0000000..7ea609e --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt @@ -0,0 +1,33 @@ +package com.sopt.now.data + +import com.sopt.now.data.api.AuthService +import com.sopt.now.data.dto.LoginDto.RequestLogInDto +import com.sopt.now.data.dto.SignUp.RequestSignUpDto +import com.sopt.now.domain.AuthRepository +import com.sopt.now.domain.model.AuthData +import retrofit2.Response + +class AuthRepoImpl( + private val authService: AuthService, +) : AuthRepository { + override suspend fun logIn(authData: AuthData): Result> = runCatching { + authService.logIn( + request = RequestLogInDto( + authenticationId = authData.id, + password = authData.pw + ) + ) + } + override suspend fun signUp(authData: AuthData): Result> = runCatching { + authService.signUp( + RequestSignUpDto( + authenticationId = authData.id, + password = authData.pw, + nickname = authData.name ?: "", + phone = authData.phone ?: "" + ) + ) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/api/ApiFactory.kt b/app/src/main/java/com/sopt/now/data/api/ApiFactory.kt new file mode 100644 index 0000000..ad27bc0 --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/api/ApiFactory.kt @@ -0,0 +1,35 @@ +package com.sopt.now.data.api + +import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory +import com.sopt.now.BuildConfig +import kotlinx.serialization.json.Json +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit + +object ApiFactory { + private const val BASE_URL: String = BuildConfig.AUTH_BASE_URL + + val loggingInterceptor = HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY + } + + val client = OkHttpClient.Builder() + .addInterceptor(loggingInterceptor) + .build() + + val retrofit: Retrofit by lazy { + Retrofit.Builder() + .client(client) + .baseUrl(BASE_URL) + .addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) + .build() + } + + inline fun create(): T = retrofit.create(T::class.java) +} + +object ServicePool { + val authService = ApiFactory.create() +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/api/AuthService.kt b/app/src/main/java/com/sopt/now/data/api/AuthService.kt new file mode 100644 index 0000000..5cc16cf --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/api/AuthService.kt @@ -0,0 +1,30 @@ +package com.sopt.now.data.api + +import com.sopt.now.data.dto.LoginDto.RequestLogInDto +import com.sopt.now.data.dto.SignUp.RequestSignUpDto +import com.sopt.now.data.dto.LoginDto.ResponseLogInDto +import com.sopt.now.data.dto.SignUp.ResponseSignUpDto +import com.sopt.now.data.dto.ResponseUserProfile +import retrofit2.Call +import retrofit2.Response +import retrofit2.http.Body +import retrofit2.http.GET +import retrofit2.http.Header +import retrofit2.http.POST + +interface AuthService { + @POST("member/join") + suspend fun signUp( + @Body request: RequestSignUpDto, + ): Response + + @POST("member/login") + suspend fun logIn( + @Body request: RequestLogInDto, + ): Response + + @GET("member/info") + fun getUserInfo( + @Header("memberId") memberId : Int + ): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/domain/AuthRepository.kt b/app/src/main/java/com/sopt/now/domain/AuthRepository.kt new file mode 100644 index 0000000..d36ec4b --- /dev/null +++ b/app/src/main/java/com/sopt/now/domain/AuthRepository.kt @@ -0,0 +1,9 @@ +package com.sopt.now.domain + +import com.sopt.now.domain.model.AuthData +import retrofit2.Response + +interface AuthRepository { + suspend fun logIn(authData: AuthData): Result> + suspend fun signUp(authData: AuthData): Result> +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/domain/model/AuthData.kt b/app/src/main/java/com/sopt/now/domain/model/AuthData.kt new file mode 100644 index 0000000..8eff2b9 --- /dev/null +++ b/app/src/main/java/com/sopt/now/domain/model/AuthData.kt @@ -0,0 +1,10 @@ +package com.sopt.now.domain.model + +import android.provider.ContactsContract.CommonDataKinds.Phone + +data class AuthData( + val id: String, + val pw: String, + val name: String? = null, + val phone: String? = null +) From edb7692ea5e9049ebff15cb707ad2f5476fe8b54 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:01:09 +0900 Subject: [PATCH 03/25] =?UTF-8?q?[mod]=20:=20Friend=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/presentation/Friend/FriendAdapter.kt | 27 +++++++++++++++++++ .../now/presentation/Friend/FriendData.kt | 10 +++++++ .../presentation/Friend/FriendViewHolder.kt | 17 ++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/presentation/Friend/FriendAdapter.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/Friend/FriendData.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/Friend/FriendViewHolder.kt diff --git a/app/src/main/java/com/sopt/now/presentation/Friend/FriendAdapter.kt b/app/src/main/java/com/sopt/now/presentation/Friend/FriendAdapter.kt new file mode 100644 index 0000000..0ad150a --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Friend/FriendAdapter.kt @@ -0,0 +1,27 @@ +package com.sopt.now.presentation.Friend + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.sopt.now.databinding.ItemFriendBinding + +class FriendAdapter() : RecyclerView.Adapter() { + private var friendList: List = emptyList() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FriendViewHolder { + val inflater = LayoutInflater.from(parent.context) + val binding = ItemFriendBinding.inflate(inflater, parent, false) + return FriendViewHolder(binding) + } + + override fun onBindViewHolder(holder: FriendViewHolder, position: Int) { + holder.onBind(friendList[position]) + } + + override fun getItemCount() = friendList.size + + fun setFriendList(friendList: List) { + this.friendList = friendList.toList() + notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/presentation/Friend/FriendData.kt b/app/src/main/java/com/sopt/now/presentation/Friend/FriendData.kt new file mode 100644 index 0000000..7a2fd5c --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Friend/FriendData.kt @@ -0,0 +1,10 @@ +package com.sopt.now.presentation.Friend + +import androidx.annotation.DrawableRes + +data class FriendData( + @DrawableRes val profileImage: Int, + val name: String, + val selfDescription: String, + + ) diff --git a/app/src/main/java/com/sopt/now/presentation/Friend/FriendViewHolder.kt b/app/src/main/java/com/sopt/now/presentation/Friend/FriendViewHolder.kt new file mode 100644 index 0000000..1c6514a --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Friend/FriendViewHolder.kt @@ -0,0 +1,17 @@ +package com.sopt.now.presentation.Friend + +import androidx.recyclerview.widget.RecyclerView +import com.sopt.now.databinding.ItemFriendBinding + + +class FriendViewHolder(private val binding: ItemFriendBinding) : + RecyclerView.ViewHolder(binding.root) { + + fun onBind(friendData: FriendData) { + binding.run { + ivProfile.setImageResource(friendData.profileImage) + tvName.text = friendData.name + tvSelfDescription.text = friendData.selfDescription + } + } +} From 45e1a0198874e98cf81c735a88f3c984459900b8 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:01:32 +0900 Subject: [PATCH 04/25] =?UTF-8?q?[mod]=20:=20HomeFragment=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/presentation/Home/HomeFragment.kt | 52 ++++++++++++ .../now/presentation/Home/HomeViewModel.kt | 82 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/presentation/Home/HomeFragment.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/Home/HomeViewModel.kt diff --git a/app/src/main/java/com/sopt/now/presentation/Home/HomeFragment.kt b/app/src/main/java/com/sopt/now/presentation/Home/HomeFragment.kt new file mode 100644 index 0000000..332ff26 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Home/HomeFragment.kt @@ -0,0 +1,52 @@ +package com.sopt.now.presentation.Home + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import androidx.fragment.app.viewModels +import androidx.recyclerview.widget.ConcatAdapter +import androidx.recyclerview.widget.LinearLayoutManager +import com.sopt.now.presentation.Friend.FriendAdapter +import com.sopt.now.presentation.User.UserAdapter +import com.sopt.now.databinding.FragmentHomeBinding + + + +class HomeFragment: Fragment() { + private var _binding: FragmentHomeBinding? = null + private val binding: FragmentHomeBinding + get() = requireNotNull(_binding) + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + _binding = FragmentHomeBinding.inflate(inflater, container, false) + return binding.root + } + private val viewModel by viewModels() + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val friendAdapter = FriendAdapter() + val userAdapter = UserAdapter() + + friendAdapter.setFriendList(viewModel.mockFriendList) + userAdapter.setUserList(viewModel.mockUserList) + val concatAdapter = ConcatAdapter(userAdapter, friendAdapter) + + binding.rvFriends.run { + adapter = concatAdapter + layoutManager = LinearLayoutManager(requireContext()) + } + + + } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/presentation/Home/HomeViewModel.kt b/app/src/main/java/com/sopt/now/presentation/Home/HomeViewModel.kt new file mode 100644 index 0000000..0caed54 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Home/HomeViewModel.kt @@ -0,0 +1,82 @@ +package com.sopt.now.presentation.Home + +import androidx.lifecycle.ViewModel +import com.sopt.now.presentation.Friend.FriendData +import com.sopt.now.R +import com.sopt.now.presentation.User.UserData + +class HomeViewModel : ViewModel() { + + val mockFriendList = listOf( + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "이의경", + selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "우상욱", + selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "배지현", + selfDescription = "표정 풀자 ^^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "이의경", + selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "우상욱", + selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "배지현", + selfDescription = "표정 풀자 ^^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "이의경", + selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "우상욱", + selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "배지현", + selfDescription = "표정 풀자 ^^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "이의경", + selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "우상욱", + selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", + ), + FriendData( + profileImage = R.drawable.ic_person_black_24, + name = "배지현", + selfDescription = "표정 풀자 ^^", + ), + + + ) + + val mockUserList = listOf( + UserData( + profileImage = R.drawable.pic, + name = "주효은", + selfDescription = "34기 YB입니다!!", + ), + ) +} \ No newline at end of file From afc9148252cb0834e59c38e436b98e39d08bcf9d Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:01:52 +0900 Subject: [PATCH 05/25] =?UTF-8?q?[mod]=20:=20Login=20ViewModel=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/presentation/Login/LoginActivity.kt | 66 +++++++++++++++++++ .../now/presentation/Login/LoginViewModel.kt | 58 ++++++++++++++++ .../Login/LoginViewModelFactory.kt | 18 +++++ 3 files changed, 142 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/Login/LoginViewModelFactory.kt diff --git a/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt b/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt new file mode 100644 index 0000000..ccf6359 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt @@ -0,0 +1,66 @@ +package com.sopt.now.presentation.Login + +import android.content.Intent +import android.os.Bundle +import android.widget.Toast +import androidx.activity.viewModels +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.Observer +import com.sopt.now.databinding.ActivityLoginBinding +import com.sopt.now.domain.model.AuthData +import com.sopt.now.presentation.MainActivity +import com.sopt.now.presentation.SignUpActivity + + +class LoginActivity : AppCompatActivity() { + private lateinit var binding: ActivityLoginBinding + private val viewModel: LoginViewModel by viewModels { LoginViewModelFactory() } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(binding.root) + + initViews() + observeLoginViewModel() + + } + + private fun initViews() { + binding.btnLogin.setOnClickListener { + val loginRequest = getLoginData() + viewModel.logIn(loginRequest) + } + binding.btnSignup.setOnClickListener { + val intent = Intent(this@LoginActivity, SignUpActivity::class.java) + startActivity(intent) + } + } + + private fun observeLoginViewModel() { + viewModel.loginResult.observe(this, Observer { success -> + if (success) { + viewModel.userId.value?.let { userId -> + val intent = Intent(this@LoginActivity, MainActivity::class.java) + intent.putExtra("userId", userId) + startActivity(intent) + finish() + } + } + }) + + viewModel.errorMessage.observe(this, Observer { errorMessage -> + Toast.makeText(this@LoginActivity, errorMessage, Toast.LENGTH_SHORT).show() + }) + } + + private fun getLoginData(): AuthData { + val id = binding.etId.text.toString() + val password = binding.pw2.text.toString() + return AuthData( + id = id, + pw = password + ) + } + +} + diff --git a/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt new file mode 100644 index 0000000..677d513 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt @@ -0,0 +1,58 @@ +package com.sopt.now.presentation.Login + + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.sopt.now.domain.AuthRepository +import com.sopt.now.domain.model.AuthData +import kotlinx.coroutines.launch +import retrofit2.HttpException + +class LoginViewModel( + private val authRepository: AuthRepository +) : ViewModel() { + val loginResult: MutableLiveData = MutableLiveData() + val errorMessage: MutableLiveData = MutableLiveData() + val userId: MutableLiveData = MutableLiveData() + fun logIn(authData: AuthData) { + viewModelScope.launch{ + authRepository.logIn(authData) + .onSuccess { response -> + val userId = response.headers()["Location"] + userId?.let { + this@LoginViewModel.userId.value =it + loginResult.value = true + } + } + .onFailure{ t -> + if(t is HttpException){ + val error = t.message() + errorMessage.postValue("$error") + } + errorMessage.postValue("서버 에러 발생")} + +// ServicePool.authService.logIn(loginRequest).enqueue(object : Callback { +// override fun onResponse( +// call: Call, +// response: Response, +// ) { +// if (response.isSuccessful) { +// val userId = response.headers()["location"] +// userId?.let { +// this@LoginViewModel.userId.postValue(it) +// loginResult.postValue(true) +// } +// } else { +// val error = response.message() +// errorMessage.postValue("$error") +// } +// } +// +// override fun onFailure(call: Call, t: Throwable) { +// errorMessage.postValue("서버 에러 발생") +// } +// }) + } +} + } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModelFactory.kt b/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModelFactory.kt new file mode 100644 index 0000000..db9a923 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModelFactory.kt @@ -0,0 +1,18 @@ +package com.sopt.now.presentation.Login + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.sopt.now.data.AuthRepoImpl +import com.sopt.now.data.api.ServicePool + +class LoginViewModelFactory : ViewModelProvider.Factory{ + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(LoginViewModel::class.java)) { //modelClass가 LoginViewModel인지 확인 + val repository = + AuthRepoImpl(ServicePool.authService)//authService를 인자로 받아서 Repository인스턴스 생성 + return LoginViewModel(repository) as T + } else { + throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") + } + } +} \ No newline at end of file From d6c142259429243c84a4b9433ee0db0dd0992e8f Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:02:17 +0900 Subject: [PATCH 06/25] =?UTF-8?q?[CHORE]=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/presentation/Home/MyPageFragment.kt | 79 +++++++++++++++++++ .../com/sopt/now/presentation/MainActivity.kt | 68 ++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/presentation/Home/MyPageFragment.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/MainActivity.kt diff --git a/app/src/main/java/com/sopt/now/presentation/Home/MyPageFragment.kt b/app/src/main/java/com/sopt/now/presentation/Home/MyPageFragment.kt new file mode 100644 index 0000000..2536374 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Home/MyPageFragment.kt @@ -0,0 +1,79 @@ +package com.sopt.now.presentation.Home + +import android.os.Bundle +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.fragment.app.Fragment +import com.sopt.now.data.api.ServicePool +import com.sopt.now.databinding.FragmentMyPageBinding +import com.sopt.now.data.dto.ResponseUserProfile +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + + +class MyPageFragment : Fragment() { + private var _binding: FragmentMyPageBinding? = null + private val binding: FragmentMyPageBinding + get() = requireNotNull(_binding) + + private var userId: String? = null + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View { + _binding = FragmentMyPageBinding.inflate(inflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + userId = arguments?.getString("userId") + Log.d("MyPageFragment", "userId: $userId") + userId?.let { getUserInfo(it) } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + private fun getUserInfo(userId: String) { + ServicePool.authService.getUserInfo(userId.toInt()) + .enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response, + ) { + if (response.isSuccessful) { + val userProfile = response.body() + Log.d("MyPageFragment", "User profile: $userProfile") + + userProfile?.let { + with(binding) { + tvUserId.text = "ID: ${it.data.authenticationId}" + tvUserName.text = "Name: ${it.data.nickname}" + tvPhone.text = "Phone: ${it.data.phone}" + } + } + } else { + onFailure(call, Throwable("Fail: ${response.code()}")) + } + } + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(requireContext(), t.message.toString(), Toast.LENGTH_SHORT) + .show() + } + + }) + } + companion object{ + const val userId= "userId" + } +} diff --git a/app/src/main/java/com/sopt/now/presentation/MainActivity.kt b/app/src/main/java/com/sopt/now/presentation/MainActivity.kt new file mode 100644 index 0000000..c9ad0c3 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/MainActivity.kt @@ -0,0 +1,68 @@ +package com.sopt.now.presentation + +import android.os.Bundle +import android.util.Log +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment +import com.sopt.now.presentation.Home.HomeFragment +import com.sopt.now.R +import com.sopt.now.presentation.Home.MyPageFragment +import com.sopt.now.presentation.Home.SearchFragment +import com.sopt.now.databinding.ActivityMainBinding + +class MainActivity : AppCompatActivity() { + private lateinit var binding: ActivityMainBinding + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + val userId = intent.getStringExtra("userId") + Log.d("main","$userId") + + val currentFragment = supportFragmentManager.findFragmentById(binding.fcvHome.id) + if (currentFragment == null) { + supportFragmentManager.beginTransaction() + .add(binding.fcvHome.id, HomeFragment()) + .commit() + } + clickBottomNavigation() + } + + private fun clickBottomNavigation() { + binding.bnvHome.setOnItemSelectedListener { + when (it.itemId) { + R.id.menu_home -> { + replaceFragment(HomeFragment()) + true + } + R.id.menu_search -> { + replaceFragment(SearchFragment()) + true + } + R.id.menu_mypage -> { + val userId = intent.getStringExtra("userId") + + userId?.let { + val myPageFragment = MyPageFragment() + val bundle = Bundle().apply { + putString("userId", it) + } + myPageFragment.arguments = bundle + replaceFragment(myPageFragment) + } + true + } + else -> false + } + } + } + + private fun replaceFragment(fragment: Fragment) { + supportFragmentManager.beginTransaction() + .replace(R.id.fcv_home, fragment) + .commit() + } + +} + + From f996c6e4a2675d0b567c24d6e9d7f6d00b738244 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:02:36 +0900 Subject: [PATCH 07/25] =?UTF-8?q?[MOD]=20:=20Dto=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../now/data/dto/LoginDto/RequestLogInDto.kt | 12 ++++++++++ .../now/data/dto/LoginDto/ResponseLogInDto.kt | 12 ++++++++++ .../sopt/now/data/dto/ResponseUserProfile.kt | 24 +++++++++++++++++++ .../now/data/dto/SignUp/RequestSignUpDto.kt | 16 +++++++++++++ .../now/data/dto/SignUp/ResponseSignUpDto.kt | 12 ++++++++++ 5 files changed, 76 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/data/dto/LoginDto/RequestLogInDto.kt create mode 100644 app/src/main/java/com/sopt/now/data/dto/LoginDto/ResponseLogInDto.kt create mode 100644 app/src/main/java/com/sopt/now/data/dto/ResponseUserProfile.kt create mode 100644 app/src/main/java/com/sopt/now/data/dto/SignUp/RequestSignUpDto.kt create mode 100644 app/src/main/java/com/sopt/now/data/dto/SignUp/ResponseSignUpDto.kt diff --git a/app/src/main/java/com/sopt/now/data/dto/LoginDto/RequestLogInDto.kt b/app/src/main/java/com/sopt/now/data/dto/LoginDto/RequestLogInDto.kt new file mode 100644 index 0000000..94d80bb --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/dto/LoginDto/RequestLogInDto.kt @@ -0,0 +1,12 @@ +package com.sopt.now.data.dto.LoginDto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestLogInDto( + @SerialName("authenticationId") + val authenticationId: String, + @SerialName("password") + val password: String, + ) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/dto/LoginDto/ResponseLogInDto.kt b/app/src/main/java/com/sopt/now/data/dto/LoginDto/ResponseLogInDto.kt new file mode 100644 index 0000000..62ec481 --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/dto/LoginDto/ResponseLogInDto.kt @@ -0,0 +1,12 @@ +package com.sopt.now.data.dto.LoginDto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ResponseLogInDto ( + @SerialName("code") + val code: Int, + @SerialName("message") + val message: String, +) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/dto/ResponseUserProfile.kt b/app/src/main/java/com/sopt/now/data/dto/ResponseUserProfile.kt new file mode 100644 index 0000000..e0344f5 --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/dto/ResponseUserProfile.kt @@ -0,0 +1,24 @@ +package com.sopt.now.data.dto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ResponseUserProfile( + @SerialName("code") + val code: Int, + @SerialName("message") + val message: String, + @SerialName("data") + val data: UserData, +) { + @Serializable + data class UserData( + @SerialName("authenticationId") + val authenticationId: String, + @SerialName("nickname") + val nickname: String, + @SerialName("phone") + val phone: String, + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/dto/SignUp/RequestSignUpDto.kt b/app/src/main/java/com/sopt/now/data/dto/SignUp/RequestSignUpDto.kt new file mode 100644 index 0000000..69d4136 --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/dto/SignUp/RequestSignUpDto.kt @@ -0,0 +1,16 @@ +package com.sopt.now.data.dto.SignUp + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RequestSignUpDto( + @SerialName("authenticationId") + val authenticationId: String, + @SerialName("password") + val password: String, + @SerialName("nickname") + val nickname: String, + @SerialName("phone") + val phone: String, +) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/dto/SignUp/ResponseSignUpDto.kt b/app/src/main/java/com/sopt/now/data/dto/SignUp/ResponseSignUpDto.kt new file mode 100644 index 0000000..191093c --- /dev/null +++ b/app/src/main/java/com/sopt/now/data/dto/SignUp/ResponseSignUpDto.kt @@ -0,0 +1,12 @@ +package com.sopt.now.data.dto.SignUp + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ResponseSignUpDto( + @SerialName("code") + val code: Int, + @SerialName("message") + val message: String, +) \ No newline at end of file From 804bf8316a29e2e18f4f56121320a444eb7f2f90 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:03:00 +0900 Subject: [PATCH 08/25] =?UTF-8?q?[MOD]=20:=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopt/now/Friend/FriendData.kt | 10 --- .../main/java/com/sopt/now/SignUpActivity.kt | 68 ------------------- .../java/com/sopt/now/User/UserAdapter.kt | 39 ----------- .../main/java/com/sopt/now/api/AuthService.kt | 29 -------- .../sopt/now/dto/LoginDto/RequestLogInDto.kt | 12 ---- .../sopt/now/dto/SignUp/RequestSignUpDto.kt | 16 ----- .../sopt/now/dto/SignUp/ResponseSignUpDto.kt | 12 ---- 7 files changed, 186 deletions(-) delete mode 100644 app/src/main/java/com/sopt/now/Friend/FriendData.kt delete mode 100644 app/src/main/java/com/sopt/now/SignUpActivity.kt delete mode 100644 app/src/main/java/com/sopt/now/User/UserAdapter.kt delete mode 100644 app/src/main/java/com/sopt/now/api/AuthService.kt delete mode 100644 app/src/main/java/com/sopt/now/dto/LoginDto/RequestLogInDto.kt delete mode 100644 app/src/main/java/com/sopt/now/dto/SignUp/RequestSignUpDto.kt delete mode 100644 app/src/main/java/com/sopt/now/dto/SignUp/ResponseSignUpDto.kt diff --git a/app/src/main/java/com/sopt/now/Friend/FriendData.kt b/app/src/main/java/com/sopt/now/Friend/FriendData.kt deleted file mode 100644 index 0939ffb..0000000 --- a/app/src/main/java/com/sopt/now/Friend/FriendData.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.sopt.now.Friend - -import androidx.annotation.DrawableRes - -data class FriendData( - @DrawableRes val profileImage: Int, - val name: String, - val selfDescription: String, - - ) diff --git a/app/src/main/java/com/sopt/now/SignUpActivity.kt b/app/src/main/java/com/sopt/now/SignUpActivity.kt deleted file mode 100644 index 4043b74..0000000 --- a/app/src/main/java/com/sopt/now/SignUpActivity.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.sopt.now - -import android.content.Intent -import android.os.Bundle -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProvider -import com.sopt.now.databinding.ActivitySignupBinding -import com.sopt.now.dto.SignUp.RequestSignUpDto - - -class SignUpActivity : AppCompatActivity() { - private lateinit var binding: ActivitySignupBinding - private lateinit var viewModel: SignUpViewModel - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - binding = ActivitySignupBinding.inflate(layoutInflater) - setContentView(binding.root) - - viewModel = ViewModelProvider(this).get(SignUpViewModel::class.java) - - initViews() - observeSignUpViewModel() - } - - private fun initViews() { - binding.btnSignup2.setOnClickListener { - val signUpRequest = getSignUpRequestDto() - viewModel.signUp(signUpRequest) - } - } - - private fun observeSignUpViewModel() { - viewModel.signUpResult.observe(this, Observer { success -> - if (success) { - viewModel.userId.value?.let { userId -> - val intent = Intent(this@SignUpActivity, LoginActivity::class.java).apply { - putExtra("userId", userId) - } - Toast.makeText( - this@SignUpActivity, - R.string.sign_up_success, - Toast.LENGTH_SHORT - ).show() - startActivity(intent) - finish() - } - } - }) - viewModel.errorMessage.observe(this, Observer { errorMessage -> - Toast.makeText(this@SignUpActivity, errorMessage, Toast.LENGTH_SHORT).show() - }) - } - - private fun getSignUpRequestDto(): RequestSignUpDto { - val id = binding.etIdSignup.text.toString() - val password = binding.etPwSignup.text.toString() - val nickname = binding.etNicknameSignup.text.toString() - val phoneNumber = binding.etMbtiSignup.text.toString() - return RequestSignUpDto( - authenticationId = id, - password = password, - nickname = nickname, - phone = phoneNumber - ) - } -} diff --git a/app/src/main/java/com/sopt/now/User/UserAdapter.kt b/app/src/main/java/com/sopt/now/User/UserAdapter.kt deleted file mode 100644 index 66d74f9..0000000 --- a/app/src/main/java/com/sopt/now/User/UserAdapter.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.sopt.now.User - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import com.sopt.now.databinding.ItemUserBinding - -class UserAdapter() : RecyclerView.Adapter() { - private var userList: List = emptyList() - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder { - val binding = ItemUserBinding.inflate(LayoutInflater.from(parent.context), parent, false) - return UserViewHolder(binding) - } - - override fun onBindViewHolder(holder: UserViewHolder, position: Int) { - val userData = userList[position] -// holder.bind(userData) - } - - override fun getItemCount(): Int { - return userList.size - } - - fun setUserList(userList: List) { - this.userList = userList.toList() - notifyDataSetChanged() - } - - class UserViewHolder(private val binding: ItemUserBinding) : - RecyclerView.ViewHolder(binding.root) { - - fun bind(userData: UserDataInput) { - binding.run { - tvName.text = userData.userNickName - tvSelfDescription.text = "34기 YB 주효은입니다!!!" - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/api/AuthService.kt b/app/src/main/java/com/sopt/now/api/AuthService.kt deleted file mode 100644 index 9f97dc3..0000000 --- a/app/src/main/java/com/sopt/now/api/AuthService.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.sopt.now.api - -import com.sopt.now.dto.LoginDto.RequestLogInDto -import com.sopt.now.dto.SignUp.RequestSignUpDto -import com.sopt.now.dto.LoginDto.ResponseLogInDto -import com.sopt.now.dto.SignUp.ResponseSignUpDto -import com.sopt.now.dto.ResponseUserProfile -import retrofit2.Call -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.Header -import retrofit2.http.POST - -interface AuthService { - @POST("member/join") - fun signUp( - @Body request: RequestSignUpDto, - ): Call - - @POST("member/login") - fun logIn( - @Body request: RequestLogInDto, - ): Call - - @GET("member/info") - fun getUserInfo( - @Header("memberId") memberId : Int - ): Call -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/dto/LoginDto/RequestLogInDto.kt b/app/src/main/java/com/sopt/now/dto/LoginDto/RequestLogInDto.kt deleted file mode 100644 index e8d6a24..0000000 --- a/app/src/main/java/com/sopt/now/dto/LoginDto/RequestLogInDto.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.sopt.now.dto.LoginDto - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class RequestLogInDto( - @SerialName("authenticationId") - val authenticationId: String, - @SerialName("password") - val password: String, - ) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/dto/SignUp/RequestSignUpDto.kt b/app/src/main/java/com/sopt/now/dto/SignUp/RequestSignUpDto.kt deleted file mode 100644 index c224118..0000000 --- a/app/src/main/java/com/sopt/now/dto/SignUp/RequestSignUpDto.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.sopt.now.dto.SignUp - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class RequestSignUpDto( - @SerialName("authenticationId") - val authenticationId: String, - @SerialName("password") - val password: String, - @SerialName("nickname") - val nickname: String, - @SerialName("phone") - val phone: String, -) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/dto/SignUp/ResponseSignUpDto.kt b/app/src/main/java/com/sopt/now/dto/SignUp/ResponseSignUpDto.kt deleted file mode 100644 index 86bea43..0000000 --- a/app/src/main/java/com/sopt/now/dto/SignUp/ResponseSignUpDto.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.sopt.now.dto.SignUp - -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class ResponseSignUpDto( - @SerialName("code") - val code: Int, - @SerialName("message") - val message: String, -) \ No newline at end of file From d17144ff26363834ab985c95db1917bd83b5d9b5 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:03:24 +0900 Subject: [PATCH 09/25] =?UTF-8?q?[MOD]=20:=20mbti=EB=A5=BC=20phone?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/activity_login.xml | 2 +- app/src/main/res/layout/fragment_my_page.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index e926ea0..f1e270c 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".LoginActivity"> + tools:context=".presentation.Login.LoginActivity"> + tools:context=".presentation.MainActivity"> Date: Fri, 24 May 2024 22:03:45 +0900 Subject: [PATCH 10/25] =?UTF-8?q?[FEAT]=20:=20SignUp=20ViewModel=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/now/presentation/SignUpActivity.kt | 69 +++++++++++++++++++ .../sopt/now/presentation/SignUpViewModel.kt | 46 +++++++++++++ .../User/SignUpViewModelFactory.kt | 19 +++++ 3 files changed, 134 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/User/SignUpViewModelFactory.kt diff --git a/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt b/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt new file mode 100644 index 0000000..b07fa39 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt @@ -0,0 +1,69 @@ +package com.sopt.now.presentation + +import android.content.Intent +import android.os.Bundle +import android.widget.Toast +import androidx.activity.viewModels +import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.Observer +import com.sopt.now.R +import com.sopt.now.databinding.ActivitySignupBinding +import com.sopt.now.domain.model.AuthData +import com.sopt.now.presentation.Login.LoginActivity +import com.sopt.now.presentation.User.SignUpViewModelFactory + + +class SignUpActivity : AppCompatActivity() { + private lateinit var binding: ActivitySignupBinding + private val viewModel: SignUpViewModel by viewModels { SignUpViewModelFactory() } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivitySignupBinding.inflate(layoutInflater) + setContentView(binding.root) + + initViews() + observeSignUpViewModel() + } + + private fun initViews() { + binding.btnSignup2.setOnClickListener { + val signUpRequest = getSignUpData() + viewModel.signUp(signUpRequest) + } + } + + private fun observeSignUpViewModel() { + viewModel.signUpResult.observe(this, Observer { success -> + if (success) { + viewModel.userId.value?.let { userId -> + val intent = Intent(this@SignUpActivity, LoginActivity::class.java).apply { + putExtra("userId", userId) + } + Toast.makeText( + this@SignUpActivity, + R.string.sign_up_success, + Toast.LENGTH_SHORT + ).show() + startActivity(intent) + finish() + } + } + }) + viewModel.errorMessage.observe(this, Observer { errorMessage -> + Toast.makeText(this@SignUpActivity, errorMessage, Toast.LENGTH_SHORT).show() + }) + } + + private fun getSignUpData(): AuthData { + val id = binding.etIdSignup.text.toString() + val password = binding.etPwSignup.text.toString() + val nickname = binding.etNicknameSignup.text.toString() + val phoneNumber = binding.etMbtiSignup.text.toString() + return AuthData( + id = id, + pw = password, + name = nickname, + phone = phoneNumber + ) + } +} diff --git a/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt new file mode 100644 index 0000000..f37bda0 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt @@ -0,0 +1,46 @@ +package com.sopt.now.presentation + + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.google.gson.JsonObject +import com.sopt.now.domain.AuthRepository +import com.sopt.now.domain.model.AuthData +import kotlinx.coroutines.launch +import org.json.JSONObject +import retrofit2.HttpException + + +class SignUpViewModel( + private val authRepository: AuthRepository, +) : ViewModel() { + val signUpResult: MutableLiveData = MutableLiveData() + val errorMessage: MutableLiveData = MutableLiveData() + val userId: MutableLiveData = MutableLiveData() + fun signUp(authData: AuthData) { + viewModelScope.launch { + runCatching { + authRepository.signUp(authData) + .onSuccess { response -> + if (response.isSuccessful) { + val userId = response.headers()["Location"] + userId?.let { + this@SignUpViewModel.userId.value = it + signUpResult.value = true + } + } else { + val error = response.errorBody()?.string() + val jsonObject = error?.let { JSONObject(it) } + + val message = jsonObject?.getString("message") + errorMessage.postValue(message.toString()) + } + } + .onFailure { t -> + errorMessage.postValue(t.message.toString()) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/presentation/User/SignUpViewModelFactory.kt b/app/src/main/java/com/sopt/now/presentation/User/SignUpViewModelFactory.kt new file mode 100644 index 0000000..5414b74 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/User/SignUpViewModelFactory.kt @@ -0,0 +1,19 @@ +package com.sopt.now.presentation.User + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.sopt.now.data.AuthRepoImpl +import com.sopt.now.data.api.ServicePool +import com.sopt.now.presentation.SignUpViewModel + +class SignUpViewModelFactory :ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(SignUpViewModel::class.java)) { + val repository = + AuthRepoImpl(ServicePool.authService)//authService를 인자로 받아서 Repository인스턴스 생성 + return SignUpViewModel(repository) as T + } else { + throw IllegalArgumentException("Failed to create ViewModel: ${modelClass.name}") + } + } +} \ No newline at end of file From cf5d656966b65e0e63ff27cae5592fefd1393a3d Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:04:06 +0900 Subject: [PATCH 11/25] =?UTF-8?q?[FEAT]=20:=20USER=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/now/presentation/User/UserAdapter.kt | 39 +++++++++++++++++++ .../sopt/now/presentation/User/UserData.kt | 10 +++++ .../now/presentation/User/UserDataInput.kt | 20 ++++++++++ 3 files changed, 69 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/presentation/User/UserAdapter.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/User/UserData.kt create mode 100644 app/src/main/java/com/sopt/now/presentation/User/UserDataInput.kt diff --git a/app/src/main/java/com/sopt/now/presentation/User/UserAdapter.kt b/app/src/main/java/com/sopt/now/presentation/User/UserAdapter.kt new file mode 100644 index 0000000..5e312c1 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/User/UserAdapter.kt @@ -0,0 +1,39 @@ +package com.sopt.now.presentation.User + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.sopt.now.databinding.ItemUserBinding + +class UserAdapter() : RecyclerView.Adapter() { + private var userList: List = emptyList() + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder { + val binding = ItemUserBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return UserViewHolder(binding) + } + + override fun onBindViewHolder(holder: UserViewHolder, position: Int) { + val userData = userList[position] +// holder.bind(userData) + } + + override fun getItemCount(): Int { + return userList.size + } + + fun setUserList(userList: List) { + this.userList = userList.toList() + notifyDataSetChanged() + } + + class UserViewHolder(private val binding: ItemUserBinding) : + RecyclerView.ViewHolder(binding.root) { + + fun bind(userData: UserDataInput) { + binding.run { + tvName.text = userData.userNickName + tvSelfDescription.text = "34기 YB 주효은입니다!!!" + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/presentation/User/UserData.kt b/app/src/main/java/com/sopt/now/presentation/User/UserData.kt new file mode 100644 index 0000000..da3a280 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/User/UserData.kt @@ -0,0 +1,10 @@ +package com.sopt.now.presentation.User + +import androidx.annotation.DrawableRes + +data class UserData( + @DrawableRes val profileImage: Int, + val name: String, + val selfDescription: String, + + ) diff --git a/app/src/main/java/com/sopt/now/presentation/User/UserDataInput.kt b/app/src/main/java/com/sopt/now/presentation/User/UserDataInput.kt new file mode 100644 index 0000000..ec1f2fe --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/User/UserDataInput.kt @@ -0,0 +1,20 @@ +package com.sopt.now.presentation.User + +import android.os.Parcelable +import android.provider.ContactsContract.CommonDataKinds.Nickname +import android.provider.ContactsContract.CommonDataKinds.Phone +import android.security.identity.AccessControlProfileId +import kotlinx.parcelize.Parcelize +import java.net.Authenticator +import java.sql.Struct + + +@Parcelize +data class UserDataInput( + val userId: String, + val userPW: String, + val userNickName: String, + val userMbti: String, +) : Parcelable { + +} \ No newline at end of file From b1fd2308a45086b060330514fae0503305218f6f Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 24 May 2024 22:04:18 +0900 Subject: [PATCH 12/25] =?UTF-8?q?[CHORE]=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../now/presentation/Home/SearchFragment.kt | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/sopt/now/presentation/Home/SearchFragment.kt diff --git a/app/build.gradle b/app/build.gradle index d034de9..47b4a50 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -71,5 +71,5 @@ dependencies { // define any required OkHttp artifacts without version implementation("com.squareup.okhttp3:okhttp") implementation("com.squareup.okhttp3:logging-interceptor") - + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9") } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/presentation/Home/SearchFragment.kt b/app/src/main/java/com/sopt/now/presentation/Home/SearchFragment.kt new file mode 100644 index 0000000..46f8696 --- /dev/null +++ b/app/src/main/java/com/sopt/now/presentation/Home/SearchFragment.kt @@ -0,0 +1,20 @@ +package com.sopt.now.presentation.Home + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import com.sopt.now.R + +class SearchFragment : Fragment() { + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_search, container, false) + } + +} From d5b0160abd1a4ac9709d57334ada50f969c9b0d1 Mon Sep 17 00:00:00 2001 From: Hyoeun <137873124+hyoeunjoo@users.noreply.github.com> Date: Fri, 31 May 2024 01:06:42 +0900 Subject: [PATCH 13/25] =?UTF-8?q?[CHORE]=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 6 +- app/src/main/java/com/sopt/now/Test.kt | 121 ++++++++++++++++++ .../java/com/sopt/now/data/AuthRepoImpl.kt | 8 +- .../com/sopt/now/domain/model/AuthData.kt | 2 +- .../now/presentation/Login/LoginActivity.kt | 6 +- .../now/presentation/Login/LoginViewModel.kt | 4 +- .../sopt/now/presentation/SignUpActivity.kt | 6 +- .../sopt/now/presentation/SignUpViewModel.kt | 6 +- app/src/main/res/layout/activity_test.xml | 13 ++ 10 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/sopt/now/Test.kt create mode 100644 app/src/main/res/layout/activity_test.xml diff --git a/app/build.gradle b/app/build.gradle index 47b4a50..0ee8a97 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -72,4 +72,6 @@ dependencies { implementation("com.squareup.okhttp3:okhttp") implementation("com.squareup.okhttp3:logging-interceptor") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9") + + implementation 'com.google.android.gms:play-services-location:21.2.0' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bfe69bf..9d8d085 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + + + + diff --git a/app/src/main/java/com/sopt/now/Test.kt b/app/src/main/java/com/sopt/now/Test.kt new file mode 100644 index 0000000..85097ff --- /dev/null +++ b/app/src/main/java/com/sopt/now/Test.kt @@ -0,0 +1,121 @@ +//package com.sopt.now +// +//import android.content.pm.PackageManager +//import android.location.Location +//import android.os.Bundle +//import android.os.PersistableBundle +//import android.widget.Toast +//import androidx.activity.result.ActivityResultLauncher +//import androidx.activity.result.contract.ActivityResultContracts +//import androidx.appcompat.app.AlertDialog +//import androidx.appcompat.app.AppCompatActivity +//import androidx.core.app.ActivityCompat +//import androidx.core.content.ContextCompat +//import com.google.android.gms.location.FusedLocationProviderClient +//import com.google.android.gms.location.LocationServices +//import com.sopt.now.databinding.ActivityLoginBinding +//import com.sopt.now.databinding.ActivityTestBinding +// +////class TestActivity : AppCompatActivity(){ +//// private lateinit var binding: ActivityTestBinding +//// +//// override fun onCreate(savedInstanceState: Bundle?) { +//// super.onCreate(savedInstanceState) +//// binding = ActivityTestBinding.inflate(layoutInflater) +//// setContentView(binding.root) +//// } +////} +// +//class TestActivity : AppCompatActivity() { +// +// private lateinit var binding: ActivityTestBinding +// private lateinit var fusedLocationClient: FusedLocationProviderClient +// private lateinit var requestPermissionLauncher: ActivityResultLauncher +// +// override fun onCreate(savedInstanceState: Bundle?) { +// super.onCreate(savedInstanceState) +// binding = ActivityTestBinding.inflate(layoutInflater) +// setContentView(binding.root) +// +// // 위치 제공자 초기화 +// fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) +// +// // 권한 요청 런처 초기화 +// requestPermissionLauncher = +// registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean -> +// if (isGranted) { +// // 권한이 허용된 경우 위치 정보 가져오기 +// getLastKnownLocation() +// } else { +// // 권한이 거부된 경우 처리 +// showPermissionDeniedMessage() +// } +// } +// +// binding.getLocationButton.setOnClickListener { +// checkPermissionAndRequestLocation() +// } +// } +// +// private fun checkPermissionAndRequestLocation() { +// when { +// ContextCompat.checkSelfPermission( +// this, +// android.Manifest.permission.ACCESS_FINE_LOCATION +// ) == PackageManager.PERMISSION_GRANTED -> { +// // 권한이 이미 허용된 경우 +// getLastKnownLocation() +// } +// +// ActivityCompat.shouldShowRequestPermissionRationale( +// this, +// android.Manifest.permission.ACCESS_FINE_LOCATION +// ) -> { +// // 권한 요청 이유 설명이 필요한 경우 +// showRationaleDialog() +// } +// +// else -> { +// // 권한 요청 +// requestPermissionLauncher.launch(android.Manifest.permission.ACCESS_FINE_LOCATION) +// } +// } +// } +// +// private fun getLastKnownLocation() { +// if (ActivityCompat.checkSelfPermission( +// this, +// android.Manifest.permission.ACCESS_FINE_LOCATION +// ) == PackageManager.PERMISSION_GRANTED +// ) { +// fusedLocationClient.lastLocation +// .addOnSuccessListener { location: Location? -> +// // 위치 정보를 성공적으로 가져온 경우 +// if (location != null) { +// binding.locationTextView.text = +// "위도: ${location.latitude}, 경도: ${location.longitude}" +// } else { +// binding.locationTextView.text = "위치 정보를 가져올 수 없습니다." +// } +// } +// } +// } +// +// private fun showRationaleDialog() { +// // 권한 요청 이유를 사용자에게 설명하는 다이얼로그 등을 표시 +// // 예시: AlertDialog를 사용하여 권한 요청 이유 설명 +// AlertDialog.Builder(this) +// .setTitle("권한 필요") +// .setMessage("위치 정보를 가져오려면 위치 접근 권한이 필요합니다.") +// .setPositiveButton("확인") { _, _ -> +// requestPermissionLauncher.launch(android.Manifest.permission.ACCESS_FINE_LOCATION) +// } +// .setNegativeButton("취소", null) +// .show() +// } +// +// private fun showPermissionDeniedMessage() { +// // 권한 거부 시 사용자에게 표시할 메시지 +// Toast.makeText(this, "권한이 거부되었습니다. 위치 정보를 가져올 수 없습니다.", Toast.LENGTH_SHORT).show() +// } +//} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt b/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt index 7ea609e..b6c6691 100644 --- a/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt +++ b/app/src/main/java/com/sopt/now/data/AuthRepoImpl.kt @@ -4,13 +4,13 @@ import com.sopt.now.data.api.AuthService import com.sopt.now.data.dto.LoginDto.RequestLogInDto import com.sopt.now.data.dto.SignUp.RequestSignUpDto import com.sopt.now.domain.AuthRepository -import com.sopt.now.domain.model.AuthData +import com.sopt.now.domain.model.AuthEntity import retrofit2.Response class AuthRepoImpl( private val authService: AuthService, ) : AuthRepository { - override suspend fun logIn(authData: AuthData): Result> = runCatching { + override suspend fun logIn(authData: AuthEntity): Result> = runCatching { authService.logIn( request = RequestLogInDto( authenticationId = authData.id, @@ -18,7 +18,7 @@ class AuthRepoImpl( ) ) } - override suspend fun signUp(authData: AuthData): Result> = runCatching { + override suspend fun signUp(authData: AuthEntity): Result> = runCatching { authService.signUp( RequestSignUpDto( authenticationId = authData.id, @@ -28,6 +28,4 @@ class AuthRepoImpl( ) ) } - - } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/domain/model/AuthData.kt b/app/src/main/java/com/sopt/now/domain/model/AuthData.kt index 8eff2b9..7516d50 100644 --- a/app/src/main/java/com/sopt/now/domain/model/AuthData.kt +++ b/app/src/main/java/com/sopt/now/domain/model/AuthData.kt @@ -2,7 +2,7 @@ package com.sopt.now.domain.model import android.provider.ContactsContract.CommonDataKinds.Phone -data class AuthData( +data class AuthEntity( val id: String, val pw: String, val name: String? = null, diff --git a/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt b/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt index ccf6359..29e08fb 100644 --- a/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt +++ b/app/src/main/java/com/sopt/now/presentation/Login/LoginActivity.kt @@ -7,7 +7,7 @@ import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import com.sopt.now.databinding.ActivityLoginBinding -import com.sopt.now.domain.model.AuthData +import com.sopt.now.domain.model.AuthEntity import com.sopt.now.presentation.MainActivity import com.sopt.now.presentation.SignUpActivity @@ -53,10 +53,10 @@ class LoginActivity : AppCompatActivity() { }) } - private fun getLoginData(): AuthData { + private fun getLoginData(): AuthEntity { val id = binding.etId.text.toString() val password = binding.pw2.text.toString() - return AuthData( + return AuthEntity( id = id, pw = password ) diff --git a/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt b/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt index 677d513..c576bef 100644 --- a/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt +++ b/app/src/main/java/com/sopt/now/presentation/Login/LoginViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.sopt.now.domain.AuthRepository -import com.sopt.now.domain.model.AuthData +import com.sopt.now.domain.model.AuthEntity import kotlinx.coroutines.launch import retrofit2.HttpException @@ -15,7 +15,7 @@ class LoginViewModel( val loginResult: MutableLiveData = MutableLiveData() val errorMessage: MutableLiveData = MutableLiveData() val userId: MutableLiveData = MutableLiveData() - fun logIn(authData: AuthData) { + fun logIn(authData: AuthEntity) { viewModelScope.launch{ authRepository.logIn(authData) .onSuccess { response -> diff --git a/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt b/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt index b07fa39..d0df3e8 100644 --- a/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt +++ b/app/src/main/java/com/sopt/now/presentation/SignUpActivity.kt @@ -8,7 +8,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import com.sopt.now.R import com.sopt.now.databinding.ActivitySignupBinding -import com.sopt.now.domain.model.AuthData +import com.sopt.now.domain.model.AuthEntity import com.sopt.now.presentation.Login.LoginActivity import com.sopt.now.presentation.User.SignUpViewModelFactory @@ -54,12 +54,12 @@ class SignUpActivity : AppCompatActivity() { }) } - private fun getSignUpData(): AuthData { + private fun getSignUpData(): AuthEntity { val id = binding.etIdSignup.text.toString() val password = binding.etPwSignup.text.toString() val nickname = binding.etNicknameSignup.text.toString() val phoneNumber = binding.etMbtiSignup.text.toString() - return AuthData( + return AuthEntity( id = id, pw = password, name = nickname, diff --git a/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt b/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt index f37bda0..092ba22 100644 --- a/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt +++ b/app/src/main/java/com/sopt/now/presentation/SignUpViewModel.kt @@ -4,12 +4,10 @@ package com.sopt.now.presentation import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.google.gson.JsonObject import com.sopt.now.domain.AuthRepository -import com.sopt.now.domain.model.AuthData +import com.sopt.now.domain.model.AuthEntity import kotlinx.coroutines.launch import org.json.JSONObject -import retrofit2.HttpException class SignUpViewModel( @@ -18,7 +16,7 @@ class SignUpViewModel( val signUpResult: MutableLiveData = MutableLiveData() val errorMessage: MutableLiveData = MutableLiveData() val userId: MutableLiveData = MutableLiveData() - fun signUp(authData: AuthData) { + fun signUp(authData: AuthEntity) { viewModelScope.launch { runCatching { authRepository.signUp(authData) diff --git a/app/src/main/res/layout/activity_test.xml b/app/src/main/res/layout/activity_test.xml new file mode 100644 index 0000000..ec0dc44 --- /dev/null +++ b/app/src/main/res/layout/activity_test.xml @@ -0,0 +1,13 @@ + + + +