Get how many pixels do the Viewholder (RecyclerView) moved when swiped - kotlin

Hello i am using a recyclerView and i am wanting to know if there exist any way to
get the pixel position of the row Viewholder beign swiped.
Any ideas?

From ItemTouchHelper.Callback override onChildDraw as it gives all info you need , or use a helper like this and see usage here

Related

How to fill RecyclerView equally with LinearLayoutManager in XML?

I have a huge thing that I cannot understand! Hoping on your help!
Example:
6 children are
Equally filled in RecyclerView by height with GridLayoutManager. But I need LinearLayoutManager(Don't ask me why, it doesn't matter).
Example using GridLayoutManager - all 6 children are equally filled:
Example using LinearLayoutManager - 6 children filled and a huge white spot is left at the bottom:
So, how to fill RecyclerView so it would fill the screen with 6 children with LinearLayoutManager as it is filling with GridLayoutManager?
I'm asking how to make it in XML!!!
Thank you!

How to store items position in a RecyclerView after drag&drop

I have a simple todo list app with a RecyclerView/FirestoreRecyclerAdapter/ItemTouchHelper with items A, B, C, D (see picture attached). Now I would like to effectivly store the position of these items in Firestore, initially when I add an item and when ever I vertically drag & drop them. How can I do that conceptionally or with a existing/sample code. It's important to store it in the cloud so the items position stay the same if I look a it from another device.
Some ideas about it:
The adapter positions (int) start from 0 (in this case D). When I add the item E, then this has adapter position 0, and the positions of all the other items change. So the stored position in Firestore should probably increase by 1 each time a new item is added which will be displayed at the top. But what if I have thousends of items (e.g. in a photo gallery app). Is it effective if I update the position for all the items each time I drag & drop an item?
I guess this should be a very common problem.
MainActivity of my Todo App (https://i.stack.imgur.com/o3jJ1.jpg)
Here is my code for the method ItemTouchHelper.Callback onMoved():
#Override
public void onMoved(#NonNull RecyclerView recyclerView, #NonNull RecyclerView.ViewHolder viewHolder, int fromPos, #NonNull RecyclerView.ViewHolder target, int toPos, int x, int y) {
super.onMoved(recyclerView, viewHolder, fromPos, target, toPos, x, y);
for (int maxItems = recyclerView.getChildCount(), i = 0; i < maxItems; ++i) {
RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(recyclerView.getChildAt(i));
int layoutPosition = holder.getLayoutPosition();
int adapterPosition = holder.getAdapterPosition();
TodoAdapter.TodoHolder h = (TodoAdapter.TodoHolder)holder;
String documentID = h.getDocumentID();
TextView textViewTitle = (TextView)h.itemView.findViewById(R.id.todo_title);
CharSequence title = textViewTitle.getText();
DocumentReference docRef = mFirestore.collection("todos").document(documentID);
docRef.update("position", adapterPosition);
}
}
Now I would like to effectivly store the position of these items in Firestore, initially when I add an item and when ever I vertically drag & drop them.
While this is technically possible, I don't think that Firestore is the best option for this problem since everything in Firestore in about the number of reads and writes. So everytime you change the position of an item, you'll perfrom a number of write operations that is equal to the number of remaining items. Try to take a look also at Firebase realtime database. Both work together very well.
How can I do that conceptionally
Simply by adding an order number property for each element, representing the position in the list and then order them (ascending or descending) according to that property. Once you move an element from a location to another, update the position of every remaining obejct by one.
It's important to store it in the cloud so the items position stay the same if I look a it from another device.
If you'll keep all elements ordered, then every user will be able to see the same arrangement.
So the stored position in Firestore should probably increase by 1 each time a new item is added
Right, the position will be increased by one, every time you add a new item.
Is it effective if I update the position for all the items each time I drag & drop an item?
It will definitely be very costly to update the position of an item at the beginning of a list. Let's take an example. Let's say you have a collection of 1000 items and you want to add a new item as the second item in the list. This means that you be charged with one write operation for the adding of the item plus another 999 write operations to update the position of the remaining 999 items. So in total you'll be charged with 1000 write operation. It's up to you to decide if this feet your needs or not.

Knob drags beyond right boundary [More 1.5.1]

When creating a nice slider using Mootools More 1.5.1 Slider class, I noticed that the 'knob' can be dragged too far to the right.
Consider this slider scenario:
|--|~|----------------|
I find I am able to do this:
|---------------------||~|
which is no good when the parent div has overflow:hidden set.
This occurs because the Drag object in the Slider class sets the left most x position ( limit.x[1] ) as the width of the passed in element (parent of the knob).
I would expect this limit to be the the element width minus the knob width.
I get the same problem whether the 'knob' is inside or outside the 'element' (above and below in the DOM).
The only way I could fix this was with a hack:
if(mySlider.drag.options.limit.x[1]===mySlider.element.getSize().x){
mySlider.drag.options.limit.x[1] -= mySlider.knob.getSize().x;
mySlider.drag.setOptions(mySlider.drag.options);
}
Check out this Fiddle (examples of broken and hacked).
Am I missing something here? Or should this be raised as a bug?

Set Fixed Height for NSSplitView subview

OK, so here's the deal :
I'm having a vertical NSSplitView (actually using DMSplitView sublass) with 2 subviews in it
I want the bottom one to be of fixed height
DMSplitView manages to "fix" its size under certain conditions (e.g. when the window is resized the bottom view stays as is)
However, if the user tries to drag-resize the view (although both min/max constraints have been set) he's able to, which means that the bottom view is not of fixed height after all.
And this all of my (related) code :
[_mainHorizontalSplitView setMinSize:25 ofSubviewAtIndex:1];
[_mainHorizontalSplitView setMaxSize:25 ofSubviewAtIndex:1];
So, any ideas of a possible workaround for this?
Just found it (actually a modification to DMSplitView delegate) :
- (CGFloat)splitView:(NSSplitView *)splitView
constrainSplitPosition:(CGFloat)proposedPosition
ofSubviewAt:(NSInteger)dividerIndex
{
return [self positionOfDividerAtIndex:dividerIndex];
}

Make the divider of an NSSplitView undraggable and don't show the dragging cursor

I have an NSSplitView (NO UISplitView(Controller)!!) with three subviews. Now, for the last divider (index 1), I want the divider to not show the dragging cursor (two arrows pointing out of eachother). I have this to stop the dragging, but the cursor is still showing up:
- (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex {
if (dividerIndex == 1) {
return [splitView frame].size.width - 161;
}
}
Note that I only want to hide the cursor for the divider at index 1. Can anyone help me? Thanks. :)
No, I don't want to use BWToolkit.
I know this has been answered for a while, but the supplied answer did not suit my needs.
The delegate method splitView:effectiveRect:forDrawnRect:ofDividerAtIndex: allows you to set the effective rectangle for dragging the divider. If you return NSZeroRect no drag cursor will ever appear, regardless of your setup in splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt:.
Try using splitView:constrainMaxCoordinate:ofSubviewAt: and splitView:constrainMinCoordinate:ofSubviewAt: instead of splitView:constrainSplitPosition:ofSubviewAt:.
The former two methods are called once as the user drags the mouse and they give enough information for NSSplitView to know how to change the cursor during the drag.
The latter is called repeatedly as the user drags the splitter, so NSSplitView doesn't have enough information to know that you're returning a constant value each time and therefore can't change the cursor.