diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanActivity.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanActivity.kt index 76c5e81b..d8fe71b3 100644 --- a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanActivity.kt +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanActivity.kt @@ -1,13 +1,89 @@ package org.sopt.pingle.presentation.ui.main.plan import android.os.Bundle +import androidx.activity.viewModels +import androidx.fragment.app.Fragment +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope +import androidx.viewpager2.widget.ViewPager2 +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import org.sopt.pingle.R import org.sopt.pingle.databinding.ActivityPlanBinding import org.sopt.pingle.util.base.BindingActivity class PlanActivity : BindingActivity(R.layout.activity_plan) { + private val planViewModel: PlanViewModel by viewModels() + private lateinit var fragmentList: ArrayList override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_plan) + + setPlanFragmentStateAdapter() + addListeners() + collectData() + } + + private fun setPlanFragmentStateAdapter() { + // TODO 차후에 나머지 개최 프로세스 fragment 추가 + fragmentList = ArrayList() + fragmentList.apply { + add(PlanTitleFragment()) + add(PlanDateTimeFragment()) + add(PlanOpenChattingFragment()) + } + + val adapter = PlanFragmentStateAdapter(fragmentList, this) + with(binding.vpPlan) { + this.adapter = adapter + isUserInputEnabled = false + registerOnPageChangeCallback(object : + ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + planViewModel.setCurrentPage(position) + } + }) + } + } + + private fun addListeners() { + binding.btnPlan.setOnClickListener { + when (binding.vpPlan.currentItem) { + // TODO 핑글 개최 api 연동 + fragmentList.size - 1 -> {} + else -> { + binding.vpPlan.currentItem++ + } + } + } + binding.toolbar.ivAllTopbarArrowWithTitleArrowLeft.setOnClickListener { + when (binding.vpPlan.currentItem) { + 0 -> { + // TODO 나가기 확인 모달 + } + + else -> { + binding.vpPlan.currentItem-- + } + } + } + binding.tvPlanClose.setOnClickListener { + // TODO 나가기 확인 모달 + } + } + + private fun collectData() { + planViewModel.currentPage.flowWithLifecycle(lifecycle).onEach { currentPage -> + when (currentPage) { + fragmentList.size - 1 -> { + binding.btnPlan.text = getString(R.string.plan_pingle) + } + + // TODO 다른 다음으로 스트링과 합치기 + else -> { + binding.btnPlan.text = getString(R.string.plan_next) + } + } + }.launchIn(lifecycleScope) } } diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanDateTimeFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanDateTimeFragment.kt new file mode 100644 index 00000000..e522a8a7 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanDateTimeFragment.kt @@ -0,0 +1,13 @@ +package org.sopt.pingle.presentation.ui.main.plan + +import android.os.Bundle +import android.view.View +import org.sopt.pingle.R +import org.sopt.pingle.databinding.FragmentPlanDateTimeBinding +import org.sopt.pingle.util.base.BindingFragment + +class PlanDateTimeFragment : BindingFragment(R.layout.fragment_plan_date_time) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } +} diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanFragmentStateAdapter.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanFragmentStateAdapter.kt new file mode 100644 index 00000000..7a784ee4 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanFragmentStateAdapter.kt @@ -0,0 +1,15 @@ +package org.sopt.pingle.presentation.ui.main.plan + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.viewpager2.adapter.FragmentStateAdapter + +class PlanFragmentStateAdapter( + private val fragmentList: ArrayList, + fragmentActivity: FragmentActivity +) : FragmentStateAdapter(fragmentActivity) { + override fun getItemCount(): Int = fragmentList.size + override fun createFragment(position: Int): Fragment { + return fragmentList[position] + } +} diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanOpenChattingFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanOpenChattingFragment.kt new file mode 100644 index 00000000..53585426 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanOpenChattingFragment.kt @@ -0,0 +1,13 @@ +package org.sopt.pingle.presentation.ui.main.plan + +import android.os.Bundle +import android.view.View +import org.sopt.pingle.R +import org.sopt.pingle.databinding.FragmentPlanOpenChattingBinding +import org.sopt.pingle.util.base.BindingFragment + +class PlanOpenChattingFragment : BindingFragment(R.layout.fragment_plan_open_chatting) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } +} diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanTitleFragment.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanTitleFragment.kt new file mode 100644 index 00000000..69fba4ba --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanTitleFragment.kt @@ -0,0 +1,13 @@ +package org.sopt.pingle.presentation.ui.main.plan + +import android.os.Bundle +import android.view.View +import org.sopt.pingle.R +import org.sopt.pingle.databinding.FragmentPlanTitleBinding +import org.sopt.pingle.util.base.BindingFragment + +class PlanTitleFragment : BindingFragment(R.layout.fragment_plan_title) { + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + } +} diff --git a/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt new file mode 100644 index 00000000..e3d14475 --- /dev/null +++ b/app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt @@ -0,0 +1,18 @@ +package org.sopt.pingle.presentation.ui.main.plan + +import androidx.lifecycle.ViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow + +class PlanViewModel : ViewModel() { + private val _currentPage = MutableStateFlow(FIRST_PAGE_POSITION) + val currentPage get() = _currentPage.asStateFlow() + + fun setCurrentPage(position: Int) { + _currentPage.value = position + } + + companion object { + const val FIRST_PAGE_POSITION = 0 + } +} diff --git a/app/src/main/res/layout/activity_plan.xml b/app/src/main/res/layout/activity_plan.xml index fc16e19f..e25ae8f8 100644 --- a/app/src/main/res/layout/activity_plan.xml +++ b/app/src/main/res/layout/activity_plan.xml @@ -9,19 +9,77 @@ + android:layout_height="match_parent"> - + + + + + + + + + + + app:layout_constraintEnd_toEndOf="@id/gl_end" + app:layout_constraintStart_toStartOf="@id/gl_start"> + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_plan_date_time.xml b/app/src/main/res/layout/fragment_plan_date_time.xml new file mode 100644 index 00000000..67ed5d4c --- /dev/null +++ b/app/src/main/res/layout/fragment_plan_date_time.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_plan_open_chatting.xml b/app/src/main/res/layout/fragment_plan_open_chatting.xml new file mode 100644 index 00000000..67ed5d4c --- /dev/null +++ b/app/src/main/res/layout/fragment_plan_open_chatting.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_plan_title.xml b/app/src/main/res/layout/fragment_plan_title.xml new file mode 100644 index 00000000..67ed5d4c --- /dev/null +++ b/app/src/main/res/layout/fragment_plan_title.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fbf8e8ca..d50e51b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,6 +19,12 @@ 기존 단체\n입장하기 신규 단체\n개설하기 + + 나중에 만드시겠어요? + 나가기 + 다음으로 + 핑글 개최하기 + 입장하기 단체 입장\n완료!