Skip to content

Commit

Permalink
add feat for export all ips
Browse files Browse the repository at this point in the history
  • Loading branch information
DevoTalk committed Jun 9, 2024
1 parent 21abc58 commit 0d21924
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 83 deletions.
30 changes: 30 additions & 0 deletions fast cf ip scanner/Resources/Images/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 25 additions & 13 deletions fast cf ip scanner/ViewModels/ScanPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ public partial class ScanPageViewModel : BaseViewModel
[ObservableProperty]
ObservableCollection<IPModel> validIPs;

[ObservableProperty]
bool exportBtnVisible = false;

[ObservableProperty]
bool isBusy = false;

IpOptionModel _ipOption;

readonly IPService _iPServices;
readonly WorkerService _workerServices;
public ScanPageViewModel(IPService iPServices,WorkerService workerService)
public ScanPageViewModel(IPService iPServices, WorkerService workerService)
{
validIPs = new ObservableCollection<IPModel>();

_iPServices = iPServices;
_workerServices = workerService;

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

var selectedProtocol =
var selectedProtocol =
await App.Current.MainPage.DisplayActionSheet("which protocol", "Cancel", null, protocols);
if(selectedProtocol == "Cancel" || selectedProtocol == null)

if (selectedProtocol == "Cancel" || selectedProtocol == null)
{
return;
}

IsBusy = true;
ExportBtnVisible = false;

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

Expand All @@ -50,7 +54,7 @@ async void GetValidIPs()
var ips = await _iPServices.GetIps();
if (ips.Length < 1)
{
await App.Current.MainPage.DisplayAlert("Error", $"have a error try again ","OK");
await App.Current.MainPage.DisplayAlert("Error", $"have a error try again ", "OK");
}
else
{
Expand All @@ -68,8 +72,9 @@ async void GetValidIPs()
await _iPServices.AddValidIpToDb(validIp);
}
IsBusy = false;
ExportBtnVisible = true;
}

[RelayCommand]
async Task ShowOptionsForSearchIp()
{
Expand All @@ -79,6 +84,13 @@ async Task ShowOptionsForSearchIp()
});
}

[RelayCommand]
async Task ExportAllIPsToClipboard()
{
var ips = string.Join(",", ValidIPs.Select(ip => ip.IP.ToString()));
await Clipboard.SetTextAsync(ips);
await App.Current.MainPage.DisplayAlert("Copied", $"the ips is copied", "OK");
}
[RelayCommand]
async Task ShowSelectedIPOption(IPModel ipModel)
{
Expand All @@ -87,7 +99,7 @@ async Task ShowSelectedIPOption(IPModel ipModel)
var workers = await _workerServices.GetWorkers();

string[] Options;
if(workers.Count == 0)
if (workers.Count == 0)
{
Options = new string[3];
Options[2] = "Please add a worker";
Expand All @@ -99,10 +111,10 @@ async Task ShowSelectedIPOption(IPModel ipModel)
Options[0] = "Copy";

Options[1] = "speed test";

for (int i = 2; i <= workers.Count; i++)
{
Options[i] = workers[i-2].Url;
Options[i] = workers[i - 2].Url;
}
var reslut = await App.Current.MainPage.DisplayActionSheet($"What to Do With {ipModel.IP}", null, null, Options);

Expand All @@ -114,15 +126,15 @@ async Task ShowSelectedIPOption(IPModel ipModel)
await Clipboard.SetTextAsync(ip);
await App.Current.MainPage.DisplayAlert("Copied", $"the {ip} is copied", "OK");
}
else if(reslut== "speed test")
else if (reslut == "speed test")
{
IsBusy = true;
var downloadSizeForSpeedTestToMB = _ipOption.DownloadSizeForSpeedTest * 1024 * 1024;
var speed = await _iPServices.GetDownloadSpeedAsync($"https://speed.cloudflare.com/__down?bytes={downloadSizeForSpeedTestToMB}", ipModel.IP);
IsBusy = false;
await App.Current.MainPage.DisplayAlert("speed", $"{speed} Mb", "ok");
}
else if(reslut == "Please add a worker")
else if (reslut == "Please add a worker")
{
await Shell.Current.GoToAsync(nameof(SettingPage));
return;
Expand Down
152 changes: 82 additions & 70 deletions fast cf ip scanner/Views/ScanPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,95 @@
<ContentPage.Resources>
<services:InverseBooleanConverter x:Key="InverseBooleanConverter" />
</ContentPage.Resources>

<ScrollView>

<VerticalStackLayout>
<Grid
ColumnSpacing="10"
Padding="10"
Margin="10">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button
Text="Start"
Style="{StaticResource MyBtn}"
Grid.Column="0"
Command="{Binding GetValidIPsCommand}"
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
HeightRequest="50"
/>

<Button
Text="Options"
Style="{StaticResource MyBtn}"
Grid.Column="1"
Command="{Binding ShowOptionsForSearchIpCommand}"
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
/>

</Grid>
<Grid RowDefinitions="*, Auto">
<!-- Scrollable Content -->
<ScrollView Grid.Row="0">
<VerticalStackLayout>
<Grid
ColumnSpacing="10"
Padding="10"
Margin="10">

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button
Text="Start"
Style="{StaticResource MyBtn}"
Grid.Column="0"
Command="{Binding GetValidIPsCommand}"
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
HeightRequest="50"
/>

<Button
Text="Options"
Style="{StaticResource MyBtn}"
Grid.Column="1"
Command="{Binding ShowOptionsForSearchIpCommand}"
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}"
/>
</Grid>

<CollectionView ItemsSource="{Binding ValidIPs}"
x:Name="validIPCollectionView"
HorizontalOptions="Center"
SelectionChangedCommand="{Binding ShowSelectedIPOptionCommand}"
SelectionChangedCommandParameter="{Binding Source={x:Reference validIPCollectionView}, Path=SelectedItem}"
SelectionMode="Single"
IsVisible="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:IPModel">
<Grid Padding="15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="ip :" TextColor="White" />
<Label Grid.Row="0" Grid.Column="1" Text="{Binding IP}" TextColor="White" />

<CollectionView ItemsSource="{Binding ValidIPs}"
x:Name="validIPCollectionView"
HorizontalOptions="Center"
SelectionChangedCommand="{Binding ShowSelectedIPOptionCommand}"
SelectionChangedCommandParameter="{Binding Source={x:Reference validIPCollectionView}, Path=SelectedItem}"
SelectionMode="Single"
IsVisible="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:IPModel">
<Grid Padding="15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="ip :" TextColor="White" />
<Label Grid.Row="0" Grid.Column="1" Text="{Binding IP}" TextColor="White" />
<Label Grid.Row="1" Grid.Column="0" Text="ping :" TextColor="White" />
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Ping}" TextColor="White" />

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

<Label Grid.Row="2" Grid.Column="0" Text="ports :" TextColor="White" />
<Label Grid.Row="2" Grid.Column="1" Text="{Binding Ports}" TextColor="White" />
<Label Grid.Row="3" Grid.Column="0" Text="TimeOut :" TextColor="White" />
<Label Grid.Row="3" Grid.Column="1" Text="{Binding CountOfTimeout}" TextColor="White" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

<Label Grid.Row="3" Grid.Column="0" Text="TimeOut :" TextColor="White" />
<Label Grid.Row="3" Grid.Column="1" Text="{Binding CountOfTimeout}" TextColor="White" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" />
</VerticalStackLayout>
</ScrollView>

<ActivityIndicator IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}" />
</VerticalStackLayout>
</ScrollView>
<Button
Grid.Row="1"
Text="export all ips to clipboard"
IsVisible="{Binding ExportBtnVisible}"
IsEnabled="{Binding ExportBtnVisible}"
Command="{Binding ExportAllIPsToClipboardCommand}"
HeightRequest="50"
HorizontalOptions="FillAndExpand"
VerticalOptions="End"
BackgroundColor="DimGray"
TextColor="White">

</Button>
</Grid>

</ContentPage>
</ContentPage>
1 change: 1 addition & 0 deletions fast cf ip scanner/fast cf ip scanner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<None Remove="Resources\Images\copy.svg" />
<None Remove="Resources\Images\scan.svg" />
<None Remove="Resources\Images\setting.svg" />
</ItemGroup>
Expand Down

0 comments on commit 0d21924

Please sign in to comment.