From 17ca9aa3a598b9469b4f8042d0970ec2ac22ef5c Mon Sep 17 00:00:00 2001 From: Seungmin-develop Date: Fri, 25 Mar 2022 21:39:58 +0900 Subject: [PATCH] [feat] #113 My Project List & View My Project Server Connection --- .../category/model/ProjectService.kt | 2 +- .../myideamanage/model/MyProjectService.kt | 16 + .../myideamanage/model/MyProjectViewModel.kt | 14 + .../model/ResponseMyProjectListData.kt | 23 + .../view/adapter/MyIdeaListAdapter.kt | 21 +- .../view/fragment/MyIdeaFragment.kt | 16 + .../view/fragment/MyIdeaManageFragment.kt | 43 +- .../view/fragment/MyIdeaModifyFragment.kt | 75 +- .../infraandroid/util/BindingConversion.kt | 6 + .../infraandroid/util/ServiceCreator.kt | 2 + .../main/res/layout/fragment_team_idea.xml | 687 +++++++++--------- .../main/res/layout/fragment_view_idea.xml | 2 +- .../layout/item_my_idea_list_recyclerview.xml | 206 +++--- app/src/main/res/navigation/nav_graph.xml | 8 + 14 files changed, 656 insertions(+), 465 deletions(-) create mode 100644 app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectService.kt create mode 100644 app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt create mode 100644 app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/ResponseMyProjectListData.kt 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 7423bb1..b12227f 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 @@ -21,7 +21,7 @@ interface ProjectService { fun viewProject( @Header("X-ACCESS-TOKEN") jwt: String, @Header("X-REFRESH-TOKEN") refreshToken: Int, - @Query("pj_num") projectNum : Int, + @Query("pj_num") projectNum : Int?, @Query("user_id") userId : String ): Call } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectService.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectService.kt new file mode 100644 index 0000000..af667a7 --- /dev/null +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectService.kt @@ -0,0 +1,16 @@ +package com.example.infraandroid.myinfo.myideamanage.model + +import com.example.infraandroid.category.model.ResponseLookUpAllProjectData +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Header +import retrofit2.http.Query + +interface MyProjectService { + @GET("/project/myProject?") + fun viewMyProject( + @Header("X-ACCESS-TOKEN") jwt: String, + @Header("X-REFRESH-TOKEN") refreshToken: Int, + @Query("user_id") userId : String + ): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt new file mode 100644 index 0000000..fdea325 --- /dev/null +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/MyProjectViewModel.kt @@ -0,0 +1,14 @@ +package com.example.infraandroid.myinfo.myideamanage.model + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +class MyProjectViewModel : ViewModel() { + private val _currentObservingProjectNum = MutableLiveData() + val currentObservingProjectNum: LiveData = _currentObservingProjectNum + + fun updateObservingProjectNum(projectNum: Int){ + _currentObservingProjectNum.value = projectNum + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/ResponseMyProjectListData.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/ResponseMyProjectListData.kt new file mode 100644 index 0000000..a73096c --- /dev/null +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/model/ResponseMyProjectListData.kt @@ -0,0 +1,23 @@ +package com.example.infraandroid.myinfo.myideamanage.model + +data class ResponseMyProjectListData( + val code: Int, + val isSuccess: Boolean, + val message: String, + val result: ArrayList + ) { + data class Result( + val hashtag: ArrayList, + val pj_categoryName: String, + val pj_daysub: Int, + val pj_deadline: String, + val pj_header: String, + val pj_num: Int, + val pj_photo: ArrayList, + val pj_progress: String, + val pj_recruit: String, + val pj_recruitPerson: Int, + val pj_subCategoryNum: Int, + val pj_totalPerson: Int + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/adapter/MyIdeaListAdapter.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/adapter/MyIdeaListAdapter.kt index e46577d..1606d4f 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/adapter/MyIdeaListAdapter.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/adapter/MyIdeaListAdapter.kt @@ -9,9 +9,11 @@ import com.example.infraandroid.util.ImageRound import com.example.infraandroid.R import com.example.infraandroid.databinding.ItemMyIdeaListRecyclerviewBinding import com.example.infraandroid.myinfo.myideamanage.model.MyIdeaListInfo +import com.example.infraandroid.myinfo.myideamanage.model.ResponseMyProjectListData +import com.example.infraandroid.myinfo.myideamanage.view.fragment.MyIdeaManageFragmentDirections class MyIdeaListAdapter(): RecyclerView.Adapter() { - val myideaList = mutableListOf() + var myideaList = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { val binding = ItemMyIdeaListRecyclerviewBinding.inflate( @@ -30,21 +32,12 @@ class MyIdeaListAdapter(): RecyclerView.Adapter() { inner class MyIdeaListViewHolder( private val binding: ItemMyIdeaListRecyclerviewBinding ): RecyclerView.ViewHolder(binding.root){ - fun onBind(myIdeaListInfo: MyIdeaListInfo){ - binding.projectCategoryTitle.text = myIdeaListInfo.projectName - binding.projectCategoryTextView.text = myIdeaListInfo.projectCategory - binding.hashTagOne.text = myIdeaListInfo.hashTagOne - binding.hashTagTwo.text = myIdeaListInfo.hashTagTwo - - ImageRound.roundAll(binding.projectImageView, 36f) - - Glide.with(itemView) - .load(myIdeaListInfo.projectImg) - .into(binding.projectImageView) - + fun onBind(myIdeaListInfo: ResponseMyProjectListData.Result){ + binding.myProject = myIdeaListInfo //내 아이디어 관리 클릭 이벤트 itemView.setOnClickListener { - it.findNavController().navigate(R.id.action_myInfoMyIdeaFragment_to_myInfoTeamIdeaFragment) + val action = MyIdeaManageFragmentDirections.actionMyInfoMyIdeaFragmentToMyInfoTeamIdeaFragment(myIdeaListInfo.pj_header, myIdeaListInfo.pj_num) + it.findNavController().navigate(action) } } } diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaFragment.kt index de39673..1112d7c 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaFragment.kt @@ -7,18 +7,30 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider +import androidx.navigation.fragment.navArgs import androidx.viewpager2.widget.ViewPager2 import com.example.infraandroid.databinding.MyInfoTeamIdeaBinding +import com.example.infraandroid.myinfo.myideamanage.model.MyProjectViewModel import com.example.infraandroid.myinfo.myideamanage.view.adapter.TeamPagerAdapter import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator // 내 정보 > 내 아이디어 관리 탭 레이아웃의 부모 레이아웃 class MyIdeaFragment : Fragment() { + private lateinit var viewModel : MyProjectViewModel private var mBinding : MyInfoTeamIdeaBinding? = null private lateinit var tabLayout: TabLayout private lateinit var viewPager: ViewPager2 + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + activity?.run{ + viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()) + .get(MyProjectViewModel::class.java) + } + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -36,6 +48,10 @@ class MyIdeaFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + val args: MyIdeaFragmentArgs by navArgs() + viewModel.updateObservingProjectNum(args.myProjectNum) + mBinding?.titleTextView?.text = args.myIdeaTitle + val bottomSheetDialogFragment = MyProjectMoreMenuBottomSheetFragment() mBinding?.moreImageButton?.setOnClickListener { diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaManageFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaManageFragment.kt index ba09ed3..9707b74 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaManageFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaManageFragment.kt @@ -9,7 +9,13 @@ import androidx.navigation.findNavController import com.example.infraandroid.R import com.example.infraandroid.databinding.FragmentMyInfoMyIdeaBinding import com.example.infraandroid.myinfo.myideamanage.model.MyIdeaListInfo +import com.example.infraandroid.myinfo.myideamanage.model.ResponseMyProjectListData import com.example.infraandroid.myinfo.myideamanage.view.adapter.MyIdeaListAdapter +import com.example.infraandroid.util.InfraApplication +import com.example.infraandroid.util.ServiceCreator +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response //내 정보 > 내 아이디어 관리 파일.kt class MyIdeaManageFragment : Fragment() { @@ -29,17 +35,40 @@ class MyIdeaManageFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) mBinding?.myIdeaListRecyclerView?.adapter = myIdeaListAdapter - myIdeaListAdapter.myideaList.clear() - myIdeaListAdapter.myideaList.addAll( - listOf( - MyIdeaListInfo("https://img.insight.co.kr/static/2019/11/06/700/kzbv1474r107jj01027m.jpg","멸종위기 동물", "공모전","6/8", "동물", "웹디자인","마감임박!") - ) - ) - myIdeaListAdapter.notifyDataSetChanged() mBinding?.myIdeaListBackButton?.setOnClickListener { it.findNavController().navigate(R.id.action_myInfoMyIdeaFragment_to_my_info_fragment) } + + val call : Call = ServiceCreator.myProjectService + .viewMyProject(InfraApplication.prefs.getString("jwt", "null"), InfraApplication.prefs.getString("refreshToken", "null").toInt(), InfraApplication.prefs.getString("userId","null")) + + call.enqueue(object: Callback{ + override fun onResponse( + call: Call, + response: Response + ) { + if(response.isSuccessful){ + val body = response.body() + if(body!=null){ + when(body.code){ + 1000->{ + val data = body.result + if(data!=null){ + myIdeaListAdapter.myideaList = data + } + myIdeaListAdapter.notifyDataSetChanged() + } + } + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + TODO("Not yet implemented") + } + }) + } override fun onDestroyView() { diff --git a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyFragment.kt b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyFragment.kt index 39111fa..a5f09d6 100644 --- a/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyFragment.kt +++ b/app/src/main/java/com/example/infraandroid/myinfo/myideamanage/view/fragment/MyIdeaModifyFragment.kt @@ -5,33 +5,70 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import androidx.lifecycle.ViewModelProvider import androidx.navigation.findNavController +import androidx.navigation.fragment.navArgs import com.example.infraandroid.R +import com.example.infraandroid.category.model.ResponseViewIdeaData import com.example.infraandroid.databinding.FragmentTeamIdeaBinding +import com.example.infraandroid.myinfo.myideamanage.model.MyProjectViewModel +import com.example.infraandroid.util.BaseFragment +import com.example.infraandroid.util.InfraApplication +import com.example.infraandroid.util.ServiceCreator +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response //내 정보 > 내 아이디어 > 아이디어 탭 .kt -class MyIdeaModifyFragment : Fragment() { - private var mBinding : FragmentTeamIdeaBinding? = null - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - val binding = FragmentTeamIdeaBinding.inflate(inflater, container, false) - mBinding = binding - return mBinding?.root - } +class MyIdeaModifyFragment : BaseFragment(R.layout.fragment_team_idea) { - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - mBinding?.teamIdeaModifyBtnTv?.setOnClickListener{ - it.findNavController().navigate(R.id.action_myInfoTeamIdeaFragment_to_myInfoProjectModifyFragment) + private lateinit var viewModel : MyProjectViewModel + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + activity?.run{ + viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory()) + .get(MyProjectViewModel::class.java) } } - override fun onDestroyView() { - mBinding = null - super.onDestroyView() + override fun FragmentTeamIdeaBinding.onCreateView(){ + + } + + override fun FragmentTeamIdeaBinding.onViewCreated(){ + + val call: Call = ServiceCreator.projectService + .viewProject( + InfraApplication.prefs.getString("jwt", "null"), + InfraApplication.prefs.getString("refreshToken", "null").toInt(), + viewModel.currentObservingProjectNum.value, + InfraApplication.prefs.getString("userId", "null") + ) + + call.enqueue(object: Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if(response.isSuccessful){ + when(response.body()?.code){ + 1000->{ + binding.myIdea = response.body()?.result + } + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + TODO("Not yet implemented") + } + + }) + + binding?.teamIdeaModifyBtnTv?.setOnClickListener{ + it.findNavController().navigate(R.id.action_myInfoTeamIdeaFragment_to_myInfoProjectModifyFragment) + } } } \ No newline at end of file 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 805b21e..1657f63 100644 --- a/app/src/main/java/com/example/infraandroid/util/BindingConversion.kt +++ b/app/src/main/java/com/example/infraandroid/util/BindingConversion.kt @@ -117,4 +117,10 @@ object BindingConversions { fun setRecruitText(textView: TextView, nowRecruit: Int, totalRecruit: Int){ textView.text = "${nowRecruit}/${totalRecruit}명" } + + @JvmStatic + @BindingAdapter("nowRecruitString", "totalRecruitString") + fun setRecruitTextString(textView: TextView, nowRecruit: String?, totalRecruit: String?){ + textView.text = "${nowRecruit}/${totalRecruit}명" + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/infraandroid/util/ServiceCreator.kt b/app/src/main/java/com/example/infraandroid/util/ServiceCreator.kt index 1e1a952..de7435f 100644 --- a/app/src/main/java/com/example/infraandroid/util/ServiceCreator.kt +++ b/app/src/main/java/com/example/infraandroid/util/ServiceCreator.kt @@ -7,6 +7,7 @@ import com.example.infraandroid.id.model.LoginService import com.example.infraandroid.id.model.SMSService import com.example.infraandroid.id.model.SignUpService import com.example.infraandroid.id.model.UserDoubleCheckService +import com.example.infraandroid.myinfo.myideamanage.model.MyProjectService import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit @@ -34,4 +35,5 @@ object ServiceCreator { val profileViewService : ProfileViewService = retrofit.create(ProfileViewService::class.java) val createProjectService : CreateProjectService = retrofit.create(CreateProjectService::class.java) val projectService : ProjectService = retrofit.create(ProjectService::class.java) + val myProjectService : MyProjectService = retrofit.create(MyProjectService::class.java) } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_team_idea.xml b/app/src/main/res/layout/fragment_team_idea.xml index e5d7f5e..1853aa1 100644 --- a/app/src/main/res/layout/fragment_team_idea.xml +++ b/app/src/main/res/layout/fragment_team_idea.xml @@ -1,375 +1,412 @@ - + xmlns:tools="http://schemas.android.com/tools"> - + + + + - + + + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + android:layout_height="wrap_content" + android:background="@drawable/category_info_background" + android:fillViewport="true"> + + + + + + + + + + + + + + - + + - + android:layout_marginTop="22dp" + android:layout_marginHorizontal="40dp" + android:orientation="vertical" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/category_team_idea_textview"> + + + + + + + + + - + 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: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="@{myIdea.pj_progress}" + 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:includeFontPadding="false" + 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="@{myIdea.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="@{myIdea.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 + android:orientation="horizontal" + app:layout_constraintStart_toStartOf="parent" + android:layout_marginStart="40dp" + app:layout_constraintTop_toBottomOf="@id/hash_tag_team_idea" + android:layout_marginTop="26dp" + app:layout_constraintBottom_toBottomOf="parent" + android:layout_marginBottom="50dp"> + + + + + + + + + + + + + + + + + + + \ 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 0fb3d6c..e57a205 100644 --- a/app/src/main/res/layout/fragment_view_idea.xml +++ b/app/src/main/res/layout/fragment_view_idea.xml @@ -341,7 +341,7 @@ android:layout_height="wrap_content" android:fontFamily="@font/noto_sans_kr_regular" android:includeFontPadding="false" - android:text="@{viewIdea.pj_content}" + android:text="@{viewIdea.pj_progress}" android:textColor="@color/black" android:textSize="15sp" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/layout/item_my_idea_list_recyclerview.xml b/app/src/main/res/layout/item_my_idea_list_recyclerview.xml index e7f7f03..9523060 100644 --- a/app/src/main/res/layout/item_my_idea_list_recyclerview.xml +++ b/app/src/main/res/layout/item_my_idea_list_recyclerview.xml @@ -1,110 +1,120 @@ - - + + + - + android:layout_marginVertical="15dp" + android:layout_marginHorizontal="20dp"> - + - + - + - + - + - + + + + + - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 99cf116..2b7a554 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -233,6 +233,14 @@ android:id="@+id/action_myInfoTeamIdeaFragment_to_myInfoProjectModifyFragment" app:destination="@id/myInfoProjectModifyFragment" app:enterAnim="@anim/slide_in_bottom" /> + +