11using Avalonia . Controls ;
22using Avalonia . Controls . Notifications ;
33using Avalonia . Interactivity ;
4+ using ReactiveUI ;
45using SukiUI . Dialogs ;
56using SukiUI . Toasts ;
67using System ;
8+ using System . Collections . ObjectModel ;
79using System . IO ;
810using System . Linq ;
911using System . Text . RegularExpressions ;
@@ -20,10 +22,27 @@ private static string GetTranslation(string key)
2022 return FeaturesHelper . GetTranslation ( key ) ;
2123 }
2224
25+ public ObservableCollection < PartModel > Parts { get ; set ; } = new ObservableCollection < PartModel > ( ) ;
26+
2327 public ModifypartitionView ( )
2428 {
2529 InitializeComponent ( ) ;
2630 _ = LoadMassage ( ) ;
31+ _ = this . WhenAnyValue ( part => part . SearchBox . Text )
32+ . Subscribe ( option =>
33+ {
34+ if ( PartList . ItemsSource != null )
35+ {
36+ if ( ! string . IsNullOrEmpty ( SearchBox . Text ) )
37+ {
38+ PartList . ItemsSource = Parts . Where ( part => part . Name . Contains ( SearchBox . Text , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
39+ }
40+ else
41+ {
42+ PartList . ItemsSource = Parts . Where ( info => info != null ) . ToList ( ) ;
43+ }
44+ }
45+ } ) ;
2746 }
2847
2948 public async Task LoadMassage ( )
@@ -44,12 +63,14 @@ private async void SetFastboot(object sender, RoutedEventArgs args)
4463 NewPartitionFormat . IsEnabled = false ;
4564 NewPartitionStartpoint . IsEnabled = false ;
4665 NewPartitionEndpoint . IsEnabled = false ;
66+ ShowAllPart . IsEnabled = true ;
4767 }
4868 else
4969 {
5070 NewPartitionFormat . IsEnabled = true ;
5171 NewPartitionStartpoint . IsEnabled = true ;
5272 NewPartitionEndpoint . IsEnabled = true ;
73+ ShowAllPart . IsEnabled = false ;
5374 }
5475 }
5576
@@ -91,13 +112,14 @@ public void AddPartList()
91112 {
92113 string size = string . Format ( "{0}" , StringHelper . DiskSize ( choice ) ) ;
93114 PartSize . Text = size ;
94- PartModel [ ] part = new PartModel [ parts . Length - 5 ] ;
115+ PartModel [ ] part = new PartModel [ parts . Length - 6 ] ;
95116 for ( int i = 6 ; i < parts . Length ; i ++ )
96117 {
97118 string [ ] items = StringHelper . Items ( parts [ i ] . ToCharArray ( ) ) ;
98119 part [ i - 6 ] = new PartModel ( items [ 0 ] , items [ 1 ] , items [ 2 ] , items [ 3 ] , items [ 4 ] , items [ 5 ] , items [ 6 ] ) ;
99120 }
100- PartList . ItemsSource = part ;
121+ Parts = new ObservableCollection < PartModel > ( part ) ;
122+ PartList . ItemsSource = Parts ;
101123 }
102124 else
103125 {
@@ -173,6 +195,7 @@ private async void ReadPart(object sender, RoutedEventArgs args)
173195 {
174196 BusyPart . IsBusy = true ;
175197 ReadPartBut . IsEnabled = false ;
198+ PartList . ItemsSource = null ;
176199 Global . checkdevice = false ;
177200 string allinfo = await CallExternalProgram . Fastboot ( $ "-s { Global . thisdevice } getvar all") ;
178201 string [ ] parts = new string [ 1000 ] ;
@@ -192,7 +215,8 @@ private async void ReadPart(object sender, RoutedEventArgs args)
192215 string size = StringHelper . byte2AUnit ( ( ulong ) Convert . ToInt64 ( partinfos [ 3 ] . Replace ( "0x" , "" ) , 16 ) ) ;
193216 part [ i ] = new PartModel ( i . ToString ( ) , null , null , size , null , partinfos [ 2 ] , null ) ;
194217 }
195- PartList . ItemsSource = part ;
218+ Parts = new ObservableCollection < PartModel > ( part ) ;
219+ PartList . ItemsSource = Parts ;
196220 BusyPart . IsBusy = false ;
197221 ReadPartBut . IsEnabled = true ;
198222 Global . checkdevice = true ;
@@ -201,36 +225,60 @@ private async void ReadPart(object sender, RoutedEventArgs args)
201225 {
202226 BusyPart . IsBusy = true ;
203227 ReadPartBut . IsEnabled = false ;
228+ PartList . ItemsSource = null ;
204229 Global . checkdevice = false ;
205230 string allinfo = await CallExternalProgram . Fastboot ( $ "-s { Global . thisdevice } getvar all") ;
206- string [ ] vparts = new string [ 1000 ] ;
231+ string [ ] parts = new string [ 1000 ] ;
207232 string [ ] allinfos = allinfo . Split ( new char [ ] { '\r ' , '\n ' } , StringSplitOptions . RemoveEmptyEntries ) ;
208- for ( int i = 0 ; i < allinfos . Length ; i ++ )
233+ if ( ( bool ) ShowAllPart . IsChecked )
209234 {
210- if ( allinfos [ i ] . Contains ( "is-logical" ) && allinfos [ i ] . Contains ( "yes" ) )
235+ for ( int i = 0 ; i < allinfos . Length ; i ++ )
236+ {
237+ if ( allinfos [ i ] . Contains ( "partition-size" ) )
238+ {
239+ parts [ i ] = allinfos [ i ] ;
240+ }
241+ }
242+ parts = parts . Where ( s => ! string . IsNullOrEmpty ( s ) ) . ToArray ( ) ;
243+ PartModel [ ] part = new PartModel [ parts . Length ] ;
244+ for ( int i = 0 ; i < parts . Length ; i ++ )
211245 {
212- string [ ] vpartinfos = allinfos [ i ] . Split ( new char [ ] { ':' , ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
213- vparts [ i ] = vpartinfos [ 2 ] ;
246+ string [ ] partinfos = parts [ i ] . Split ( new char [ ] { ':' , ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
247+ string size = StringHelper . byte2AUnit ( ( ulong ) Convert . ToInt64 ( partinfos [ 3 ] . Replace ( "0x" , "" ) , 16 ) ) ;
248+ part [ i ] = new PartModel ( i . ToString ( ) , null , null , size , null , partinfos [ 2 ] , null ) ;
214249 }
250+ Parts = new ObservableCollection < PartModel > ( part ) ;
215251 }
216- vparts = vparts . Where ( s => ! string . IsNullOrEmpty ( s ) ) . ToArray ( ) ;
217- PartModel [ ] part = new PartModel [ vparts . Length ] ;
218- for ( int i = 0 ; i < vparts . Length ; i ++ )
252+ else
219253 {
220- for ( int j = 0 ; j < allinfos . Length ; j ++ )
254+ for ( int i = 0 ; i < allinfos . Length ; i ++ )
255+ {
256+ if ( allinfos [ i ] . Contains ( "is-logical" ) && allinfos [ i ] . Contains ( "yes" ) )
257+ {
258+ string [ ] vpartinfos = allinfos [ i ] . Split ( new char [ ] { ':' , ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
259+ parts [ i ] = vpartinfos [ 2 ] ;
260+ }
261+ }
262+ parts = parts . Where ( s => ! string . IsNullOrEmpty ( s ) ) . ToArray ( ) ;
263+ PartModel [ ] vpart = new PartModel [ parts . Length ] ;
264+ for ( int i = 0 ; i < parts . Length ; i ++ )
221265 {
222- if ( allinfos [ j ] . Contains ( "partition-size" ) )
266+ for ( int j = 0 ; j < allinfos . Length ; j ++ )
223267 {
224- string [ ] partinfos = allinfos [ j ] . Split ( new char [ ] { ':' , ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
225- if ( partinfos [ 2 ] == vparts [ i ] )
268+ if ( allinfos [ j ] . Contains ( "partition-size" ) )
226269 {
227- string size = StringHelper . byte2AUnit ( ( ulong ) Convert . ToInt64 ( partinfos [ 3 ] . Replace ( "0x" , "" ) , 16 ) ) ;
228- part [ i ] = new PartModel ( i . ToString ( ) , null , null , size , null , partinfos [ 2 ] , null ) ;
270+ string [ ] partinfos = allinfos [ j ] . Split ( new char [ ] { ':' , ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
271+ if ( partinfos [ 2 ] == parts [ i ] )
272+ {
273+ string size = StringHelper . byte2AUnit ( ( ulong ) Convert . ToInt64 ( partinfos [ 3 ] . Replace ( "0x" , "" ) , 16 ) ) ;
274+ vpart [ i ] = new PartModel ( i . ToString ( ) , null , null , size , null , partinfos [ 2 ] , null ) ;
275+ }
229276 }
230277 }
231278 }
279+ Parts = new ObservableCollection < PartModel > ( vpart ) ;
232280 }
233- PartList . ItemsSource = part ;
281+ PartList . ItemsSource = Parts ;
234282 BusyPart . IsBusy = false ;
235283 ReadPartBut . IsEnabled = true ;
236284 Global . checkdevice = true ;
0 commit comments