Skip to content

Commit

Permalink
제출 전 마지막 커밋
Browse files Browse the repository at this point in the history
  • Loading branch information
minhye1013 committed Feb 26, 2024
1 parent d11063e commit 7e355f2
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<ResponseRegisterStoreData> {
val retrofit = Retrofit.Builder()
Expand All @@ -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")
}


}
6 changes: 3 additions & 3 deletions app/src/main/java/org/gdsc_android/picky_panda/AddFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand All @@ -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()
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ class HomeFragment : Fragment() {
_binding = null
}

}

}
70 changes: 65 additions & 5 deletions app/src/main/java/org/gdsc_android/picky_panda/MyPageFragment.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<ImageView>(R.id.profilePicImageView)
val idTextView = view.findViewById<TextView>(R.id.idTextView)
val descriptionCountTextView = view.findViewById<TextView>(R.id.descriptionCountTextView)
val reviewCountTextView = view.findViewById<TextView>(R.id.reviewCountTextView)
val savedRestaurantCountTextView = view.findViewById<TextView>(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<RecyclerView>(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
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ResponseMyStoreListData.Data.RecentlyEvaluatedList>) :
RecyclerView.Adapter<RecentlyEvaluatedAdapter.ViewHolder>() {

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

data class RecentlyEvaluatedList(
val id: Int,
val restaurantImage: String,
val placeName: String,
val address: String,
val options: String
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ interface ServiceApi {

@GET("/profile") //마이페이지 조회
fun myStoreList(
@Header("Authorization") authorization: String
): Call<ResponseMyStoreListData>

@GET("maps/api/geocode/json")
Expand Down
Loading

0 comments on commit 7e355f2

Please sign in to comment.