-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from TeamPINGLE/feat-plan-view
[feat] 핑글 개최 프로세스 전체 뷰 구현
- Loading branch information
Showing
11 changed files
with
261 additions
and
10 deletions.
There are no files selected for viewing
78 changes: 77 additions & 1 deletion
78
app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ActivityPlanBinding>(R.layout.activity_plan) { | ||
private val planViewModel: PlanViewModel by viewModels() | ||
private lateinit var fragmentList: ArrayList<Fragment> | ||
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) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanDateTimeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FragmentPlanDateTimeBinding>(R.layout.fragment_plan_date_time) { | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanFragmentStateAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Fragment>, | ||
fragmentActivity: FragmentActivity | ||
) : FragmentStateAdapter(fragmentActivity) { | ||
override fun getItemCount(): Int = fragmentList.size | ||
override fun createFragment(position: Int): Fragment { | ||
return fragmentList[position] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanOpenChattingFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FragmentPlanOpenChattingBinding>(R.layout.fragment_plan_open_chatting) { | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanTitleFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FragmentPlanTitleBinding>(R.layout.fragment_plan_title) { | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/org/sopt/pingle/presentation/ui/main/plan/PlanViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<data> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters