UpdatePage.xaml.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Net.Http;
  3. using System.Threading.Tasks;
  4. using InABox.Mobile;
  5. using Xamarin.Forms;
  6. using Xamarin.Forms.Xaml;
  7. namespace PRS.Mobile
  8. {
  9. [XamlCompilation(XamlCompilationOptions.Compile)]
  10. public partial class UpdatePage
  11. {
  12. public UpdatePage()
  13. {
  14. InitializeComponent();
  15. ProgressVisible = true;
  16. Task.Run(async () =>
  17. {
  18. bool blatest = await MobileUtils.AppVersion.IsUsingLatestVersion();
  19. if (!blatest)
  20. {
  21. var info = await MobileUtils.AppVersion.GetLatestVersion(false);
  22. Dispatcher.BeginInvokeOnMainThread(() =>
  23. {
  24. _update.Text = $"Update from {MobileUtils.AppVersion.InstalledVersionNumber} to {info.Version}";
  25. _update.IsEnabled = true;
  26. });
  27. }
  28. else
  29. {
  30. _update.Text = $"Up to date ({MobileUtils.AppVersion.InstalledVersionNumber})";
  31. _update.IsEnabled = false;
  32. }
  33. });
  34. Task.Run(async () =>
  35. {
  36. String response = "";
  37. try
  38. {
  39. using (HttpClient client = new HttpClient())
  40. {
  41. response = await client.GetStringAsync("https://prsdigital.com.au/updates/prsmobile/Release%20Notes.txt");
  42. }
  43. }
  44. catch (Exception eLatest)
  45. {
  46. response = "Error retrieving release notes!";
  47. }
  48. Device.BeginInvokeOnMainThread(() =>
  49. {
  50. _releaseNotes.Text = response;
  51. ProgressVisible = false;
  52. });
  53. });
  54. }
  55. private void _update_OnClicked(object sender, MobileButtonClickEventArgs args)
  56. {
  57. MobileUtils.AppVersion.OpenAppInStore();
  58. }
  59. }
  60. }