add map view page

This commit is contained in:
2022-03-18 00:17:40 +08:00
parent ba7b3e7389
commit 4067bc2768
10 changed files with 9358 additions and 3463 deletions

View File

@ -49,6 +49,9 @@
<ui:OptionEntryCell Height="44" Icon="online.png"
Title="{r:Text Store}"
Text="{Binding Store, Mode=TwoWay}"/>
<ui:OptionSelectCell Height="44"
Detail="{r:Text ViewLocation}"
Command="{Binding ViewLocation}"/>
<ui:OptionDatePickerCell Height="44" Icon="bars.png"
Title="{r:Text CreatedTime}"
Date="{Binding CreatedDate, Mode=TwoWay}"/>

View File

@ -60,6 +60,7 @@ namespace Billing.Views
public Command SelectCategory { get; }
public Command SelectWallet { get; }
public Command ViewLocation { get; }
public event EventHandler<Bill> BillChecked;
@ -76,6 +77,7 @@ namespace Billing.Views
createDate = date;
SelectCategory = new Command(OnSelectCategory);
SelectWallet = new Command(OnSelectWallet);
ViewLocation = new Command(() => { }, () => false);
InitializeComponent();
Title = Resource.AddBill;
@ -86,7 +88,12 @@ namespace Billing.Views
{
this.bill = bill;
SelectCategory = new Command(OnSelectCategory);
SelectWallet = new Command(OnSelectWallet);
SelectWallet = new Command(OnSelectWallet);
#if __ANDROID__
ViewLocation = new Command(() => { }, () => false);
#else
ViewLocation = new Command(OnViewLocation, () => bill != null && bill.Latitude != null && bill.Longitude != null);
#endif
InitializeComponent();
Title = Resource.EditBill;
@ -129,7 +136,7 @@ namespace Billing.Views
{
editorAmount.SetFocus();
if (App.SaveLocation)
if (bill == null && App.SaveLocation)
{
_ = GetCurrentLocation();
}
@ -280,5 +287,22 @@ namespace Billing.Views
{
SetValue(WalletProperty, account);
}
private async void OnViewLocation()
{
if (bill == null)
{
return;
}
if (Tap.IsBusy)
{
return;
}
using (Tap.Start())
{
var page = new ViewLocationPage(bill);
await Navigation.PushAsync(page);
}
}
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<ui:BillingPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ui="clr-namespace:Billing.UI"
xmlns:v="clr-namespace:Billing.Views"
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"
x:Class="Billing.Views.ViewLocationPage"
x:Name="viewLocationPage"
x:DataType="v:ViewLocationPage"
BindingContext="{x:Reference viewLocationPage}">
<ContentPage.Content>
<maps:Map x:Name="map" IsShowingUser="False"
MoveToLastRegionOnLayoutChange="False"/>
</ContentPage.Content>
</ui:BillingPage>

View File

@ -0,0 +1,31 @@
using Billing.Models;
using Billing.UI;
using Xamarin.Forms.Maps;
namespace Billing.Views
{
public partial class ViewLocationPage : BillingPage
{
//private readonly Bill bill;
public ViewLocationPage(Bill bill)
{
//this.bill = bill;
Title = bill.Name;
InitializeComponent();
if (bill.Latitude != null && bill.Longitude != null)
{
var address = $"({bill.Latitude}, {bill.Longitude})";
map.Pins.Add(new Pin
{
Label = string.IsNullOrEmpty(bill.Store) ? address : bill.Store,
Type = PinType.Generic,
Position = new Position(bill.Latitude.Value, bill.Longitude.Value),
Address = address
});
}
}
}
}