-
Notifications
You must be signed in to change notification settings - Fork 0
Fix single mode #7
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,49 @@ | ||
package com.dotloop.swipy | ||
|
||
import com.dotloop.swipy.SwipableCellHandler.Mode.Single | ||
import java.util.* | ||
|
||
class SwipableCellHandler { | ||
|
||
private val openPositions: MutableSet<Int> = HashSet() | ||
private var mode = Single | ||
class SwipableCellHandler() { | ||
|
||
private val openHistory: MutableMap<Int, SwipeLayout> = HashMap() | ||
var mode = Single | ||
|
||
fun bindSwipableCell(swipeLayout: SwipeLayout, position: Int) { | ||
swipeLayout.tag = position | ||
swipeLayout.onSwipeListeners = (object : OnSwipeListener { | ||
override fun onClose(layout: SwipeLayout) { | ||
openPositions.remove(layout.tag as Int) | ||
openHistory.remove(layout.tag as Int) | ||
} | ||
|
||
override fun onStartOpen(layout: SwipeLayout) { | ||
val position = layout.tag as Int | ||
/**if (mode == Attributes.Mode.Single && | ||
* !openPositions.isEmpty() && | ||
* !openPositions.contains(position)) | ||
* adapter.notifyItemChanged(position); */ | ||
val pos = layout.tag as Int | ||
if (mode == Single && !openHistory.isEmpty() && !openHistory.containsKey(pos)) { | ||
openHistory.keys.forEach { openHistory[it]?.close(smooth = true, notify = true) } | ||
} | ||
} | ||
|
||
override fun onOpen(layout: SwipeLayout) { | ||
openPositions.add(layout.tag as Int) | ||
openHistory[layout.tag as Int] = layout | ||
} | ||
}) | ||
|
||
swipeLayout.simpleOnLayoutChangeListenerListener = (object : SimpleOnLayoutChangeListener { | ||
swipeLayout.simpleOnLayoutChangeListener = (object : SimpleOnLayoutChangeListener { | ||
override fun onLayoutChange(layout: SwipeLayout) = | ||
if (isOpen(layout.tag as Int)) layout.open(false, false) | ||
else layout.close(false, false) | ||
if (isOpen(layout.tag as Int)) layout.open(smooth = false, notify = false) | ||
else layout.close(smooth = false, notify = false) | ||
}) | ||
|
||
} | ||
|
||
@JvmOverloads | ||
fun reset(position: Int? = null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this method being used? If not, can you remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, it's not used. You don't think it could be useful to have a method to programmatically close all the "open" cells? Meaning cell being swiped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is fine to leave it. |
||
when (position) { | ||
null -> openPositions.clear() | ||
else -> openPositions.remove(position) | ||
null -> openHistory.clear() | ||
else -> openHistory.remove(position) | ||
} | ||
} | ||
|
||
fun isOpen(position: Int): Boolean { | ||
return openPositions.contains(position) | ||
} | ||
|
||
fun setMode(mode: Mode) { | ||
this.mode = mode | ||
return openHistory.containsKey(position) | ||
} | ||
|
||
enum class Mode { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the empty constructor can be removed