Comments (8)
regarding your first topic. You can extend the SimpleDragCallback
and overwrite the
@Override
public void onMoved(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, int fromPos, RecyclerView.ViewHolder target, int toPos, int x, int y) {
super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y);
}
For the second thing I've implemented a IDraggable
interface which will be checked in the SimpleDragCallback
and disable the drag feature for the items which are not draggable.
This is in v1.2.2
from fastadapter.
In case someone needs to know when an item has been dropped, this is how I implemented:
I extended the original interface from fastAdapterExtensions and added one more callback method.
public interface ImprovedItemTouchCallback extends ItemTouchCallback { void onDrop(Integer mFrom, Integer mTo); }
And this is my callback that remembers the location of the item to send the information on the onDrop. I also added a small snippet that checks if the target is draggable, so my item does not swipe with it (very specific for my user case i guess, it can be removed)
public class ImprovedDragCallback extends SimpleDragCallback {
private Integer mFrom = null;
private Integer mTo = null;
private ImprovedItemTouchCallback callback;
public ImprovedDragCallback(ImprovedItemTouchCallback itemTouchCallback) {
super(itemTouchCallback);
this.callback = itemTouchCallback;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
if (target.itemView.getTag() instanceof IDraggable) {
if (((IDraggable) target.itemView.getTag()).isDraggable()) {
if (mFrom == null) {
mFrom = viewHolder.getAdapterPosition();
}
mTo = target.getAdapterPosition();
return super.onMove(recyclerView, viewHolder, target);
}
}
return false;
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
if (mFrom != null && mTo != null) {
callback.onDrop(mFrom, mTo);
}
// clear saved positions
mFrom = mTo = null;
}
}
from fastadapter.
Maybe you would like to try a pr?
from fastadapter.
I tried to make the project work on my machine and was failing for some weird reasons. So, I gave up on the pull request. I will give another try later, with more appropriated naming.
from fastadapter.
Please let us know if we could help you.
from fastadapter.
@hsdmiranda so the onMoved()
method does not fire after dropping an item?
from fastadapter.
Sorry for the delay, crazy week here. @mikepenz the onMoved its called before the oDrop. The onMove is called every time an item passes over another item.
from fastadapter.
@hsdmiranda no problem. Oh cool. :)
from fastadapter.
Related Issues (20)
- how to use multiple items for different models with Model Adapter HOT 3
- compile error HOT 2
- CreateBinding is being called each time item is being collapsed or expanded. HOT 8
- Setting a Snackbar using UndoHelper's withSnackbar does nothing.
- List is not updating after adapter.set()
- Second added item is blank HOT 6
- SelectExtensions.select() not working when create view HOT 2
- Is there any way to add multiple row? HOT 5
- How made dynamic model list? HOT 6
- Overload resolution ambiguity. All these functions match. HOT 4
- How can I judge the item is the last one in AbstractBindingItem HOT 1
- EventHook + RecycledViewPool HOT 3
- How to get access to function of Item from ViewHolder? HOT 4
- ItemFilter publishResults NPE HOT 1
- FastAdapter intercepting clicks for other ViewPager tabs HOT 1
- Drag & drop - animation is broken HOT 1
- could not resolve FastItemAdapter , FooterAdapter, ProgressItem HOT 3
- Weird behavior on scroll with expandable HOT 2
- Runtime layout changes can affect more than one item HOT 5
- Can I Swipe item view then remain it's state then delete button can click HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastadapter.