diff --git a/app/src/main/java/org/gdsc_android/picky_panda/AddDetailFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/AddDetailFragment.kt index 53dc226..88093bc 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/AddDetailFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/AddDetailFragment.kt @@ -1,5 +1,6 @@ package org.gdsc_android.picky_panda +import android.content.Context import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater @@ -11,14 +12,8 @@ import android.widget.Toast import androidx.core.view.children import androidx.lifecycle.lifecycleScope import com.google.android.material.chip.Chip -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.plus -import okhttp3.ResponseBody import org.gdsc_android.picky_panda.data.CategoryClass -import org.gdsc_android.picky_panda.data.GeocodingResponse import org.gdsc_android.picky_panda.data.GetGeocodingResult import org.gdsc_android.picky_panda.data.RequestRegisterStoreData import org.gdsc_android.picky_panda.data.ResponseRegisterStoreData @@ -29,10 +24,6 @@ import retrofit2.Callback import retrofit2.Response import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.Query class AddDetailFragment : Fragment() { private lateinit var binding: FragmentAddDetailBinding @@ -200,10 +191,10 @@ class AddDetailFragment : Fragment() { if (result == null || result.geometry?.location == null) { throw Exception("No location found for the address.") } - val latitude = result.geometry.location.lat - val longitude = result.geometry.location.lng + val latitude = result.geometry.location.lat + val longitude = result.geometry.location.lng - return GetGeocodingResult(latitude, longitude) + return GetGeocodingResult(latitude, longitude) } private suspend fun saveStoreDataToServer(data: RequestRegisterStoreData): Call { val retrofit = Retrofit.Builder() @@ -212,8 +203,10 @@ class AddDetailFragment : Fragment() { .build() val service = retrofit.create(ServiceApi::class.java) + // SharedPreferences + val sharedPreferences = requireActivity().getSharedPreferences("user_data", Context.MODE_PRIVATE) + val accessToken = sharedPreferences.getString("accessToken", "") + return service.registerStore(data,"Bearer $accessToken") } - - } \ No newline at end of file diff --git a/app/src/main/java/org/gdsc_android/picky_panda/AddFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/AddFragment.kt index 01cb80b..52f0be2 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/AddFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/AddFragment.kt @@ -24,7 +24,7 @@ class AddFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // 각 EditText의 입력 여부에 따라 NextButton 활성화/비활성화 설정 + // Set the NextButton to be enabled/disabled depending on whether each EditText has been filled in binding.placeNameEditTextText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} @@ -43,7 +43,7 @@ class AddFragment : Fragment() { checkInputsAndEnableButton() } }) - //nextButton 누르면 정보 리스트에 담고 AddDetailFragment로 이동 + //NextButton is pressed, store the information in a list and move to the AddDetailFragment binding.nextButton.setOnClickListener { val placeName = binding.placeNameEditTextText.text.toString() val editTextTextPostalAddress = binding.editTextTextPostalAddress.text.toString() @@ -60,7 +60,7 @@ class AddFragment : Fragment() { } private fun checkInputsAndEnableButton() { - // 두 EditText의 입력 여부에 따라 Button 활성화/비활성화 설정 + // Set the Button to be enabled/disabled depending on whether the two EditTexts have been filled in val isPlaceNameNotEmpty = binding.placeNameEditTextText.text.isNotBlank() val isPostalAddressNotEmpty = binding.editTextTextPostalAddress.text.isNotBlank() diff --git a/app/src/main/java/org/gdsc_android/picky_panda/HomeFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/HomeFragment.kt index aee4ea9..4de71e4 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/HomeFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/HomeFragment.kt @@ -99,5 +99,4 @@ class HomeFragment : Fragment() { _binding = null } -} - +} \ No newline at end of file diff --git a/app/src/main/java/org/gdsc_android/picky_panda/MyPageFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/MyPageFragment.kt index 561f9ec..38220e7 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/MyPageFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/MyPageFragment.kt @@ -1,12 +1,23 @@ package org.gdsc_android.picky_panda +import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope +import androidx.recyclerview.widget.RecyclerView +import kotlinx.coroutines.launch import org.gdsc_android.picky_panda.MyPageFragment +import org.gdsc_android.picky_panda.adapter.RecentlyEvaluatedAdapter +import org.gdsc_android.picky_panda.data.ResponseMyStoreListData +import org.gdsc_android.picky_panda.data.ServiceApi import org.gdsc_android.picky_panda.databinding.FragmentMyPageBinding +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory class MyPageFragment : Fragment() { private lateinit var binding: FragmentMyPageBinding @@ -22,26 +33,75 @@ class MyPageFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // MyPageFragment에서 ImageButton 클릭 시 SettingFragment로 이동 + // Coroutine + viewLifecycleOwner.lifecycleScope.launch { + // Get userProfile + val userProfile = getUserProfile() + + // profile info + val profileImageView = view.findViewById(R.id.profilePicImageView) + val idTextView = view.findViewById(R.id.idTextView) + val descriptionCountTextView = view.findViewById(R.id.descriptionCountTextView) + val reviewCountTextView = view.findViewById(R.id.reviewCountTextView) + val savedRestaurantCountTextView = view.findViewById(R.id.savedRestaurantCountTextView) + + idTextView.text = userProfile?.data?.email + descriptionCountTextView.text = userProfile?.data?.myDescriptionCount.toString() + reviewCountTextView.text = userProfile?.data?.myReviewCount.toString() + savedRestaurantCountTextView.text = userProfile?.data?.mySavedRestaurantCount.toString() + + + // recycler view setting + val recyclerView = view.findViewById(R.id.RecentlyEvaluatedRecyclerView) + val adapter = RecentlyEvaluatedAdapter(respnse.data?.recentlyEvaluatedList ?: emptyList()) + recyclerView.adapter = adapter + } + + // move to SettingFragment binding.settingButton.setOnClickListener { (activity as MainActivity).replaceFragment(SettingFragment()) } - //// MyPageFragment에서 Button 클릭 시 RegisterFragment로 이동 + // move to RegisterFragment binding.registerButton.setOnClickListener { (activity as MainActivity).replaceFragment(RegisterFragment()) } - //// MyPageFragment에서 Button 클릭 시 MyReviewFragment로 이동 + //// move to MyReviewFragment binding.reviewButton.setOnClickListener { (activity as MainActivity).replaceFragment(MyReviewFragment()) } - //// MyPageFragment에서 Button 클릭 시 SavedFragment로 이동 + //// move to SavedFragment binding.savedButton.setOnClickListener { (activity as MainActivity).replaceFragment(SavedFragment()) } - //// MyPageFragment에서 Button 클릭 시 RecentlyEvaluatedFragment로 이동 + //// move to RecentlyEvaluatedFragment binding.moreButton.setOnClickListener { (activity as MainActivity).replaceFragment(RecentlyEvaluatedFragment()) } } + suspend fun getUserProfile(): ResponseMyStoreListData? { + val retrofit = Retrofit.Builder() + .baseUrl("http://34.64.159.113:8081") + .addConverterFactory(GsonConverterFactory.create()) + .build() + + val service = retrofit.create(ServiceApi::class.java) + + return try { + val sharedPreferences = requireActivity().getSharedPreferences("user_data", Context.MODE_PRIVATE) + val accessToken = sharedPreferences.getString("accessToken", "") + val response = service.myStoreList("Bearer $accessToken").execute() + + if (response.isSuccessful) { + response.body() + } else { + null + } + } catch (e: Exception) { + null + } + } + + + } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/MyReviewFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/MyReviewFragment.kt index 2e2d161..7c0b3f0 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/MyReviewFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/MyReviewFragment.kt @@ -22,7 +22,7 @@ class MyReviewFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // SavedFragment에서 ImageButton 클릭 시 MypageFragment로 돌아감 + // move to MypageFragment binding.fromMyReviewToMyPageButton.setOnClickListener { (activity as MainActivity).replaceFragment(MyPageFragment()) } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/RecentlyEvaluatedFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/RecentlyEvaluatedFragment.kt index cd04a5b..39e9726 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/RecentlyEvaluatedFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/RecentlyEvaluatedFragment.kt @@ -21,7 +21,7 @@ class RecentlyEvaluatedFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // RegisterFragment에서 ImageButton 클릭 시 MypageFragment로 돌아감 + // move to MypageFragment binding.fromRecentlyEvaluatedToMyPageButton.setOnClickListener { (activity as MainActivity).replaceFragment(MyPageFragment()) } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/RegisterFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/RegisterFragment.kt index 648af9d..8a12dfb 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/RegisterFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/RegisterFragment.kt @@ -21,7 +21,7 @@ class RegisterFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // RegisterFragment에서 ImageButton 클릭 시 MypageFragment로 돌아감 + // move to MypageFragment binding.fromRegisterToMyPageButton.setOnClickListener { (activity as MainActivity).replaceFragment(MyPageFragment()) } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/SavedFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/SavedFragment.kt index 52ace06..e090578 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/SavedFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/SavedFragment.kt @@ -22,7 +22,7 @@ class SavedFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // SavedFragment에서 ImageButton 클릭 시 MypageFragment로 돌아감 + // move to MypageFragment binding.fromSavedToMyPageButton.setOnClickListener { (activity as MainActivity).replaceFragment(MyPageFragment()) } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/SettingFragment.kt b/app/src/main/java/org/gdsc_android/picky_panda/SettingFragment.kt index 33e6e7c..ea6f21c 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/SettingFragment.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/SettingFragment.kt @@ -22,7 +22,7 @@ class SettingFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - // SettingFragment에서 ImageButton 클릭 시 MypageFragment로 돌아감 + //move to MypageFragment binding.fromSettingToMyPageButton.setOnClickListener { (activity as MainActivity).replaceFragment(MyPageFragment()) } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/adapter/RecentlyEvaluatedAdapter.kt b/app/src/main/java/org/gdsc_android/picky_panda/adapter/RecentlyEvaluatedAdapter.kt new file mode 100644 index 0000000..d12df49 --- /dev/null +++ b/app/src/main/java/org/gdsc_android/picky_panda/adapter/RecentlyEvaluatedAdapter.kt @@ -0,0 +1,36 @@ +package org.gdsc_android.picky_panda.adapter + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import org.gdsc_android.picky_panda.R +import org.gdsc_android.picky_panda.data.ResponseMyStoreListData +import org.gdsc_android.picky_panda.data.ResponseRegisterStoreData + +class RecentlyEvaluatedAdapter(private val items: List) : + RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.items, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val item = items[position] + holder.placeNameTextView.text = item.placeName + holder.addressTextView.text = item.address + holder.optionTextView.text = item.options + } + + override fun getItemCount(): Int { + return items.size + } + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + val placeNameTextView: TextView = view.findViewById(R.id.recentlyEvaluatedRestaurantNameTextView) + val addressTextView: TextView = view.findViewById(R.id.recentlyEvaluatedAddressTextView) + val optionTextView: TextView = view.findViewById(R.id.recentlyEvaluatedOptionTextView) + } +} diff --git a/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMySectionStoreListData.kt b/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMySectionStoreListData.kt index 44d58d4..79e1104 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMySectionStoreListData.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMySectionStoreListData.kt @@ -2,7 +2,8 @@ package org.gdsc_android.picky_panda.data data class ResponseMySectionStoreListData( val code: Int, - val message: String + val message: String, + val data: Data? ){ data class Data( val id: Int, diff --git a/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMyStoreListData.kt b/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMyStoreListData.kt index f256b48..5e5e183 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMyStoreListData.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/data/ResponseMyStoreListData.kt @@ -3,21 +3,22 @@ package org.gdsc_android.picky_panda.data data class ResponseMyStoreListData( val code: Int, val message: String, + val data: Data? ){ data class Data( val profileImage: String, val email: String, val myDescriptionCount: Int, val myReviewCount: Int, - val mySavedRestaurantCount: Int - ) - - data class recentlyEvaluatedList( - val id: Int, - val restaurantImage: String, - val placeName: String, - val address: String, - val options: String + val mySavedRestaurantCount: Int, + val recentlyEvaluatedList: List ) + data class RecentlyEvaluatedList( + val id: Int, + val restaurantImage: String, + val placeName: String, + val address: String, + val options: String + ) } diff --git a/app/src/main/java/org/gdsc_android/picky_panda/data/ServiceApi.kt b/app/src/main/java/org/gdsc_android/picky_panda/data/ServiceApi.kt index fd8cdfe..a9b7ced 100644 --- a/app/src/main/java/org/gdsc_android/picky_panda/data/ServiceApi.kt +++ b/app/src/main/java/org/gdsc_android/picky_panda/data/ServiceApi.kt @@ -87,6 +87,7 @@ interface ServiceApi { @GET("/profile") //마이페이지 조회 fun myStoreList( + @Header("Authorization") authorization: String ): Call @GET("maps/api/geocode/json") diff --git a/app/src/main/res/layout/fragment_my_page.xml b/app/src/main/res/layout/fragment_my_page.xml index a04da02..e91ebc3 100644 --- a/app/src/main/res/layout/fragment_my_page.xml +++ b/app/src/main/res/layout/fragment_my_page.xml @@ -71,24 +71,22 @@ - + android:layout_gravity="center"> +