Skip to content

Commit

Permalink
Hide delete button after swapping slide positions
Browse files Browse the repository at this point in the history
  • Loading branch information
aforcier committed Nov 5, 2020
1 parent a1ad339 commit cf3b754
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,10 @@ abstract class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelec
toggleDeleteSlideMode()
}

override fun onStoryFrameMovedLongPressed() {
disableDeleteSlideMode()
}

private fun toggleDeleteSlideMode() {
if (delete_slide_view.visibility == View.VISIBLE) {
disableDeleteSlideMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface OnStoryFrameSelectorTappedListener {
fun onStoryFrameAddTapped()
fun onCurrentFrameTapped()
fun onStoryFrameLongPressed(oldIndex: Int, newIndex: Int)
fun onStoryFrameMovedLongPressed()
}

class StoryFrameSelectorFragment : Fragment() {
Expand Down Expand Up @@ -57,6 +58,10 @@ class StoryFrameSelectorFragment : Fragment() {
selectedFrameIndexChange.first, selectedFrameIndexChange.second)
})

storyViewModel.onUserMovedLongPressedFrame.observe(this, Observer {
storyFrameTappedListener?.onStoryFrameMovedLongPressed()
})

storyViewModel.onFrameIndexMoved.observe(this, Observer<Pair<Int, Int>> { positionFrameIndexChange ->
updateContentUiStateMovedIndex(positionFrameIndexChange.first, positionFrameIndexChange.second)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St
private val _onUserLongPressedFrame = SingleLiveEvent<Pair<Int, Int>>()
val onUserLongPressedFrame = _onUserLongPressedFrame

private val _onUserMovedLongPressedFrame = SingleLiveEvent<Unit>()
val onUserMovedLongPressedFrame = _onUserMovedLongPressedFrame

fun createNewStory() {
loadStory(StoryRepository.DEFAULT_NONE_SELECTED)
}
Expand Down Expand Up @@ -113,6 +116,10 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St
_onUserLongPressedFrame.value = Pair(oldIndex, index)
}

private fun setMovedLongPressedFrame() {
_onUserMovedLongPressedFrame.call()
}

fun updateCurrentSelectedFrameOnRetryResult(frameSaveResult: FrameSaveResult) {
repository.updateCurrentStorySaveResultOnFrame(
currentSelectedFrameIndex,
Expand Down Expand Up @@ -221,6 +228,7 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St
}

fun swapItemsInPositions(pos1: Int, pos2: Int) {
setMovedLongPressedFrame()
repository.swapItemsInPositions(pos1, pos2)
// adjust currentSelectedFrameIndex so it reflects the movement only
// if the movement occurred entierly to the left of the selection, don't update it
Expand Down

0 comments on commit cf3b754

Please sign in to comment.