From 7747c23804a1d6449d6c08d3a7cc4d429d74fd33 Mon Sep 17 00:00:00 2001 From: Michael Gordeev Date: Sat, 21 Dec 2019 16:06:59 +0300 Subject: [PATCH] Almost done app --- GUT.Schedule/GUT.Schedule.sln | 27 + .../GUT.Schedule/Assets/AboutAssets.txt | 19 + GUT.Schedule/GUT.Schedule/Calendar.cs | 36 + GUT.Schedule/GUT.Schedule/Data.cs | 16 + .../GUT.Schedule/DatePickerFragment.cs | 40 + GUT.Schedule/GUT.Schedule/ExportActivity.cs | 22 + GUT.Schedule/GUT.Schedule/Extensions.cs | 23 + GUT.Schedule/GUT.Schedule/GUT.Schedule.csproj | 136 + GUT.Schedule/GUT.Schedule/MainActivity.cs | 130 + GUT.Schedule/GUT.Schedule/Parser.cs | 71 + .../Properties/AndroidManifest.xml | 8 + .../GUT.Schedule/Properties/AssemblyInfo.cs | 30 + .../GUT.Schedule/Resources/AboutResources.txt | 44 + .../Resources/Resource.designer.cs | 8782 +++++++++++++++++ .../Resources/layout/activity_main.xml | 135 + .../Resources/layout/export_progress.xml | 29 + .../Resources/layout/splash_screen.xml | 34 + .../GUT.Schedule/Resources/menu/menu_main.xml | 9 + .../mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../Resources/mipmap-hdpi/ic_launcher.png | Bin 0 -> 1634 bytes .../mipmap-hdpi/ic_launcher_foreground.png | Bin 0 -> 1441 bytes .../mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 3552 bytes .../Resources/mipmap-mdpi/ic_launcher.png | Bin 0 -> 1362 bytes .../mipmap-mdpi/ic_launcher_foreground.png | Bin 0 -> 958 bytes .../mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2413 bytes .../Resources/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 2307 bytes .../mipmap-xhdpi/ic_launcher_foreground.png | Bin 0 -> 2056 bytes .../mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 4858 bytes .../Resources/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 3871 bytes .../mipmap-xxhdpi/ic_launcher_foreground.png | Bin 0 -> 3403 bytes .../mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 8001 bytes .../Resources/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 5016 bytes .../mipmap-xxxhdpi/ic_launcher_foreground.png | Bin 0 -> 4889 bytes .../mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 10893 bytes .../GUT.Schedule/Resources/values/colors.xml | 6 + .../values/ic_launcher_background.xml | 4 + .../GUT.Schedule/Resources/values/styles.xml | 17 + GUT.Schedule/GUT.Schedule/StartActivity.cs | 79 + 39 files changed, 9707 insertions(+) create mode 100644 GUT.Schedule/GUT.Schedule.sln create mode 100644 GUT.Schedule/GUT.Schedule/Assets/AboutAssets.txt create mode 100644 GUT.Schedule/GUT.Schedule/Calendar.cs create mode 100644 GUT.Schedule/GUT.Schedule/Data.cs create mode 100644 GUT.Schedule/GUT.Schedule/DatePickerFragment.cs create mode 100644 GUT.Schedule/GUT.Schedule/ExportActivity.cs create mode 100644 GUT.Schedule/GUT.Schedule/Extensions.cs create mode 100644 GUT.Schedule/GUT.Schedule/GUT.Schedule.csproj create mode 100644 GUT.Schedule/GUT.Schedule/MainActivity.cs create mode 100644 GUT.Schedule/GUT.Schedule/Parser.cs create mode 100644 GUT.Schedule/GUT.Schedule/Properties/AndroidManifest.xml create mode 100644 GUT.Schedule/GUT.Schedule/Properties/AssemblyInfo.cs create mode 100644 GUT.Schedule/GUT.Schedule/Resources/AboutResources.txt create mode 100644 GUT.Schedule/GUT.Schedule/Resources/Resource.designer.cs create mode 100644 GUT.Schedule/GUT.Schedule/Resources/layout/activity_main.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/layout/export_progress.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/layout/splash_screen.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/menu/menu_main.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-hdpi/ic_launcher.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-hdpi/ic_launcher_foreground.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-hdpi/ic_launcher_round.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-mdpi/ic_launcher.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-mdpi/ic_launcher_foreground.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-mdpi/ic_launcher_round.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xhdpi/ic_launcher.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xhdpi/ic_launcher_foreground.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xhdpi/ic_launcher_round.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xxhdpi/ic_launcher.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xxhdpi/ic_launcher_foreground.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xxxhdpi/ic_launcher.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xxxhdpi/ic_launcher_foreground.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 GUT.Schedule/GUT.Schedule/Resources/values/colors.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/values/ic_launcher_background.xml create mode 100644 GUT.Schedule/GUT.Schedule/Resources/values/styles.xml create mode 100644 GUT.Schedule/GUT.Schedule/StartActivity.cs diff --git a/GUT.Schedule/GUT.Schedule.sln b/GUT.Schedule/GUT.Schedule.sln new file mode 100644 index 0000000..056c894 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29609.76 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GUT.Schedule", "GUT.Schedule\GUT.Schedule.csproj", "{A0471165-37F5-4309-8A92-42F1A6589EEE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0471165-37F5-4309-8A92-42F1A6589EEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0471165-37F5-4309-8A92-42F1A6589EEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0471165-37F5-4309-8A92-42F1A6589EEE}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {A0471165-37F5-4309-8A92-42F1A6589EEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0471165-37F5-4309-8A92-42F1A6589EEE}.Release|Any CPU.Build.0 = Release|Any CPU + {A0471165-37F5-4309-8A92-42F1A6589EEE}.Release|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {456DD1C4-9BC4-4D79-A999-8F85492E7C20} + EndGlobalSection +EndGlobal diff --git a/GUT.Schedule/GUT.Schedule/Assets/AboutAssets.txt b/GUT.Schedule/GUT.Schedule/Assets/AboutAssets.txt new file mode 100644 index 0000000..dcb0409 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/Assets/AboutAssets.txt @@ -0,0 +1,19 @@ +Any raw assets you want to be deployed with your application can be placed in +this directory (and child directories) and given a Build Action of "AndroidAsset". + +These files will be deployed with your package and will be accessible using Android's +AssetManager, like this: + +public class ReadAsset : Activity +{ + protected override void OnCreate (Bundle bundle) + { + base.OnCreate (bundle); + + InputStream input = Assets.Open ("my_asset.txt"); + } +} + +Additionally, some Android functions will automatically load asset files: + +Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/Calendar.cs b/GUT.Schedule/GUT.Schedule/Calendar.cs new file mode 100644 index 0000000..384bb6f --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/Calendar.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using Android.App; +using Android.Database; +using Android.Provider; +using Android.Support.V4.Content; + +namespace GUT.Schedule +{ + public static class Calendar + { + public static void LoadCalendars() + { + Data.Calendars = new List<(string, string)>(); + + var calendarsUri = CalendarContract.Calendars.ContentUri; + string[] calendarsProjection = { + CalendarContract.Calendars.InterfaceConsts.Id, + CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, + CalendarContract.Calendars.InterfaceConsts.AccountName, + CalendarContract.Calendars.InterfaceConsts.OwnerAccount, + CalendarContract.Calendars.InterfaceConsts.AccountType, + }; + + using CursorLoader loader = new CursorLoader(Application.Context, calendarsUri, calendarsProjection, null, null, null); + ICursor cursor = (ICursor)loader.LoadInBackground(); + + cursor.MoveToNext(); + for (int i = 0; i < cursor.Count; i++) + { + if (cursor.GetString(4) == "com.google" && !cursor.GetString(3).Contains("google")) + Data.Calendars.Add((cursor.GetString(0), $"{cursor.GetString(1)} ({cursor.GetString(2)})")); + cursor.MoveToNext(); + } + } + } +} \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/Data.cs b/GUT.Schedule/GUT.Schedule/Data.cs new file mode 100644 index 0000000..8c7ddfd --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/Data.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace GUT.Schedule +{ + public static class Data + { + public static List<(string Id, string Name)> Faculties { get; set; } + public static List<(string Id, string Name)> Groups { get; set; } + public static List<(string Id, string Name)> Calendars { get; set; } + public static DateTime StartDate { get; set; } = DateTime.Today; + public static DateTime EndDate { get; set; } = DateTime.Today.AddDays(7); + + public static (int faculty, int group, int calendar, int reminder) ExportData { get; set; } + } +} \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/DatePickerFragment.cs b/GUT.Schedule/GUT.Schedule/DatePickerFragment.cs new file mode 100644 index 0000000..3886b49 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/DatePickerFragment.cs @@ -0,0 +1,40 @@ +using System; +using Android.OS; +using Android.Widget; +using Android.Support.V4.App; +using System.Threading.Tasks; + +namespace GUT.Schedule +{ + public class DatePickerFragment : DialogFragment, Android.App.DatePickerDialog.IOnDateSetListener + { + DateTime date; + bool dismissed = false; + public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState) + { + DateTime now = DateTime.Today; + return new Android.App.DatePickerDialog(Activity, this, now.Year, now.Month - 1, now.Day); + } + + public void OnDateSet(DatePicker view, int year, int month, int dayOfMonth) + { + SetDate(view.DateTime); + } + + public async Task GetDate(FragmentManager manager, string tag) + { + Show(manager, tag); + + while (!dismissed) + await Task.Delay(500); + + return date; + } + + private void SetDate(DateTime date) + { + this.date = date; + dismissed = true; + } + } +} \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/ExportActivity.cs b/GUT.Schedule/GUT.Schedule/ExportActivity.cs new file mode 100644 index 0000000..6370cd9 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/ExportActivity.cs @@ -0,0 +1,22 @@ +using Android.App; +using Android.OS; +using System.Threading.Tasks; + +namespace GUT.Schedule +{ + [Activity(Theme = "@style/AppTheme.NoActionBar")] + public class ExportActivity : Activity + { + protected override async void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + SetContentView(Resource.Layout.export_progress); + + await Task.Delay(5000); + + base.OnBackPressed(); + } + + public override void OnBackPressed() { } + } +} \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/Extensions.cs b/GUT.Schedule/GUT.Schedule/Extensions.cs new file mode 100644 index 0000000..93eb589 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/Extensions.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Android.App; +using Android.Content; +using Android.OS; +using Android.Runtime; +using Android.Views; +using Android.Widget; + +namespace GUT.Schedule +{ + public static class Extensions + { + public static void SetList(this Spinner spinner, Context context, IEnumerable array) + { + ArrayAdapter adapter = new ArrayAdapter(context, Resource.Layout.support_simple_spinner_dropdown_item, array.ToList()); + spinner.Adapter = adapter; + } + } +} \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/GUT.Schedule.csproj b/GUT.Schedule/GUT.Schedule/GUT.Schedule.csproj new file mode 100644 index 0000000..4fee7e4 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/GUT.Schedule.csproj @@ -0,0 +1,136 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {A0471165-37F5-4309-8A92-42F1A6589EEE} + {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {84dd83c5-0fe3-4294-9419-09e7c8ba324f} + Library + Properties + GUT.Schedule + GUT.Schedule + 512 + True + Resources\Resource.designer.cs + Resource + Off + false + v9.0 + Properties\AndroidManifest.xml + Resources + Assets + true + true + + + True + portable + False + bin\Debug\ + DEBUG;TRACE + prompt + 4 + True + None + False + + + True + portable + True + bin\Release\ + TRACE + prompt + 4 + true + False + SdkOnly + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4.3.4 + + + + + + + + + Designer + + + + + + + + Designer + + + + + \ No newline at end of file diff --git a/GUT.Schedule/GUT.Schedule/MainActivity.cs b/GUT.Schedule/GUT.Schedule/MainActivity.cs new file mode 100644 index 0000000..8ec1f37 --- /dev/null +++ b/GUT.Schedule/GUT.Schedule/MainActivity.cs @@ -0,0 +1,130 @@ +using System; +using System.Linq; +using Android.App; +using Android.Content; +using Android.OS; +using Android.Support.Design.Widget; +using Android.Support.V7.App; +using Android.Views; +using Android.Widget; + +namespace GUT.Schedule +{ + [Activity(Theme = "@style/AppTheme")] + public class MainActivity : AppCompatActivity + { + Button start, end, export; + Spinner faculty, course, group, reminder, calendar; + CheckBox groupTitle; + TextView error; + + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + SetContentView(Resource.Layout.activity_main); + + AssignVariables(); + AddEvents(); + + faculty.SetList(this, Data.Faculties.Select(i => i.Name)); + course.SetList(this, "12345".ToCharArray()); + + reminder.SetList(this, new string[] + { + "Нет", + "Во время начала", + "За 5 мин", + "За 10 мин" + }); + calendar.SetList(this, Data.Calendars.Select(i => i.Name)); + + end.Text = Data.EndDate.ToShortDateString(); + start.Text = Data.StartDate.ToShortDateString(); + } + + public override bool OnCreateOptionsMenu(IMenu menu) + { + MenuInflater.Inflate(Resource.Menu.menu_main, menu); + return true; + } + + public override bool OnOptionsItemSelected(IMenuItem item) + { + int id = item.ItemId; + if (id == Resource.Id.github) + { + StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse("https://github.com/xfox111/GUTSchedule"))); + return true; + } + + return base.OnOptionsItemSelected(item); + } + + private void Export_Click(object sender, EventArgs e) + { + error.Visibility = ViewStates.Gone; + + if (Data.StartDate > Data.EndDate) + { + error.Text = "Ошибка: Неправильный диапазон дат"; + error.Visibility = ViewStates.Visible; + } + + + StartActivity(new Intent(this, typeof(ExportActivity))); + } + + private async void End_Click(object sender, EventArgs e) + { + DatePickerFragment picker = new DatePickerFragment(); + Data.EndDate = await picker.GetDate(SupportFragmentManager, "datePicker"); + end.Text = Data.EndDate.ToShortDateString(); + } + + private async void Start_Click(object sender, EventArgs e) + { + DatePickerFragment picker = new DatePickerFragment(); + Data.StartDate = await picker.GetDate(SupportFragmentManager, "datePicker"); + start.Text = Data.StartDate.ToShortDateString(); + } + + private async void UpdateGroupsList(object sender, AdapterView.ItemSelectedEventArgs e) + { + if (course.SelectedItem == null) + return; + + await Parser.LoadGroups(Data.Faculties[faculty.SelectedItemPosition].Id, course.SelectedItemPosition + 1); + group.SetList(this, Data.Groups.Select(i => i.Name)); + } + + public override void OnBackPressed() { } + + #region Init stuff + private void AssignVariables() + { + start = FindViewById