From a62c053fdc66ad255b7b014974a2de6b3e14209e Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 27 Mar 2025 23:35:16 -0400 Subject: [PATCH] Changes to Gain/Loss and add better handling for device type (Phone vs Tablet) --- Navigator/Core/BaseViewModel.cs | 8 +++++ .../DeviceScreenInfo/DeviceScreenInfo.cs | 32 ++++++++++++++++--- .../DeviceScreenInfo/IDeviceScreenInfo.cs | 2 +- Navigator/ViewModels/AboutViewModel.cs | 15 +++++++++ Navigator/ViewModels/GainLossViewModel.cs | 26 +++++++-------- Navigator/Views/AboutPage.xaml | 1 + 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/Navigator/Core/BaseViewModel.cs b/Navigator/Core/BaseViewModel.cs index 3592fae..6931978 100644 --- a/Navigator/Core/BaseViewModel.cs +++ b/Navigator/Core/BaseViewModel.cs @@ -53,6 +53,14 @@ namespace Navigator.Core } } + public double ScreenDensity + { + get + { + return DeviceScreenInfo.GetScreenDimensions().Density; + } + } + protected bool SetProperty(ref T backingStore, T value,[CallerMemberName] string propertyName = "",Action onChanged = null) { if (EqualityComparer.Default.Equals(backingStore, value))return false; diff --git a/Navigator/Services/DeviceScreenInfo/DeviceScreenInfo.cs b/Navigator/Services/DeviceScreenInfo/DeviceScreenInfo.cs index 5f4d41d..59233a9 100644 --- a/Navigator/Services/DeviceScreenInfo/DeviceScreenInfo.cs +++ b/Navigator/Services/DeviceScreenInfo/DeviceScreenInfo.cs @@ -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; } + + /// + /// Get android device default orientation diagonal screen size + /// + /// Return diagonal screen size in inches + //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; + //} } } diff --git a/Navigator/Services/DeviceScreenInfo/IDeviceScreenInfo.cs b/Navigator/Services/DeviceScreenInfo/IDeviceScreenInfo.cs index 4e4a467..1696f2f 100644 --- a/Navigator/Services/DeviceScreenInfo/IDeviceScreenInfo.cs +++ b/Navigator/Services/DeviceScreenInfo/IDeviceScreenInfo.cs @@ -4,7 +4,7 @@ namespace Navigator.Services { public interface IDeviceScreenInfo { - (double Width, double Height) GetScreenDimensions(); + (double Width, double Height, double Density) GetScreenDimensions(); bool IsDeviceTablet(); } diff --git a/Navigator/ViewModels/AboutViewModel.cs b/Navigator/ViewModels/AboutViewModel.cs index f32fea7..27a8785 100644 --- a/Navigator/ViewModels/AboutViewModel.cs +++ b/Navigator/ViewModels/AboutViewModel.cs @@ -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(); diff --git a/Navigator/ViewModels/GainLossViewModel.cs b/Navigator/ViewModels/GainLossViewModel.cs index e31b8ef..297835d 100644 --- a/Navigator/ViewModels/GainLossViewModel.cs +++ b/Navigator/ViewModels/GainLossViewModel.cs @@ -56,25 +56,27 @@ 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) { - List gainLossSummaryItems=(List)serviceResult.ContextSpecificResult; - if(null!=gainLossSummaryItems) + DateTime currentDate = (DateTime)serviceResult.ContextSpecificResult; + if("ALL".Equals(listViewSelectedItem))serviceResult=MarketDataServiceClient.GetInstance().GetGainLossDetails(currentDate); + else serviceResult=MarketDataServiceClient.GetInstance().GetGainLossDetails(currentDate,listViewSelectedItem); + + if(serviceResult.Success) { - foreach(GainLossSummaryItemDetail gainLossSummaryItem in gainLossSummaryItems) + List gainLossSummaryItems=(List)serviceResult.ContextSpecificResult; + if(null!=gainLossSummaryItems) { - if(!String.IsNullOrEmpty(gainLossSummaryItem.CompanyName)&&gainLossSummaryItem.CompanyName.Length>30)gainLossSummaryItem.CompanyName=gainLossSummaryItem.CompanyName.Substring(0,30)+"..."; + foreach(GainLossSummaryItemDetail gainLossSummaryItem in gainLossSummaryItems) + { + if(!String.IsNullOrEmpty(gainLossSummaryItem.CompanyName)&&gainLossSummaryItem.CompanyName.Length>30)gainLossSummaryItem.CompanyName=gainLossSummaryItem.CompanyName.Substring(0,30)+"..."; + } + GainLossSummary=new ObservableCollection(gainLossSummaryItems); } - GainLossSummary=new ObservableCollection(gainLossSummaryItems); } } - //else - //{ - // Debug.WriteLine(serviceResult.Message); - //} } } finally @@ -118,7 +120,6 @@ namespace Navigator.ViewModels List accounts = (List)serviceResult.ContextSpecificResult; accounts.Insert(0, "ALL"); Accounts = new ObservableCollection(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; diff --git a/Navigator/Views/AboutPage.xaml b/Navigator/Views/AboutPage.xaml index 601bef1..8d6de75 100644 --- a/Navigator/Views/AboutPage.xaml +++ b/Navigator/Views/AboutPage.xaml @@ -74,6 +74,7 @@