Exemplo n.º 1
0
        private async Task UpdateAppAsync()
        {
            var latestRelease = await _githubService.GetLatestVersionCodeAsync();

            var currentAppVersion = _appUpdater.GetCurrentVersion();

            if (latestRelease.CheckIsLatestRelease(currentAppVersion))
            {
                if (!_appUpdater.CheckIsAppAfterUpdate())
                {
                    DialogService.DisplayToast(StringResources.ApplicationIsUpToDate, ToastTime.Short);
                    return;
                }

                var dialogAnswer = await DialogService
                                   .DisplayAlertAsync(StringResources.Warning, StringResources.DoYouWantToRemoveOldApplicationInstallationFile,
                                                      StringResources.Yes, StringResources.No);

                if (dialogAnswer)
                {
                    _appUpdater.RemoveApkFile();
                }
                return;
            }

            var description = $"{StringResources.CurrentVersion}: {currentAppVersion}\n{StringResources.Update}: {latestRelease.TagName}\n" +
                              $"{StringResources.Description}:\n{latestRelease.Description}\n\n" +
                              StringResources.DoYouWantToDownloadUpdateNow;

            var dialogResponse = await DialogService.DisplayAlertAsync(StringResources.Update,
                                                                       description, StringResources.Yes, StringResources.No);

            if (!dialogResponse)
            {
                return;
            }

            _appUpdater.UpdateApp(latestRelease);
        }