Changes to Gain/Loss and add better handling for device type (Phone vs Tablet)

This commit is contained in:
2025-03-27 23:35:16 -04:00
parent 044c7bb01b
commit a62c053fdc
6 changed files with 66 additions and 18 deletions

View File

@@ -53,6 +53,14 @@ namespace Navigator.Core
}
}
public double ScreenDensity
{
get
{
return DeviceScreenInfo.GetScreenDimensions().Density;
}
}
protected bool SetProperty<T>(ref T backingStore, T value,[CallerMemberName] string propertyName = "",Action onChanged = null)
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))return false;

View File

@@ -1,17 +1,41 @@
using Xamarin.Essentials;
using System;
using Xamarin.Essentials;
namespace Navigator.Services
{
public class DeviceScreenInfo : IDeviceScreenInfo
{
public (double Width, double Height) GetScreenDimensions()
public (double Width, double Height, double Density) GetScreenDimensions()
{
return (DeviceDisplay.MainDisplayInfo.Width, DeviceDisplay.MainDisplayInfo.Height);
return (DeviceDisplay.MainDisplayInfo.Width, DeviceDisplay.MainDisplayInfo.Height, DeviceDisplay.MainDisplayInfo.Density);
}
public bool IsDeviceTablet()
{
return DeviceInfo.Idiom.Equals(DeviceIdiom.Tablet);
}
// return DeviceInfo.Idiom.Equals(DeviceIdiom.Tablet); // Idiom not working
// return GetDiagonalScreenSize()<=8.0?true:false; // Diagonal not working
return DeviceDisplay.MainDisplayInfo.Density<=2.00?true:false;
}
/// <summary>
/// Get android device default orientation diagonal screen size
/// </summary>
/// <returns>Return diagonal screen size in inches</returns>
//private double GetDiagonalScreenSize()
//{
// double width = DeviceDisplay.MainDisplayInfo.Width;
// double height = DeviceDisplay.MainDisplayInfo.Height;
// double density = DeviceDisplay.MainDisplayInfo.Density*100.00;
// double sizeDiagonal=0.00;
// height/=density;
// height=Math.Pow(height, 2.00);
// width/=density;
// width=Math.Pow(width, 2.00);
// sizeDiagonal = Math.Sqrt(width + height);
// return sizeDiagonal;
//}
}
}

View File

@@ -4,7 +4,7 @@ namespace Navigator.Services
{
public interface IDeviceScreenInfo
{
(double Width, double Height) GetScreenDimensions();
(double Width, double Height, double Density) GetScreenDimensions();
bool IsDeviceTablet();
}

View File

@@ -20,6 +20,7 @@ namespace Navigator.ViewModels
{
Title = "About";
Message=MarketDataServiceClient.GetInstance().GetBaseUri();
Status="";
PropertyChanged+=OnViewModelPropertyChanged;
}
@@ -106,6 +107,18 @@ namespace Navigator.ViewModels
set{SetProperty(ref status,value);}
}
public String Date
{
get
{
DateTime latestPricingDate = Utility.Epoch;
ServiceResult serviceResult = MarketDataServiceClient.GetInstance().GetLatestPricingDate();
if(serviceResult.Success)latestPricingDate=(DateTime)serviceResult.ContextSpecificResult;
if(Utility.IsEpoch(latestPricingDate))return "Latest Pricing Date: ---";
return "Latest Pricing Date: "+latestPricingDate.ToShortDateString();
}
}
public String ScreenDimensions
{
get
@@ -115,6 +128,8 @@ namespace Navigator.ViewModels
sb.Append(Utility.FormatNumber(ScreenWidth,0));
sb.Append("x");
sb.Append(Utility.FormatNumber(ScreenHeight,0));
sb.Append("x");
sb.Append(Utility.FormatNumber(ScreenDensity,0));
sb.Append(")");
sb.Append(IsDeviceTablet?"Tablet":"Phone");
return sb.ToString();

View File

@@ -56,8 +56,13 @@ namespace Navigator.ViewModels
if(!String.IsNullOrEmpty(listViewSelectedItem))
{
ServiceResult serviceResult=null;
if("ALL".Equals(listViewSelectedItem))serviceResult=MarketDataServiceClient.GetInstance().GetGainLossDetails(DateTime.Now);
else serviceResult=MarketDataServiceClient.GetInstance().GetGainLossDetails(DateTime.Now,listViewSelectedItem);
serviceResult = MarketDataServiceClient.GetInstance().GetLatestPricingDate();
if(serviceResult.Success)
{
DateTime currentDate = (DateTime)serviceResult.ContextSpecificResult;
if("ALL".Equals(listViewSelectedItem))serviceResult=MarketDataServiceClient.GetInstance().GetGainLossDetails(currentDate);
else serviceResult=MarketDataServiceClient.GetInstance().GetGainLossDetails(currentDate,listViewSelectedItem);
if(serviceResult.Success)
{
@@ -71,10 +76,7 @@ namespace Navigator.ViewModels
GainLossSummary=new ObservableCollection<GainLossSummaryItemDetail>(gainLossSummaryItems);
}
}
//else
//{
// Debug.WriteLine(serviceResult.Message);
//}
}
}
}
finally
@@ -118,7 +120,6 @@ namespace Navigator.ViewModels
List<String> accounts = (List<String>)serviceResult.ContextSpecificResult;
accounts.Insert(0, "ALL");
Accounts = new ObservableCollection<string>(accounts);
// ListViewSelectedItem="ALL";
}
});
workerTask.ContinueWith((continuation)=>
@@ -173,7 +174,6 @@ namespace Navigator.ViewModels
refreshCommand=new RelayCommand(param=>
{
HandleListViewSelectedItem();
// IsRefreshing=false;
},param=>{return !IsRefreshing;});
}
return refreshCommand;

View File

@@ -74,6 +74,7 @@
</Button>
<Label Text="{Binding Status,Mode=TwoWay}" />
<Label Text="{Binding ScreenDimensions, Mode=OneWay}"/>
<Label Text="{Binding Date, Mode=OneWay}"/>
</StackLayout>
</StackLayout>
</ScrollView>