From d31a800317a86ce15e9653e9f34b3d3135eabf2a Mon Sep 17 00:00:00 2001 From: Seungmin-develop Date: Tue, 22 Mar 2022 15:38:23 +0900 Subject: [PATCH] [feat] #105 Project View Server Connection --- .idea/deploymentTargetDropDown.xml | 17 - .../category/model/ProjectService.kt | 4 +- .../model/ResponseApplyProjectData.kt | 6 +- .../category/model/ResponseViewIdeaData.kt | 7 +- .../category/view/adapter/IdeaListAdapter.kt | 5 +- .../view/fragment/CategoryViewIdeaFragment.kt | 62 +- .../id/model/ResponseLoginData.kt | 2 + .../infraandroid/id/view/LoginFragment.kt | 1 + .../infraandroid/util/BindingConversion.kt | 58 +- .../main/res/layout/fragment_view_idea.xml | 858 ++++++++++-------- 10 files changed, 576 insertions(+), 444 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index 949dc96..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/category/model/ProjectService.kt b/app/src/main/java/com/example/infraandroid/category/model/ProjectService.kt index cb8dbb9..7423bb1 100644 --- a/app/src/main/java/com/example/infraandroid/category/model/ProjectService.kt +++ b/app/src/main/java/com/example/infraandroid/category/model/ProjectService.kt @@ -12,13 +12,15 @@ interface ProjectService { @POST("/project/apply") fun postApplyProject( + @Header("X-ACCESS-TOKEN") jwt: String, + @Header("X-REFRESH-TOKEN") refreshToken: Int, @Body body : RequestApplyProjectData ): Call @GET("/project/contact") fun viewProject( @Header("X-ACCESS-TOKEN") jwt: String, - @Header("X-REFRESH-TOKEN") refreshToken: String, + @Header("X-REFRESH-TOKEN") refreshToken: Int, @Query("pj_num") projectNum : Int, @Query("user_id") userId : String ): Call diff --git a/app/src/main/java/com/example/infraandroid/category/model/ResponseApplyProjectData.kt b/app/src/main/java/com/example/infraandroid/category/model/ResponseApplyProjectData.kt index f8d33e2..5a2046c 100644 --- a/app/src/main/java/com/example/infraandroid/category/model/ResponseApplyProjectData.kt +++ b/app/src/main/java/com/example/infraandroid/category/model/ResponseApplyProjectData.kt @@ -1,14 +1,12 @@ package com.example.infraandroid.category.model -import org.w3c.dom.Comment - data class ResponseApplyProjectData( val isSuccess: Boolean, val code: Int, val message: String, - val result: Comment? + val result: Result? ){ - data class Comment( + data class Result( val comment: String, ) } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/category/model/ResponseViewIdeaData.kt b/app/src/main/java/com/example/infraandroid/category/model/ResponseViewIdeaData.kt index 6d73348..74699d8 100644 --- a/app/src/main/java/com/example/infraandroid/category/model/ResponseViewIdeaData.kt +++ b/app/src/main/java/com/example/infraandroid/category/model/ResponseViewIdeaData.kt @@ -7,7 +7,7 @@ data class ResponseViewIdeaData( val result: Result ){ data class Result( - val hashtag: List, + val hashtag: ArrayList, val pjLikeCount: Int, val pj_categoryName: String, val pj_content: String, @@ -15,6 +15,7 @@ data class ResponseViewIdeaData( val pj_endTerm: String, val pj_header: String, val pj_progress: String, + val pj_recruit: String, val pj_recruitPerson: String, val pj_startTerm: String, val pj_subCategoryName: String, @@ -22,6 +23,8 @@ data class ResponseViewIdeaData( val pj_views: Int, val user_id: String, val user_nickname: String, - val user_prPhoto: String + val user_prPhoto: String, + val pj_photo: ArrayList, + val pj_like: Int ) } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/category/view/adapter/IdeaListAdapter.kt b/app/src/main/java/com/example/infraandroid/category/view/adapter/IdeaListAdapter.kt index f0979a3..fcff5f9 100644 --- a/app/src/main/java/com/example/infraandroid/category/view/adapter/IdeaListAdapter.kt +++ b/app/src/main/java/com/example/infraandroid/category/view/adapter/IdeaListAdapter.kt @@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView import com.example.infraandroid.util.ImageRound import com.example.infraandroid.R import com.example.infraandroid.category.model.ResponseLookUpAllProjectData +import com.example.infraandroid.category.view.fragment.IdeaListFragmentDirections import com.example.infraandroid.databinding.ItemIdeaListRecyclerviewBinding class IdeaListAdapter(): RecyclerView.Adapter() { @@ -34,8 +35,8 @@ class IdeaListAdapter(): RecyclerView.Adapter() { ImageRound.roundAll(binding.projectImageView, 36f) binding.projectList = ideaListInfo itemView.setOnClickListener { - it.findNavController().navigate(R.id.action_idea_list_fragment_to_categoryViewIdeaFragment) - + val action = IdeaListFragmentDirections.actionIdeaListFragmentToCategoryViewIdeaFragment(ideaListInfo.pj_num) + it.findNavController().navigate(action) } } } diff --git a/app/src/main/java/com/example/infraandroid/category/view/fragment/CategoryViewIdeaFragment.kt b/app/src/main/java/com/example/infraandroid/category/view/fragment/CategoryViewIdeaFragment.kt index 34897d3..efc9077 100644 --- a/app/src/main/java/com/example/infraandroid/category/view/fragment/CategoryViewIdeaFragment.kt +++ b/app/src/main/java/com/example/infraandroid/category/view/fragment/CategoryViewIdeaFragment.kt @@ -8,10 +8,14 @@ import android.view.ViewGroup import android.widget.Toast import androidx.appcompat.widget.AppCompatButton import androidx.fragment.app.Fragment +import androidx.navigation.fragment.navArgs +import com.example.infraandroid.R import com.example.infraandroid.category.model.RequestApplyProjectData import com.example.infraandroid.category.model.ResponseApplyProjectData +import com.example.infraandroid.category.model.ResponseViewIdeaData import com.example.infraandroid.databinding.FragmentViewIdeaBinding import com.example.infraandroid.id.viewmodel.SignUpViewModel.Companion.TAG +import com.example.infraandroid.util.BaseFragment import com.example.infraandroid.util.InfraApplication import com.example.infraandroid.util.ServiceCreator import retrofit2.Call @@ -20,31 +24,54 @@ import retrofit2.Response // 다른 사람의 아이디어를 눌렀을 때 볼 수 있는 자세히 보기 뷰 -class CategoryViewIdeaFragment : Fragment(){ - private var mBinding : FragmentViewIdeaBinding? = null +class CategoryViewIdeaFragment : BaseFragment(R.layout.fragment_view_idea){ + + override fun FragmentViewIdeaBinding.onCreateView(){ - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - val binding = FragmentViewIdeaBinding.inflate(inflater, container, false) - mBinding = binding - return mBinding?.root } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + override fun FragmentViewIdeaBinding.onViewCreated() { + val args: CategoryViewIdeaFragmentArgs by navArgs() + val projectNum = args.projectNum + Log.d(TAG, "onViewCreated: $projectNum") + + val call: Call = ServiceCreator.projectService + .viewProject(InfraApplication.prefs.getString("jwt", "null"), + InfraApplication.prefs.getString("refreshToken", "null").toInt(), + projectNum, + InfraApplication.prefs.getString("userId", "null") + ) + + call.enqueue(object:Callback{ + override fun onResponse( + call: Call, + response: Response + ) { + if(response.isSuccessful){ + when(response.body()?.code){ + 1000 -> { + Log.d(TAG, "onResponse: "+"접속연결성공!") + binding.viewIdea = response.body()?.result } + } + } + } - val applyButton = mBinding?.teamIdeaApplyButton as AppCompatButton + override fun onFailure(call: Call, t: Throwable) { + Log.d(TAG, "onFailure: $t") + } + + }) + + + val applyButton = binding.teamIdeaApplyButton as AppCompatButton applyButton.setOnClickListener { val requestApplyProjectData = RequestApplyProjectData( - projectNum = 1, + projectNum = projectNum, userId = InfraApplication.prefs.getString("userId", "null") ) val call: Call = ServiceCreator.projectService - .postApplyProject(requestApplyProjectData) + .postApplyProject(InfraApplication.prefs.getString("jwt","null"), InfraApplication.prefs.getString("refreshToken", "null").toInt(), requestApplyProjectData) call.enqueue(object:Callback{ override fun onResponse( call: Call, @@ -65,9 +92,4 @@ class CategoryViewIdeaFragment : Fragment(){ }) } } - - override fun onDestroyView() { - mBinding = null - super.onDestroyView() - } } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt b/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt index 0125daa..e8ec0c7 100644 --- a/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt +++ b/app/src/main/java/com/example/infraandroid/id/model/ResponseLoginData.kt @@ -17,5 +17,7 @@ data class ResponseLoginData( val userName : String, @SerializedName("user_nickname") val userNickName : String, + @SerializedName("jwtRefreshIdx") + val refreshToken : Int ) } diff --git a/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt b/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt index 6a86216..f1cde68 100644 --- a/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt +++ b/app/src/main/java/com/example/infraandroid/id/view/LoginFragment.kt @@ -84,6 +84,7 @@ class LoginFragment : BaseFragment(R.layout.fragment_login when(code){ 1000 -> { InfraApplication.prefs.setString("jwt", response.body()?.result?.jwt.toString()) + InfraApplication.prefs.setString("refreshToken", response.body()?.result?.refreshToken.toString()) InfraApplication.prefs.setString("userId", response.body()?.result?.userId.toString()) InfraApplication.prefs.setString("userNickName", response.body()?.result?.userNickName.toString()) Toast.makeText(requireActivity(),"요청에 성공하셨습니다.", Toast.LENGTH_SHORT).show() diff --git a/app/src/main/java/com/example/infraandroid/util/BindingConversion.kt b/app/src/main/java/com/example/infraandroid/util/BindingConversion.kt index ca3bc37..1ad529a 100644 --- a/app/src/main/java/com/example/infraandroid/util/BindingConversion.kt +++ b/app/src/main/java/com/example/infraandroid/util/BindingConversion.kt @@ -11,16 +11,50 @@ import androidx.core.view.isVisible import androidx.databinding.BindingAdapter import com.bumptech.glide.Glide import com.example.infraandroid.R +import org.w3c.dom.Text object BindingConversions { @JvmStatic @BindingAdapter("loadImg") - fun loadImage(imageView: ImageView, url: String){ + fun loadImage(imageView: ImageView, url: String?){ Glide.with(imageView.context).load(url) .error(R.drawable.ic_infra_logo) .into(imageView) } + @JvmStatic + @BindingAdapter("projectImg") + fun projectImg(imageView: ImageView, url: String?){ + if(url==null){ + imageView.isGone = true + } + else{ + Glide.with(imageView.context).load(url) + .into(imageView) + } + } + + @JvmStatic + @BindingAdapter("makingTerm") + fun makingTerm(textView: TextView, startDate: String, endDate: String){ + val startYear = startDate.substring(0 until 5).toInt() + val startMonth = startDate.substring(5 until 7).toInt() + val startDay = startDate.substring(9 until 11).toInt() + val endYear = startDate.substring(0 until 5).toInt() + val endMonth = startDate.substring(5 until 7).toInt() + val endDay = startDate.substring(9 until 11).toInt() + textView.text = "${startYear}년 ${startMonth}월 ${startDay}일-${endYear}년 ${endMonth}월 ${endDay}일" + } + + @JvmStatic + @BindingAdapter("loadCircleImg") + fun loadCircleImg(imageView: ImageView, url: String?){ + Glide.with(imageView.context).load(url) + .circleCrop() + .error(R.drawable.ic_infra_logo) + .into(imageView) + } + @JvmStatic @BindingAdapter("getStringFromInt") fun getStringFromInt(textView: TextView, num: Int){ @@ -48,7 +82,7 @@ object BindingConversions { @JvmStatic @BindingAdapter("deadline") - fun setDeadlineText(textView: TextView, comment: String){ + fun setDeadlineText(textView: TextView, comment: String?){ textView.text = comment when(comment){ "마감" -> textView.setTextColor(Color.parseColor("#8F8F8F")) @@ -56,4 +90,24 @@ object BindingConversions { "모집중" -> textView.setTextColor(Color.parseColor("#4B8EFF")) } } + + @JvmStatic + @BindingAdapter(value = ["endRecruitDate", "status"], requireAll = true) + fun setEndRecruitText(textView: TextView, endRecruitDate: String, status: String){ + val year = endRecruitDate.substring(0 until 5).toInt() + val month = endRecruitDate.substring(5 until 7).toInt() + val day = endRecruitDate.substring(9 until 11).toInt() + textView.text = "{$year}년 {$month}월 {$day}일까지 모집" + when(status){ + "마감" -> textView.setTextColor(Color.parseColor("#8F8F8F")) + "마감임박" -> textView.setTextColor(Color.parseColor("#9277F8")) + "모집중" -> textView.setTextColor(Color.parseColor("#4B8EFF")) + } + } + + @JvmStatic + @BindingAdapter("intToString") + fun intToString(textView: TextView, number: Int){ + textView.text = number.toString() + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_view_idea.xml b/app/src/main/res/layout/fragment_view_idea.xml index dea7f1a..24e74e1 100644 --- a/app/src/main/res/layout/fragment_view_idea.xml +++ b/app/src/main/res/layout/fragment_view_idea.xml @@ -1,468 +1,534 @@ - + xmlns:tools="http://schemas.android.com/tools"> - + + + + - + + - - + android:layout_height="0dp" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintBottom_toBottomOf="parent"> - - - - - - - - - - + + - - - + app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintTop_toTopOf="parent"> + + app:layout_constraintTop_toTopOf="@id/category_team_idea_constraint_layout" /> + - + android:layout_marginLeft="4dp" + android:text=">" + android:textColor="@color/infra_gray_i" + android:textSize="14sp" + app:layout_constraintBottom_toBottomOf="@id/category_team_idea_category_textview" + app:layout_constraintLeft_toRightOf="@id/category_team_idea_category_textview" + app:layout_constraintTop_toTopOf="@id/category_team_idea_category_textview" /> + - + android:layout_marginLeft="4dp" + android:text="@{viewIdea.pj_subCategoryName}" + android:textColor="@color/infra_gray_i" + android:textSize="14sp" + app:layout_constraintBottom_toBottomOf="@id/category_team_idea_category_detail" + app:layout_constraintLeft_toRightOf="@id/category_team_idea_category_detail" + app:layout_constraintTop_toTopOf="@id/category_team_idea_category_detail" /> - - - - + + + + + + + - + android:layout_height="40dp" + android:layout_marginTop="23dp" + android:layout_marginHorizontal="20dp" + android:background="@drawable/rounded_edittext_gray" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_title_textview"> - - - + - - - + + + + + + + + + + + + + + + - - - - - - + android:includeFontPadding="false" + android:text="아이디어 내용" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_state_constraintlayout" /> + + + + + + + + + + + android:includeFontPadding="false" + android:text="제작 기간" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_idea_linearlayout" /> + + android:includeFontPadding="false" + android:text="2022년 1월 25일 - 2022년 2월 15일" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_period_textview" + android:layout_marginTop="12dp" + android:layout_marginStart="40dp" /> + + + - + android:includeFontPadding="false" + android:text="진행 상황" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_period_text_textview" /> - - + android:fontFamily="@font/noto_sans_kr_regular" + android:includeFontPadding="false" + android:text="@{viewIdea.pj_content}" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_progress_textview" + android:layout_marginTop="12dp" + android:layout_marginStart="40dp" /> + + + + android:text="팀장" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_progress_text_textview" /> + android:id="@+id/category_team_idea_leader_profile_iv" + android:layout_width="71dp" + android:layout_height="71dp" + loadCircleImg="@{viewIdea.user_prPhoto}" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_leader_textview" + android:layout_marginTop="15dp" + android:layout_marginStart="35dp" /> + - + android:text="@{viewIdea.user_nickname}" + android:textColor="@color/black" + android:textSize="15sp" + app:layout_constraintStart_toEndOf="@id/category_team_idea_leader_profile_iv" + app:layout_constraintTop_toTopOf="@id/category_team_idea_leader_profile_iv" + app:layout_constraintBottom_toBottomOf="@id/category_team_idea_leader_profile_iv" + android:layout_marginStart="16dp" /> + + + + + + + + + + + + + + + + + + + + + + + - - + - - - \ No newline at end of file + + + + \ No newline at end of file