From 21fbf58374c5b0140480d5df2abf047db86e21ee Mon Sep 17 00:00:00 2001 From: otcroz Date: Wed, 14 Sep 2022 01:32:15 +0900 Subject: [PATCH] =?UTF-8?q?#19=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C?= =?UTF-8?q?=20achieve=20=EB=B0=B0=EC=97=B4=20=ED=94=84=EB=A6=AC=ED=8D=BC?= =?UTF-8?q?=EB=9F=B0=EC=8A=A4=20=EC=A0=80=EC=9E=A5,=20data=20class=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1,=20array.xml=EC=97=90=20=EC=97=85=EC=A0=81?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SHAPEUP2022/.idea/misc.xml | 5 ++ .../shape_up_2022/achieve/AchieveActivity.kt | 53 ++++++++++++++++--- .../shape_up_2022/achieve/AchieveFragment1.kt | 36 ++++++++++++- .../shape_up_2022/adapter/AchieveAdapter.kt | 3 +- .../adapter/AchieveProgressAdapter.kt | 28 ++++++++++ .../shape_up_2022/auth/LoginActivity.kt | 15 +++--- .../common/SaveSharedPreference.kt | 20 +++++++ .../shape_up_2022/retrofit/MyApplication.kt | 4 +- .../retrofit/NetworkServiceUsers.kt | 6 ++- .../main/res/layout/achieve_fragment_1.xml | 5 ++ .../src/main/res/layout/activity_achieve.xml | 8 ++- SHAPEUP2022/app/src/main/res/values/array.xml | 16 ++++++ 12 files changed, 173 insertions(+), 26 deletions(-) create mode 100644 SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveProgressAdapter.kt diff --git a/SHAPEUP2022/.idea/misc.xml b/SHAPEUP2022/.idea/misc.xml index f3883f3..693f068 100644 --- a/SHAPEUP2022/.idea/misc.xml +++ b/SHAPEUP2022/.idea/misc.xml @@ -158,13 +158,18 @@ + + + + + diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveActivity.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveActivity.kt index 9e4ada1..f78d206 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveActivity.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveActivity.kt @@ -4,6 +4,8 @@ import android.content.DialogInterface import android.content.Intent import com.example.shape_up_2022.adapter.AchieveAdapter import android.os.Bundle +import android.util.Log +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import com.example.shape_up_2022.* @@ -12,10 +14,15 @@ import com.example.shape_up_2022.common.MyPageActivity import com.example.shape_up_2022.common.SaveSharedPreference import com.example.shape_up_2022.databinding.ActivityAchieveBinding import com.example.shape_up_2022.common.SimulationActivity +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.TodoActivity import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response class AchieveActivity : AppCompatActivity() { @@ -40,7 +47,10 @@ class AchieveActivity : AppCompatActivity() { binding.pbAchieveTodo.progress = 50 } */ - + + /* 반려견 이름 업데이트 */ + getPetInfo() + binding.tabs.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{ override fun onTabSelected(tab: TabLayout.Tab?) { @@ -60,10 +70,9 @@ class AchieveActivity : AppCompatActivity() { TabLayoutMediator(binding.tabs, binding.achievePager) { tab,position-> when(position){ - 0->tab.text = "종합" - 1->tab.text = "진행도" - 2->tab.text = "성실도" - 3->tab.text = "호감도" + 0->tab.text = "진행도" + 1->tab.text = "성실도" + 2->tab.text = "호감도" } }.attach() @@ -103,7 +112,7 @@ class AchieveActivity : AppCompatActivity() { override fun onStart() { super.onStart() - + /* 가족 그룹에 가입되어 있지 않은 상태일 때 */ val eventHandler = object : DialogInterface.OnClickListener { override fun onClick(p0: DialogInterface?, p1: Int) { if(p1 == DialogInterface.BUTTON_POSITIVE) { @@ -120,8 +129,36 @@ class AchieveActivity : AppCompatActivity() { .setPositiveButton("확인", eventHandler) .setCancelable(false) - /* if(SaveSharedPreference.getFamliyID(this)!! == ""){ + + if(SaveSharedPreference.getFamliyID(this)!! == ""){ builder.show() - }*/ + } + } + + /* 강아지 정보 업데이트 */ + 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.achievePetName.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/achieve/AchieveFragment1.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveFragment1.kt index 5732103..8a410e5 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveFragment1.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/achieve/AchieveFragment1.kt @@ -5,7 +5,13 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.recyclerview.widget.LinearLayoutManager import com.example.shape_up_2022.R +import com.example.shape_up_2022.adapter.AchieveProgressAdapter +import com.example.shape_up_2022.common.SaveSharedPreference +import com.example.shape_up_2022.databinding.AchieveFragment1Binding +import com.example.shape_up_2022.simulation.SimWalkSearchAdapter // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER @@ -21,6 +27,7 @@ class AchieveFragment1 : Fragment() { // TODO: Rename and change types of parameters private var param1: String? = null private var param2: String? = null + lateinit var binding : AchieveFragment1Binding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -36,7 +43,12 @@ class AchieveFragment1 : Fragment() { savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment - return inflater.inflate(R.layout.achieve_fragment_1, container, false) + binding = AchieveFragment1Binding.inflate(inflater, container, false) + + // 리사이클러 뷰 + achieveList() + + return binding.root } companion object { @@ -58,4 +70,26 @@ class AchieveFragment1 : Fragment() { } } } + + /* 업적 리사이클러 뷰 */ + private fun achieveList(){ + val achieveAdapter = AchieveProgressAdapter(requireContext(), addAchieveList()) + binding.walkSearchRecyclerView.layoutManager = LinearLayoutManager(requireContext()) + binding.walkSearchRecyclerView.adapter = achieveAdapter // data array + } + + /* 업적 목록 추가 */ + data class AchieveProgress(val content: String, val checked: Boolean) + + private fun addAchieveList(): ArrayList{ + var data = arrayListOf() + // 배열 가져오기 + val achieveArray: Array = resources.getStringArray(R.array.achieve_progress) // 업적 데이터 + val achieveChecked : ArrayList = SaveSharedPreference.getAchieve(requireContext())!! // 달성 여부 + + // 목록 추가 + for(i in achieveArray.indices) AchieveProgress(achieveArray[i], achieveChecked[i]) + + return data + } } \ No newline at end of file diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveAdapter.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveAdapter.kt index c6e2a97..6fa85cb 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveAdapter.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveAdapter.kt @@ -10,13 +10,12 @@ import com.example.shape_up_2022.achieve.AchieveFragment4 class AchieveAdapter(fragment: FragmentActivity): FragmentStateAdapter(fragment) { - override fun getItemCount(): Int =4 + override fun getItemCount(): Int =3 override fun createFragment(position: Int): Fragment { return when (position){ 0-> AchieveFragment1() 1-> AchieveFragment2() - 2-> AchieveFragment3() else -> AchieveFragment4() } diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveProgressAdapter.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveProgressAdapter.kt new file mode 100644 index 0000000..1825d89 --- /dev/null +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/adapter/AchieveProgressAdapter.kt @@ -0,0 +1,28 @@ +package com.example.shape_up_2022.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.example.shape_up_2022.achieve.AchieveFragment1 +import com.example.shape_up_2022.databinding.ItemAchieveBinding +import com.example.shape_up_2022.retrofit.myItem + + +class ViewHolderAchieve(val binding: ItemAchieveBinding): RecyclerView.ViewHolder(binding.root) +class AchieveProgressAdapter(val context: Context, val datas:ArrayList?): + RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return ViewHolderAchieve(ItemAchieveBinding.inflate(LayoutInflater.from(parent.context), parent,false )) + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + val binding = (holder as ViewHolderAchieve).binding + val model = datas!![position] + + } + + override fun getItemCount(): Int { + return datas?.size ?: 0 + } +} \ No newline at end of file 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 b2e55fb..c317e15 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 @@ -51,15 +51,16 @@ class LoginActivity : AppCompatActivity() { if(response.body()?.loginSuccess == "true"){ // 로그인 성공 // 프리퍼런스에 값 저장 - SaveSharedPreference.setUserEmail(baseContext, inputID) - SaveSharedPreference.setUserName(baseContext, response.body()!!.userName) - SaveSharedPreference.setUserID(baseContext, response.body()!!.userID) - SaveSharedPreference.setFamliyID(baseContext, response.body()!!.familyID?:null) - SaveSharedPreference.setUserTested(baseContext, response.body()!!.tested) + SaveSharedPreference.setUserEmail(baseContext, inputID) // 이메일 + SaveSharedPreference.setUserName(baseContext, response.body()!!.user.name) // 이름 + SaveSharedPreference.setUserID(baseContext, response.body()!!.user._id) // userID + SaveSharedPreference.setFamliyID(baseContext, response.body()!!.user.familyID?:null) // familyID + SaveSharedPreference.setUserTested(baseContext, response.body()!!.user.tested) // 성향점검 여부 + SaveSharedPreference.setAchieve(baseContext, response.body()!!.user.achieve) // 업적 달성 여부 // petID 프리퍼런스에 저장 - if(response.body()!!.familyID!! != null){ - callGetPetID(response.body()!!.familyID!!) + if(response.body()!!.user.familyID!! != null){ + callGetPetID(response.body()!!.user.familyID!!) } } else { // 로그인 실패 or null diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SaveSharedPreference.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SaveSharedPreference.kt index 5076b6a..63a5709 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SaveSharedPreference.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/common/SaveSharedPreference.kt @@ -3,6 +3,8 @@ package com.example.shape_up_2022.common import android.content.Context import android.content.SharedPreferences import androidx.preference.PreferenceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class SaveSharedPreference { companion object{ @@ -67,6 +69,24 @@ class SaveSharedPreference { } fun getPetID(ctx: Context?): String? { return getSharedPreferences(ctx!!)!!.getString("petID", "") } + // User의 achieve + fun setAchieve(ctx: Context, achieve: ArrayList?) { + if (achieve==null) return + val gson = Gson() + val json = gson.toJson(achieve) + val editor = getSharedPreferences(ctx)!!.edit() + editor.putString("achieve", json) + editor.commit() + } + fun getAchieve(ctx: Context?): ArrayList? { + val json = getSharedPreferences(ctx!!)!!.getString("achieve", "") + val gson = Gson() + return gson.fromJson( + json, + object : TypeToken>() {}.type + ) + } + // 저장된 SharedPreference 값 전체 삭제 fun clearAll(ctx: Context?) { 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 c7ce64d..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 @@ -35,8 +35,8 @@ class MyApplication: Application() { var client = OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor()).build() /* 서버 요청용 */ - val apiserver = "http://ec2-13-124-250-65.ap-northeast-2.compute.amazonaws.com:5000/" - // http://192.168.219.113:5000/ + val apiserver = "http://192.168.219.113:5000/" + // http://ec2-13-124-250-65.ap-northeast-2.compute.amazonaws.com:5000/ var networkServiceUsers: NetworkServiceUsers val retrofitUsers: Retrofit diff --git a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceUsers.kt b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceUsers.kt index c264219..78f3057 100644 --- a/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceUsers.kt +++ b/SHAPEUP2022/app/src/main/java/com/example/shape_up_2022/retrofit/NetworkServiceUsers.kt @@ -31,11 +31,12 @@ interface NetworkServiceUsers { } +// req, res 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 familyID: String?, val tested: Boolean) +data class LoginRes(val loginSuccess: String, val user: UserInfo) data class AddFamilyReq(val userID: String) data class AddFamilyRes(val success: String, val message: String, val familyID: String) @@ -45,3 +46,6 @@ data class JoinFamilyRes(val success: String, val message: String, val familyID: data class CompleteTestReq(val userID: String) data class CompleteTestRes(val success: String, val message: String) + +// data class +data class UserInfo(val _id: String, val name: String, val email: String, val tested: Boolean, val familyID: String, val achieve: ArrayList) \ No newline at end of file diff --git a/SHAPEUP2022/app/src/main/res/layout/achieve_fragment_1.xml b/SHAPEUP2022/app/src/main/res/layout/achieve_fragment_1.xml index 1bb0629..1bf785a 100644 --- a/SHAPEUP2022/app/src/main/res/layout/achieve_fragment_1.xml +++ b/SHAPEUP2022/app/src/main/res/layout/achieve_fragment_1.xml @@ -16,6 +16,11 @@ + + - + android:layout_height="wrap_content" + app:tabGravity="fill"> 의료비 + + 반려견을 입양했어요 + 우리가족의 반려견 호감도를 점검했어요 + 반려견을 쓰다듬었어요 + 투두리스트 100% 3일 달성 + 예산서에서 지출 항목을 추가했어요 + 강아지에게 사료를 줬어요 + 산책을 하고 산책 리뷰를 작성했어요 + 강아지의 장난감을 세척했어요 + 강아지의 건강 상태를 확인했어요 + 강아지에게 이름을 가르쳤어요 + 강아지 산책을 위한 산책길을 3번 탐색했어요 + 강아지가 짖는 소리를 들었어요 + 가족들의 성실도가 50% 넘었어요 + 반려견 선호도 점검을 진행했어요 + \ No newline at end of file