Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show delete button when long pressing a slide #602

Merged
merged 2 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,21 @@ class StoryFrameSelectorAdapter : RecyclerView.Adapter<StoryFrameSelectorAdapter

class StoryFrameHolderItem(v: View) : StoryFrameHolder(v) {
private var onFrameSelected: (() -> 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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Pair<Int, Int>> { positionFrameIndexChange ->
updateContentUiStateMovedIndex(positionFrameIndexChange.first, positionFrameIndexChange.second)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class StoryViewModel(private val repository: StoryRepository, val storyIndex: St
private val _onUserTappedCurrentFrame = SingleLiveEvent<Unit>()
val onUserTappedCurrentFrame = _onUserTappedCurrentFrame

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 @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down