@@ -27,6 +27,8 @@ public MyFavoriteSongCollection(List<ISongDetail> dataSet, HashSet<string> hashS
2727
2828 public void Add ( ISongDetail item )
2929 {
30+ NormalizeIndex ( ) ;
31+ var currentHash = IsEmpty ? null : Current . Hash ;
3032 if ( ! _hashSet . Add ( item . Hash ) )
3133 {
3234 return ;
@@ -43,11 +45,19 @@ public void Add(ISongDetail item)
4345 sorted . Add ( item ) ;
4446 Sorted = sorted . ToArray ( ) ;
4547 }
48+ NormalizeIndex ( ) ;
49+ if ( currentHash is not null )
50+ {
51+ SetCursor ( currentHash ) ;
52+ }
4653 }
4754 public void Clear ( )
4855 {
4956 _dataSet . Clear ( ) ;
5057 _hashSet . Clear ( ) ;
58+ Origin = Array . Empty < ISongDetail > ( ) ;
59+ Sorted = Origin ;
60+ NormalizeIndex ( ) ;
5161 }
5262 public bool Contains ( ISongDetail item )
5363 {
@@ -63,26 +73,12 @@ public void CopyTo(ISongDetail[] array, int arrayIndex)
6373 }
6474 public bool Remove ( ISongDetail item )
6575 {
66- if ( ! _hashSet . Remove ( item . Hash ) )
67- {
68- return false ;
69- }
70- _dataSet . Remove ( item ) ;
71- Origin = _dataSet . ToArray ( ) ;
72- if ( ! IsSorted )
73- {
74- Sorted = Origin ;
75- }
76- else if ( Sorted . Any ( x => x . Hash == item . Hash ) )
77- {
78- var sorted = new List < ISongDetail > ( Sorted ) ;
79- sorted . Remove ( item ) ;
80- Sorted = sorted . ToArray ( ) ;
81- }
82- return true ;
76+ return Remove ( item . Hash ) ;
8377 }
8478 public bool Remove ( string hashBase64Str )
8579 {
80+ NormalizeIndex ( ) ;
81+ var currentHash = IsEmpty ? null : Current . Hash ;
8682 if ( ! _hashSet . Remove ( hashBase64Str ) )
8783 {
8884 return false ;
@@ -98,6 +94,15 @@ public bool Remove(string hashBase64Str)
9894 {
9995 Sorted = Origin ;
10096 }
97+ else
98+ {
99+ Sorted = Sorted . Where ( x => x . Hash != hashBase64Str ) . ToArray ( ) ;
100+ }
101+ NormalizeIndex ( ) ;
102+ if ( currentHash is not null && currentHash != hashBase64Str )
103+ {
104+ SetCursor ( currentHash ) ;
105+ }
101106 return true ;
102107 }
103108 public HashSet < string > ExportHashSet ( )
0 commit comments