diff --git a/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt b/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt index 25098796a..b3a919bf4 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt @@ -1900,6 +1900,23 @@ abstract class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelec } override fun onCurrentFrameTapped() { + toggleDeleteSlideMode() + } + + override fun onStoryFrameLongPressed(oldIndex: Int, newIndex: Int) { + // On long press we want to switch to that frame and show the delete slide move all together. + if (oldIndex != newIndex) { + // The long-pressed frame was not the one already in focus - switch to it first. + onStoryFrameSelected(oldIndex, newIndex) + } + toggleDeleteSlideMode() + } + + override fun onStoryFrameMovedLongPressed() { + disableDeleteSlideMode() + } + + private fun toggleDeleteSlideMode() { if (delete_slide_view.visibility == View.VISIBLE) { disableDeleteSlideMode() } else { diff --git a/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorAdapter.kt b/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorAdapter.kt index a647d3062..0076a81a2 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorAdapter.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorAdapter.kt @@ -80,15 +80,21 @@ class StoryFrameSelectorAdapter : RecyclerView.Adapter Unit)? = null + private var onFrameLongPressed: (() -> Unit)? = null init { clickableView.setOnClickListener { onFrameSelected?.invoke() } + clickableView.setOnLongClickListener { + onFrameLongPressed?.invoke() + true + } } override fun onBind(uiState: StoryFrameListItemUiState) { onFrameSelected = requireNotNull(uiState.onItemTapped) { "OnItemTapped is required." } + onFrameLongPressed = requireNotNull(uiState.onItemLongPressed) { "OnItemLongPressed is required." } uiState as StoryFrameListItemUiStateFrame val loadThumbnailImage = { diff --git a/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorFragment.kt b/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorFragment.kt index c31289e95..22d8d2210 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorFragment.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/story/StoryFrameSelectorFragment.kt @@ -24,6 +24,8 @@ interface OnStoryFrameSelectorTappedListener { fun onStoryFrameSelected(oldIndex: Int, newIndex: Int) fun onStoryFrameAddTapped() fun onCurrentFrameTapped() + fun onStoryFrameLongPressed(oldIndex: Int, newIndex: Int) + fun onStoryFrameMovedLongPressed() } class StoryFrameSelectorFragment : Fragment() { @@ -51,6 +53,15 @@ class StoryFrameSelectorFragment : Fragment() { storyFrameTappedListener?.onCurrentFrameTapped() }) + storyViewModel.onUserLongPressedFrame.observe(this, Observer { selectedFrameIndexChange -> + storyFrameTappedListener?.onStoryFrameLongPressed( + selectedFrameIndexChange.first, selectedFrameIndexChange.second) + }) + + storyViewModel.onUserMovedLongPressedFrame.observe(this, Observer { + storyFrameTappedListener?.onStoryFrameMovedLongPressed() + }) + storyViewModel.onFrameIndexMoved.observe(this, Observer> { positionFrameIndexChange -> updateContentUiStateMovedIndex(positionFrameIndexChange.first, positionFrameIndexChange.second) }) diff --git a/stories/src/main/java/com/wordpress/stories/compose/story/StoryViewModel.kt b/stories/src/main/java/com/wordpress/stories/compose/story/StoryViewModel.kt index 9d9324fd6..90c08774a 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/story/StoryViewModel.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/story/StoryViewModel.kt @@ -47,6 +47,12 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St private val _onUserTappedCurrentFrame = SingleLiveEvent() val onUserTappedCurrentFrame = _onUserTappedCurrentFrame + private val _onUserLongPressedFrame = SingleLiveEvent>() + val onUserLongPressedFrame = _onUserLongPressedFrame + + private val _onUserMovedLongPressedFrame = SingleLiveEvent() + val onUserMovedLongPressedFrame = _onUserMovedLongPressedFrame + fun createNewStory() { loadStory(StoryRepository.DEFAULT_NONE_SELECTED) } @@ -104,6 +110,16 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St } } + private fun setLongPressedFrame(index: Int) { + val oldIndex = currentSelectedFrameIndex + setSelectedFrame(index) + _onUserLongPressedFrame.value = Pair(oldIndex, index) + } + + private fun setMovedLongPressedFrame() { + _onUserMovedLongPressedFrame.call() + } + fun updateCurrentSelectedFrameOnRetryResult(frameSaveResult: FrameSaveResult) { repository.updateCurrentStorySaveResultOnFrame( currentSelectedFrameIndex, @@ -212,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 @@ -291,6 +308,9 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St oneFrameUiState.onItemTapped = { setSelectedFrameByUser(index, userInitiated = true) } + oneFrameUiState.onItemLongPressed = { + setLongPressedFrame(index) + } uiStateItems.add(oneFrameUiState) } return newUiState @@ -300,6 +320,7 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St sealed class StoryFrameListItemUiState() { var onItemTapped: (() -> Unit)? = null + var onItemLongPressed: (() -> Unit)? = null data class StoryFrameListItemUiStateFrame( var selected: Boolean = false,