mirror of
https://github.com/XFox111/GUTSchedule.git
synced 2026-04-22 06:58:01 +03:00
Added catches for some errors, Allowed to write schedule to any calendar
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Android.App;
|
||||
using Android.Content;
|
||||
using Android.OS;
|
||||
using Android.Widget;
|
||||
using GUT.Schedule.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -22,17 +24,30 @@ namespace GUT.Schedule
|
||||
|
||||
status = FindViewById<TextView>(Resource.Id.status);
|
||||
|
||||
status.Text = "Загрузка расписания";
|
||||
List<Subject> schedule = await Parser.LoadSchedule();
|
||||
try
|
||||
{
|
||||
status.Text = "Загрузка расписания";
|
||||
List<Subject> schedule = await Parser.LoadSchedule();
|
||||
|
||||
schedule = schedule.FindAll(i => i.StartTime.Date >= Data.StartDate && i.StartTime.Date <= Data.EndDate); // Filtering schedule according to export range
|
||||
schedule = schedule.FindAll(i => i.StartTime.Date >= Data.StartDate && i.StartTime.Date <= Data.EndDate); // Filtering schedule according to export range
|
||||
|
||||
status.Text = "Экспортирование в календарь";
|
||||
Calendar.Export(schedule);
|
||||
status.Text = "Экспортирование в календарь";
|
||||
Calendar.Export(schedule);
|
||||
|
||||
|
||||
status.Text = "Готово";
|
||||
await Task.Delay(1000);
|
||||
status.Text = "Готово";
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
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<DialogClickEventArgs>)null);
|
||||
|
||||
Android.Support.V7.App.AlertDialog dialog = builder.Create();
|
||||
dialog.Show();
|
||||
}
|
||||
base.OnBackPressed(); // Navigates back to main activity (always because I don't allow backward navigation)
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using Android.Support.V4.App;
|
||||
using Android.Support.V4.Content;
|
||||
using Android.Support.V7.App;
|
||||
using Android.Widget;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
|
||||
@@ -33,7 +34,7 @@ namespace GUT.Schedule
|
||||
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.WriteCalendar) != Permission.Granted)
|
||||
{
|
||||
if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.WriteCalendar))
|
||||
ShowDialog();
|
||||
ShowRationale();
|
||||
else
|
||||
RequestPermissions();
|
||||
}
|
||||
@@ -43,15 +44,31 @@ namespace GUT.Schedule
|
||||
|
||||
private async void Proceed()
|
||||
{
|
||||
status.Text = "Загрузка списка календарей";
|
||||
Calendar.LoadCalendars();
|
||||
try
|
||||
{
|
||||
status.Text = "Загрузка списка календарей";
|
||||
Calendar.LoadCalendars();
|
||||
if (Calendar.Calendars.Count == 0)
|
||||
ShowDialog("Создайте новый календарь", "На вашем устройстве нет календарей пригодных для записи расписания");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ShowDialog(e.GetType().ToString(), e.Message);
|
||||
}
|
||||
|
||||
status.Text = "Загрузка списка факультетов";
|
||||
await Parser.LoadFaculties();
|
||||
try
|
||||
{
|
||||
status.Text = "Загрузка списка факультетов";
|
||||
await Parser.LoadFaculties();
|
||||
|
||||
status.Text = "Загрузка дат смещения";
|
||||
using (HttpClient client = new HttpClient())
|
||||
status.Text = "Загрузка дат смещения";
|
||||
using HttpClient client = new HttpClient();
|
||||
Data.FirstWeekDay = int.Parse(await client.GetStringAsync("https://xfox111.net/schedule_offset.txt"));
|
||||
}
|
||||
catch
|
||||
{
|
||||
ShowDialog("Не удалось загрузить данные", "Проверьте интернет-соединение или попробуйте позже");
|
||||
}
|
||||
|
||||
StartActivity(new Intent(this, typeof(MainActivity)));
|
||||
}
|
||||
@@ -63,7 +80,7 @@ namespace GUT.Schedule
|
||||
if (grantResults.All(i => i == Permission.Granted))
|
||||
Proceed();
|
||||
else
|
||||
ShowDialog();
|
||||
ShowRationale();
|
||||
}
|
||||
|
||||
private void RequestPermissions() =>
|
||||
@@ -74,7 +91,7 @@ namespace GUT.Schedule
|
||||
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)
|
||||
|
||||
private void ShowDialog()
|
||||
private void ShowRationale()
|
||||
{
|
||||
Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this);
|
||||
builder.SetMessage("Разрешите приложению получать доступ к календарю. Без этого разрешения приложение не сможет добавлять расписание в ваш календарь")
|
||||
@@ -85,6 +102,17 @@ namespace GUT.Schedule
|
||||
dialog.Show();
|
||||
}
|
||||
|
||||
private void ShowDialog(string title, string content)
|
||||
{
|
||||
Android.Support.V7.App.AlertDialog.Builder builder = new Android.Support.V7.App.AlertDialog.Builder(this);
|
||||
builder.SetMessage(content)
|
||||
.SetTitle(title)
|
||||
.SetPositiveButton("ОК", (EventHandler<DialogClickEventArgs>)null);
|
||||
|
||||
Android.Support.V7.App.AlertDialog dialog = builder.Create();
|
||||
dialog.Show();
|
||||
}
|
||||
|
||||
public override void OnBackPressed() { } // Disables back button
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,7 @@ namespace GUT.Schedule
|
||||
string[] calendarsProjection = {
|
||||
CalendarContract.Calendars.InterfaceConsts.Id,
|
||||
CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName,
|
||||
CalendarContract.Calendars.InterfaceConsts.AccountName,
|
||||
CalendarContract.Calendars.InterfaceConsts.OwnerAccount,
|
||||
CalendarContract.Calendars.InterfaceConsts.AccountType,
|
||||
CalendarContract.Calendars.InterfaceConsts.AccountName
|
||||
};
|
||||
|
||||
// Retrieving calendars data
|
||||
@@ -38,8 +36,7 @@ namespace GUT.Schedule
|
||||
cursor.MoveToNext();
|
||||
for (int i = 0; i < cursor.Count; i++)
|
||||
{
|
||||
if (cursor.GetString(4) == "com.google" && !cursor.GetString(3).Contains("google")) // Loading only users' main calendars
|
||||
Calendars.Add((cursor.GetString(0), $"{cursor.GetString(1)} ({cursor.GetString(2)})"));
|
||||
Calendars.Add((cursor.GetString(0), $"{cursor.GetString(1)} ({cursor.GetString(2)})"));
|
||||
cursor.MoveToNext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="101" android:versionName="1.0.1" package="com.xfox111.gut.schedule" android:installLocation="auto">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="102" android:versionName="1.0.2" package="com.xfox111.gut.schedule" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
|
||||
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="ГУТ.Расписание" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBar"></application>
|
||||
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||
|
||||
Reference in New Issue
Block a user