diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 61a9130..fb7f4a8 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d5d35ec..860da66 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000..797acea
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 83fe0e8..312fc96 100644
--- a/README.md
+++ b/README.md
@@ -1,82 +1,152 @@
-#### 1. 구현방법
-- 2차 세미나에서 배운 내용을 바탕으로 FollowingRepo.kt, FollowingRepoAdapter.kt, FollowingRepoFragment.kt, RepoInfoActivity.kt 등의 파일들을
-만들어 코드를 작성하였다.
-- 먼저 부분 화면 Fragment를 만들어 ist로 구현해 화면으로 보여주기 위해 item_repo.xml을 만들어
+# ![마크업 이미지3](https://user-images.githubusercontent.com/80473521/118394517-1e93bd80-b680-11eb-9fb1-a14cb453e3ba.jpg) Seventh Seminar Assignment ![마크업 이미지3](https://user-images.githubusercontent.com/80473521/118394517-1e93bd80-b680-11eb-9fb1-a14cb453e3ba.jpg)
+
+
+## ![마크업 이미지1](https://user-images.githubusercontent.com/80473521/118394520-1fc4ea80-b680-11eb-9641-df4063f3f257.jpg) 자동 로그인 구현하기
+
+1) SignInActivity로 처음 들어왔을 때 SharedPreference에서 ID/PW가 있다면? 로그인 과정을 건너뛴다.
+2) 로그인할 때 성공하면 SharedPreference에 집어 넣는다.
+3) 서비스에서 로그아웃하면 SharedPreference를 clear한다.
+
+result => 위와 같은 과정으로 자동 로그인처럼 구현할 수 있다.
+
+### 1. Lv1-1 Activity에서 어떻게 처리했는지 정리
+< SignInActivity 코드 정리 >
```kotlin
-
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ searchUserAuthStorage()
+ loginButtonEvent()
+ signUpResult()
+ }
+ private fun searchUserAuthStorage() {
+ with(SoptUserAuthStorage.getInstance(this)) {
+ if (hasUserData()) {
+ requestLogin(getUserData().let { RequestLoginData(it.id, it.password) })
+ }
+ }
+ }
+
+ private fun loginButtonEvent() {
+ binding.button.setOnClickListener{
+ val requestLoginData = RequestLoginData(
+ id = binding.idedit.text.toString(),
+ password = binding.passedit.text.toString()
+ )
+ requestLogin(requestLoginData)
+ }
+ }
+ private fun signUpResult() {
+ binding.signup.setOnClickListener {
+ signUpActivityLauncher.launch(
+ Intent(this, SignUpActivity::class.java)
+ )
+ }
+ }
```
-이와 같은 3개의 TextView를 생성하였다. 레포지터리 이름과 레포지터리 설명이 너무 긴경우 ...이 나오도록
+- SignInActivity가 onCreate일 때 이전에 작성한 ID/PW가 있으면 바로 로그인 시키고 없으면 원래 과정으로 진행
+- 전의 세미나에서 만든 것 그대로
+'button' 버튼을 누르면 id, password 데이터를 전달,
+'signup' 텍스트를 누르면 SignUpActivity로 이동
+
```kotlin
-android:ellipsize="end"
+private fun requestLogin(requestLoginData: RequestLoginData) {
+ val call: Call = ServiceCreator.soptService
+ .postLogin(requestLoginData)
+ call.enqueueUtil(
+ onSuccess = { response ->
+ val data = response.data
+ showToast(data?.user_nickname.toString())
+ with(SoptUserAuthStorage.getInstance(this)) {
+ saveUserData(requestLoginData.let { SoptUserInfo(it.id, it.password) })
+ }
+ startHomeActivity()
+ }
+ )
+ }
```
-코드도 추가해주었다.
-* RecyclerView를 이용해 HomeActivity에 해당 Fragment를 보여주기 위해 fragment_following_repo.xml에
+- 확장함수를 이용하여 requestLogin 간단하게 구현
+
+< 코틀린 확장 함수>
+- ToastUtil.kt
```kotlin
-
+fun Context.showToast(msg: String) {
+ Toast.makeText(this, msg, Toast.LENGTH_SHORT)
+ .show()
+}
```
-위와 같은 코드를 작성하고 화면에 보여주기 위해 HomeActivity에
+- RetrofitEnqueueUtil.kt
```kotlin
-val repoFragment = FollowingRepoFragment()
- val manager = supportFragmentManager
- val transaction = manager.beginTransaction()
- transaction.replace(R.id.fragment_container,repoFragment)
- transaction.addToBackStack(null)
- transaction.commit()
+fun Call.enqueueUtil(
+ onSuccess: (ResponseType) -> Unit,
+ onError: ((stateCode: Int) -> Unit)? = null
+) {
+ this.enqueue(object : Callback {
+ override fun onResponse(call: Call, response: Response) {
+ if (response.isSuccessful) {
+ onSuccess.invoke(response.body() ?: return)
+ } else {
+ onError?.invoke(response.code())
+ }
+ }
+
+ override fun onFailure(call: Call, t: Throwable) {
+ Log.d("NetworkTest", "error:$t")
+ }
+ })
+}
```
-위와 같은 코드를 추가해주었다. 이 코드를 통해 Fragment가 HomeActivity의 화면에 뜨게 된다.
-* HomeActivity화면에 MORE 버튼을 추가하여 2차 세미나 시간에 만든 Fragment를 가진 Activity를 띄워주기 위해 먼저
+### 2. Lv1-2 SharedPreference 어떻게 코드를 정리했는지 코드 첨부
+- SharedPreference를 계속 만들면 비효율적이므로 object을 이용해 한 번만 만들기
```kotlin
-
+class SoptUserAuthStorage private constructor(context: Context) {
+ private val sharedPreferences = context.getSharedPreferences(
+ "${context.packageName}.$STORAGE_KEY",
+ Context.MODE_PRIVATE
+ )
-
-
-```
-activity_home.xml파일에 MORE button과 Fragment를 가진 Activity가 띄워질 위치 선정을 위해 LinearLayout을 생성했다.
-(앞서 직접 만든 레포지터리 이름, 설명 등의 Fragment를 가진 Activity도 해당 위치에 띄워질 수 있도록 위의 LinearLayout을 이용했다.)
-* 그리고 MORE button을 눌렀을 경우 2차 세미나에서 만든 Fragment를 가진 Activity가 띄워질 수 있도록
-```kotlin
-binding.btnMore.setOnClickListener(){
- val infoFragment = FollowingListFragment()
- val manager = supportFragmentManager
- val transaction = manager.beginTransaction()
- transaction.replace(R.id.fragment_container,infoFragment)
- transaction.addToBackStack(null)
- transaction.commit()
-```
-위와 같은 코드를 HomeActivity에 추가하였다.
+ private val editor = sharedPreferences.edit()
-![Screenshot_20210425-135256_Se1_hw](https://user-images.githubusercontent.com/80473521/115981424-99604000-a5ce-11eb-8ff4-1dabe69c326f.jpg)
-![Screenshot_20210425-135312_Se1_hw](https://user-images.githubusercontent.com/80473521/115981442-c57bc100-a5ce-11eb-94a5-64c47e17c7bd.jpg)
+ companion object {
+ private const val STORAGE_KEY = "user_auth"
+ private const val USER_ID_KEY = "user_id"
+ private const val USER_PW_KEY = "user_pw"
+
+ @Volatile
+ private var instance: SoptUserAuthStorage? = null
+
+ @JvmStatic
+ fun getInstance(context: Context) = instance ?: synchronized(this) {
+ instance ?: SoptUserAuthStorage(context).apply {
+ instance = this
+ }
+ }
+ }
+ fun getUserData(): SoptUserInfo = SoptUserInfo(
+ id = sharedPreferences.getString(USER_ID_KEY, "") ?: "",
+ password = sharedPreferences.getString(USER_PW_KEY, "") ?: ""
+ )
+ fun saveUserData(userData: SoptUserInfo) {
+ editor.putString(USER_ID_KEY, userData.id)
+ .putString(USER_PW_KEY, userData.password)
+ .apply()
+ }
+ fun hasUserData(): Boolean {
+ with(getUserData()) {
+ return id.isNotEmpty() && password.isNotEmpty()
+ }
+ }
+ fun clearAuthStorage() {
+ sharedPreferences.edit()
+ .clear()
+ .apply()
+ }
+}
+```
+### 3. 과제를 통해 배운 내용 or 개발자로 성장한 내용
+- 이번 과제를 하면서 처음 SharedPreference를 만들어보았습니다. 처음이라 굉장히 어렵다고 생각이 들었고 열심히 세미나 복습을 하면서 과제를 진행해나갔습니다.
+어려운 부분은 파트장님의 코드를 보면서 이렇게 만들 수 있구나 생각하고 배울 점은 코드에 반영해가며 과제를 해나간 것 같습니다.
+꽤 오랜 시간동안 세미나를 듣고 과제를 해나가면서 그 전보다 한층 더 성장할 수 있었다고 생각이 듭니다. sopt를 들어와 활동한 것은 제가 개발자로 성장할 수 있는 좋은 기회였다고 생각합니다.
+감사합니다!
diff --git a/app/build.gradle b/app/build.gradle
index 0ed6ab8..8f61000 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -47,4 +47,10 @@ dependencies {
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
+
+ implementation 'com.squareup.retrofit2:retrofit:2.9.0'
+
+ implementation 'com.google.code.gson:gson:2.8.6'
+
+ implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 71d88a3..bb70a4e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,23 +2,25 @@
+
-
-
-
+
+
+
-
+
-
+
diff --git a/app/src/main/java/com/example/se1_hw/SignInActivity.kt b/app/src/main/java/com/example/se1_hw/SignInActivity.kt
deleted file mode 100644
index aa4105c..0000000
--- a/app/src/main/java/com/example/se1_hw/SignInActivity.kt
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.example.se1_hw
-
-import android.app.Activity
-import android.content.Intent
-import androidx.appcompat.app.AppCompatActivity
-import android.os.Bundle
-import android.util.Log
-import android.widget.Toast
-import com.example.se1_hw.databinding.ActivityMainBinding
-
-class SignInActivity : AppCompatActivity() {
- private lateinit var binding:ActivityMainBinding
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- binding = ActivityMainBinding.inflate(layoutInflater)
- Log.d("onCreate", "onCreate(run)")
- setContentView(binding.root)
- initButtonClickEvent()
- initTextClickEvent()
- }
- private fun initButtonClickEvent() {
- binding.button.setOnClickListener{
- val userID = binding.idedit.text
- val userPWD = binding.passedit.text
- if (userID.isNullOrBlank() || userPWD.isNullOrBlank()) {
- Toast.makeText(
- this@SignInActivity,
- "아이디/비밀번호를 확인해주세요!",
- Toast.LENGTH_SHORT
- ).show()
- } else {
- val intent = Intent(this@SignInActivity, HomeActivity::class.java)
- startActivity(intent)
- Toast.makeText(
- this@SignInActivity,
- "로그인 성공",
- Toast.LENGTH_SHORT
- ).show()
- }
-
- }
- }
- private fun initTextClickEvent(){
- binding.signup.setOnClickListener{
- val intent = Intent(this@SignInActivity, SignUpActivity::class.java)
- startActivityForResult(intent,REQUEST_CODE)
- }
- }
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?){
- super.onActivityResult(requestCode, resultCode, data)
- if(requestCode == REQUEST_CODE){
- if(resultCode == Activity.RESULT_OK){
- binding.idedit.setText(data!!.getStringExtra("id"))
- binding.passedit.setText(data!!.getStringExtra("password"))
- }
- }
- }
-
- companion object{
- private const val REQUEST_CODE = 100
- }
-
- override fun onStart() {
- super.onStart()
- Log.d("onStart", "onStart(run)")
- }
- override fun onRestart() {
- super.onRestart()
- Log.d("onRestart", "onRestart(run)")
- }
- override fun onResume() {
- super.onResume()
- Log.d("onResume", "onResume(run)")
- }
- override fun onPause() {
- super.onPause()
- Log.d("onPause", "onPause(run)")
- }
- override fun onStop() {
- super.onStop()
- Log.d("onStop", "onStop(run)")
- }
- override fun onDestroy() {
- super.onDestroy()
- Log.d("onDestroy", "onDestroy(run)")
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/SignUpActivity.kt b/app/src/main/java/com/example/se1_hw/SignUpActivity.kt
deleted file mode 100644
index c0b18d9..0000000
--- a/app/src/main/java/com/example/se1_hw/SignUpActivity.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.example.se1_hw
-
-import android.app.Activity
-import android.content.Intent
-import androidx.appcompat.app.AppCompatActivity
-import android.os.Bundle
-import android.util.Log
-import android.widget.Toast
-import com.example.se1_hw.databinding.ActivitySignUpBinding
-
-class SignUpActivity : AppCompatActivity() {
- lateinit var binding: ActivitySignUpBinding
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- binding = ActivitySignUpBinding.inflate(layoutInflater)
- Log.d("onCreate", "onCreate(run)")
- setContentView(binding.root)
-
- initputResult()
-
- }
- private fun initputResult(){
- binding.btn.setOnClickListener{
- val userNAME = binding.nameEdit.text
- val userID = binding.idEdit.text
- val userPWD = binding.pwdEdit.text
-
- if (userNAME.isNullOrBlank() || userID.isNullOrBlank() || userPWD.isNullOrBlank()) {
- Toast.makeText(
- this@SignUpActivity,
- "빈 칸이 있는지 확인해주세요!",
- Toast.LENGTH_SHORT
- ).show()
- }else {
- val intent = Intent(this@SignUpActivity, SignInActivity::class.java)
- intent.putExtra("id", userID.toString())
- intent.putExtra("pwd", userPWD.toString())
- setResult(Activity.RESULT_OK, intent)
- finish()
- }
- }
- }
- override fun onStart() {
- super.onStart()
- Log.d("onStart", "onStart(run)")
- }
- override fun onRestart() {
- super.onRestart()
- Log.d("onRestart", "onRestart(run)")
- }
- override fun onResume() {
- super.onResume()
- Log.d("onResume", "onResume(run)")
- }
- override fun onPause() {
- super.onPause()
- Log.d("onPause", "onPause(run)")
- }
- override fun onStop() {
- super.onStop()
- Log.d("onStop", "onStop(run)")
- }
- override fun onDestroy() {
- super.onDestroy()
- Log.d("onDestroy", "onDestroy(run)")
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/api/ServiceCreator.kt b/app/src/main/java/com/example/se1_hw/api/ServiceCreator.kt
new file mode 100644
index 0000000..467e8bd
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/api/ServiceCreator.kt
@@ -0,0 +1,13 @@
+package com.example.se1_hw.api
+
+import retrofit2.Retrofit
+import retrofit2.converter.gson.GsonConverterFactory
+
+object ServiceCreator {
+ private const val BASE_URL = "http://cherishserver.com"
+
+ private val retrofit: Retrofit = Retrofit.Builder()
+ .baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build()
+
+ val soptService: SoptService = retrofit.create(SoptService::class.java)
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/api/SoptService.kt b/app/src/main/java/com/example/se1_hw/api/SoptService.kt
new file mode 100644
index 0000000..5ede9b3
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/api/SoptService.kt
@@ -0,0 +1,20 @@
+package com.example.se1_hw.api
+
+import com.example.se1_hw.data.request.RequestLoginData
+import com.example.se1_hw.data.request.RequestSignUpData
+import com.example.se1_hw.data.response.ResponseLoginData
+import com.example.se1_hw.data.response.ResponseSignUpData
+import retrofit2.Call
+import retrofit2.http.Body
+import retrofit2.http.POST
+
+interface SoptService {
+ @POST("/login/signin")
+ fun postLogin(
+ @Body body: RequestLoginData
+ ) : Call
+ @POST("/login/signup")
+ fun postSignUp(
+ @Body body: RequestSignUpData
+ ) : Call
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/data/SoptUserAuthStorage.kt b/app/src/main/java/com/example/se1_hw/data/SoptUserAuthStorage.kt
new file mode 100644
index 0000000..a0798e9
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/data/SoptUserAuthStorage.kt
@@ -0,0 +1,53 @@
+package com.example.se1_hw.data
+
+import android.content.Context
+import com.example.se1_hw.data.local.SoptUserInfo
+
+class SoptUserAuthStorage private constructor(context: Context) {
+
+ private val sharedPreferences = context.getSharedPreferences(
+ "${context.packageName}.$STORAGE_KEY",
+ Context.MODE_PRIVATE
+ )
+
+ private val editor = sharedPreferences.edit()
+
+ companion object {
+ private const val STORAGE_KEY = "user_auth"
+ private const val USER_ID_KEY = "user_id"
+ private const val USER_PW_KEY = "user_pw"
+
+ @Volatile
+ private var instance: SoptUserAuthStorage? = null
+
+ @JvmStatic
+ fun getInstance(context: Context) = instance ?: synchronized(this) {
+ instance ?: SoptUserAuthStorage(context).apply {
+ instance = this
+ }
+ }
+ }
+
+ fun getUserData(): SoptUserInfo = SoptUserInfo(
+ id = sharedPreferences.getString(USER_ID_KEY, "") ?: "",
+ password = sharedPreferences.getString(USER_PW_KEY, "") ?: ""
+ )
+
+ fun saveUserData(userData: SoptUserInfo) {
+ editor.putString(USER_ID_KEY, userData.id)
+ .putString(USER_PW_KEY, userData.password)
+ .apply()
+ }
+
+ fun hasUserData(): Boolean {
+ with(getUserData()) {
+ return id.isNotEmpty() && password.isNotEmpty()
+ }
+ }
+
+ fun clearAuthStorage() {
+ sharedPreferences.edit()
+ .clear()
+ .apply()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/FollowingRepo.kt b/app/src/main/java/com/example/se1_hw/data/following/FollowingRepo.kt
similarity index 72%
rename from app/src/main/java/com/example/se1_hw/FollowingRepo.kt
rename to app/src/main/java/com/example/se1_hw/data/following/FollowingRepo.kt
index 9b10991..a6a92c1 100644
--- a/app/src/main/java/com/example/se1_hw/FollowingRepo.kt
+++ b/app/src/main/java/com/example/se1_hw/data/following/FollowingRepo.kt
@@ -1,4 +1,4 @@
-package com.example.se1_hw
+package com.example.se1_hw.data.following
data class FollowingRepo(
val repotext1: String,
diff --git a/app/src/main/java/com/example/se1_hw/FollowingUserInfo.kt b/app/src/main/java/com/example/se1_hw/data/following/FollowingUserInfo.kt
similarity index 67%
rename from app/src/main/java/com/example/se1_hw/FollowingUserInfo.kt
rename to app/src/main/java/com/example/se1_hw/data/following/FollowingUserInfo.kt
index 71de0a8..8ae5e3b 100644
--- a/app/src/main/java/com/example/se1_hw/FollowingUserInfo.kt
+++ b/app/src/main/java/com/example/se1_hw/data/following/FollowingUserInfo.kt
@@ -1,4 +1,4 @@
-package com.example.se1_hw
+package com.example.se1_hw.data.following
data class FollowingUserInfo (
val userImage: String,
diff --git a/app/src/main/java/com/example/se1_hw/data/local/SoptUserInfo.kt b/app/src/main/java/com/example/se1_hw/data/local/SoptUserInfo.kt
new file mode 100644
index 0000000..8abbf5d
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/data/local/SoptUserInfo.kt
@@ -0,0 +1,7 @@
+package com.example.se1_hw.data.local
+
+import com.example.se1_hw.data.request.RequestLoginData
+data class SoptUserInfo(
+ val id: String,
+ val password: String
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/data/request/RequestLoginData.kt b/app/src/main/java/com/example/se1_hw/data/request/RequestLoginData.kt
new file mode 100644
index 0000000..dcc419d
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/data/request/RequestLoginData.kt
@@ -0,0 +1,9 @@
+package com.example.se1_hw.data.request
+
+import com.google.gson.annotations.SerializedName
+
+data class RequestLoginData (
+ @SerializedName("email")
+ val id: String,
+ val password: String
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/data/request/RequestSignUpData.kt b/app/src/main/java/com/example/se1_hw/data/request/RequestSignUpData.kt
new file mode 100644
index 0000000..104629f
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/data/request/RequestSignUpData.kt
@@ -0,0 +1,13 @@
+package com.example.se1_hw.data.request
+
+import com.google.gson.annotations.SerializedName
+
+data class RequestSignUpData(
+ @SerializedName("email")
+ val id: String,
+ val password: String,
+ val sex: String,
+ val nickname: String,
+ val phone: String,
+ val birth: String
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/data/response/ResponseLoginData.kt b/app/src/main/java/com/example/se1_hw/data/response/ResponseLoginData.kt
new file mode 100644
index 0000000..14313f4
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/data/response/ResponseLoginData.kt
@@ -0,0 +1,15 @@
+package com.example.se1_hw.data.response
+
+import com.google.gson.annotations.SerializedName
+
+data class ResponseLoginData(
+ val success: Boolean,
+ val message: String,
+ val data: LoginData?
+)
+data class LoginData(
+ @SerializedName("UserId")
+ val userId: Int,
+ val user_nickname: String,
+ val token: String
+)
diff --git a/app/src/main/java/com/example/se1_hw/data/response/ResponseSignUpData.kt b/app/src/main/java/com/example/se1_hw/data/response/ResponseSignUpData.kt
new file mode 100644
index 0000000..5860d08
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/data/response/ResponseSignUpData.kt
@@ -0,0 +1,11 @@
+package com.example.se1_hw.data.response
+
+data class ResponseSignUpData(
+ val success: Boolean,
+ val message: String,
+ val data: Data?
+){
+ data class Data(
+ val nickname: String
+ )
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/HomeActivity.kt b/app/src/main/java/com/example/se1_hw/ui/activity/HomeActivity.kt
similarity index 90%
rename from app/src/main/java/com/example/se1_hw/HomeActivity.kt
rename to app/src/main/java/com/example/se1_hw/ui/activity/HomeActivity.kt
index 5c165e3..9d79b75 100644
--- a/app/src/main/java/com/example/se1_hw/HomeActivity.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/activity/HomeActivity.kt
@@ -1,9 +1,12 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.activity
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
+import com.example.se1_hw.R
import com.example.se1_hw.databinding.ActivityHomeBinding
+import com.example.se1_hw.ui.fragment.FollowingListFragment
+import com.example.se1_hw.ui.fragment.FollowingRepoFragment
class HomeActivity : AppCompatActivity() {
lateinit var binding: ActivityHomeBinding
diff --git a/app/src/main/java/com/example/se1_hw/RepoInfoActivity.kt b/app/src/main/java/com/example/se1_hw/ui/activity/RepoInfoActivity.kt
similarity index 84%
rename from app/src/main/java/com/example/se1_hw/RepoInfoActivity.kt
rename to app/src/main/java/com/example/se1_hw/ui/activity/RepoInfoActivity.kt
index 0d22ae2..80fb354 100644
--- a/app/src/main/java/com/example/se1_hw/RepoInfoActivity.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/activity/RepoInfoActivity.kt
@@ -1,9 +1,10 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.activity
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
+import com.example.se1_hw.R
import com.example.se1_hw.databinding.ActivityRepoInfoBinding
-import com.example.se1_hw.databinding.ActivityUserInfoBinding
+import com.example.se1_hw.ui.fragment.FollowingRepoFragment
class RepoInfoActivity : AppCompatActivity() {
private lateinit var binding: ActivityRepoInfoBinding
diff --git a/app/src/main/java/com/example/se1_hw/ui/activity/SignInActivity.kt b/app/src/main/java/com/example/se1_hw/ui/activity/SignInActivity.kt
new file mode 100644
index 0000000..11230c4
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/ui/activity/SignInActivity.kt
@@ -0,0 +1,78 @@
+package com.example.se1_hw.ui.activity
+
+import android.app.Activity
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import androidx.activity.result.contract.ActivityResultContracts
+import com.example.se1_hw.api.ServiceCreator
+import com.example.se1_hw.data.SoptUserAuthStorage
+import com.example.se1_hw.data.local.SoptUserInfo
+import com.example.se1_hw.data.request.RequestLoginData
+import com.example.se1_hw.data.response.ResponseLoginData
+import com.example.se1_hw.databinding.ActivityMainBinding
+import com.example.se1_hw.utils.enqueueUtil
+import com.example.se1_hw.utils.showToast
+import retrofit2.Call
+
+class SignInActivity : AppCompatActivity() {
+ private lateinit var binding:ActivityMainBinding
+
+ private val signUpActivityLauncher = registerForActivityResult(
+ ActivityResultContracts.StartActivityForResult()
+ ){
+ binding.idedit.setText(it.data?.getStringExtra("ID"))
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ searchUserAuthStorage()
+ loginButtonEvent()
+ signUpResult()
+ }
+ private fun searchUserAuthStorage() {
+ with(SoptUserAuthStorage.getInstance(this)) {
+ if (hasUserData()) {
+ requestLogin(getUserData().let { RequestLoginData(it.id, it.password) })
+ }
+ }
+ }
+
+ private fun loginButtonEvent() {
+ binding.button.setOnClickListener{
+ val requestLoginData = RequestLoginData(
+ id = binding.idedit.text.toString(),
+ password = binding.passedit.text.toString()
+ )
+ requestLogin(requestLoginData)
+ }
+ }
+ private fun signUpResult() {
+ binding.signup.setOnClickListener {
+ signUpActivityLauncher.launch(
+ Intent(this, SignUpActivity::class.java)
+ )
+ }
+ }
+ private fun startHomeActivity(){
+ val intent = Intent(this, HomeActivity::class.java)
+ startActivity(intent)
+ }
+
+ private fun requestLogin(requestLoginData: RequestLoginData) {
+ val call: Call = ServiceCreator.soptService
+ .postLogin(requestLoginData)
+ call.enqueueUtil(
+ onSuccess = { response ->
+ val data = response.data
+ showToast(data?.user_nickname.toString())
+ with(SoptUserAuthStorage.getInstance(this)) {
+ saveUserData(requestLoginData.let { SoptUserInfo(it.id, it.password) })
+ }
+ startHomeActivity()
+ }
+ )
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/ui/activity/SignUpActivity.kt b/app/src/main/java/com/example/se1_hw/ui/activity/SignUpActivity.kt
new file mode 100644
index 0000000..304a441
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/ui/activity/SignUpActivity.kt
@@ -0,0 +1,103 @@
+package com.example.se1_hw.ui.activity
+
+import android.app.Activity
+import android.content.Intent
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.util.Log
+import android.widget.Toast
+import com.example.se1_hw.api.ServiceCreator
+import com.example.se1_hw.data.request.RequestLoginData
+import com.example.se1_hw.data.request.RequestSignUpData
+import com.example.se1_hw.data.response.ResponseLoginData
+import com.example.se1_hw.data.response.ResponseSignUpData
+import com.example.se1_hw.databinding.ActivitySignUpBinding
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
+
+class SignUpActivity : AppCompatActivity() {
+ lateinit var binding: ActivitySignUpBinding
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivitySignUpBinding.inflate(layoutInflater)
+ Log.d("onCreate", "onCreate(run)")
+ setContentView(binding.root)
+
+ initputResult()
+
+ }
+ private fun initputResult(){
+ binding.btn.setOnClickListener{
+ val requestSignUpData = RequestSignUpData(
+ id = binding.idEdit.text.toString(),
+ password = binding.pwdEdit.text.toString(),
+ nickname = binding.nameEdit.text.toString(),
+ sex = "0",
+ phone = "010-7940-2825",
+ birth = "1999-05-29"
+ )
+ val call: Call = ServiceCreator.soptService.postSignUp(requestSignUpData)
+ call.enqueue(object : Callback {
+ override fun onResponse(
+ call: Call,
+ response: Response
+ ){
+ if(response.isSuccessful){
+ Toast.makeText(this@SignUpActivity, "회원가입 성공", Toast.LENGTH_SHORT).show()
+ startLogin()
+ }else {
+ Toast.makeText(
+ this@SignUpActivity,
+ "다시 입력해주세요!",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+ override fun onFailure(call: Call, t:Throwable){
+ Log.d("NetworkTest", "error:$t")
+ }
+ })
+
+ }
+ }
+ private fun startLogin(){
+ val id = binding.idEdit.text.toString()
+ val password = binding.pwdEdit.text.toString()
+ val name = binding.nameEdit.text.toString()
+ if(id.isNullOrBlank() || password.isNullOrBlank() || name.isNullOrBlank()){
+ Toast.makeText(this@SignUpActivity, "빈 칸이 있는지 확인해주세요!", Toast.LENGTH_SHORT).show()
+ }
+ else {
+ val intent = Intent()
+ intent.putExtra("id", id).putExtra("password", password)
+ setResult(Activity.RESULT_OK, intent)
+ finish()
+ }
+ }
+ override fun onStart() {
+ super.onStart()
+ Log.d("onStart", "onStart(run)")
+ }
+ override fun onRestart() {
+ super.onRestart()
+ Log.d("onRestart", "onRestart(run)")
+ }
+ override fun onResume() {
+ super.onResume()
+ Log.d("onResume", "onResume(run)")
+ }
+ override fun onPause() {
+ super.onPause()
+ Log.d("onPause", "onPause(run)")
+ }
+ override fun onStop() {
+ super.onStop()
+ Log.d("onStop", "onStop(run)")
+ }
+ override fun onDestroy() {
+ super.onDestroy()
+ Log.d("onDestroy", "onDestroy(run)")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/UserInfoActivity.kt b/app/src/main/java/com/example/se1_hw/ui/activity/UserInfoActivity.kt
similarity index 84%
rename from app/src/main/java/com/example/se1_hw/UserInfoActivity.kt
rename to app/src/main/java/com/example/se1_hw/ui/activity/UserInfoActivity.kt
index e677c73..c88fdd2 100644
--- a/app/src/main/java/com/example/se1_hw/UserInfoActivity.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/activity/UserInfoActivity.kt
@@ -1,9 +1,10 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.activity
import android.os.Bundle
-import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
+import com.example.se1_hw.R
import com.example.se1_hw.databinding.ActivityUserInfoBinding
+import com.example.se1_hw.ui.fragment.FollowingListFragment
class UserInfoActivity:AppCompatActivity() {
private lateinit var binding: ActivityUserInfoBinding
diff --git a/app/src/main/java/com/example/se1_hw/FollowingListAdapter.kt b/app/src/main/java/com/example/se1_hw/ui/adapter/FollowingListAdapter.kt
similarity index 91%
rename from app/src/main/java/com/example/se1_hw/FollowingListAdapter.kt
rename to app/src/main/java/com/example/se1_hw/ui/adapter/FollowingListAdapter.kt
index c8d6c3f..2c0ee7e 100644
--- a/app/src/main/java/com/example/se1_hw/FollowingListAdapter.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/adapter/FollowingListAdapter.kt
@@ -1,8 +1,9 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
+import com.example.se1_hw.data.following.FollowingUserInfo
import com.example.se1_hw.databinding.ItemFollowUserBinding
class FollowingListAdapter : RecyclerView.Adapter() {
diff --git a/app/src/main/java/com/example/se1_hw/FollowingRepoAdapter.kt b/app/src/main/java/com/example/se1_hw/ui/adapter/FollowingRepoAdapter.kt
similarity index 92%
rename from app/src/main/java/com/example/se1_hw/FollowingRepoAdapter.kt
rename to app/src/main/java/com/example/se1_hw/ui/adapter/FollowingRepoAdapter.kt
index 02389a1..adce6c6 100644
--- a/app/src/main/java/com/example/se1_hw/FollowingRepoAdapter.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/adapter/FollowingRepoAdapter.kt
@@ -1,8 +1,9 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
+import com.example.se1_hw.data.following.FollowingRepo
import com.example.se1_hw.databinding.ItemRepoBinding
class FollowingRepoAdapter : RecyclerView.Adapter() {
diff --git a/app/src/main/java/com/example/se1_hw/FollowingListFragment.kt b/app/src/main/java/com/example/se1_hw/ui/fragment/FollowingListFragment.kt
similarity index 61%
rename from app/src/main/java/com/example/se1_hw/FollowingListFragment.kt
rename to app/src/main/java/com/example/se1_hw/ui/fragment/FollowingListFragment.kt
index d507a0e..f907733 100644
--- a/app/src/main/java/com/example/se1_hw/FollowingListFragment.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/fragment/FollowingListFragment.kt
@@ -1,11 +1,13 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
+import com.example.se1_hw.data.following.FollowingUserInfo
import com.example.se1_hw.databinding.FragmentFollowingListBinding
+import com.example.se1_hw.ui.adapter.FollowingListAdapter
class FollowingListFragment: Fragment() {
@@ -40,22 +42,22 @@ class FollowingListFragment: Fragment() {
followingListAdapter.userList.addAll(
listOf(
- FollowingUserInfo(
- userImage = "지금은 빈칸",
- userName = "cyj2825"
- ),
- FollowingUserInfo(
- userImage = "지금은 빈칸",
- userName = "1"
- ),
- FollowingUserInfo(
- userImage = "지금은 빈칸",
- userName = "2"
- ),
- FollowingUserInfo(
- userImage = "지금은 빈칸",
- userName = "3"
- )
+ FollowingUserInfo(
+ userImage = "지금은 빈칸",
+ userName = "cyj2825"
+ ),
+ FollowingUserInfo(
+ userImage = "지금은 빈칸",
+ userName = "1"
+ ),
+ FollowingUserInfo(
+ userImage = "지금은 빈칸",
+ userName = "2"
+ ),
+ FollowingUserInfo(
+ userImage = "지금은 빈칸",
+ userName = "3"
+ )
)
)
followingListAdapter.notifyDataSetChanged()
diff --git a/app/src/main/java/com/example/se1_hw/FollowingRepoFragment.kt b/app/src/main/java/com/example/se1_hw/ui/fragment/FollowingRepoFragment.kt
similarity index 54%
rename from app/src/main/java/com/example/se1_hw/FollowingRepoFragment.kt
rename to app/src/main/java/com/example/se1_hw/ui/fragment/FollowingRepoFragment.kt
index 49e09ed..9ee49e4 100644
--- a/app/src/main/java/com/example/se1_hw/FollowingRepoFragment.kt
+++ b/app/src/main/java/com/example/se1_hw/ui/fragment/FollowingRepoFragment.kt
@@ -1,12 +1,13 @@
-package com.example.se1_hw
+package com.example.se1_hw.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
-import com.example.se1_hw.databinding.FragmentFollowingListBinding
+import com.example.se1_hw.data.following.FollowingRepo
import com.example.se1_hw.databinding.FragmentFollowingRepoBinding
+import com.example.se1_hw.ui.adapter.FollowingRepoAdapter
class FollowingRepoFragment : Fragment() {
private var _binding:FragmentFollowingRepoBinding?=null
@@ -39,26 +40,26 @@ class FollowingRepoFragment : Fragment() {
followingRepoAdapter.repoList.addAll(
listOf(
- FollowingRepo(
- repotext1 = "레포지터리 이름",
- repotext2 = "레포지터리 설명",
- repotext3 = "언어"
- ),
- FollowingRepo(
- repotext1 = "레포지터리 이름",
- repotext2 = "레포지터리 설명",
- repotext3 = "언어"
- ),
- FollowingRepo(
- repotext1 = "지금은 빈칸~!",
- repotext2 = "레포지터리 설명1",
- repotext3 = "언어2"
- ),
- FollowingRepo(
- repotext1 = "지금은 빈칸!",
- repotext2 = "레포지터리 설명2",
- repotext3 = "언어2"
- )
+ FollowingRepo(
+ repotext1 = "레포지터리 이름",
+ repotext2 = "레포지터리 설명",
+ repotext3 = "언어"
+ ),
+ FollowingRepo(
+ repotext1 = "레포지터리 이름",
+ repotext2 = "레포지터리 설명",
+ repotext3 = "언어"
+ ),
+ FollowingRepo(
+ repotext1 = "지금은 빈칸~!",
+ repotext2 = "레포지터리 설명1",
+ repotext3 = "언어2"
+ ),
+ FollowingRepo(
+ repotext1 = "지금은 빈칸!",
+ repotext2 = "레포지터리 설명2",
+ repotext3 = "언어2"
+ )
)
)
followingRepoAdapter.notifyDataSetChanged()
diff --git a/app/src/main/java/com/example/se1_hw/utils/RetrofitEnqueueUtil.kt b/app/src/main/java/com/example/se1_hw/utils/RetrofitEnqueueUtil.kt
new file mode 100644
index 0000000..eb183f1
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/utils/RetrofitEnqueueUtil.kt
@@ -0,0 +1,25 @@
+package com.example.se1_hw.utils
+
+import android.util.Log
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
+
+fun Call.enqueueUtil(
+ onSuccess: (ResponseType) -> Unit,
+ onError: ((stateCode: Int) -> Unit)? = null
+) {
+ this.enqueue(object : Callback {
+ override fun onResponse(call: Call, response: Response) {
+ if (response.isSuccessful) {
+ onSuccess.invoke(response.body() ?: return)
+ } else {
+ onError?.invoke(response.code())
+ }
+ }
+
+ override fun onFailure(call: Call, t: Throwable) {
+ Log.d("NetworkTest", "error:$t")
+ }
+ })
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/se1_hw/utils/ToastUtil.kt b/app/src/main/java/com/example/se1_hw/utils/ToastUtil.kt
new file mode 100644
index 0000000..396fe7a
--- /dev/null
+++ b/app/src/main/java/com/example/se1_hw/utils/ToastUtil.kt
@@ -0,0 +1,10 @@
+package com.example.se1_hw.utils
+
+import android.content.Context
+import android.content.res.AssetManager
+import android.widget.Toast
+
+fun Context.showToast(msg: String) {
+ Toast.makeText(this, msg, Toast.LENGTH_SHORT)
+ .show()
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml
index 59bdac7..8c088db 100644
--- a/app/src/main/res/layout/activity_home.xml
+++ b/app/src/main/res/layout/activity_home.xml
@@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".HomeActivity">
+ tools:context=".ui.activity.HomeActivity">
+ tools:context=".ui.activity.SignInActivity">
+ tools:context=".ui.activity.RepoInfoActivity">
+ tools:context=".ui.activity.SignUpActivity">
+ tools:context=".ui.activity.UserInfoActivity">