Skip to content

Commit

Permalink
Merge pull request #339 from DKU-Dgaja/an-feat(#337)-스터디-신청-페이지전체-스터디…
Browse files Browse the repository at this point in the history
…-상세-페이지-로직-구현

[AN] feat(#337): 스터디 신청 페이지전체 스터디 상세 페이지 로직 구현
  • Loading branch information
saesang authored Jun 4, 2024
2 parents 40e283b + 34a1bcd commit 932ecc0
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class StudyInfo(
@SerializedName("info")
val info: String,
@SerializedName("last_commit_day")
val lastCommitDay: String,
val lastCommitDay: String?,
@SerializedName("maximum_member")
val maximumMember: Int,
@SerializedName("period_type")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.takseha.data.dto.mystudy


import com.google.gson.annotations.SerializedName

data class Commit(
@SerializedName("commit_date")
val commitDate: String,
@SerializedName("commit_sha")
val commitSha: String,
@SerializedName("id")
val id: Int,
@SerializedName("like_count")
val likeCount: LikeCount,
@SerializedName("message")
val message: String,
@SerializedName("rejection-reason")
val rejectionReason: String,
@SerializedName("status")
val status: String,
@SerializedName("study_info_id")
val studyInfoId: Int,
@SerializedName("study_todo_id")
val studyTodoId: Int,
@SerializedName("user_id")
val userId: Int
)

data class LikeCount(
@SerializedName("like_count")
val likeCount: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ data class Todo(
@SerializedName("todo_date")
val todoDate: String,
@SerializedName("todo_link")
val todoLink: String
val todoLink: String,
@SerializedName("commits")
val commitList: List<Commit>
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.Color
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -13,10 +14,16 @@ import com.takseha.presentation.R
import com.takseha.presentation.databinding.ItemFeedBinding
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import kotlin.math.abs

class FeedRVAdapter(val context : Context, val studyInfoList : List<StudyInfo>) : RecyclerView.Adapter<FeedRVAdapter.ViewHolder>() {
private val backgroundColorList = listOf("#00BE93", "#00A19A", "#008291", "#08647A", "#386C5F", "#6E9B7B")

interface ItemClick {
fun onClick(view: View, position: Int)
}
var itemClick: ItemClick? = null

class ViewHolder(val binding: ItemFeedBinding) : RecyclerView.ViewHolder(binding.root) {
val backgroundColor = binding.studyInfoLayout
val studyName = binding.studyName
Expand All @@ -36,14 +43,25 @@ class FeedRVAdapter(val context : Context, val studyInfoList : List<StudyInfo>)

@RequiresApi(Build.VERSION_CODES.O)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.backgroundColor.setBackgroundColor(Color.parseColor(backgroundColorList[position % 6]))
if (studyInfoList[position].profileImageUrl.isEmpty()) {
holder.backgroundColor.setBackgroundColor(Color.parseColor(backgroundColorList[position % 6]))
} else {
holder.backgroundColor.setBackgroundColor(Color.parseColor(studyInfoList[position].profileImageUrl))
}
holder.studyName.text = studyInfoList[position].topic
holder.commitRule.text = setCommitRule(studyInfoList[position].periodType)
holder.teamInfo.text = context.getString(R.string.study_team_rank_full, position, studyInfoList[position].lastCommitDay)
holder.teamScore.text = studyInfoList[position].score.toString()
holder.teamInfo.text = context.getString(R.string.study_team_rank_full, if (studyInfoList[position].id - 10 > 0) studyInfoList[position].id - 10 else abs(studyInfoList[position].id - 10) + 2, if (studyInfoList[position].lastCommitDay == null ) "없음" else studyInfoList[position].lastCommitDay)
holder.teamScore.text = (studyInfoList[position].id * 10 + 2).toString()
holder.totalDayCnt.text = context.getString(R.string.study_total_day_cnt, calculateTotalDayCnt(studyInfoList[position].createdDateTime))
holder.currentMember.text = studyInfoList[position].currentMember.toString()
holder.totalMember.text = context.getString(R.string.study_member_rv, studyInfoList[position].maximumMember)

// 클릭 이벤트 처리
if (itemClick != null) {
holder?.itemView?.setOnClickListener { v ->
itemClick!!.onClick(v, position)
}
}
}

override fun getItemCount(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class MyStudyRVAdapter(val context : Context, val studyInfoList : List<MyStudyWi
holder.totalNum.text = studyInfoList[position].studyInfo.maximumMember.toString()
}
TodoStatus.TODO_INCOMPLETE -> {
holder.noTodoAlarm.visibility = GONE
holder.todoTitle.visibility = VISIBLE
holder.todoCheck.visibility = VISIBLE
holder.todoTimeText.visibility = VISIBLE
holder.todoTime.visibility = VISIBLE
holder.todoCheck.text = "미완료"
holder.todoTitle.text = studyInfoList[position].todoTitle
holder.todoTime.text = studyInfoList[position].todoTime
Expand All @@ -74,6 +79,11 @@ class MyStudyRVAdapter(val context : Context, val studyInfoList : List<MyStudyWi
}
}
else -> {
holder.noTodoAlarm.visibility = GONE
holder.todoTitle.visibility = VISIBLE
holder.todoCheck.visibility = VISIBLE
holder.todoTimeText.visibility = VISIBLE
holder.todoTime.visibility = VISIBLE
holder.todoCheck.text = "완료"
holder.todoTitle.text = studyInfoList[position].todoTitle
holder.todoTime.text = studyInfoList[position].todoTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.takseha.presentation.ui.feed

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
Expand All @@ -10,9 +11,13 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.takseha.data.dto.feed.StudyInfo
import com.takseha.data.dto.mystudy.MyStudyWithTodo
import com.takseha.presentation.R
import com.takseha.presentation.adapter.FeedRVAdapter
import com.takseha.presentation.adapter.MyStudyRVAdapter
import com.takseha.presentation.databinding.FragmentFeedHomeBinding
import com.takseha.presentation.ui.mystudy.MyStudyMainActivity
import com.takseha.presentation.viewmodel.feed.FeedHomeViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -52,21 +57,37 @@ class FeedHomeFragment : Fragment() {
// }

viewLifecycleOwner.lifecycleScope.launch {
viewModel.getFeedList(null, 5, "createdDateTime")
viewModel.getFeedList(null, 10, "createdDateTime")
viewModel.uiState.collectLatest {
val feedRVAdapter = FeedRVAdapter(requireContext(), it.studyInfoList)
if (it.studyInfoList.isNotEmpty()) {
val feedRVAdapter = FeedRVAdapter(requireContext(), it.studyInfoList)

if (feedRVAdapter.itemCount > 0) {
isNoStudyLayout.visibility = View.GONE
}
if (feedRVAdapter.itemCount == 0) {
isNoStudyLayout.visibility = View.VISIBLE
}

feedList.adapter = feedRVAdapter
feedList.layoutManager = LinearLayoutManager(requireContext())

feedList.adapter = feedRVAdapter
feedList.layoutManager = LinearLayoutManager(requireContext())
clickFeedItem(feedRVAdapter, it.studyInfoList)
}
}
}
}
}

private fun clickFeedItem(feedRVAdapter: FeedRVAdapter, studyList: List<StudyInfo>) {
feedRVAdapter.itemClick = object : FeedRVAdapter.ItemClick {
override fun onClick(view: View, position: Int) {
val intent = Intent(requireContext(), StudyApplyActivity::class.java)
intent.putExtra("studyInfoId", studyList[position].id)
intent.putExtra("studyImgColor", studyList[position].profileImageUrl)
Log.d("FeedHomeFragment", intent.extras.toString())
startActivity(intent)
}
}
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,102 @@
package com.takseha.presentation.ui.feed

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.takseha.data.dto.feed.StudyPeriod
import com.takseha.data.dto.feed.StudyStatus
import com.takseha.data.dto.mystudy.MyStudyInfo
import com.takseha.presentation.R
import com.takseha.presentation.databinding.ActivityStudyApplyBinding
import com.takseha.presentation.viewmodel.feed.StudyApplyViewModel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlin.math.abs


class StudyApplyActivity : AppCompatActivity() {
private lateinit var binding: ActivityStudyApplyBinding
private val viewModel: StudyApplyViewModel by viewModels()


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_study_apply)
setBinding()

val studyInfoId = intent.getIntExtra("studyInfoId", 0)
val studyImgColor =
if (intent.getStringExtra("studyImgColor") == "") "#000000" else intent.getStringExtra("studyImgColor")

window.statusBarColor = Color.parseColor(studyImgColor)

viewModel.getStudyInfo(studyInfoId)

lifecycleScope.launch {
viewModel.uiState.collectLatest {
setMyStudyInfo(studyInfoId, studyImgColor!!, it.studyInfo)
}
}

with(binding) {
backBtn.setOnClickListener {
finish()
}
studyEnterBtn.setOnClickListener {

}
studyLinkCopyBtn.setOnClickListener {

}
}
}

private fun setMyStudyInfo(studyInfoId: Int, studyImgColor: String, myStudyInfo: MyStudyInfo) {
with(binding) {
studyBackgroundImg.setBackgroundColor(Color.parseColor(studyImgColor))
studyName.text = myStudyInfo.topic
studyDetail.text = myStudyInfo.info
studyRuleText.text = setCommitRule(myStudyInfo.periodType)
isStudyOpenText.text = setStudyStatus(myStudyInfo.status)
studyRankText.text = getString(
R.string.study_team_rank, studyInfoId * 10 + 2,
if (studyInfoId - 10 > 0) studyInfoId - 10 else abs(studyInfoId - 10) + 2
)
teamRankFullText.text = getString(
R.string.study_team_rank_full,
if (studyInfoId - 10 > 0) studyInfoId - 10 else abs(studyInfoId - 10) + 2,
if (myStudyInfo.lastCommitDay == null) "없음" else myStudyInfo.lastCommitDay
)
studyGithubLinkText.text = myStudyInfo.githubLinkInfo.branchName
studyMemberCntText.text = String.format(
getString(R.string.feed_member_number),
myStudyInfo.currentMember,
myStudyInfo.maximumMember
)
}
}

private fun setCommitRule(periodType: StudyPeriod): String {
when (periodType) {
StudyPeriod.STUDY_PERIOD_EVERYDAY -> return baseContext.getString(R.string.feed_rule_everyday)
StudyPeriod.STUDY_PERIOD_WEEK -> return baseContext.getString(R.string.feed_rule_week)
StudyPeriod.STUDY_PERIOD_NONE -> return baseContext.getString(R.string.feed_rule_free)
}
}

private fun setStudyStatus(status: StudyStatus): String {
when (status) {
StudyStatus.STUDY_PRIVATE -> return baseContext.getString(R.string.study_lock)
StudyStatus.STUDY_PUBLIC -> return baseContext.getString(R.string.study_unlock)
StudyStatus.STUDY_DELETED -> return baseContext.getString(R.string.study_deleted)
}
}

private fun setBinding() {
binding = ActivityStudyApplyBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class MainHomeFragment : Fragment() {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.apply {
myStudyState.collectLatest {
setMyStudyList(it.myStudiesWithTodo)
if (it.myStudiesWithTodo.isNotEmpty()) {
setMyStudyList(it.myStudiesWithTodo)
}
}
}
}
Expand All @@ -84,8 +86,8 @@ class MainHomeFragment : Fragment() {
with(binding) {
val myStudyRVAdapter = MyStudyRVAdapter(requireContext(), studyList)

if (myStudyRVAdapter.itemCount > 0) {
isNoStudyLayout.visibility = View.GONE
if (myStudyRVAdapter.itemCount == 0) {
isNoStudyLayout.visibility = View.VISIBLE
}

myStudyList.adapter = myStudyRVAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ class CommitConventionActivity : AppCompatActivity() {
setBinding()

val studyInfoId = intent.getIntExtra("studyInfoId", 0)
val conventionInfo = intent.getSerializableExtra("conventionInfo") as StudyConvention
val conventionInfo =
if (intent.getSerializableExtra("conventionInfo") == null) StudyConvention(
false,
"",
0,
"",
"",
studyInfoId
) else intent.getSerializableExtra("conventionInfo") as StudyConvention

with(binding) {
var convention = conventionInfo.name
Expand Down Expand Up @@ -106,7 +114,12 @@ class CommitConventionActivity : AppCompatActivity() {
}
}

private fun setInitConvention(convention: String, content: String, description: String, active: Boolean) {
private fun setInitConvention(
convention: String,
content: String,
description: String,
active: Boolean
) {
with(binding) {
conventionEditText.setText(convention)
contentEditText.setText(content)
Expand All @@ -117,7 +130,7 @@ class CommitConventionActivity : AppCompatActivity() {

private fun isConventionActive(active: Boolean) {
with(binding) {
if(active) {
if (active) {
isNotConventionText.visibility = View.GONE
isConventionText.visibility = View.VISIBLE
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class MyStudyHomeFragment : Fragment() {
): View? {
_binding = FragmentMyStudyHomeBinding.inflate(inflater, container, false)

viewModel.getMyStudyList(null, 10)

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.myStudyState.collectLatest {
setMyStudyList(it.myStudiesWithTodo)
if (it.myStudiesWithTodo.isNotEmpty()) {
setMyStudyList(it.myStudiesWithTodo)
}
}
}
}
Expand All @@ -52,8 +52,8 @@ class MyStudyHomeFragment : Fragment() {
with(binding) {
val myStudyRVAdapter = MyStudyRVAdapter(requireContext(), studyList)

if (myStudyRVAdapter.itemCount > 0) {
isNoStudyLayout.visibility = View.GONE
if (myStudyRVAdapter.itemCount == 0) {
isNoStudyLayout.visibility = View.VISIBLE
}

myStudyList.adapter = myStudyRVAdapter
Expand Down
Loading

0 comments on commit 932ecc0

Please sign in to comment.