Skip to content

Commit

Permalink
강아지 정보 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
otcroz committed Sep 13, 2022
1 parent 9933255 commit af1a540
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 8 deletions.
1 change: 0 additions & 1 deletion SHAPEUP2022/.idea/gradle.xml

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

3 changes: 3 additions & 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 @@ -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()
}
Expand Down Expand Up @@ -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()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -28,7 +35,7 @@ class MainActivity : AppCompatActivity() {
val bindingYouTube = ActivityYoutubeBinding.inflate(layoutInflater)

// 강아지 현재 상태, 정보

getPetInfo()

// 프래그먼트 연결 - 캘린더 프래그먼트
viewFragment(MainCalenderFragment() , R.id.fragment_calender)
Expand Down Expand Up @@ -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<GetPetInfoRes> = MyApplication.networkServicePet.getPetInfo(
petID = petID
)

call?.enqueue(object : Callback<GetPetInfoRes> {
override fun onResponse(call: Call<GetPetInfoRes>, response: Response<GetPetInfoRes>) {
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<GetPetInfoRes>, t: Throwable) {
Log.d("mobileApp", "onFailure $t")
Toast.makeText(baseContext, "네트워크 오류 발생", Toast.LENGTH_SHORT).show()
}
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,8 +38,10 @@ class SimulationActivity : AppCompatActivity() {

setContentView(binding.root)

// 실내/외출 모드 전환
// 강아지 정보
getPetInfo()

// 실내/외출 모드 전환
binding.btnout.setOnClickListener {
binding.btnout.visibility = View.INVISIBLE
binding.indoor.visibility = View.INVISIBLE
Expand Down Expand Up @@ -192,4 +201,31 @@ class SimulationActivity : AppCompatActivity() {
}
}
}

/* 강아지 정보 업데이트 */
private fun getPetInfo(){
val petID = SaveSharedPreference.getPetID(this)!!
Log.d("mobileApp", "$petID")

val call: Call<GetPetInfoRes> = MyApplication.networkServicePet.getPetInfo(
petID = petID
)

call?.enqueue(object : Callback<GetPetInfoRes> {
override fun onResponse(call: Call<GetPetInfoRes>, response: Response<GetPetInfoRes>) {
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<GetPetInfoRes>, t: Throwable) {
Log.d("mobileApp", "onFailure $t")
Toast.makeText(baseContext, "네트워크 오류 발생", Toast.LENGTH_SHORT).show()
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.shape_up_2022.data

class GlobalVariableMamage {
companion object{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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<GetPetInfoRes>

}

// 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)
1 change: 1 addition & 0 deletions SHAPEUP2022/app/src/main/res/layout/simulation_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/sim_main_pet_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down

0 comments on commit af1a540

Please sign in to comment.