2017-01-31 21:22:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Android.App;
|
|
|
|
|
using Android.Content;
|
|
|
|
|
using Android.Runtime;
|
|
|
|
|
using Android.Views;
|
|
|
|
|
using Android.Widget;
|
|
|
|
|
using Android.OS;
|
|
|
|
|
using Orarend;
|
2017-02-08 21:21:11 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Android.Graphics;
|
2017-02-13 12:27:20 +00:00
|
|
|
|
using Java.Lang;
|
2017-02-13 21:30:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-02-14 22:37:20 +00:00
|
|
|
|
using System.Threading;
|
2017-02-16 23:34:01 +00:00
|
|
|
|
using System.IO;
|
2017-01-31 21:22:05 +00:00
|
|
|
|
|
|
|
|
|
namespace OrarendAndroidApp
|
|
|
|
|
{
|
2017-02-18 15:17:39 +00:00
|
|
|
|
[Activity(Label = "Órarend", MainLauncher = true, Theme = "@android:style/Theme.Holo.Light")]
|
2017-01-31 21:22:05 +00:00
|
|
|
|
public class MainActivity : Activity
|
|
|
|
|
{
|
2017-02-10 18:09:29 +00:00
|
|
|
|
private Handler handler;
|
2017-02-13 12:27:20 +00:00
|
|
|
|
private Órarend órarend;
|
2017-02-16 23:34:01 +00:00
|
|
|
|
|
2017-01-31 21:22:05 +00:00
|
|
|
|
protected override void OnCreate(Bundle bundle)
|
|
|
|
|
{
|
|
|
|
|
base.OnCreate(bundle);
|
2017-02-08 21:21:11 +00:00
|
|
|
|
SetContentView(Resource.Layout.MainLayout);
|
2017-02-17 14:33:49 +00:00
|
|
|
|
ActionBar.SetDisplayShowTitleEnabled(false);
|
|
|
|
|
ActionBar.CustomView = FindViewById<Spinner>(Resource.Id.spinner);
|
2017-02-18 15:17:39 +00:00
|
|
|
|
handler = new Handler();
|
2017-02-16 23:34:01 +00:00
|
|
|
|
string[] list = FileList();
|
|
|
|
|
if (list.Contains("beallitasok"))
|
|
|
|
|
API.BeállításBetöltés(OpenFileInput("beallitasok"));
|
|
|
|
|
if (list.Contains("orarend"))
|
|
|
|
|
API.ÓrarendBetöltés(OpenFileInput("orarend"));
|
|
|
|
|
if (list.Contains("osztaly"))
|
|
|
|
|
API.OsztályBetöltés(OpenFileInput("osztaly"));
|
2017-02-18 15:17:39 +00:00
|
|
|
|
if (list.Contains("helyettesites"))
|
|
|
|
|
API.HelyettesítésBetöltés(OpenFileInput("helyettesites"));
|
2017-02-14 22:37:20 +00:00
|
|
|
|
var timer = new Timer(CsengőTimer, null, TimeSpan.Zero, new TimeSpan(0, 0, 1));
|
2017-02-18 23:45:06 +00:00
|
|
|
|
if (API.Órarendek.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
órarend = API.Órarendek.First();
|
|
|
|
|
órarendfrissítés();
|
|
|
|
|
}
|
2017-02-13 12:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-19 02:04:31 +00:00
|
|
|
|
private void órarendlistafrissítés()
|
2017-02-18 15:17:39 +00:00
|
|
|
|
{
|
|
|
|
|
handler.Post(() =>
|
|
|
|
|
{
|
|
|
|
|
var list = FindViewById<Spinner>(Resource.Id.spinner);
|
2017-02-19 02:04:31 +00:00
|
|
|
|
var adapter = (ArrayAdapter)list.Adapter ?? new ArrayAdapter(this, Resource.Layout.simple_list_item_1, API.Órarendek);
|
|
|
|
|
list.Adapter = adapter;
|
|
|
|
|
adapter.NotifyDataSetChanged(); //TODO: Teszt
|
2017-02-18 15:17:39 +00:00
|
|
|
|
list.ItemSelected += ÓrarendClick;
|
2017-02-19 02:04:31 +00:00
|
|
|
|
//list.SetSelection(list.SelectedItemPosition); //Szöveg frissítése - TODO: Teszt
|
2017-02-18 15:17:39 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ÓrarendClick(object sender, AdapterView.ItemSelectedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
órarend = API.Órarendek[e.Position];
|
2017-02-19 02:04:31 +00:00
|
|
|
|
órarendfrissítés();
|
2017-02-18 15:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 14:33:49 +00:00
|
|
|
|
private void addCell(string text, Color color, TableRow tr1, bool clickable = false, int[] tag = null)
|
|
|
|
|
{
|
|
|
|
|
TextView textview = new TextView(this);
|
|
|
|
|
textview.SetText(text, TextView.BufferType.Normal);
|
|
|
|
|
textview.SetTextColor(color);
|
|
|
|
|
textview.SetPadding(10, 10, 10, 10);
|
|
|
|
|
textview.SetBackgroundResource(Resource.Drawable.cell_shape_light);
|
|
|
|
|
textview.Tag = tag;
|
|
|
|
|
if (textview.Clickable = clickable)
|
|
|
|
|
textview.Click += ÓraClick;
|
|
|
|
|
tr1.AddView(textview);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:27:20 +00:00
|
|
|
|
private void HelyettesítésFrissítés()
|
|
|
|
|
{
|
2017-02-17 22:45:47 +00:00
|
|
|
|
var bar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
|
|
|
|
|
handler.Post(() => bar.Visibility = ViewStates.Visible);
|
|
|
|
|
API.HelyettesítésFrissítés(OpenFileOutput("helyettesites", FileCreationMode.Private)).ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
handler.Post(() =>
|
|
|
|
|
{
|
|
|
|
|
bar.Visibility = ViewStates.Gone;
|
2017-02-18 15:17:39 +00:00
|
|
|
|
Toast.MakeText(this, "Helyettesítések frissítve", ToastLength.Short).Show();
|
2017-02-17 22:45:47 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2017-02-17 14:33:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 22:45:47 +00:00
|
|
|
|
private void ÓrarendFrissítés(Órarend ór = null)
|
2017-02-17 14:33:49 +00:00
|
|
|
|
{ //TODO: Meghívni minden tervezett alkalommal; hozzáadásnál csak a hozzáadott órarendet frissítse
|
2017-02-17 22:45:47 +00:00
|
|
|
|
var bar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
|
|
|
|
|
handler.Post(() => bar.Visibility = ViewStates.Visible);
|
|
|
|
|
API.Frissítés(OpenFileOutput("orarend", FileCreationMode.Private), OpenFileOutput("osztaly", FileCreationMode.Private), ór).ContinueWith(t =>
|
2017-02-17 14:33:49 +00:00
|
|
|
|
{
|
2017-02-10 18:09:29 +00:00
|
|
|
|
handler.Post(() =>
|
|
|
|
|
{
|
2017-02-17 22:45:47 +00:00
|
|
|
|
if (TaskHiba(t) && órarend != null && (ór == null || ór == órarend))
|
2017-02-18 23:45:06 +00:00
|
|
|
|
órarendfrissítés();
|
2017-02-17 22:45:47 +00:00
|
|
|
|
bar.Visibility = ViewStates.Gone;
|
2017-02-19 02:04:31 +00:00
|
|
|
|
órarendlistafrissítés();
|
2017-02-18 23:45:06 +00:00
|
|
|
|
Toast.MakeText(this, "Órarend és osztálylista frissítve", ToastLength.Long).Show();
|
2017-02-10 18:09:29 +00:00
|
|
|
|
});
|
2017-02-17 14:33:49 +00:00
|
|
|
|
});
|
2017-01-31 21:22:05 +00:00
|
|
|
|
}
|
2017-02-13 12:27:20 +00:00
|
|
|
|
|
2017-02-18 23:45:06 +00:00
|
|
|
|
private void órarendfrissítés()
|
|
|
|
|
{
|
|
|
|
|
var table = FindViewById<TableLayout>(Resource.Id.tableLayout1);
|
|
|
|
|
if (table.ChildCount > 1)
|
|
|
|
|
table.RemoveViews(1, table.ChildCount - 1);
|
|
|
|
|
TableRow tr = new TableRow(this);
|
|
|
|
|
addCell("", Color.Black, tr);
|
|
|
|
|
addCell("Hétfő", Color.Black, tr);
|
|
|
|
|
addCell("Kedd", Color.Black, tr);
|
|
|
|
|
addCell("Szerda", Color.Black, tr);
|
|
|
|
|
addCell("Csütörtök", Color.Black, tr);
|
|
|
|
|
addCell("Péntek", Color.Black, tr);
|
|
|
|
|
addCell("Szombat", Color.Black, tr);
|
|
|
|
|
table.AddView(tr, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
|
|
|
|
|
for (int j = 0; j < 16; j++)
|
|
|
|
|
{
|
|
|
|
|
tr = new TableRow(this);
|
|
|
|
|
bool notnull = false;
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{ //Kihagyja az üres sorokat
|
|
|
|
|
if (órarend.ÓrákAHét[i][j] != null)
|
|
|
|
|
{
|
|
|
|
|
notnull = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (notnull)
|
|
|
|
|
{
|
|
|
|
|
addCell((j + 1).ToString(), Color.Black, tr);
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
addCell(órarend.ÓrákAHét[i][j] != null ? órarend.ÓrákAHét[i][j].EgyediNév : "", Color.Black, tr, true, new int[2] { i, j });
|
|
|
|
|
table.AddView(tr, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 22:37:20 +00:00
|
|
|
|
private TextView selected;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Kiválasztja az adott órát
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ÓraClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var tv = (TextView)sender;
|
|
|
|
|
var ij = (int[])tv.Tag;
|
2017-02-18 15:17:39 +00:00
|
|
|
|
Óra óra = órarend.ÓrákAHét[ij[0]][ij[1]];
|
2017-02-14 22:37:20 +00:00
|
|
|
|
if (óra == null)
|
|
|
|
|
return;
|
|
|
|
|
if (selected != null && selected != sender)
|
|
|
|
|
selected.SetBackgroundResource(Resource.Drawable.cell_shape_light);
|
|
|
|
|
tv.SetBackgroundResource(Resource.Drawable.cell_shape_selected_light);
|
|
|
|
|
selected = tv;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.pozTV).Text = ((TextView)((TableRow)FindViewById<TableLayout>(Resource.Id.tableLayout1).GetChildAt(1)).GetChildAt(ij[0] + 1)).Text + " " + (ij[1] + 1) + ". óra";
|
|
|
|
|
FindViewById<TextView>(Resource.Id.pozTV).Visibility = ViewStates.Visible;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.nevTV).Text = óra.TeljesNév;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.nevTV).Visibility = ViewStates.Visible;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.teremTV).Text = óra.Terem;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.teremTV).Visibility = ViewStates.Visible;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.tanarTV).Text = óra.Tanár.Név;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.tanarTV).Visibility = ViewStates.Visible;
|
|
|
|
|
FindViewById<TextView>(Resource.Id.idoTV).Text = órarend.Órakezdetek[ij[1]].ToString("hh\\:mm") + "-" + órarend.Órakezdetek[ij[1]].Add(new TimeSpan(0, 45, 0)).ToString("hh\\:mm");
|
|
|
|
|
FindViewById<TextView>(Resource.Id.idoTV).Visibility = ViewStates.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 12:27:20 +00:00
|
|
|
|
public override bool OnCreateOptionsMenu(IMenu menu)
|
|
|
|
|
{
|
|
|
|
|
MenuInflater.Inflate(Resource.Menu.main_menu_light, menu);
|
2017-02-18 15:17:39 +00:00
|
|
|
|
if (API.Osztályok == null || API.Osztályok.Length == 0)
|
|
|
|
|
ÓrarendFrissítés();
|
|
|
|
|
else
|
2017-02-19 02:04:31 +00:00
|
|
|
|
órarendlistafrissítés();
|
2017-02-13 12:27:20 +00:00
|
|
|
|
return base.OnCreateOptionsMenu(menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnOptionsItemSelected(IMenuItem item)
|
|
|
|
|
{
|
|
|
|
|
switch (item.ItemId)
|
|
|
|
|
{
|
|
|
|
|
case Resource.Id.menu_refresh:
|
|
|
|
|
{
|
2017-02-17 22:45:47 +00:00
|
|
|
|
HelyettesítésFrissítés();
|
2017-02-13 12:27:20 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-18 15:17:39 +00:00
|
|
|
|
case Resource.Id.menu_add:
|
|
|
|
|
{
|
|
|
|
|
var intent = new Intent(this, typeof(EditActivity));
|
2017-02-19 02:04:31 +00:00
|
|
|
|
intent.PutExtra("add", true);
|
2017-02-18 15:17:39 +00:00
|
|
|
|
StartActivity(intent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Resource.Id.menu_edit:
|
|
|
|
|
{
|
|
|
|
|
var intent = new Intent(this, typeof(EditActivity));
|
2017-02-19 02:04:31 +00:00
|
|
|
|
intent.PutExtra("add", false);
|
|
|
|
|
intent.PutExtra("index", API.Órarendek.IndexOf(órarend));
|
2017-02-18 15:17:39 +00:00
|
|
|
|
StartActivity(intent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-13 12:27:20 +00:00
|
|
|
|
case Resource.Id.menu_preferences: //TODO
|
|
|
|
|
break;
|
2017-02-18 15:17:39 +00:00
|
|
|
|
case Resource.Id.menu_fullrefresh:
|
|
|
|
|
{
|
2017-02-17 22:45:47 +00:00
|
|
|
|
ÓrarendFrissítés();
|
2017-02-13 12:27:20 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return base.OnOptionsItemSelected(item);
|
|
|
|
|
}
|
2017-02-13 21:30:38 +00:00
|
|
|
|
|
|
|
|
|
private void Hiba(string msg)
|
|
|
|
|
{
|
|
|
|
|
new AlertDialog.Builder(this).SetMessage(msg).SetNeutralButton("OK", (s, e) => { ((AlertDialog)s).Dismiss(); ((AlertDialog)s).Dispose(); }).SetTitle("Hiba").Show();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 14:33:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Az összes hibát kiírja, ami a <see cref="Task"/> futása közben keletkezett
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="t"></param>
|
|
|
|
|
/// <returns>Igaz, ha nem volt hiba</returns>
|
|
|
|
|
private bool TaskHiba(Task t)
|
2017-02-13 21:30:38 +00:00
|
|
|
|
{
|
2017-02-17 14:33:49 +00:00
|
|
|
|
bool ret = true;
|
2017-02-13 21:30:38 +00:00
|
|
|
|
foreach (var ex in (IEnumerable<System.Exception>)t.Exception?.InnerExceptions ?? new System.Exception[0])
|
2017-02-17 14:33:49 +00:00
|
|
|
|
{
|
2017-02-13 21:30:38 +00:00
|
|
|
|
Hiba(ex.ToString());
|
2017-02-17 14:33:49 +00:00
|
|
|
|
ret = false;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
2017-02-13 21:30:38 +00:00
|
|
|
|
}
|
2017-02-14 22:37:20 +00:00
|
|
|
|
|
|
|
|
|
private void CsengőTimer(object state)
|
|
|
|
|
{
|
|
|
|
|
handler.Post(() =>
|
|
|
|
|
{
|
2017-02-18 15:17:39 +00:00
|
|
|
|
var kezdveg = FindViewById<TextView>(Resource.Id.kezdvegTV);
|
2017-02-14 22:37:20 +00:00
|
|
|
|
if (órarend == null)
|
2017-02-18 15:17:39 +00:00
|
|
|
|
{
|
|
|
|
|
kezdveg.Text = "Nincs órarend kiválasztva";
|
2017-02-14 22:37:20 +00:00
|
|
|
|
return;
|
2017-02-18 15:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
var most = DateTime.Now - DateTime.Today;
|
2017-02-14 22:37:20 +00:00
|
|
|
|
bool talált = false;
|
|
|
|
|
var kovora = FindViewById<TextView>(Resource.Id.kovoraTV);
|
|
|
|
|
for (int i = 0; i < órarend.Órakezdetek.Length - 1; i++)
|
|
|
|
|
{
|
|
|
|
|
var vége = órarend.Órakezdetek[i].Add(new TimeSpan(0, 45, 0));
|
|
|
|
|
if (most > órarend.Órakezdetek[i])
|
|
|
|
|
{
|
|
|
|
|
if (most < vége)
|
|
|
|
|
{
|
|
|
|
|
kezdveg.Text = "Kicsengetés: " + (vége - most).ToString("hh\\:mm\\:ss");
|
|
|
|
|
talált = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (órarend.Órakezdetek[i] == TimeSpan.Zero)
|
|
|
|
|
{ //Még nincsenek beállítva a kezdetek
|
|
|
|
|
kezdveg.Text = "Betöltés";
|
|
|
|
|
talált = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
kezdveg.Text = "Becsengetés: " + (órarend.Órakezdetek[i] - most).ToString("hh\\:mm\\:ss");
|
|
|
|
|
talált = true;
|
|
|
|
|
kovora.Visibility = ViewStates.Invisible;
|
|
|
|
|
}
|
|
|
|
|
int x = (int)DateTime.Today.DayOfWeek - 1;
|
2017-02-18 23:45:06 +00:00
|
|
|
|
if (x == -1) //Vasárnap
|
|
|
|
|
break;
|
2017-02-18 15:17:39 +00:00
|
|
|
|
var óra = órarend.ÓrákAHét[x][i];
|
2017-02-14 22:37:20 +00:00
|
|
|
|
if (x < 6 && óra != null)
|
|
|
|
|
{
|
2017-02-18 23:45:06 +00:00
|
|
|
|
kovora.Text = "Következő óra: " + óra.EgyediNév + "\n" + óra.Terem + "\n" + óra.Tanár.Név;
|
2017-02-14 22:37:20 +00:00
|
|
|
|
kovora.Visibility = ViewStates.Visible;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
kovora.Visibility = ViewStates.Invisible;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!talált)
|
|
|
|
|
{
|
|
|
|
|
kezdveg.Text = "Nincs több óra ma";
|
|
|
|
|
kovora.Visibility = ViewStates.Invisible;
|
|
|
|
|
}
|
|
|
|
|
}); //TODO: Az egészet függőlegesen görgethetővé tenni
|
|
|
|
|
}
|
2017-02-19 02:04:31 +00:00
|
|
|
|
|
|
|
|
|
public override void FinishFromChild(Activity child)
|
|
|
|
|
{
|
|
|
|
|
base.FinishFromChild(child);
|
|
|
|
|
if (child is EditActivity)
|
|
|
|
|
{
|
|
|
|
|
ÓrarendFrissítés(child.Intent.Extras.GetBoolean("add") ? API.Órarendek.Last() : API.Órarendek[child.Intent.Extras.GetInt("index")]);
|
|
|
|
|
órarendlistafrissítés();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-31 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|