thorbenprimke / realm-recyclerview

A RecyclerView that is powered by Realm and lots more
555 stars 151 forks source link

Reorder items #7

Closed kmare closed 5 years ago

kmare commented 8 years ago

This is a feature request actually. How about implementing reordering of items (drag and drop) for the recyclerview? https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf#.5pm6p02gp and https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-6a6f0c422efd#.in4t3beg5

and thank you for your great work!

thorbenprimke commented 8 years ago

I actually followed that same article as an inspiration for the swipe to dismiss.

Drag and drop should be possible but you would have to have a "order" field on the Realm object so that once a field is dragged around, the underlaying data structure can be updated as well as that the order is persisted between data/screen views.

@kmare - Do you usually have a "order" field in your data structure for this? If so, that should make it possible. This would be a pretty cool feature to add.

kmare commented 8 years ago

I haven't really started yet working on that feature, but yeah.. I plan on adding an "order" field. I don't think it's possible to (realistically) implement it any other way. Following the mentioned tutorial/links I actually implemented it on a few non-realm (sqlite) projects with custom logic just fine. Unfortunately, I don't think I'll have much time to implement it any time soon for realm-recyclerview, but if I do, I'll gladly send a pull request.

thorbenprimke commented 8 years ago

@kmare - sounds good. Yea, I'll see if I can maybe tackle this on the weekend. Should be pretty straight forward as long as I can manage drag/drop updates and realmUpdates. One solution for that might be to turn off Realm updates while the user is dragging items around. Anyhow, I'll dig into it. I'll update this thread once I start working on it so that we don't execute on it in parallel.

Do you have a use-case / would utilize it in one of your apps?

kmare commented 8 years ago

Unfortunately I'll probably have time to work on it in a couple of weeks during the christmas period anyway. Right now I'm not really using realm in a real world project. I'm mainly evaluating it in different use cases for future projects I'd like to work on. So nothing serious at the moment. For now I just built a note/google-keep like app (I know, very original..), adding features just to see what I'd be missing from realm that I wouldn't with normal sqlite operations. So far, I'm not exactly happy with the migration part of realm, but it looks like they're re-implementing it anyway. Thanks again for your work, it's much appreciated!

astigsen commented 8 years ago

you would have to have a "order" field on the Realm object so that once a field is dragged around, the underlaying data structure can be updated as well as that the order is persisted

It would be really nice if you could just use a RealmList (which is intrinsically ordered) instead of a query result.

It even has a nice move() method to reorder entries: https://realm.io/docs/java/latest/api/io/realm/RealmList.html#move-int-int-

rohan2817 commented 8 years ago

I have a field basis on which I need to sort the list, this field changes on user action rather drag and drop, but changing the order at run time adding one more extra element also randomly replacing other elements. Thought this issue is relevant here.

edgardowardo commented 8 years ago

Hi I wondered if anyone started working on this feature?