Skip to content

Commit

Permalink
#118 feat: 투표 생성 후 투표 종료 안내 스낵바 보이기
Browse files Browse the repository at this point in the history
  • Loading branch information
stopkite committed Mar 3, 2024
1 parent f638a60 commit c4ee1ee
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class LeaderVoteBeforeFragment : BaseFragment<FragmentLeaderVoteBeforeBinding>(R

private val requestLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
it.data?.apply {
getBooleanExtra(CRATE_VOTE_SUCCESS_STATE, false).let { isCreateVoteSuccess ->
if (isCreateVoteSuccess) { // 투표 생성 완료
val extras = Bundle().apply {
putInt(GROUP_ID, groupId)
putExtra(CRATE_VOTE_MSG_EXTRA, this.getString(CRATE_VOTE_MSG_EXTRA)) // 스낵바 메세지
}
initNavigation(R.id.leaderVoteProgressFragment, extras)
) { result ->
result.data?.let { data ->
val isCreateVoteSuccess = data.getBooleanExtra(CRATE_VOTE_SUCCESS_STATE, false)
if (isCreateVoteSuccess) { // 투표 생성 완료
val extras = Bundle().apply {
putInt(GROUP_ID, groupId)
putBoolean(CRATE_VOTE_SUCCESS_STATE, true) // 생성 직후 진행화면으로 넘어온 것인지 확인을 위한 변수
putString(CRATE_VOTE_MSG_EXTRA, data.getStringExtra(CRATE_VOTE_MSG_EXTRA)) // 스낵바 메세지
}
initNavigation(R.id.leaderVoteProgressFragment, extras)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@ class CreateVoteActivity : BaseActivity<ActivityCreateVoteBinding>(R.layout.acti
fun onClickCreateVote() {
// viewModel.crateVote(groupId)
val message = if (viewModel.hasEndTime.value == true) {
getString(R.string.create_vote_end_time_msg_vote_start) + viewModel.endTimeTxt.value!!.replace("투표가 종료됩니다.", "투표가 자동으로 종료돼요.")
getString(R.string.create_vote_end_time_msg_vote_start) + "\n" + viewModel.endTimeTxt.value!!.replace("투표가 종료됩니다.", "투표가 자동으로 종료돼요.")
} else {
getString(R.string.create_vote_end_time_msg_vote_start) + getString(R.string.create_vote_end_time_msg_vote_end)
getString(R.string.create_vote_end_time_msg_vote_start) + "\n" + getString(R.string.create_vote_end_time_msg_vote_end)
}

Log.d("kite", message.toString())

intent.apply {
putExtra(CRATE_VOTE_SUCCESS_STATE, true)
putExtra(CRATE_VOTE_MSG_EXTRA, message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
package com.moidot.moidot.presentation.main.group.space.leader.vote.progress

import android.os.Bundle
import android.view.View
import com.moidot.moidot.R
import com.moidot.moidot.databinding.FragmentLeaderVoteProgressBinding
import com.moidot.moidot.presentation.base.BaseFragment
import com.moidot.moidot.util.Constant.CRATE_VOTE_MSG_EXTRA
import com.moidot.moidot.util.Constant.CRATE_VOTE_SUCCESS_STATE
import com.moidot.moidot.util.Constant.GROUP_ID
import com.moidot.moidot.util.CustomSnackBar

class LeaderVoteProgressFragment : BaseFragment<FragmentLeaderVoteProgressBinding>(R.layout.fragment_leader_vote_progress) {

private val groupId by lazy { arguments?.getInt(GROUP_ID) ?: -1 }
private val voteCreateState by lazy { arguments?.getBoolean(CRATE_VOTE_SUCCESS_STATE) ?: false }
private val voteCreateSnackBarMsg by lazy { arguments?.getString(CRATE_VOTE_MSG_EXTRA) ?: getString(R.string.create_vote_end_time_msg_vote_start) }

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
showSnackBarAfterVoteCreation()
}

private fun showSnackBarAfterVoteCreation() {
if (voteCreateState) CustomSnackBar.makeSnackBar(binding.root, voteCreateSnackBarMsg).show()
}

}
3 changes: 1 addition & 2 deletions app/src/main/res/layout/fragment_leader_vote_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red500">
android:layout_height="match_parent">

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<string name="create_vote_start_vote">투표 시작하기</string>
<string name="create_vote_date_picker_title">날짜 선택</string>
<string name="create_vote_time_picker_title">시간 선택</string>
<string name="create_vote_end_time_msg_vote_start">투표가 시작되었어요!\n</string>
<string name="create_vote_end_time_msg_vote_start">투표가 시작되었어요!</string>
<string name="create_vote_end_time_msg_vote_end">종료하기를 누르면 투표가 종료돼요.</string>

<!-- MemberVote -->
Expand Down

0 comments on commit c4ee1ee

Please sign in to comment.