diff --git a/GUT.Schedule/GUT.Schedule/Activities/ExportActivity.cs b/GUT.Schedule/GUT.Schedule/Activities/ExportActivity.cs index 1071e28..bcf3385 100644 --- a/GUT.Schedule/GUT.Schedule/Activities/ExportActivity.cs +++ b/GUT.Schedule/GUT.Schedule/Activities/ExportActivity.cs @@ -1,10 +1,10 @@ using Android.App; -using Android.Content; using Android.OS; using Android.Widget; using GUT.Schedule.Models; using System; using System.Collections.Generic; +using System.Net.Http; using System.Threading.Tasks; namespace GUT.Schedule @@ -17,13 +17,18 @@ namespace GUT.Schedule { TextView status; - protected override async void OnCreate(Bundle savedInstanceState) + protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.export_progress); status = FindViewById(Resource.Id.status); + Export(); + } + + private async void Export() + { try { status.Text = "Загрузка расписания"; @@ -38,15 +43,28 @@ namespace GUT.Schedule status.Text = "Готово"; await Task.Delay(1000); } + catch (HttpRequestException e) + { + Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this); + builder.SetMessage("Невозможно загрузить расписание. Проверьте интернет-соединение или попробуйте позже") + .SetTitle(e.Message) + .SetPositiveButton("ОК", (s, e) => base.OnBackPressed()) + .SetNegativeButton("Повторить", (s, e) => Export()); + + Android.Support.V7.App.AlertDialog dialog = builder.Create(); + dialog.Show(); + return; + } catch (Exception e) { Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this); builder.SetMessage(e.Message) .SetTitle(e.GetType().ToString()) - .SetPositiveButton("ОК", (EventHandler)null); + .SetPositiveButton("ОК", (s, e) => base.OnBackPressed()); Android.Support.V7.App.AlertDialog dialog = builder.Create(); dialog.Show(); + return; } base.OnBackPressed(); // Navigates back to main activity (always because I don't allow backward navigation) } diff --git a/GUT.Schedule/GUT.Schedule/Activities/StartActivity.cs b/GUT.Schedule/GUT.Schedule/Activities/StartActivity.cs index 989a4c1..2704c99 100644 --- a/GUT.Schedule/GUT.Schedule/Activities/StartActivity.cs +++ b/GUT.Schedule/GUT.Schedule/Activities/StartActivity.cs @@ -61,6 +61,11 @@ namespace GUT.Schedule using HttpClient client = new HttpClient(); Data.FirstWeekDay = int.Parse(await client.GetStringAsync("https://xfox111.net/schedule_offset.txt")); } + catch(HttpRequestException e) + { + ShowDialog(e.Message, "Невозможно загрузить расписание. Проверьте интернет-соединение или попробуйте позже", Proceed, FinishAndRemoveTask, "Повторить", "Выйти"); + return; + } catch (Exception e) { ShowDialog(e.GetType().ToString(), e.Message, FinishAndRemoveTask); @@ -85,14 +90,16 @@ namespace GUT.Schedule Manifest.Permission.ReadCalendar, Manifest.Permission.WriteCalendar, Manifest.Permission.Internet - }, 76); // IDK why I need requestCode value to be set (instead of 76 there can be any other number. Anyway it doesn't affect anything) + }, 0); - private void ShowDialog(string title, string content, Action action = null) + private void ShowDialog(string title, string content, Action posAction = null, Action negAction = null, string posActionLabel = null, string negActionLabel = null) { Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this); builder.SetMessage(content) - .SetTitle(title) - .SetPositiveButton("ОК", (s, e) => action?.Invoke()); + .SetTitle(title).SetPositiveButton(posActionLabel ?? "OK", (s, e) => posAction?.Invoke()); + + if (negAction != null) + builder.SetNegativeButton(negActionLabel ?? "Close", (s, e) => negAction.Invoke()); Android.Support.V7.App.AlertDialog dialog = builder.Create(); dialog.Show(); diff --git a/GUT.Schedule/GUT.Schedule/Properties/AndroidManifest.xml b/GUT.Schedule/GUT.Schedule/Properties/AndroidManifest.xml index 65bf1e3..56bc423 100644 --- a/GUT.Schedule/GUT.Schedule/Properties/AndroidManifest.xml +++ b/GUT.Schedule/GUT.Schedule/Properties/AndroidManifest.xml @@ -1,5 +1,5 @@  - +