Browse Source

Adjusted ToolGrid for Tablet/Phone sizes
Tweaked Menu Size
Improved App Version Handling

Frank van den Bos 1 year ago
parent
commit
aa805a7640

+ 32 - 51
InABox.Mobile/InABox.Mobile.Android/Version_Android.cs

@@ -45,48 +45,35 @@ namespace InABox.Mobile.Android
         /// <inheritdoc />
         public async Task<bool> IsUsingLatestVersion()
         {
-            var latestVersion = string.Empty;
-
             try
             {
-                latestVersion = await GetLatestVersionNumber(false);
-
-                return Version.Parse(latestVersion).CompareTo(Version.Parse(_versionName)) <= 0;
+                var info = await GetLatestVersion(false);
+                return String.IsNullOrWhiteSpace(info.Version) 
+                       || (Version.Parse(info.Version).CompareTo(Version.Parse(_versionName)) <= 0);
             }
             catch (Exception e)
             {
                 MobileLogging.Log(e,"Version");
-                //throw new LatestVersionException($"Error comparing current app version number with latest. Version name={_versionName} and lastest version={latestVersion} .", e);
             }
 
             return true;
         }
-
-        /// <inheritdoc />
-        public async Task<string> GetLatestVersionNumber(bool force)
-        {
-            return await GetLatestVersionNumber(_packageName, force);
-        }
-
-        private static string _latestversionnumber = "";
         
-        /// <inheritdoc />
-        public async Task<string> GetLatestVersionNumber(string appName,bool force)
+        private static AppInfo _info;
+        
+        public async Task<AppInfo> GetLatestVersion(bool force)
         {
+            
             if (force)
-                _latestversionnumber = "";
+                _info = null;
             
-            if (!String.IsNullOrWhiteSpace(_latestversionnumber))
-                return _latestversionnumber;
+            if (_info != null)
+                return _info;
             
-            if (string.IsNullOrWhiteSpace(appName))
-            {
-                throw new ArgumentNullException(nameof(appName));
-            }
-
-            var version = string.Empty;
-            var url = $"https://play.google.com/store/apps/details?id={appName}&hl=en";
-
+            _info = new AppInfo();
+            
+            // https://play.google.com/store/apps/details?id=comal.timesheets.Android&hl=en
+            var url = $"https://play.google.com/store/apps/details?id={_packageName}&hl=en";
             try
             {
                 using (var request = new HttpRequestMessage(HttpMethod.Get, url))
@@ -119,8 +106,7 @@ namespace InABox.Mobile.Android
 
                                         if (versionMatch.Success)
                                         {
-                                            version = versionMatch.Value.Trim();
-                                            _latestversionnumber = version;
+                                            _info.Version = versionMatch.Value.Trim();
                                         }
                                     }
                                     catch (Exception e)
@@ -139,37 +125,32 @@ namespace InABox.Mobile.Android
             }
             catch (Exception ex)
             {
-                
+                MobileLogging.Log(ex,"PlayStore");
             }
 
-            return version;
+            return _info;
         }
-
-        /// <inheritdoc />
+        
         public Task OpenAppInStore()
         {
-            return OpenAppInStore(_packageName);
-        }
-
-        /// <inheritdoc />
-        public Task OpenAppInStore(string appName)
-        {
-            if (string.IsNullOrWhiteSpace(appName))
-            {
-                throw new ArgumentNullException(nameof(appName));
-            }
-
             try
             {
-                var intent = new Intent(Intent.ActionView, Net.Uri.Parse($"market://details?id={appName}"));
-                intent.SetPackage("com.android.vending");
-                intent.SetFlags(ActivityFlags.NewTask);
-                Application.Context.StartActivity(intent);
+                try
+                {
+                    var intent = new Intent(Intent.ActionView, Net.Uri.Parse($"market://details?id={_packageName}"));
+                    intent.SetPackage("com.android.vending");
+                    intent.SetFlags(ActivityFlags.NewTask);
+                    Application.Context.StartActivity(intent);
+                }
+                catch (ActivityNotFoundException)
+                {
+                    var intent = new Intent(Intent.ActionView, Net.Uri.Parse($"https://play.google.com/store/apps/details?id={_packageName}"));
+                    Application.Context.StartActivity(intent);
+                }
             }
-            catch (ActivityNotFoundException)
+            catch (Exception e)
             {
-                var intent = new Intent(Intent.ActionView, Net.Uri.Parse($"https://play.google.com/store/apps/details?id={appName}"));
-                Application.Context.StartActivity(intent);
+                MobileLogging.Log(e,"PlayStore");
             }
 
             return Task.FromResult(true);

+ 2 - 2
InABox.Mobile/InABox.Mobile.Shared/Components/MobileMenuButton/MobileMenuButtonMenu.xaml

@@ -21,7 +21,7 @@
             >
             <BindableLayout.EmptyView>
                 <Label 
-                    FontSize="Micro"
+                    FontSize="Small"
                     Text="(No Options)"
                     TextColor="Silver"/>
             </BindableLayout.EmptyView>
@@ -45,7 +45,7 @@
                             HorizontalOptions="Fill" 
                             HorizontalTextAlignment="Start"
                             VerticalTextAlignment="Center"
-                            FontSize="Micro"
+                            FontSize="Small"
                             Padding="2,5,2,2"
                             IsVisible="False">
                             

+ 14 - 3
InABox.Mobile/InABox.Mobile.Shared/Components/MobileToolGrid/MobileToolGrid.xaml.cs

@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
 using System.Globalization;
 using System.Linq;
 using System.Threading.Tasks;
+using Xamarin.Essentials;
 using Xamarin.Forms;
 using Xamarin.Forms.Xaml;
 using XF.Material.Forms;
@@ -33,17 +34,22 @@ namespace InABox.Mobile
         
         public ToolGridViewModel()
         {
-            Columns = 4;
+            Columns = Device.Idiom == TargetIdiom.Tablet ? 6 : 4;
             Items = new ObservableCollection<IMobileToolItem>();
 
             VisibleItems = new ObservableCollection<IMobileToolItem>();
             ((ObservableCollection<IMobileToolItem>)Items).CollectionChanged += (sender, args) =>
             {
-                VisibleItems.Clear();
-                DoLayout();
+                Refresh();
             };
         }
 
+        public void Refresh()
+        {
+            VisibleItems.Clear();
+            DoLayout();
+        }
+
         private void DoLayout()
         {
             int iRow = 0;
@@ -84,6 +90,11 @@ namespace InABox.Mobile
             BindableLayout.SetItemsSource(_flexgrid, _viewModel.VisibleItems);
         }
 
+        public void Refresh()
+        {
+            _viewModel.Refresh();
+        }
+
         private readonly BindableProperty BorderColorProperty = BindableProperty.Create(
             nameof(BorderColor),
             typeof(Color),

+ 10 - 19
InABox.Mobile/InABox.Mobile.Shared/IAppVersion.cs

@@ -22,6 +22,13 @@ namespace InABox.Mobile
         }
     }
 
+    public class AppInfo
+    {
+        public String Version { get; set; }
+        public DateTime Date { get; set; }
+        public String Notes { get; set; }
+    }
+
     /// <summary>
     /// LatestVersion plugin
     /// </summary>
@@ -38,29 +45,13 @@ namespace InABox.Mobile
         /// </summary>
         /// <returns>True if the current app is the latest version available, false otherwise.</returns>
         Task<bool> IsUsingLatestVersion();
-
-        /// <summary>
-        /// Gets the version number of the current app's latest version available in the public store.
-        /// </summary>
-        /// <returns>The current app's latest version number.</returns>
-        Task<string> GetLatestVersionNumber(bool force);
-
-        /// <summary>
-        /// Gets the version number of an app's latest version available in the public store.
-        /// </summary>
-        /// <returns>The specified app's latest version number</returns>
-        /// <param name="appName">Name of the app to get.</param>
-        Task<string> GetLatestVersionNumber(string appName, bool force);
-
+        
+        Task<AppInfo> GetLatestVersion(bool force);
+        
         /// <summary>
         /// Opens the current app in the public store.
         /// </summary>
         Task OpenAppInStore();
 
-        /// <summary>
-        /// Opens an app in the public store.
-        /// </summary>
-        /// <param name="appName">Name of the app to open.</param>
-        Task OpenAppInStore(string appName);
     }
 }

+ 39 - 84
InABox.Mobile/InABox.Mobile.iOS/Version_iOS.cs

@@ -3,54 +3,46 @@ using System.Json;
 using System.Net.Http;
 using Foundation;
 using System.Threading.Tasks;
-using System.Text.RegularExpressions;
 using System.Globalization;
 
 [assembly: Xamarin.Forms.Dependency(typeof(InABox.Mobile.iOS.Version_iOS))]
 namespace InABox.Mobile.iOS
 {
-
-    // internal static class iOS_VersionExtensions
-    // {
-    //     public static string MakeSafeForAppStoreShortLinkUrl(this string value)
-    //     {
-    //         // Reference: https://developer.apple.com/library/content/qa/qa1633/_index.html
-    //
-    //         var regex = new Regex(@"[©™®!¡""#$%'()*+,\\\-.\/:;<=>¿?@[\]^_`{|}~]*");
-    //
-    //         var safeValue = regex.Replace(value, "")
-    //                              .Replace(" ", "")
-    //                              .Replace("&", "and")
-    //                              .ToLower();
-    //
-    //         return safeValue;
-    //     }
-    // }
-
-    /// <summary>
-    /// <see cref="ILatestVersion"/> implementation for iOS.
-    /// </summary>
+    
     public class Version_iOS : IAppVersion
     {
         string _bundleName => NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleName").ToString();
         string _bundleIdentifier => NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleIdentifier").ToString();
         string _bundleVersion => NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
         JsonValue _appstoreInfo = null;
-
-        /// <inheritdoc />
+        
         public string InstalledVersionNumber
         {
             get => _bundleVersion;
         }
-
-
-        private async Task CheckAppStoreInfo(string appName)
+        
+        public async Task<bool> IsUsingLatestVersion()
         {
+            
+            try
+            {                
+                var info = await GetLatestVersion(false);
+                return String.IsNullOrWhiteSpace(info.Version) 
+                       || (Version.Parse(info.Version).CompareTo(Version.Parse(_bundleVersion)) <= 0);
+            }
+            catch (Exception e)
+            {
+                PRS.Mobile.MobileLogging.Log(e,"AppStore");
+            }
+            return true;
+        }
 
-            if (_appstoreInfo != null)
-                return;
 
-            var url = $"http://itunes.apple.com/lookup?bundleId={appName}";
+        private async Task CheckAppStoreInfo()
+        {
+            
+            // http://itunes.apple.com/lookup?bundleId=com.prsdigital.prssiteapp
+            var url = $"http://itunes.apple.com/lookup?bundleId={_bundleIdentifier}";
 
             using (var request = new HttpRequestMessage(HttpMethod.Get, url))
             {
@@ -90,49 +82,22 @@ namespace InABox.Mobile.iOS
             }
         }
 
-        /// <inheritdoc />
-        public async Task<bool> IsUsingLatestVersion()
-        {
-            string latestversion = string.Empty;
-            try
-            {                
-                latestversion = await GetLatestVersionNumber(false);
-                return String.IsNullOrWhiteSpace(latestversion) || (Version.Parse(latestversion).CompareTo(Version.Parse(_bundleVersion)) <= 0);
-            }
-            catch (Exception e)
-            {
-                throw new LatestVersionException($"Error comparing current app version number with latest. Bundle version={_bundleVersion} and lastest version={latestversion} .", e);
-            }
-        }
-
-        private string _latestversionnumber = "";
-
-        /// <inheritdoc />
-        public async Task<string> GetLatestVersionNumber(bool force)
-        {
-            return await GetLatestVersionNumber(_bundleIdentifier, force);
-        }
-
-        /// <inheritdoc />
-        public async Task<string> GetLatestVersionNumber(string appName, bool force)
+        private AppInfo _info = null;
+        
+        public async Task<AppInfo> GetLatestVersion(bool force)
         {
+            
             if (force)
-                _latestversionnumber = "";
+                _info = null;
 
-            if (!String.IsNullOrWhiteSpace(_latestversionnumber))
-                return _latestversionnumber;
+            if (_info != null)
+                return _info;
             
-            String version = "";
             
-            if (string.IsNullOrWhiteSpace(appName))
-            {
-                throw new ArgumentNullException(nameof(appName));
-            }
-
-            await CheckAppStoreInfo(appName);
-
+            _info = new AppInfo();
             try
             {
+                await CheckAppStoreInfo();
                 if (_appstoreInfo.ContainsKey("results"))
                 {
                     var results = _appstoreInfo["results"];
@@ -140,40 +105,30 @@ namespace InABox.Mobile.iOS
                     {
                         var result = results[0];
                         if (result.ContainsKey("version"))
-                            version = result["version"];
+                            _info.Version = result["version"];
+                        if (result.ContainsKey("releaseDate") && DateTime.TryParse(result["releaseDate"],out DateTime release))
+                            _info.Date = release;
+                        if (result.ContainsKey("releaseNotes"))
+                            _info.Notes = result["releaseNotes"];
                     }
                 }
-                //version = _appstoreInfo["results"]?[0]?["version"] ?? "";
             }
             catch (Exception e)
             {
+                MobileLogging.Log(e,"AppStore");
             }
-            return version;
+            return _info;
 
         }
 
         /// <inheritdoc />
         public Task OpenAppInStore()
         {
-            return OpenAppInStore(_bundleName);
-        }
-
-        /// <inheritdoc />
-        public Task OpenAppInStore(string appName)
-        {
-            if (string.IsNullOrWhiteSpace(appName))
-            {
-                throw new ArgumentNullException(nameof(appName));
-            }
-
             try
             {
-
                 var location = RegionInfo.CurrentRegion.Name.ToLower();
                 var trackid = _appstoreInfo["results"][0]["trackId"];
-
-                var url = String.Format("https://itunes.apple.com/{0}/app/{1}/id{2}?mt=8",location,appName,trackid);
-
+                var url = String.Format("https://itunes.apple.com/{0}/app/{1}/id{2}?mt=8",location,_bundleName,trackid);
                 //appName = appName.MakeSafeForAppStoreShortLinkUrl();
 
 #if __IOS__