Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SPOTeam_android/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spoteam_android

import Gender
import android.os.Parcel
import android.os.Parcelable
import com.example.spoteam_android.data.ApiModels
Expand Down Expand Up @@ -207,7 +208,7 @@ data class StudyDetailsResult( //StudyFragment에서 detail하게 들어갔을
val heartCount: Int,
val memberCount: Int,
val maxPeople: Int,
val gender: String,
val gender: Gender,
val minAge: Int,
val maxAge: Int,
val fee: Int,
Expand All @@ -222,6 +223,21 @@ data class Owner(
val ownerName: String
)

data class StudyRequest(
val themes: List<String>,
val title: String,
val goal: String,
val introduction: String,
val isOnline: Boolean,
val profileImage: String?,
val regions: List<String>?,
val maxPeople: Int,
val gender: Gender,
val minAge: Int,
val maxAge: Int,
val fee: Int,
val hasFee: Boolean
)

data class MemberResponse(
val isSuccess: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spoteam_android

import StudyViewModel
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
Expand All @@ -16,6 +17,7 @@ import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import com.example.spoteam_android.data.ApiModels
import com.example.spoteam_android.databinding.ActivityMainBinding
Expand Down Expand Up @@ -58,6 +60,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private lateinit var fab: FloatingActionButton
private val weatherViewModel: WeatherViewModel by viewModels() // Hilt 사용
private val viewModel: StudyViewModel by viewModels()

@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -228,9 +231,16 @@ class MainActivity : AppCompatActivity() {
}

findViewById<View>(R.id.activity_main_registerstudy_ib).setOnClickListener {
showFragment(RegisterStudyFragment())
showStudyFrameLayout(false) // RegisterFragment를 보이도록 하되 FrameLayout은 숨김
viewModel.reset()
val fragment = RegisterStudyFragment().apply {
arguments = Bundle().apply {
putSerializable("mode", StudyFormMode.CREATE)
}
}
showFragment(fragment)
showStudyFrameLayout(false)
}

}

fun switchFragment(fragment: Fragment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.spoteam_android.ui.mypage
import android.app.AlertDialog
import android.os.Bundle
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
Expand All @@ -12,6 +13,7 @@ import android.widget.ImageView
import android.widget.PopupWindow
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -23,6 +25,9 @@ import com.example.spoteam_android.R
import com.example.spoteam_android.ReportStudyMemberFragment
import com.example.spoteam_android.RetrofitInstance
import com.example.spoteam_android.databinding.ItemRecyclerViewPlusToggleBinding
import com.example.spoteam_android.ui.community.CommunityAPIService
import com.example.spoteam_android.ui.community.GetHostResponse
import com.example.spoteam_android.ui.study.RegisterStudyFragment
import com.example.spoteam_android.ui.community.MyRecruitingStudyDetail
import com.example.spoteam_android.ui.interestarea.GetHostInterface
import retrofit2.Call
Expand Down Expand Up @@ -132,11 +137,23 @@ class BoardAdapter(
leaveStudy.visibility = View.VISIBLE
}

// 클릭 리스너 설정
editInfo.setOnClickListener {
Toast.makeText(view.context, "정보 수정하기 클릭됨", Toast.LENGTH_SHORT).show()
popupWindow.dismiss()
editInfo.setOnClickListener {
popupWindow.dismiss()

val fragment = RegisterStudyFragment().apply {
arguments = Bundle().apply {
putSerializable("mode", StudyFormMode.EDIT)
putInt("studyId", studyId)
}
}

// Fragment 이동
(view.context as? AppCompatActivity)?.supportFragmentManager
?.beginTransaction()
?.replace(R.id.main_frm, fragment)
?.addToBackStack(null)
?.commit()
}

endStudy.setOnClickListener {
// 스터디 종료 다이얼로그 띄우기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ class DetailStudyFragment : Fragment() {
val themes = studyDetails.themes
val displayedThemes = themes.take(3).joinToString("/") // 최대 2개 항목
val remainingCount = (themes.size - 2).coerceAtLeast(0) // 2개를 초과한 항목 수
studyViewModel.studyOwner.value = studyDetails.studyOwner.ownerName
studyViewModel.setStudyOwner(studyDetails.studyOwner.ownerName)



binding.fragmentDetailStudyChipTv.text = "${displayedThemes}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ class IntroduceStudyFragment : Fragment() {
): View? {
binding = FragmentIntroduceStudyBinding.inflate(inflater, container, false)

viewModel.studyRequest.observe(viewLifecycleOwner) { request ->
if (viewModel.mode.value == StudyFormMode.EDIT && request != null) {
binding.fragmentIntroduceStudynameEt.setText(request.title)
binding.fragmentIntroduceStudypurposeEt.setText(request.goal)
binding.fragmentIntroduceStudyEt.setText(request.introduction)
}
}




// 초기화 함수 호출
initActivityResultLaunchers()
initAddImageButton()
Expand Down Expand Up @@ -186,9 +197,17 @@ class IntroduceStudyFragment : Fragment() {
}

private fun goToNextFragment() {
val transaction = parentFragmentManager.beginTransaction()
transaction.replace(R.id.main_frm, OnlineStudyFragment()) // 변경할 Fragment로 교체
transaction.commit()
val nextFragment = OnlineStudyFragment().apply {
arguments = Bundle().apply {
putSerializable("mode", viewModel.mode.value)
viewModel.studyId.value?.let { putInt("studyId", it) }
}
}

parentFragmentManager.beginTransaction()
.replace(R.id.main_frm, nextFragment)
.addToBackStack(null)
.commit()
}

private fun goToPreviusFragment() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spoteam_android.ui.study

import StudyFormMode
import StudyViewModel
import android.os.Bundle
import android.view.LayoutInflater
Expand All @@ -10,13 +11,30 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.example.spoteam_android.R
import com.example.spoteam_android.databinding.FragmentRegisterStudyBinding
import com.google.android.material.chip.Chip

class RegisterStudyFragment : Fragment() {

private lateinit var binding: FragmentRegisterStudyBinding
private var currentStep = 1 // 현재 단계
private val viewModel: StudyViewModel by activityViewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val mode = arguments?.getSerializable("mode", StudyFormMode::class.java) ?: StudyFormMode.CREATE
val studyId = arguments?.getInt("studyId", -1) ?: -1

viewModel.setMode(mode)

if (mode == StudyFormMode.CREATE) {
viewModel.reset()
}
if (mode == StudyFormMode.EDIT && studyId != -1) {
viewModel.fetchStudyDetail(studyId)
}
}


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -25,6 +43,7 @@ class RegisterStudyFragment : Fragment() {

// ChipGroup 설정 메소드 호출
setChipGroup()
observeThemes()

// '다음' 버튼 클릭 리스너 설정
binding.fragmentRegisterStudyBt.setOnClickListener {
Expand Down Expand Up @@ -77,6 +96,24 @@ class RegisterStudyFragment : Fragment() {
viewModel.updateThemes(selectedThemes)
}

private fun observeThemes() {
viewModel.themes.observe(viewLifecycleOwner) { themes ->
for (i in 0 until binding.fragmentRegisterStudyChipgroup.childCount) {
val chip = binding.fragmentRegisterStudyChipgroup.getChildAt(i) as? Chip
chip?.let {
val normalizedChipText = normalizeText(it.text.toString())
val normalizedServerTextList = themes.map { theme -> normalizeServerText(theme) }

it.isChecked = normalizedServerTextList.contains(normalizedChipText)
}
}

// 수정 모드에서 테마가 미리 선택되어 있는 경우, 버튼도 활성화
binding.fragmentRegisterStudyBt.isEnabled = themes.isNotEmpty()
}
}



private fun updateProgressBar() {
currentStep++
Expand All @@ -85,8 +122,30 @@ class RegisterStudyFragment : Fragment() {
}

private fun goToNextFragment() {
val transaction = parentFragmentManager.beginTransaction()
transaction.replace(R.id.main_frm, IntroduceStudyFragment())
transaction.commit()
val nextFragment = IntroduceStudyFragment().apply {
arguments = Bundle().apply {
putSerializable("mode", viewModel.mode.value)
viewModel.studyId.value?.let { putInt("studyId", it) }
}
}

parentFragmentManager.beginTransaction()
.replace(R.id.main_frm, nextFragment)
.addToBackStack(null)
.commit()
}


private fun normalizeText(text: String): String {
return text.replace(" ", "").replace("및", "/")
}

private fun normalizeServerText(text: String): String {
return text
.replace("전공및진로학습", "전공/진로학습")
.replace("시사뉴스", "시사/뉴스")
.replace("자율학습", "자율 학습")
.replace(" ", "")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ enum class Gender {
@SerializedName("FEMALE")
FEMALE
}

enum class StudyFormMode {
CREATE,
EDIT
}

data class ApiResponsed(
@SerializedName("isSuccess") val isSuccess: Boolean,
Expand Down
Loading