From 0d21924cff341cf6c161871e2b81588673ae682f Mon Sep 17 00:00:00 2001 From: ali h Date: Sun, 9 Jun 2024 17:45:53 +0330 Subject: [PATCH] add feat for export all ips --- fast cf ip scanner/Resources/Images/copy.svg | 30 ++++ .../ViewModels/ScanPageViewModel.cs | 38 +++-- fast cf ip scanner/Views/ScanPage.xaml | 152 ++++++++++-------- fast cf ip scanner/fast cf ip scanner.csproj | 1 + 4 files changed, 138 insertions(+), 83 deletions(-) create mode 100644 fast cf ip scanner/Resources/Images/copy.svg diff --git a/fast cf ip scanner/Resources/Images/copy.svg b/fast cf ip scanner/Resources/Images/copy.svg new file mode 100644 index 0000000..ff4b524 --- /dev/null +++ b/fast cf ip scanner/Resources/Images/copy.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/fast cf ip scanner/ViewModels/ScanPageViewModel.cs b/fast cf ip scanner/ViewModels/ScanPageViewModel.cs index 5cec2f2..0624c0b 100644 --- a/fast cf ip scanner/ViewModels/ScanPageViewModel.cs +++ b/fast cf ip scanner/ViewModels/ScanPageViewModel.cs @@ -11,17 +11,20 @@ public partial class ScanPageViewModel : BaseViewModel [ObservableProperty] ObservableCollection 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(); - + _iPServices = iPServices; _workerServices = workerService; @@ -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 validIp = new List(); @@ -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 { @@ -68,8 +72,9 @@ async void GetValidIPs() await _iPServices.AddValidIpToDb(validIp); } IsBusy = false; + ExportBtnVisible = true; } - + [RelayCommand] async Task ShowOptionsForSearchIp() { @@ -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) { @@ -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"; @@ -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); @@ -114,7 +126,7 @@ 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; @@ -122,7 +134,7 @@ async Task ShowSelectedIPOption(IPModel ipModel) 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; diff --git a/fast cf ip scanner/Views/ScanPage.xaml b/fast cf ip scanner/Views/ScanPage.xaml index 44336ea..a2e11db 100644 --- a/fast cf ip scanner/Views/ScanPage.xaml +++ b/fast cf ip scanner/Views/ScanPage.xaml @@ -11,83 +11,95 @@ - - - - - - - - - - - - - - + - \ No newline at end of file + diff --git a/fast cf ip scanner/fast cf ip scanner.csproj b/fast cf ip scanner/fast cf ip scanner.csproj index 0b8a6b3..e0aaf61 100644 --- a/fast cf ip scanner/fast cf ip scanner.csproj +++ b/fast cf ip scanner/fast cf ip scanner.csproj @@ -49,6 +49,7 @@ +