From cc3f62bcf2f7965a44bd2164b46da97777e14556 Mon Sep 17 00:00:00 2001 From: SOOYEON YOO Date: Wed, 17 Aug 2022 05:51:03 +0900 Subject: [PATCH] =?UTF-8?q?#31=20=EA=B0=80=EC=A1=B1=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1,=20=EA=B0=80=EC=A1=B1=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=20=EC=B0=B8=EC=97=AC=20=EB=9D=BC=EC=9A=B0=ED=84=B0=20?= =?UTF-8?q?=EC=9E=91=EC=97=85=20(#78)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/deploymentTargetDropDown.xml | 17 +++ SHAPEUP2022/.idea/misc.xml | 1 + .../shape_up_2022/auth/LoginActivity.kt | 1 + .../shape_up_2022/common/MyPageActivity.kt | 110 +++++++++++++++++- .../shape_up_2022/retrofit/MyApplication.kt | 3 +- .../retrofit/NetworkServiceAuth.kt | 6 +- .../res/layout/mypage_dialog_join_family.xml | 26 +++++ 7 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 SHAPEUP2022/.idea/deploymentTargetDropDown.xml create mode 100644 SHAPEUP2022/app/src/main/res/layout/mypage_dialog_join_family.xml diff --git a/SHAPEUP2022/.idea/deploymentTargetDropDown.xml b/SHAPEUP2022/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..071148b --- /dev/null +++ b/SHAPEUP2022/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SHAPEUP2022/.idea/misc.xml b/SHAPEUP2022/.idea/misc.xml index af4c588..4ba6552 100644 --- a/SHAPEUP2022/.idea/misc.xml +++ b/SHAPEUP2022/.idea/misc.xml @@ -75,6 +75,7 @@ + diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/auth/LoginActivity.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/auth/LoginActivity.kt index 5a12989..58d54bd 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/auth/LoginActivity.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/auth/LoginActivity.kt @@ -50,6 +50,7 @@ class LoginActivity : AppCompatActivity() { // 프리퍼런스에 값 저장 SaveSharedPreference.setUserEmail(baseContext, inputID) SaveSharedPreference.setUserName(baseContext, response.body()!!.userName) + SaveSharedPreference.setUserID(baseContext, response.body()!!.userID) // 메인 페이지로 이동 val intent = Intent(baseContext, MainActivity::class.java) diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MyPageActivity.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MyPageActivity.kt index 9170848..debb2bd 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MyPageActivity.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MyPageActivity.kt @@ -1,24 +1,28 @@ package com.example.shape_up_2022.common +import android.content.DialogInterface import android.content.Intent import android.graphics.BitmapFactory import android.net.Uri -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.provider.MediaStore import android.util.Log import android.view.View +import android.view.ViewGroup import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity import com.example.shape_up_2022.achieve.AchieveActivity import com.example.shape_up_2022.databinding.ActivityMyPageBinding -import com.example.shape_up_2022.retrofit.LogoutRes -import com.example.shape_up_2022.retrofit.MyApplication +import com.example.shape_up_2022.databinding.MypageDialogJoinFamilyBinding +import com.example.shape_up_2022.retrofit.* import com.example.shape_up_2022.todo.TodoActivity +import com.google.android.material.datepicker.MaterialDatePicker.Builder.datePicker import retrofit2.Call import retrofit2.Callback import retrofit2.Response -import java.lang.Exception + class MyPageActivity : AppCompatActivity() { @@ -99,6 +103,104 @@ class MyPageActivity : AppCompatActivity() { }) } + val eventhandler_save = object : DialogInterface.OnClickListener { + override fun onClick(p0: DialogInterface?, p1: Int) { + if(p1== DialogInterface.BUTTON_POSITIVE) { + // retorfit 요청 + Log.d("mobileApp", "${SaveSharedPreference.getUserID(baseContext)}") + val reqUserID = SaveSharedPreference.getUserID(baseContext)!! + val call: Call = MyApplication.networkServiceAuth.addFamliy( + AddFamilyReq(reqUserID) + ) + + call?.enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if(response.isSuccessful){ + Log.d("mobileApp", "$response ${response.body()}") + // 프리퍼런스에 값 저장 + SaveSharedPreference.setFamliyID(baseContext, response.body()!!.familyID) + + // UI 변경하기 + binding.noFamFamilyBtns.visibility = View.GONE + binding.mypageFamilyList.visibility = View.VISIBLE + + // 토스트 출력하기 + Toast.makeText(baseContext, "그룹 생성에 성공하셨습니다!", Toast.LENGTH_SHORT).show() + + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.d("mobileApp", "onFailure $t") + Toast.makeText(baseContext, "그룹 생성에 실패했습니다.", Toast.LENGTH_SHORT).show() + } + }) + } + } + } + val dialogBinding = MypageDialogJoinFamilyBinding.inflate(layoutInflater) + val eventhandler_join = object : DialogInterface.OnClickListener { + override fun onClick(p0: DialogInterface?, p1: Int) { + if(p1== DialogInterface.BUTTON_POSITIVE) { + // retorfit 요청 + val call: Call = MyApplication.networkServiceAuth.joinFamliy( + JoinFamilyReq(dialogBinding.dialogInputFamilycode.text.toString(), SaveSharedPreference.getUserEmail(baseContext)!!) + ) + // retrofit 요청 + call?.enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if(response.isSuccessful){ + Log.d("mobileApp", "$response ${response.body()}") + // 프리퍼런스에 값 저장 + SaveSharedPreference.setFamliyID(baseContext, response.body()!!.familyID) + + // UI 변경하기 + binding.noFamFamilyBtns.visibility = View.GONE + binding.mypageFamilyList.visibility = View.VISIBLE + + // 토스트 출력하기 + Toast.makeText(baseContext, "그룹 참여에 성공하셨습니다!", Toast.LENGTH_SHORT).show() + + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.d("mobileApp", "onFailure $t") + Toast.makeText(baseContext, "그룹 참여에 실패했습니다.", Toast.LENGTH_SHORT).show() + } + }) + } + } + } + + + var builder_save = AlertDialog.Builder(this) + .setTitle("가족 그룹 생성") + .setMessage("가족 그룹을 생성하시겠습니까?") + .setPositiveButton("네!", eventhandler_save) + .setNegativeButton("아니오", null) + .setCancelable(true) + + var builder_join = AlertDialog.Builder(this) + .setTitle("가족 그룹 가입") + .setView(dialogBinding.root) + .setPositiveButton("가입하기", eventhandler_join) + .setCancelable(true) + + // 가족 그룹 생성 + binding.mypageSavefam.setOnClickListener { + builder_save.show() + } + + // 가족 그룹 참여 + binding.mypageJoinfam.setOnClickListener { + if (dialogBinding.root.parent != null) (dialogBinding.root.parent as ViewGroup).removeView( + dialogBinding.root + ) + builder_join.setView(dialogBinding.root) + builder_join.show() + } + // 탭바 연결 binding.navHome.setOnClickListener { val intent_home = Intent(this, MainActivity::class.java) diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/MyApplication.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/MyApplication.kt index 1010dab..11b35e6 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/MyApplication.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/MyApplication.kt @@ -23,7 +23,8 @@ class MyApplication: Application() { var networkServiceAuth: NetworkServiceAuth val retrofitAuth: Retrofit get() = Retrofit.Builder() - .baseUrl("http://192.168.219.108:5000/") + .baseUrl("http://192.168.219.104:5000/") + .client(client) .addConverterFactory(GsonConverterFactory.create()) .build() // "http://ec2-13-124-250-65.ap-northeast-2.compute.amazonaws.com:5000/" diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceAuth.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceAuth.kt index a65cc74..e12a962 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceAuth.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceAuth.kt @@ -39,15 +39,15 @@ data class RegisterReq(val name: String, val email: String, val password: String data class RegisterRes(val success: String) data class LoginReq(val email: String, val password: String) -data class LoginRes(val loginSuccess: String, val userId: String, val userName: String, val message: String) +data class LoginRes(val loginSuccess: String, val userID: String, val userName: String, val message: String) data class LogoutRes(val success: String, val err: String) data class AddFamilyReq(val userID: String) -data class AddFamilyRes(val success: String) +data class AddFamilyRes(val success: String, val message: String, val familyID: String) data class JoinFamilyReq(val familyCode: String, val email: String) -data class JoinFamilyRes(val success: String, val message: String) +data class JoinFamilyRes(val success: String, val message: String, val familyID: String) data class CompleteTestReq(val userID: String) data class CompleteTestRes(val success: String, val message: String) diff --git a/SHAPEUP2022/app/src/main/res/layout/mypage_dialog_join_family.xml b/SHAPEUP2022/app/src/main/res/layout/mypage_dialog_join_family.xml new file mode 100644 index 0000000..8033293 --- /dev/null +++ b/SHAPEUP2022/app/src/main/res/layout/mypage_dialog_join_family.xml @@ -0,0 +1,26 @@ + + + + + + + + \ No newline at end of file