diff --git a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/PathService.cs b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/DeviceInfoService.cs
similarity index 90%
rename from TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/PathService.cs
rename to TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/DeviceInfoService.cs
index 84b8adb..b697b33 100644
--- a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/PathService.cs
+++ b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/DeviceInfoService.cs
@@ -16,10 +16,10 @@
using TunisiaPrayer.Services;
using Xamarin.Forms;
-[assembly: Xamarin.Forms.Dependency(typeof(TunisiaPrayer.Droid.PathService))]
+[assembly: Xamarin.Forms.Dependency(typeof(TunisiaPrayer.Droid.DeviceInfoService))]
namespace TunisiaPrayer.Droid
{
- public class PathService : IPathService
+ public class DeviceInfoService : IDeviceInfoService
{
private Context context = Android.App.Application.Context;
public string PublicExternalFolder
@@ -31,6 +31,15 @@ public string PublicExternalFolder
}
}
+ public string Architecture
+ {
+ get
+ {
+ return Android.OS.Build.SupportedAbis[0];
+
+ }
+ }
+
//public async void install(string filePath)
//{
diff --git a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/TunisiaPrayer.Android.csproj b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/TunisiaPrayer.Android.csproj
index 4d19d01..eefb366 100644
--- a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/TunisiaPrayer.Android.csproj
+++ b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer.Android/TunisiaPrayer.Android.csproj
@@ -81,7 +81,7 @@
-
+
diff --git a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Services/IPathService.cs b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Services/IDeviceInfoService.cs
similarity index 80%
rename from TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Services/IPathService.cs
rename to TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Services/IDeviceInfoService.cs
index bfbaa81..5e082a6 100644
--- a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Services/IPathService.cs
+++ b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Services/IDeviceInfoService.cs
@@ -5,10 +5,11 @@
namespace TunisiaPrayer.Services
{
- public interface IPathService
+ public interface IDeviceInfoService
{
//string InternalFolder { get; }
string PublicExternalFolder { get; }
+ string Architecture { get; }
//void install(string filePath);
//string PrivateExternalFolder { get; }
}
diff --git a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml
index cca2c3d..17bcbd9 100644
--- a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml
+++ b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml
@@ -2,18 +2,21 @@
+ x:Class="TunisiaPrayer.Views.UpdatesPage"
+ BackgroundColor="#272c34">
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
+
diff --git a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml.cs b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml.cs
index 9648413..17ddb73 100644
--- a/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml.cs
+++ b/TunisiaPrayerApp/TunisiaPrayer/TunisiaPrayer/Views/UpdatesPage.xaml.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
using Octokit;
using Xamarin.Forms;
@@ -17,63 +15,90 @@ namespace TunisiaPrayer.Views
public partial class UpdatesPage : ContentPage
{
public bool UpdateAvailable { get; set; } = false;
- public string IsDownloading { get; set; }
- IPathService pathService;
+ public string LatestReleaseInfo { get; set; }
+ public string UpdateButton { get; set; } = "Update";
+ IDeviceInfoService deviceService;
IPackageInstaller packageInstaller;
- private string fileUri;
+ private string _fileUri;
+ private string _newVersionTag;
public UpdatesPage()
{
InitializeComponent();
BindingContext = this;
- pathService = DependencyService.Get();
+ deviceService = DependencyService.Get();
packageInstaller = DependencyService.Get();
}
- private async void RefreshButton_Clicked(object sender, EventArgs e)
+
+ protected override async void OnAppearing()
+ {
+ await CheckForUpdates();
+ }
+
+ private async Task CheckForUpdates()
{
- var client = new GitHubClient(new ProductHeaderValue("tunisiaPrayerApp"));
- //yes that's the repo's id, it's public
- var releases = await client.Repository.Release.GetAll(451233074);
- for (int i = 0; i < releases.Count; i++)
+ if (Connectivity.NetworkAccess != NetworkAccess.Internet)
{
- rel.Text = releases[i].Name;
+ await this.DisplayToastAsync("no internet connection :(", 5000);
+ return;
}
- //releases[0].TagName != VersionTracking.CurrentVersion
- if (true)
+ var client = new GitHubClient(new ProductHeaderValue("tunisiaPrayerApp"));
+ //yes that's the repo's id, it's public
+ var releases = await client.Repository.Release.GetAll(451233074);
+ rel.Text = releases[0].Name;
+
+ if (releases[0].TagName != VersionTracking.CurrentVersion)
{
UpdateAvailable = true;
+ _newVersionTag = releases[0].TagName;
OnPropertyChanged(nameof(UpdateAvailable));
- //versionDiff.Text = $"current is {AppInfo.VersionString}, new is {releases[0].TagName}";
+ ReleaseChanges(releases[0].Body);
+ }
+ else
+ {
+ rel.Text = "No updates Available";
}
}
- private async void Button_Clicked(object sender, EventArgs e)
+ void ReleaseChanges(string release)
{
- if (await StoragePermissionDenied())
+ LatestReleaseInfo = release;
+ OnPropertyChanged(nameof(LatestReleaseInfo));
+ }
+
+ private async void UpdateButton_Clicked(object sender, EventArgs e)
+ {
+
+ if (Connectivity.NetworkAccess != NetworkAccess.Internet)
{
+ await this.DisplayToastAsync("no internet connection :(", 5000);
return;
}
- //rel.Text += "\n" + pathService.PublicExternalFolder;
- IsDownloading = "downloading";
- OnPropertyChanged(nameof(IsDownloading));
- Uri url = new Uri($"https://github.com/quran/quran_android/releases/download/v3.1.2/quran-3.1.2.apk");
-
- GetFileUri();
+ if (await StoragePermissionDenied())
+ {
+ return;
+ }
+ string appName = $"TunisiaPrayer-{deviceService.Architecture}-v{_newVersionTag}.apk";
+ Uri url = new Uri($"https://github.com/cabiste69/TunisiaPrayer/releases/download/{_newVersionTag}/{appName}");
+ GetFileUri(appName);
+ UpdateButton = "Downloading...";
+ UpdateAvailable = false;
+ OnPropertyChanged(nameof(UpdateAvailable));
+ OnPropertyChanged(nameof(UpdateButton));
WebClient myWebClient = new WebClient();
- myWebClient.DownloadFileAsync(url, fileUri);
- IsDownloading = "completed downloading";
- OnPropertyChanged(nameof(IsDownloading));
+ myWebClient.DownloadFileAsync(url, _fileUri);
myWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(InstallUpdate);
- //InstallUpdate(null, null);
}
private void InstallUpdate(object sender, AsyncCompletedEventArgs e)
{
- packageInstaller.InstallApk(fileUri);
+ UpdateButton = "Installing...";
+ OnPropertyChanged(nameof(UpdateButton));
+ packageInstaller.InstallApk(_fileUri);
}
//quite confusing but it's correct
@@ -93,9 +118,9 @@ private async Task StoragePermissionDenied()
return permissionWrite != PermissionStatus.Granted && permissionRead != PermissionStatus.Granted;
}
- private void GetFileUri()
+ private void GetFileUri(string appName)
{
- fileUri = pathService.PublicExternalFolder + "/test.apk";
+ _fileUri = $"{deviceService.PublicExternalFolder}/{appName}";
}
}