From af1a54069a4e086ecebaeb5e6d747b1f2c0bc93d Mon Sep 17 00:00:00 2001 From: otcroz Date: Tue, 13 Sep 2022 21:55:38 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B0=95=EC=95=84=EC=A7=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SHAPEUP2022/.idea/gradle.xml | 1 - SHAPEUP2022/.idea/misc.xml | 3 ++ .../shape_up_2022/auth/LoginActivity.kt | 10 ++--- .../shape_up_2022/common/MainActivity.kt | 37 +++++++++++++++++- .../common/SimulationActivity.kt | 38 ++++++++++++++++++- .../data/GlobalVariableMamage.kt | 7 ++++ .../shape_up_2022/retrofit/MyApplication.kt | 9 +++++ .../retrofit/NetworkServicePet.kt | 19 ++++++++++ .../src/main/res/layout/simulation_main.xml | 1 + 9 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/data/GlobalVariableMamage.kt create mode 100644 SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServicePet.kt diff --git a/SHAPEUP2022/.idea/gradle.xml b/SHAPEUP2022/.idea/gradle.xml index 526b4c2..a2d7c21 100644 --- a/SHAPEUP2022/.idea/gradle.xml +++ b/SHAPEUP2022/.idea/gradle.xml @@ -13,7 +13,6 @@ - diff --git a/SHAPEUP2022/.idea/misc.xml b/SHAPEUP2022/.idea/misc.xml index c3f3bf8..f3883f3 100644 --- a/SHAPEUP2022/.idea/misc.xml +++ b/SHAPEUP2022/.idea/misc.xml @@ -162,8 +162,11 @@ + + + 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 2585c9a..b2e55fb 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 @@ -62,11 +62,6 @@ class LoginActivity : AppCompatActivity() { callGetPetID(response.body()!!.familyID!!) } - // 메인 페이지로 이동 - val intent = Intent(baseContext, MainActivity::class.java) - startActivity(intent) - finish() - } else { // 로그인 실패 or null Toast.makeText(baseContext, "아이디 또는 비밀번호를 확인해주세요.", Toast.LENGTH_SHORT).show() } @@ -95,6 +90,11 @@ class LoginActivity : AppCompatActivity() { Log.d("mobileApp", "$response ${response.body()}") if(response.body()!!.success){ SaveSharedPreference.setPetID(baseContext, response.body()!!.petID) + + // 메인 페이지로 이동 + val intent = Intent(baseContext, MainActivity::class.java) + startActivity(intent) + finish() } } diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MainActivity.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MainActivity.kt index b65089f..55752bd 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MainActivity.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/MainActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import android.util.Log import android.view.View +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment @@ -14,9 +15,15 @@ import com.example.shape_up_2022.* import com.example.shape_up_2022.achieve.AchieveActivity import com.example.shape_up_2022.databinding.ActivityYoutubeBinding import com.example.shape_up_2022.databinding.MainPageBinding +import com.example.shape_up_2022.retrofit.GetPetIDRes +import com.example.shape_up_2022.retrofit.GetPetInfoRes +import com.example.shape_up_2022.retrofit.MyApplication import com.example.shape_up_2022.simulation.TestActivity import com.example.shape_up_2022.todo.MainCalenderFragment import com.example.shape_up_2022.todo.TodoActivity +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response class MainActivity : AppCompatActivity() { @@ -28,7 +35,7 @@ class MainActivity : AppCompatActivity() { val bindingYouTube = ActivityYoutubeBinding.inflate(layoutInflater) // 강아지 현재 상태, 정보 - + getPetInfo() // 프래그먼트 연결 - 캘린더 프래그먼트 viewFragment(MainCalenderFragment() , R.id.fragment_calender) @@ -132,4 +139,32 @@ class MainActivity : AppCompatActivity() { transaction.add(location, fragment) transaction.commit() } + + /* 강아지 정보 업데이트 */ + private fun getPetInfo(){ + val petID = SaveSharedPreference.getPetID(this)!! + Log.d("mobileApp", "$petID") + + val call: Call = MyApplication.networkServicePet.getPetInfo( + petID = petID + ) + + call?.enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if(response.isSuccessful){ + Log.d("mobileApp", "$response ${response.body()}") + if(response.body()!!.success){ + // 강아지 이름 업데이트 + binding.puppyProfileName.text = response.body()?.petInfo?.name + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.d("mobileApp", "onFailure $t") + Toast.makeText(baseContext, "네트워크 오류 발생", Toast.LENGTH_SHORT).show() + } + }) + } + } \ No newline at end of file diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SimulationActivity.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SimulationActivity.kt index 020eb23..f54389a 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SimulationActivity.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SimulationActivity.kt @@ -4,13 +4,20 @@ import android.content.DialogInterface import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.util.Log import android.view.View +import android.widget.Toast import androidx.appcompat.app.AlertDialog import com.example.shape_up_2022.R import com.example.shape_up_2022.achieve.AchieveActivity import com.example.shape_up_2022.databinding.SimulationMainBinding +import com.example.shape_up_2022.retrofit.GetPetInfoRes +import com.example.shape_up_2022.retrofit.MyApplication import com.example.shape_up_2022.simulation.* import com.example.shape_up_2022.todo.TodoActivity +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response class SimulationActivity : AppCompatActivity() { lateinit var binding: SimulationMainBinding @@ -31,8 +38,10 @@ class SimulationActivity : AppCompatActivity() { setContentView(binding.root) - // 실내/외출 모드 전환 + // 강아지 정보 + getPetInfo() + // 실내/외출 모드 전환 binding.btnout.setOnClickListener { binding.btnout.visibility = View.INVISIBLE binding.indoor.visibility = View.INVISIBLE @@ -192,4 +201,31 @@ class SimulationActivity : AppCompatActivity() { } } } + + /* 강아지 정보 업데이트 */ + private fun getPetInfo(){ + val petID = SaveSharedPreference.getPetID(this)!! + Log.d("mobileApp", "$petID") + + val call: Call = MyApplication.networkServicePet.getPetInfo( + petID = petID + ) + + call?.enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if(response.isSuccessful){ + Log.d("mobileApp", "$response ${response.body()}") + if(response.body()!!.success){ + // 강아지 이름 업데이트 + binding.simMainPetName.text = response.body()?.petInfo?.name + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.d("mobileApp", "onFailure $t") + Toast.makeText(baseContext, "네트워크 오류 발생", Toast.LENGTH_SHORT).show() + } + }) + } } \ No newline at end of file diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/data/GlobalVariableMamage.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/data/GlobalVariableMamage.kt new file mode 100644 index 0000000..df771e7 --- /dev/null +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/data/GlobalVariableMamage.kt @@ -0,0 +1,7 @@ +package com.example.shape_up_2022.data + +class GlobalVariableMamage { + companion object{ + + } +} \ No newline at end of file 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 05b0b29..f098c74 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 @@ -62,6 +62,14 @@ class MyApplication: Application() { .addConverterFactory(GsonConverterFactory.create()) .build() + var networkServicePet: NetworkServicePet + val retrofitPet: Retrofit + get() = Retrofit.Builder() + .baseUrl(apiserver + "api/pet/") + .client(client) + .addConverterFactory(GsonConverterFactory.create()) + .build() + init{ networkServiceYoutube = retrofitYoutube.create(NetworkServiceYoutube::class.java) @@ -71,6 +79,7 @@ class MyApplication: Application() { networkServiceUsers = retrofitUsers.create(NetworkServiceUsers::class.java) // api/users/ networkServiceTodo = retrofitTodo.create(NetworkServiceTodo::class.java) // api/todo/ networkServiceFamily = retrofitFamily.create(NetworkServiceFamily::class.java) // api/family/ + networkServicePet = retrofitPet.create(NetworkServicePet::class.java) // api/pet } diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServicePet.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServicePet.kt new file mode 100644 index 0000000..95cf052 --- /dev/null +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServicePet.kt @@ -0,0 +1,19 @@ +package com.example.shape_up_2022.retrofit + +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Path + +interface NetworkServicePet { + @GET("getPet/{petID}") + fun getPetInfo( + @Path("petID") petID: String + ): Call + +} + +// req, res +data class GetPetInfoRes(val success : Boolean, val petInfo: PetInfo) + +// data class +data class PetInfo(val name: String , val sex: String, val weight: String, val height: String) \ No newline at end of file diff --git a/SHAPEUP2022/app/src/main/res/layout/simulation_main.xml b/SHAPEUP2022/app/src/main/res/layout/simulation_main.xml index ef87f23..3fd150e 100644 --- a/SHAPEUP2022/app/src/main/res/layout/simulation_main.xml +++ b/SHAPEUP2022/app/src/main/res/layout/simulation_main.xml @@ -74,6 +74,7 @@ app:layout_constraintTop_toTopOf="parent" />