Dashboard update

main
unknown 6 months ago
parent a9c5ac5def
commit aab2c43b24
  1. 32
      Helpers/GeolocationHelper.cs
  2. 138
      Views/DashboardPage.xaml
  3. 26
      Views/DashboardPage.xaml.cs

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Justice.Helpers
{
public class GeolocationHelper
{
public static async Task<(double Latitude, double Longitude)> GetCurrentLocationAsync()
{
var location = await Geolocation.Default.GetLocationAsync();
if (location != null)
{
return (location.Latitude, location.Longitude);
}
throw new Exception("Unable to fetch location");
}
public static async Task<string> GetReadableAddressAsync(double latitude, double longitude)
{
var placemarks = await Geocoding.Default.GetPlacemarksAsync(latitude, longitude);
var placemark = placemarks.FirstOrDefault();
if ( placemark !=null)
{
return $"{placemark.SubLocality}, {placemark.Thoroughfare}, {placemark.Locality}, {placemark.CountryName}";
}
return "Address Not Found";
}
}
}

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Justice.Views.DashboardPage"
Title="DashboardPage" BackgroundColor="WhiteSmoke">
<ScrollView>
<VerticalStackLayout>
<Button Text="Get Current Location" Clicked="OnGetLocationClicked"/>
<Grid RowSpacing="10" ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<VerticalStackLayout Grid.Column="0" VerticalOptions="End">
<Label Text="9 c" FontSize="35" TextColor="LightGray" FontAttributes="Bold" Margin="10"/>
<Label x:Name="LocationLabel" FontSize="18" TextColor="LightGray" FontAttributes="Bold" Margin="5"/>
</VerticalStackLayout>
</Grid>
<Grid RowSpacing="10" ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<VerticalStackLayout Grid.Column="0" VerticalOptions="Center">
<Label Text="Welcome" FontSize="20" TextColor="LightGray" FontAttributes="Bold"/>
</VerticalStackLayout>
<Border Grid.Column="1" StrokeThickness="1" Stroke="Gray" Padding="0" HeightRequest="60" WidthRequest="60"
HorizontalOptions="End" VerticalOptions="Center">
<Border.StrokeShape>
<Ellipse />
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.2" Offset="3,4" />
</Border.Shadow>
<Image Source="unnamed2.png" Aspect="AspectFill"/>
</Border>
</Grid>
<Grid RowSpacing="10" ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" StrokeThickness="0.05" Stroke="#FF5252" HeightRequest="160" Padding="15" VerticalOptions="Start" BackgroundColor="#FFEDEE">
<Border.StrokeShape>
<RoundRectangle CornerRadius="15"/>
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.1" Offset="4,4"/>
</Border.Shadow>
<VerticalStackLayout Spacing="10" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Label Text="Emergency Contact" FontSize="17" FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="Add Contact" FontSize="12" FontAttributes="Bold" HorizontalOptions="Start" TextColor="Gray"/>
<Button Text="Add Contact" TextColor="White" FontAttributes="Bold" CornerRadius="5" BackgroundColor="#FF5252"/>
</VerticalStackLayout>
</Border>
<Border Grid.Column="1" StrokeThickness="0.05" Stroke="#FFA726" HeightRequest="160" Padding="15" VerticalOptions="Start" BackgroundColor="#FFF3E0">
<Border.StrokeShape>
<RoundRectangle CornerRadius="15"/>
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.1" Offset="4,4"/>
</Border.Shadow>
<VerticalStackLayout Spacing="10" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Label Text="Send SOS Alert" FontSize="17" FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="Send SOS Alert" FontSize="12" FontAttributes="Bold" HorizontalOptions="Start" TextColor="Gray"/>
<Button Text="SEND SOS" TextColor="White" FontAttributes="Bold" CornerRadius="5" BackgroundColor="#FFA726"/>
</VerticalStackLayout>
</Border>
</Grid>
<Grid RowSpacing="15" ColumnSpacing="15" Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" StrokeThickness="0.05" Stroke="#42A5F5" HeightRequest="160" Padding="15" VerticalOptions="Start" BackgroundColor="#E3F2FD">
<Border.StrokeShape>
<RoundRectangle CornerRadius="15"/>
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.1" Offset="4,4"/>
</Border.Shadow>
<VerticalStackLayout Spacing="10" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Label Text="Incident Report" FontSize="17" FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="Add new Report" FontSize="12" FontAttributes="Bold" HorizontalOptions="Start" TextColor="Gray"/>
<Button Text="Add Contact" TextColor="White" FontAttributes="Bold" CornerRadius="5" BackgroundColor="#42A5F5"/>
</VerticalStackLayout>
</Border>
<Border Grid.Column="1" StrokeThickness="0.05" Stroke="#8BC34A" HeightRequest="160" Padding="15" VerticalOptions="Start" BackgroundColor="#E8F5E9">
<Border.StrokeShape>
<RoundRectangle CornerRadius="15"/>
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.1" Offset="4,4"/>
</Border.Shadow>
<VerticalStackLayout Spacing="10" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Label Text="View Report" FontSize="17" FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="Check your incident report" FontSize="12" FontAttributes="Bold" HorizontalOptions="Start" TextColor="Gray"/>
<Button Text="SEND SOS" TextColor="White" FontAttributes="Bold" CornerRadius="5" BackgroundColor="#8BC34A"/>
</VerticalStackLayout>
</Border>
</Grid>
<Grid RowSpacing="15" ColumnSpacing="15" Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" StrokeThickness="0.05" Stroke="#42A5F5" HeightRequest="160" Padding="15" VerticalOptions="Start" BackgroundColor="#E3F2FD">
<Border.StrokeShape>
<RoundRectangle CornerRadius="15"/>
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.1" Offset="4,4"/>
</Border.Shadow>
<VerticalStackLayout Spacing="10" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Label Text="Helpline Numbers" FontSize="17" FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="Emergency Helpline for help" FontSize="12" FontAttributes="Bold" HorizontalOptions="Start" TextColor="Gray"/>
<Button Text="Add Contact" TextColor="White" FontAttributes="Bold" CornerRadius="5" BackgroundColor="#42A5F5"/>
</VerticalStackLayout>
</Border>
<Border Grid.Column="1" StrokeThickness="0.05" Stroke="#8BC34A" HeightRequest="160" Padding="15" VerticalOptions="Start" BackgroundColor="#E8F5E9">
<Border.StrokeShape>
<RoundRectangle CornerRadius="15"/>
</Border.StrokeShape>
<Border.Shadow>
<Shadow Brush="Teal" Opacity="0.1" Offset="4,4"/>
</Border.Shadow>
<VerticalStackLayout Spacing="10" HorizontalOptions="FillAndExpand" VerticalOptions="Start">
<Label Text="Information Center" FontSize="17" FontAttributes="Bold" HorizontalOptions="Start"/>
<Label Text="GuideLines" FontSize="12" FontAttributes="Bold" HorizontalOptions="Start" TextColor="Gray"/>
<Button Text="Information" TextColor="White" FontAttributes="Bold" CornerRadius="5" BackgroundColor="#8BC34A"/>
</VerticalStackLayout>
</Border>
</Grid>
</VerticalStackLayout>
</ScrollView>
</ContentPage>

@ -0,0 +1,26 @@
using Justice.Helpers;
using Microsoft;
namespace Justice.Views;
public partial class DashboardPage : ContentPage
{
public DashboardPage()
{
InitializeComponent();
}
public async void OnGetLocationClicked(object sender, EventArgs e)
{
try
{
var (latitude, longitude) = await GeolocationHelper.GetCurrentLocationAsync();
string address = await GeolocationHelper.GetReadableAddressAsync(latitude, longitude);
LocationLabel.Text = $"{address}";
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message,"OK");
}
}
}
Loading…
Cancel
Save