-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/AndreiMisiukevich/CardView/issues/59
- Loading branch information
1 parent
c575631
commit 545eb78
Showing
5 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
using Xamarin.Forms; | ||
|
||
namespace PanCardView.Enums | ||
{ | ||
[Flags] | ||
public enum InteractionType | ||
{ | ||
Gesture = -1, | ||
Animation = 1 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using PanCardView.Enums; | ||
namespace PanCardView.Utility | ||
{ | ||
public struct InteractionItem | ||
{ | ||
public Guid Id { get; set; } | ||
public InteractionType Type { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using PanCardView.Enums; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace PanCardView.Utility | ||
{ | ||
public sealed class InteractionQueue | ||
{ | ||
private readonly List<InteractionItem> _queue = new List<InteractionItem>(); | ||
private readonly object _queueLocker = new object(); | ||
|
||
public Guid GetFirstId(InteractionType type = InteractionType.Gesture | InteractionType.Animation) | ||
{ | ||
lock(_queueLocker) | ||
{ | ||
return _queue.FirstOrDefault(i => type.HasFlag(i.Type)).Id; | ||
} | ||
} | ||
|
||
public void Add(Guid id, InteractionType type) | ||
{ | ||
lock (_queueLocker) | ||
{ | ||
_queue.Add(new InteractionItem | ||
{ | ||
Id = id, | ||
Type = type | ||
}); | ||
} | ||
} | ||
|
||
public void Remove(Guid id) | ||
{ | ||
lock (_queueLocker) | ||
{ | ||
var item = _queue.FirstOrDefault(i => i.Id == id); | ||
_queue.Remove(item); | ||
} | ||
} | ||
|
||
public bool CheckLastId(Guid id, InteractionType type = InteractionType.Gesture | InteractionType.Animation) | ||
{ | ||
lock(_queueLocker) | ||
{ | ||
return _queue.LastOrDefault(i => type.HasFlag(i.Type)).Id == id; | ||
} | ||
} | ||
} | ||
} | ||
|