Skip to content

Commit

Permalink
#31 가족 그룹 생성, 가족 그룹 참여 라우터 작업 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
otcroz authored Aug 16, 2022
1 parent 61f4ea7 commit cc3f62b
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 8 deletions.
17 changes: 17 additions & 0 deletions SHAPEUP2022/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions SHAPEUP2022/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {

Expand Down Expand Up @@ -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<AddFamilyRes> = MyApplication.networkServiceAuth.addFamliy(
AddFamilyReq(reqUserID)
)

call?.enqueue(object : Callback<AddFamilyRes> {
override fun onResponse(call: Call<AddFamilyRes>, response: Response<AddFamilyRes>) {
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<AddFamilyRes>, 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<JoinFamilyRes> = MyApplication.networkServiceAuth.joinFamliy(
JoinFamilyReq(dialogBinding.dialogInputFamilycode.text.toString(), SaveSharedPreference.getUserEmail(baseContext)!!)
)
// retrofit 요청
call?.enqueue(object : Callback<JoinFamilyRes> {
override fun onResponse(call: Call<JoinFamilyRes>, response: Response<JoinFamilyRes>) {
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<JoinFamilyRes>, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 26 additions & 0 deletions SHAPEUP2022/app/src/main/res/layout/mypage_dialog_join_family.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginHorizontal="16dp"
android:layout_height="match_parent">

<TextView
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
android:gravity="center_horizontal"
android:text="공유 코드를 입력해주세요." />

<EditText
android:id="@+id/dialog_input_familycode"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="30dp"
android:padding="10dp"
android:background="@drawable/corner_radius_all_subcolor2" />

</LinearLayout>

0 comments on commit cc3f62b

Please sign in to comment.