Skip to content

Commit

Permalink
[MERGE] : #360 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#360] Yello / 투표하기 투표 전환 애니메이션 변경
  • Loading branch information
Chaeyeon authored Feb 3, 2024
2 parents 34f8fee + 207ea53 commit cf3a037
Show file tree
Hide file tree
Showing 13 changed files with 1,051 additions and 879 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,16 @@ class ProfileFragment : BindingFragment<FragmentProfileBinding>(R.layout.fragmen
}

private fun initAdapter() {
_adapter = ProfileFriendAdapter(viewModel,
itemClick = { profileUserModel, position -> initItemClickListener(profileUserModel, position) },
_adapter = ProfileFriendAdapter(
viewModel,
itemClick = { profileUserModel, position ->
initItemClickListener(
profileUserModel,
position,
)
},
shopClick = { initShopClickListener() },
modClick = { initProfileModClickListener() }
modClick = { initProfileModClickListener() },
)
binding.rvProfileFriendsList.adapter = adapter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.el.yello.R
import com.el.yello.databinding.ActivityVoteBinding
import com.el.yello.presentation.main.yello.vote.frame.NoteFrameAdapter
import com.el.yello.presentation.main.yello.vote.note.NoteAdapter
import com.el.yello.presentation.util.setCurrentItemWithDuration
import com.el.yello.util.amplitude.AmplitudeUtils
import com.el.yello.util.context.yelloSnackbar
Expand All @@ -22,11 +24,18 @@ import org.json.JSONObject
class VoteActivity : BindingActivity<ActivityVoteBinding>(R.layout.activity_vote) {
private val viewModel by viewModels<VoteViewModel>()

private val voteAdapter by lazy {
VoteAdapter(
this,
viewModel.backgroundIndex,
viewModel.totalListCount + 1,
private val noteAdapter by lazy {
NoteAdapter(
fragmentActivity = this,
voteListSize = viewModel.totalListCount + 1,
)
}

private val noteFrameAdapter by lazy {
NoteFrameAdapter(
fragmentActivity = this,
bgIndex = viewModel.backgroundIndex,
voteListSize = viewModel.totalListCount + 1,
)
}

Expand All @@ -44,7 +53,7 @@ class VoteActivity : BindingActivity<ActivityVoteBinding>(R.layout.activity_vote
.onEach { state ->
when (state) {
is UiState.Loading -> {}
is UiState.Success -> initVoteViewPager()
is UiState.Success -> initNoteViewPager()
is UiState.Empty -> {}
is UiState.Failure -> {
// TODO: 커스텀 스낵바로 변경
Expand All @@ -55,18 +64,23 @@ class VoteActivity : BindingActivity<ActivityVoteBinding>(R.layout.activity_vote
}.launchIn(lifecycleScope)
}

private fun initVoteViewPager() {
with(binding) {
vpVote.adapter = voteAdapter
vpVote.setPageTransformer(FadeOutTransformation())
vpVote.isUserInputEnabled = false
private fun initNoteViewPager() {
with(binding.vpVoteNote) {
adapter = noteAdapter
isUserInputEnabled = false
}
with(binding.vpVoteNoteFrame) {
adapter = noteFrameAdapter
setPageTransformer(FadeOutTransformation())
isUserInputEnabled = false
}
}

private fun setupCurrentNoteIndex() {
viewModel._currentNoteIndex.flowWithLifecycle(lifecycle)
.onEach { index ->
binding.vpVote.setCurrentItemWithDuration(index, DURATION_NOTE_TRANSITION)
binding.vpVoteNote.setCurrentItemWithDuration(index, DURATION_NOTE_TRANSITION)
binding.vpVoteNoteFrame.setCurrentItemWithDuration(index, DURATION_FRAME_TRANSITION)
if (index <= viewModel.totalListCount) {
val properties = JSONObject().put(JSON_VOTE_STEP, index + 1)
AmplitudeUtils.trackEventWithProperties(EVENT_VIEW_VOTE_QUESTION, properties)
Expand All @@ -93,8 +107,8 @@ class VoteActivity : BindingActivity<ActivityVoteBinding>(R.layout.activity_vote
}

companion object {
private const val DURATION_NOTE_TRANSITION = 400L

private const val DURATION_NOTE_TRANSITION = 500L
private const val DURATION_FRAME_TRANSITION = 400L
private const val JSON_VOTE_STEP = "vote_step"
private const val EVENT_VIEW_VOTE_QUESTION = "view_vote_question"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,50 +34,43 @@ class VoteViewModel @Inject constructor(
private val voteRepository: VoteRepository,
) : ViewModel() {
private val _noteState = MutableSharedFlow<NoteState>()
val noteState: SharedFlow<NoteState>
get() = _noteState.asSharedFlow()
val noteState: SharedFlow<NoteState> get() = _noteState.asSharedFlow()

private val _voteState = MutableStateFlow<UiState<List<Note>>>(UiState.Loading)
val voteState: StateFlow<UiState<List<Note>>>
get() = _voteState.asStateFlow()
val voteState: StateFlow<UiState<List<Note>>> get() = _voteState.asStateFlow()

private val _postVoteState = MutableStateFlow<UiState<Int>>(UiState.Loading)
val postVoteState: StateFlow<UiState<Int>>
get() = _postVoteState.asStateFlow()
val postVoteState: StateFlow<UiState<Int>> get() = _postVoteState.asStateFlow()

private val _shuffleCount = MutableStateFlow(MAX_COUNT_SHUFFLE)
val shuffleCount: StateFlow<Int>
get() = _shuffleCount.asStateFlow()
val shuffleCount: StateFlow<Int> get() = _shuffleCount.asStateFlow()

private val _backgroundIndex = MutableStateFlow(0)
val backgroundIndex: Int
get() = _backgroundIndex.value
val backgroundIndex: Int get() = _backgroundIndex.value

val _currentNoteIndex = MutableStateFlow(0)
val currentNoteIndex: Int
get() = _currentNoteIndex.value
val currentNoteIndex: Int get() = _currentNoteIndex.value

val _currentChoice = MutableLiveData<Choice>()
val currentChoice: Choice
get() = requireNotNull(_currentChoice.value)
val currentChoice: Choice get() = requireNotNull(_currentChoice.value)

val _choiceList = MutableStateFlow(mutableListOf<Choice>())
val choiceList: MutableList<Choice>
get() = requireNotNull(_choiceList.value)
val choiceList: MutableList<Choice> get() = requireNotNull(_choiceList.value)

val _voteList = MutableLiveData<List<Note>>()
val voteList: List<Note>
get() = requireNotNull(_voteList.value)
val voteList: List<Note> get() = requireNotNull(_voteList.value)

private val _votePointSum = MutableStateFlow(0)
val votePointSum: Int
get() = _votePointSum.value
val votePointSum: Int get() = _votePointSum.value

private val _totalPoint = MutableStateFlow(0)
val totalPoint: Int
get() = _totalPoint.value
val totalPoint: Int get() = _totalPoint.value

private var isTransitioning = false

private val _noteHeight = MutableStateFlow(0)
val noteHeight: StateFlow<Int> get() = _noteHeight

var totalListCount = Int.MAX_VALUE
private set

Expand Down Expand Up @@ -107,6 +100,7 @@ class VoteViewModel @Inject constructor(
notes[noteIndex].friendList = newFriendList
}

delay(400L)
totalListCount = notes.size - 1
_voteState.value = Success(notes)
_voteList.value = notes
Expand Down Expand Up @@ -229,7 +223,12 @@ class VoteViewModel @Inject constructor(

private fun postVote() {
viewModelScope.launch {
voteRepository.postVote(ChoiceList(choiceList = choiceList, totalPoint = votePointSum))
voteRepository.postVote(
ChoiceList(
choiceList = choiceList,
totalPoint = votePointSum,
),
)
.onSuccess { point ->
Timber.d("POST VOTE SUCCESS : $point")
if (point == null) {
Expand Down Expand Up @@ -286,7 +285,7 @@ class VoteViewModel @Inject constructor(
)
initCurrentChoice()
viewModelScope.launch {
delay(500L)
delay(DURATION_VIEW_SETTING)
isTransitioning = false
}
}
Expand All @@ -300,14 +299,14 @@ class VoteViewModel @Inject constructor(
return@launch
}

Timber.tag("GET_STORED_VOTE_SUCCESS").d(vote.toString())
totalListCount = vote.questionList.size - 1
_voteList.value = vote.questionList
_voteState.value = Success(vote.questionList)
_choiceList.value = vote.choiceList
_totalPoint.value = vote.totalPoint
initCurrentChoice()
// TODO: delay 없이 해결 가능한 방법 찾아보기
delay(500L)
delay(DURATION_VIEW_SETTING)
_currentNoteIndex.value = vote.currentIndex
}
}
Expand All @@ -318,5 +317,8 @@ class VoteViewModel @Inject constructor(
private const val MAX_COUNT_SHUFFLE = 3
private const val DELAY_OPTION_SELECTION = 1000L
private const val ID_EMPTY_USER = -1

// TODO: delay 없이 해결 가능한 방법 찾아보기
private const val DURATION_VIEW_SETTING = 500L
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.el.yello.presentation.main.yello.vote
package com.el.yello.presentation.main.yello.vote.frame

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.el.yello.presentation.main.yello.point.PointFragment
import com.el.yello.presentation.main.yello.vote.note.NoteFragment

class VoteAdapter(
class NoteFrameAdapter(
fragmentActivity: FragmentActivity,
private val bgIndex: Int,
private val voteListSize: Int,
Expand All @@ -15,10 +14,10 @@ class VoteAdapter(

override fun createFragment(position: Int): Fragment {
return when (position) {
in INDEX_START_POSITION until voteListSize -> NoteFragment.newInstance(
position,
bgIndex,
voteListSize,
in INDEX_START_POSITION until voteListSize -> NoteFrameFragment.newInstance(
index = position,
bgIndex = bgIndex,
voteListSize = voteListSize,
)

else -> PointFragment.newInstance()
Expand Down
Loading

0 comments on commit cf3a037

Please sign in to comment.