public static async Task <ReleaseDescription> GetLatestReleaseDescription()
        {
            String url = "https://raw.githubusercontent.com/shults-s/SmtuSchedule/master/SmtuSchedule.Android/Release.json";

            try
            {
                String json = await HttpHelper.GetAsync(url).ConfigureAwait(false);

                return(ReleaseDescription.FromJson(json));
            }
            catch
            {
                return(null);
            }
        }
Пример #2
0
        public static Task <ReleaseDescription> GetLatestReleaseDescription()
        {
            return(Task.Run(async() =>
            {
                const String Url = RepositoryRawUrl + "SmtuSchedule.Android/Release.json";

                try
                {
                    String json = await HttpUtilities.GetAsync(Url).ConfigureAwait(false);
                    return ReleaseDescription.FromJson(json).Validate();
                }
                catch
                {
                    return null;
                }
            }));
        }
Пример #3
0
        private async void CheckForUpdatesAsync(Int32 currentVersion)
        {
            if (IsPermissionDenied(Manifest.Permission.Internet))
            {
                RequestPermissions(InternetPermissionRequestCode, Manifest.Permission.Internet);
                return;
            }

            ReleaseDescription latest = await ApplicationHelper.GetLatestReleaseDescription();

            if (latest == null)
            {
                return;
            }

            String packageId = latest.GooglePlayStorePackageId;

            if (packageId == null)
            {
                if (latest.VersionCode == _application.Preferences.LastSeenUpdateVersion ||
                    latest.VersionCode <= currentVersion)
                {
                    return;
                }

                new CustomAlertDialog(this)
                .SetTitle(Resource.String.applicationUpdateAvailableDialogTitle)
                .SetMessage(Resource.String.applicationUpdateAvailableMessage)
                .SetPositiveButton(
                    Resource.String.openUpdateDownloadPageActionTitle,
                    () =>
                {
                    String url = ApplicationHelper.LatestReleaseDownloadPageUrl;
                    StartActivity(new Intent(Intent.ActionView, Uri.Parse(url)));
                }
                    )
                .SetNegativeButton(
                    Resource.String.gotItActionTitle,
                    () => _application.Preferences.SetLastSeenUpdateVersion(latest.VersionCode)
                    )
                .Show();

                return;
            }

            if (packageId == PackageName)
            {
                if (!_application.Preferences.StoreReleaseNoticeViewed)
                {
                    new CustomAlertDialog(this)
                    .SetTitle(Resource.String.googlePlayStoreReleaseAvailableDialogTitle)
                    .SetMessage(Resource.String.googlePlayStoreReleaseAvailableMessage)
                    .SetPositiveButton(
                        Resource.String.gotItActionTitle,
                        () => _application.Preferences.SetStoreReleaseNoticeViewed(true)
                        )
                    .Show();
                }

                return;
            }

            new CustomAlertDialog(this)
            .SetTitle(Resource.String.googlePlayStoreReleaseAvailableDialogTitle)
            .SetMessage(Resource.String.googlePlayStoreReleaseRelocatedMessage)
            .SetPositiveButton(
                Resource.String.openPlayMarketActionTitle,
                () =>
            {
                try
                {
                    String url = "market://details?id=" + packageId;
                    StartActivity(new Intent(Intent.ActionView, Uri.Parse(url)));
                }
                // Google Play Маркет не установлен.
                catch (ActivityNotFoundException)
                {
                    String url = "https://play.google.com/store/apps/details?id=" + packageId;
                    StartActivity(new Intent(Intent.ActionView, Uri.Parse(url)));
                }
            }
                )
            .Show();
        }
Пример #4
0
        // private async void MigrateSchedulesAsync(Int64 currentVersion)
        // {
        //     if (_application.Preferences.LastMigrationVersion == currentVersion)
        //     {
        //         return ;
        //     }
        //
        //     if (!await _application.Manager.MigrateSchedulesAsync())
        //     {
        //         ShowSnackbar(Resource.String.schedulesMigrationErrorMessage);
        //         _ = _application.SaveLogAsync();
        //     }
        //     else
        //     {
        //         _application.Preferences.SetLastMigrationVersion(currentVersion);
        //     }
        // }

        private async void CheckForCriticalUpdatesAsync(Int64 currentVersion)
        {
            if (IsPermissionDenied(Manifest.Permission.Internet))
            {
                RequestPermissions(InternetPermissionRequestCode, Manifest.Permission.Internet);
                return;
            }

            ReleaseDescription latest = await ApplicationUtilities.GetLatestReleaseDescription();

            if (latest == null)
            {
                return;
            }

            if (!latest.IsCriticalUpdate) // && !_application.Preferences.CheckUpdatesOnStart
            {
                return;
            }

            if (latest.VersionCode == _application.Preferences.LastSeenUpdateVersion ||
                latest.VersionCode <= currentVersion)
            {
                return;
            }

            Java.Lang.ICharSequence dialogMessage = (latest.VersionNotes != null)
                ? latest.VersionNotes.FromHtml()
                : Resources.GetString(Resource.String.applicationUpdateAvailableMessage).FromMarkdown();

            Int32 dialogTitleId = latest.IsCriticalUpdate
                ? Resource.String.applicationCriticalUpdateAvailableDialogTitle
                : Resource.String.applicationUpdateAvailableDialogTitle;

            String packageId = latest.GooglePlayStorePackageId;

            if (packageId == null)
            {
                new CustomAlertDialog(this)
                .SetTitle(dialogTitleId)
                .SetMessage(dialogMessage)
                .SetPositiveButton(
                    Resource.String.openUpdateDownloadPageActionTitle,
                    () =>
                {
                    String url = ApplicationUtilities.LatestReleaseDownloadPageUrl;
                    StartActivity(IntentUtilities.CreateViewIntentFromUrl(url));
                }
                    )
                .SetNegativeButton(
                    Resource.String.gotItActionTitle,
                    () => _application.Preferences.SetLastSeenUpdateVersion(latest.VersionCode)
                    )
                .Show();

                return;
            }

            void OpenWithPlayStore()
            {
                try
                {
                    Intent intent = IntentUtilities.CreateGooglePlayStoreViewIntent(
                        this,
                        packageId
                        );

                    if (intent != null)
                    {
                        StartActivity(intent);
                    }
                }
                catch (ActivityNotFoundException)
                {
                    Intent intent = IntentUtilities.CreateGooglePlayStoreViewIntent(
                        this,
                        packageId,
                        true
                        );

                    if (intent != null)
                    {
                        StartActivity(intent);
                    }
                }
            }

            if (packageId == PackageName)
            {
                new CustomAlertDialog(this)
                .SetTitle(dialogTitleId)
                .SetMessage(dialogMessage)
                .SetPositiveButton(
                    Resource.String.openPlayMarketActionTitle,
                    () => OpenWithPlayStore()
                    )
                .SetNegativeButton(
                    Resource.String.gotItActionTitle,
                    () => _application.Preferences.SetLastSeenUpdateVersion(latest.VersionCode)
                    )
                .Show();

                return;
            }

            new CustomAlertDialog(this)
            .SetTitle(Resource.String.googlePlayStoreReleaseAvailableDialogTitle)
            .SetMessage(Resource.String.googlePlayStoreReleaseRelocatedMessage)
            .SetPositiveButton(Resource.String.openPlayMarketActionTitle, () => OpenWithPlayStore())
            .Show();
        }