Skip to content

Commit 0d21924

Browse files
committed
add feat for export all ips
1 parent 21abc58 commit 0d21924

File tree

4 files changed

+138
-83
lines changed

4 files changed

+138
-83
lines changed
Lines changed: 30 additions & 0 deletions
Loading

fast cf ip scanner/ViewModels/ScanPageViewModel.cs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ public partial class ScanPageViewModel : BaseViewModel
1111
[ObservableProperty]
1212
ObservableCollection<IPModel> validIPs;
1313

14+
[ObservableProperty]
15+
bool exportBtnVisible = false;
16+
1417
[ObservableProperty]
1518
bool isBusy = false;
1619

1720
IpOptionModel _ipOption;
18-
21+
1922
readonly IPService _iPServices;
2023
readonly WorkerService _workerServices;
21-
public ScanPageViewModel(IPService iPServices,WorkerService workerService)
24+
public ScanPageViewModel(IPService iPServices, WorkerService workerService)
2225
{
2326
validIPs = new ObservableCollection<IPModel>();
24-
27+
2528
_iPServices = iPServices;
2629
_workerServices = workerService;
2730

@@ -33,15 +36,16 @@ async void GetValidIPs()
3336
{
3437
var protocols = new string[] { "Http test", "TCP test", "Terminal Ping test" };
3538

36-
var selectedProtocol =
39+
var selectedProtocol =
3740
await App.Current.MainPage.DisplayActionSheet("which protocol", "Cancel", null, protocols);
38-
39-
if(selectedProtocol == "Cancel" || selectedProtocol == null)
41+
42+
if (selectedProtocol == "Cancel" || selectedProtocol == null)
4043
{
4144
return;
4245
}
4346

4447
IsBusy = true;
48+
ExportBtnVisible = false;
4549

4650
List<IPModel> validIp = new List<IPModel>();
4751

@@ -50,7 +54,7 @@ async void GetValidIPs()
5054
var ips = await _iPServices.GetIps();
5155
if (ips.Length < 1)
5256
{
53-
await App.Current.MainPage.DisplayAlert("Error", $"have a error try again ","OK");
57+
await App.Current.MainPage.DisplayAlert("Error", $"have a error try again ", "OK");
5458
}
5559
else
5660
{
@@ -68,8 +72,9 @@ async void GetValidIPs()
6872
await _iPServices.AddValidIpToDb(validIp);
6973
}
7074
IsBusy = false;
75+
ExportBtnVisible = true;
7176
}
72-
77+
7378
[RelayCommand]
7479
async Task ShowOptionsForSearchIp()
7580
{
@@ -79,6 +84,13 @@ async Task ShowOptionsForSearchIp()
7984
});
8085
}
8186

87+
[RelayCommand]
88+
async Task ExportAllIPsToClipboard()
89+
{
90+
var ips = string.Join(",", ValidIPs.Select(ip => ip.IP.ToString()));
91+
await Clipboard.SetTextAsync(ips);
92+
await App.Current.MainPage.DisplayAlert("Copied", $"the ips is copied", "OK");
93+
}
8294
[RelayCommand]
8395
async Task ShowSelectedIPOption(IPModel ipModel)
8496
{
@@ -87,7 +99,7 @@ async Task ShowSelectedIPOption(IPModel ipModel)
8799
var workers = await _workerServices.GetWorkers();
88100

89101
string[] Options;
90-
if(workers.Count == 0)
102+
if (workers.Count == 0)
91103
{
92104
Options = new string[3];
93105
Options[2] = "Please add a worker";
@@ -99,10 +111,10 @@ async Task ShowSelectedIPOption(IPModel ipModel)
99111
Options[0] = "Copy";
100112

101113
Options[1] = "speed test";
102-
114+
103115
for (int i = 2; i <= workers.Count; i++)
104116
{
105-
Options[i] = workers[i-2].Url;
117+
Options[i] = workers[i - 2].Url;
106118
}
107119
var reslut = await App.Current.MainPage.DisplayActionSheet($"What to Do With {ipModel.IP}", null, null, Options);
108120

@@ -114,15 +126,15 @@ async Task ShowSelectedIPOption(IPModel ipModel)
114126
await Clipboard.SetTextAsync(ip);
115127
await App.Current.MainPage.DisplayAlert("Copied", $"the {ip} is copied", "OK");
116128
}
117-
else if(reslut== "speed test")
129+
else if (reslut == "speed test")
118130
{
119131
IsBusy = true;
120132
var downloadSizeForSpeedTestToMB = _ipOption.DownloadSizeForSpeedTest * 1024 * 1024;
121133
var speed = await _iPServices.GetDownloadSpeedAsync($"https://speed.cloudflare.com/__down?bytes={downloadSizeForSpeedTestToMB}", ipModel.IP);
122134
IsBusy = false;
123135
await App.Current.MainPage.DisplayAlert("speed", $"{speed} Mb", "ok");
124136
}
125-
else if(reslut == "Please add a worker")
137+
else if (reslut == "Please add a worker")
126138
{
127139
await Shell.Current.GoToAsync(nameof(SettingPage));
128140
return;

fast cf ip scanner/Views/ScanPage.xaml

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,95 @@
1111
<ContentPage.Resources>
1212
<services:InverseBooleanConverter x:Key="InverseBooleanConverter" />
1313
</ContentPage.Resources>
14-
15-
<ScrollView>
1614

17-
<VerticalStackLayout>
18-
<Grid
19-
ColumnSpacing="10"
20-
Padding="10"
21-
Margin="10">
22-
23-
<Grid.ColumnDefinitions>
24-
<ColumnDefinition Width="*" />
25-
<ColumnDefinition Width="*" />
26-
</Grid.ColumnDefinitions>
27-
<Grid.RowDefinitions>
28-
<RowDefinition Height="*"/>
29-
<RowDefinition Height="*"/>
30-
</Grid.RowDefinitions>
31-
<Button
32-
Text="Start"
33-
Style="{StaticResource MyBtn}"
34-
Grid.Column="0"
35-
Command="{Binding GetValidIPsCommand}"
36-
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
37-
HeightRequest="50"
38-
/>
39-
40-
<Button
41-
Text="Options"
42-
Style="{StaticResource MyBtn}"
43-
Grid.Column="1"
44-
Command="{Binding ShowOptionsForSearchIpCommand}"
45-
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
46-
/>
47-
48-
</Grid>
15+
<Grid RowDefinitions="*, Auto">
16+
<!-- Scrollable Content -->
17+
<ScrollView Grid.Row="0">
18+
<VerticalStackLayout>
19+
<Grid
20+
ColumnSpacing="10"
21+
Padding="10"
22+
Margin="10">
4923

24+
<Grid.ColumnDefinitions>
25+
<ColumnDefinition Width="*" />
26+
<ColumnDefinition Width="*" />
27+
</Grid.ColumnDefinitions>
28+
<Grid.RowDefinitions>
29+
<RowDefinition Height="*"/>
30+
<RowDefinition Height="*"/>
31+
</Grid.RowDefinitions>
32+
<Button
33+
Text="Start"
34+
Style="{StaticResource MyBtn}"
35+
Grid.Column="0"
36+
Command="{Binding GetValidIPsCommand}"
37+
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
38+
HeightRequest="50"
39+
/>
5040

41+
<Button
42+
Text="Options"
43+
Style="{StaticResource MyBtn}"
44+
Grid.Column="1"
45+
Command="{Binding ShowOptionsForSearchIpCommand}"
46+
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
47+
/>
48+
</Grid>
5149

50+
<CollectionView ItemsSource="{Binding ValidIPs}"
51+
x:Name="validIPCollectionView"
52+
HorizontalOptions="Center"
53+
SelectionChangedCommand="{Binding ShowSelectedIPOptionCommand}"
54+
SelectionChangedCommandParameter="{Binding Source={x:Reference validIPCollectionView}, Path=SelectedItem}"
55+
SelectionMode="Single"
56+
IsVisible="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}">
57+
<CollectionView.ItemTemplate>
58+
<DataTemplate x:DataType="model:IPModel">
59+
<Grid Padding="15">
60+
<Grid.ColumnDefinitions>
61+
<ColumnDefinition Width="Auto" />
62+
<ColumnDefinition Width="*" />
63+
</Grid.ColumnDefinitions>
64+
<Grid.RowDefinitions>
65+
<RowDefinition Height="Auto" />
66+
<RowDefinition Height="Auto" />
67+
<RowDefinition Height="Auto" />
68+
<RowDefinition Height="Auto" />
69+
</Grid.RowDefinitions>
70+
<Label Grid.Row="0" Grid.Column="0" Text="ip :" TextColor="White" />
71+
<Label Grid.Row="0" Grid.Column="1" Text="{Binding IP}" TextColor="White" />
5272

53-
<CollectionView ItemsSource="{Binding ValidIPs}"
54-
x:Name="validIPCollectionView"
55-
HorizontalOptions="Center"
56-
SelectionChangedCommand="{Binding ShowSelectedIPOptionCommand}"
57-
SelectionChangedCommandParameter="{Binding Source={x:Reference validIPCollectionView}, Path=SelectedItem}"
58-
SelectionMode="Single"
59-
IsVisible="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}">
60-
<CollectionView.ItemTemplate>
61-
<DataTemplate x:DataType="model:IPModel">
62-
<Grid Padding="15">
63-
<Grid.ColumnDefinitions>
64-
<ColumnDefinition Width="Auto" />
65-
<ColumnDefinition Width="*" />
66-
</Grid.ColumnDefinitions>
67-
<Grid.RowDefinitions>
68-
<RowDefinition Height="Auto" />
69-
<RowDefinition Height="Auto" />
70-
<RowDefinition Height="Auto" />
71-
<RowDefinition Height="Auto" />
72-
</Grid.RowDefinitions>
73-
<Label Grid.Row="0" Grid.Column="0" Text="ip :" TextColor="White" />
74-
<Label Grid.Row="0" Grid.Column="1" Text="{Binding IP}" TextColor="White" />
73+
<Label Grid.Row="1" Grid.Column="0" Text="ping :" TextColor="White" />
74+
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Ping}" TextColor="White" />
7575

76-
<Label Grid.Row="1" Grid.Column="0" Text="ping :" TextColor="White" />
77-
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Ping}" TextColor="White" />
76+
<Label Grid.Row="2" Grid.Column="0" Text="ports :" TextColor="White" />
77+
<Label Grid.Row="2" Grid.Column="1" Text="{Binding Ports}" TextColor="White" />
7878

79-
<Label Grid.Row="2" Grid.Column="0" Text="ports :" TextColor="White" />
80-
<Label Grid.Row="2" Grid.Column="1" Text="{Binding Ports}" TextColor="White" />
79+
<Label Grid.Row="3" Grid.Column="0" Text="TimeOut :" TextColor="White" />
80+
<Label Grid.Row="3" Grid.Column="1" Text="{Binding CountOfTimeout}" TextColor="White" />
81+
</Grid>
82+
</DataTemplate>
83+
</CollectionView.ItemTemplate>
84+
</CollectionView>
8185

82-
<Label Grid.Row="3" Grid.Column="0" Text="TimeOut :" TextColor="White" />
83-
<Label Grid.Row="3" Grid.Column="1" Text="{Binding CountOfTimeout}" TextColor="White" />
84-
</Grid>
85-
</DataTemplate>
86-
</CollectionView.ItemTemplate>
87-
</CollectionView>
86+
<ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" />
87+
</VerticalStackLayout>
88+
</ScrollView>
8889

89-
<ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" />
90-
</VerticalStackLayout>
91-
</ScrollView>
90+
<Button
91+
Grid.Row="1"
92+
Text="export all ips to clipboard"
93+
IsVisible="{Binding ExportBtnVisible}"
94+
IsEnabled="{Binding ExportBtnVisible}"
95+
Command="{Binding ExportAllIPsToClipboardCommand}"
96+
HeightRequest="50"
97+
HorizontalOptions="FillAndExpand"
98+
VerticalOptions="End"
99+
BackgroundColor="DimGray"
100+
TextColor="White">
101+
102+
</Button>
103+
</Grid>
92104

93-
</ContentPage>
105+
</ContentPage>

fast cf ip scanner/fast cf ip scanner.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
5050
</ItemGroup>
5151
<ItemGroup>
52+
<None Remove="Resources\Images\copy.svg" />
5253
<None Remove="Resources\Images\scan.svg" />
5354
<None Remove="Resources\Images\setting.svg" />
5455
</ItemGroup>

0 commit comments

Comments
 (0)