Skip to content

Commit d7724ce

Browse files
committed
Rolled in a few bug fixes and unregistered event handlers before
registering new ones.
1 parent e5253dc commit d7724ce

File tree

4 files changed

+91
-18
lines changed

4 files changed

+91
-18
lines changed

SwipeListView/SwipeListViewListener.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ public SwipeListViewListener()
3939
OnChoiceEnded = () => {};
4040
OnFirstListItem = () => {};
4141
OnLastListItem = () => {};
42-
// OnChoiceChanged = (position, selected) => {};
43-
// OnChoiceStarted = () => {};
44-
// OnChoiceEnded = () => {};
45-
// OnFirstListItem = () => {};
46-
// OnLastListItem = () => {};
4742
}
4843

4944
#region ISwipeListViewListener implementation

SwipeListView/SwipeListViewTouchListener.cs

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class SwipeListViewTouchListener : Java.Lang.Object, View.IOnTouchListene
5959
private bool swipingRight;
6060
private VelocityTracker velocityTracker;
6161
private int downPosition;
62+
private int childPosition;
6263
private View _frontView;
6364
private View _backView;
6465
private bool paused;
@@ -73,11 +74,13 @@ public class SwipeListViewTouchListener : Java.Lang.Object, View.IOnTouchListene
7374

7475
private bool _isFirstItem = false;
7576
private bool _isLastItem = false;
77+
private bool _isLongPress = false;
78+
79+
private List<BackViewHolder> _backViews = new List<BackViewHolder>();
7680

7781
public SwipeListViewTouchListener(SwipeListView swipeListView, int swipeFrontView, int swipeBackView) {
7882
this._swipeFrontView = swipeFrontView;
7983
this.swipeBackView = swipeBackView;
80-
// _swipeRevealDismissView = swipeRevealDismissView;
8184
ViewConfiguration vc = ViewConfiguration.Get(swipeListView.Context);
8285
slop = vc.ScaledTouchSlop;
8386
SwipeClosesAllItemsWhenListMoves = true;
@@ -92,14 +95,15 @@ public SwipeListViewTouchListener(SwipeListView swipeListView, int swipeFrontVie
9295
SwipeActionRight = (int)SwipeListView.SwipeAction.Reveal;
9396
LeftOffset = 0;
9497
RightOffset = 0;
95-
// ChoiceOffset = 0;
96-
// RevealDismissThreshold = 0;
9798
SwipeDrawableChecked = 0;
9899
SwipeDrawableUnchecked = 0;
99100
}
100101

101102
#region "Properties"
102103
public View ParentView { get; set; }
104+
105+
106+
103107
public View FrontView
104108
{
105109
get
@@ -109,24 +113,54 @@ public View FrontView
109113
set
110114
{
111115
_frontView = value;
112-
_frontView.Click += (sender, e) => _swipeListView.OnClickFrontView(downPosition);
113-
if(SwipeOpenOnLongPress)
116+
117+
_frontView.Click -= FrontViewClick;
118+
_frontView.Click += FrontViewClick;
119+
_frontView.LongClick -= FrontViewLongClick;
120+
_frontView.LongClick += FrontViewLongClick;
121+
}
122+
}
123+
124+
private void FrontViewClick (object sender, EventArgs e)
125+
{
126+
if(!_isLongPress)
127+
{
128+
_swipeListView.OnClickFrontView(downPosition);
129+
}
130+
_isLongPress = false;
131+
}
132+
133+
private void FrontViewLongClick(object sender, Android.Views.View.LongClickEventArgs e)
134+
{
135+
if(SwipeOpenOnLongPress)
136+
{
137+
if(downPosition >= 0)
114138
{
115-
_frontView.LongClick += (sender, e) => OpenAnimate(_frontView, downPosition);
139+
_isLongPress = true;
140+
OpenAnimate(_frontView, childPosition);
116141
}
117142
}
143+
else
144+
{
145+
SwapChoiceState(childPosition);
146+
}
118147
}
119148

120149
private View BackView
121150
{
122151
get { return this._backView; }
123152
set {
124153
this._backView = value;
125-
this._backView.Click += (sender, e) => _swipeListView.OnClickBackView(downPosition);
154+
155+
this._backView.Click -= BackViewClick;
156+
this._backView.Click += BackViewClick;
126157
}
127158
}
128159

129-
// public View RevealDismissView { get; set; }
160+
private void BackViewClick(object sender, EventArgs e)
161+
{
162+
_swipeListView.OnClickBackView(downPosition);
163+
}
130164

131165
public bool IsListViewMoving { get; set; }
132166

@@ -511,7 +545,7 @@ private void GenerateRevealAnimate(View view, bool swap, bool swapRight, int pos
511545
}
512546

513547
var listener = new ObjectAnimatorListenerAdapter();
514-
listener.AnimationEnd = (animation) =>
548+
listener.AnimationEnd = (animator) =>
515549
{
516550
_swipeListView.ResetScrolling();
517551
if (swap) {
@@ -521,12 +555,37 @@ private void GenerateRevealAnimate(View view, bool swap, bool swapRight, int pos
521555
_swipeListView.OnOpened(position, swapRight);
522556
_openedRight[position] = swapRight;
523557
} else {
558+
if(_backViews != null && BackView != null)
559+
{
560+
_backViews.ForEach(b =>
561+
{
562+
if(!Opened(b.Position))
563+
{
564+
b.BackView.Visibility = ViewStates.Gone;
565+
_backViews.Remove(b);
566+
}
567+
});
568+
// _backViews.Clear();
569+
}
524570
_swipeListView.OnClosed(position, OpenedRight(position));
525571
}
526572
}
527573
ResetCell();
528574
};
529575

576+
listener.AnimationStart = (animator) =>
577+
{
578+
if(swap)
579+
{
580+
var aux = !Opened(position);
581+
if (aux && _backViews != null && BackView != null)
582+
{
583+
BackView.Visibility = ViewStates.Visible;
584+
_backViews.Add(new BackViewHolder(BackView, position));
585+
}
586+
}
587+
};
588+
530589
view.Animate()
531590
.TranslationX(moveTo)
532591
.SetDuration(_animationTime)
@@ -755,7 +814,7 @@ public bool OnTouch(View v, MotionEvent e)
755814
child = _swipeListView.GetChildAt(i);
756815
child.GetHitRect(rect);
757816

758-
int childPosition = _swipeListView.GetPositionForView(child);
817+
childPosition = _swipeListView.GetPositionForView(child);
759818

760819
// dont allow swiping if this is on the header or footer or IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter
761820
bool allowSwipe = _swipeListView.Adapter.IsEnabled(childPosition) && _swipeListView.Adapter.GetItemViewType(childPosition) >= 0;
@@ -767,7 +826,7 @@ public bool OnTouch(View v, MotionEvent e)
767826
FrontView = viewHolder;
768827

769828
downX = e.RawX;
770-
downPosition = childPosition;
829+
downPosition = childPosition - _swipeListView.HeaderViewsCount;
771830

772831
FrontView.Clickable = !Opened(downPosition);
773832
FrontView.LongClickable = !Opened(downPosition);
@@ -1065,6 +1124,13 @@ public override void OnAnimationEnd (Animator animator)
10651124
{
10661125
AnimationEnd(animator);
10671126
}
1127+
1128+
public Action<Animator> AnimationStart { get; set; }
1129+
public override void OnAnimationStart(Animator animator)
1130+
{
1131+
if(AnimationStart == null) return;
1132+
AnimationStart(animator);
1133+
}
10681134
}
10691135

10701136
public class ObjectAnimatorUpdateListener : Java.Lang.Object, Android.Animation.ValueAnimator.IAnimatorUpdateListener
@@ -1083,5 +1149,17 @@ public void OnAnimationUpdate(ValueAnimator valueAnimator)
10831149
}
10841150
#endregion
10851151
}
1152+
1153+
public class BackViewHolder
1154+
{
1155+
public View BackView { get; set; }
1156+
public int Position { get; set; }
1157+
1158+
public BackViewHolder(View backView, int position)
1159+
{
1160+
BackView = backView;
1161+
Position = position;
1162+
}
1163+
}
10861164
}
10871165

SwipeListViewSample/Resources/layout/Main.axml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
swipe:swipeMode="both"
1818
swipe:swipeActionRight="dismiss"
1919
swipe:swipeActionLeft="reveal"
20-
swipe:swipeOpenOnLongPress="true" />
20+
swipe:swipeOpenOnLongPress="false" />
2121
</LinearLayout>

SwipeListViewSample/Resources/layout/package_row.axml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:id="@+id/example_row_b_action_3"
1313
style="@style/ListButtonAction"
1414
android:textColor="#ff4D4D4D"
15-
android:text="Continue swiping to dismiss" />
15+
android:text="Continue swiping to reveal" />
1616
</LinearLayout>
1717
<RelativeLayout
1818
android:orientation="vertical"

0 commit comments

Comments
 (0)