You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Seekers/Views/HelplinePage.xaml.cs

39 lines
1.2 KiB

using Justice.Models;
using Justice.Services;
using Microsoft.Maui.ApplicationModel.Communication;
using System;
using System.Collections.ObjectModel;
namespace Justice.Views
{
public partial class HelplinePage : ContentPage
{
public ObservableCollection<Helpline> Helplines { get; set; }
public HelplinePage()
{
InitializeComponent();
Helplines = new ObservableCollection<Helpline>(HelplineService.GetHelplines());
HelplineListView.ItemsSource = Helplines;
}
private async void OnCallButtonClicked(object sender, EventArgs e)
{
if (sender is Button button && button.CommandParameter is string phoneNumber)
{
bool confirm = await DisplayAlert("Call Helpline", $"Do you want to call {phoneNumber}?", "Yes", "No");
if (confirm)
{
try
{
PhoneDialer.Open(phoneNumber);
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Unable to make the call: {ex.Message}", "OK");
}
}
}
}
}
}