Skip to content

Commit

Permalink
[feat] #113 My Project List & View My Project Server Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-j0y committed Mar 25, 2022
1 parent d410bf3 commit 17ca9aa
Showing 14 changed files with 656 additions and 465 deletions.
Original file line number Diff line number Diff line change
@@ -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<ResponseViewIdeaData>
}
Original file line number Diff line number Diff line change
@@ -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<ResponseMyProjectListData>
}
Original file line number Diff line number Diff line change
@@ -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<Int>()
val currentObservingProjectNum: LiveData<Int> = _currentObservingProjectNum

fun updateObservingProjectNum(projectNum: Int){
_currentObservingProjectNum.value = projectNum
}
}
Original file line number Diff line number Diff line change
@@ -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<Result>
) {
data class Result(
val hashtag: ArrayList<String>,
val pj_categoryName: String,
val pj_daysub: Int,
val pj_deadline: String,
val pj_header: String,
val pj_num: Int,
val pj_photo: ArrayList<String>,
val pj_progress: String,
val pj_recruit: String,
val pj_recruitPerson: Int,
val pj_subCategoryNum: Int,
val pj_totalPerson: Int
)
}
Original file line number Diff line number Diff line change
@@ -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<RecyclerView.ViewHolder>() {
val myideaList = mutableListOf<MyIdeaListInfo>()
var myideaList = mutableListOf<ResponseMyProjectListData.Result>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val binding = ItemMyIdeaListRecyclerviewBinding.inflate(
@@ -30,21 +32,12 @@ class MyIdeaListAdapter(): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Original file line number Diff line number Diff line change
@@ -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<ResponseMyProjectListData> = ServiceCreator.myProjectService
.viewMyProject(InfraApplication.prefs.getString("jwt", "null"), InfraApplication.prefs.getString("refreshToken", "null").toInt(), InfraApplication.prefs.getString("userId","null"))

call.enqueue(object: Callback<ResponseMyProjectListData>{
override fun onResponse(
call: Call<ResponseMyProjectListData>,
response: Response<ResponseMyProjectListData>
) {
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<ResponseMyProjectListData>, t: Throwable) {
TODO("Not yet implemented")
}
})

}

override fun onDestroyView() {
Original file line number Diff line number Diff line change
@@ -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<FragmentTeamIdeaBinding>(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<ResponseViewIdeaData> = 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<ResponseViewIdeaData> {
override fun onResponse(
call: Call<ResponseViewIdeaData>,
response: Response<ResponseViewIdeaData>
) {
if(response.isSuccessful){
when(response.body()?.code){
1000->{
binding.myIdea = response.body()?.result
}
}
}
}

override fun onFailure(call: Call<ResponseViewIdeaData>, t: Throwable) {
TODO("Not yet implemented")
}

})

binding?.teamIdeaModifyBtnTv?.setOnClickListener{
it.findNavController().navigate(R.id.action_myInfoTeamIdeaFragment_to_myInfoProjectModifyFragment)
}
}
}
Original file line number Diff line number Diff line change
@@ -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}"
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit 17ca9aa

Please sign in to comment.