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-01-31 21:22:05 +00:00
|
|
|
|
|
|
|
|
|
namespace OrarendAndroidApp
|
|
|
|
|
{
|
2017-02-13 12:27:20 +00:00
|
|
|
|
[Activity(Label = "Órarend", MainLauncher = true, Icon = "@drawable/icon", 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-10 18:09:29 +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-10 18:09:29 +00:00
|
|
|
|
handler = new Handler();
|
2017-02-13 21:30:38 +00:00
|
|
|
|
API.Frissítés().ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
handler.Post(() =>
|
|
|
|
|
{
|
|
|
|
|
TaskHiba(t);
|
|
|
|
|
});
|
|
|
|
|
órarend = new Órarend("Teszt", API.Osztályok.First(), "gy1");
|
|
|
|
|
API.Órarendek.Add(órarend);
|
|
|
|
|
API.Frissítés().ContinueWith(tt => HelyettesítésFrissítés());
|
|
|
|
|
});
|
2017-02-13 12:27:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 21:30:38 +00:00
|
|
|
|
private int a = 0; //TODO: TMP
|
2017-02-13 12:27:20 +00:00
|
|
|
|
private void HelyettesítésFrissítés()
|
|
|
|
|
{
|
2017-02-08 21:21:11 +00:00
|
|
|
|
var table = FindViewById<TableLayout>(Resource.Id.tableLayout1);
|
|
|
|
|
Action<string, Color, TableRow> addCell = (text, color, tr1) =>
|
2017-02-13 12:27:20 +00:00
|
|
|
|
{
|
|
|
|
|
TextView textview = new TextView(this);
|
|
|
|
|
textview.SetText(text, TextView.BufferType.Normal);
|
|
|
|
|
textview.SetTextColor(color);
|
2017-02-13 21:30:38 +00:00
|
|
|
|
textview.SetPadding(10, 10, 10, 10);
|
|
|
|
|
switch(a)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
textview.SetBackgroundResource(Resource.Drawable.cell_shape_light);
|
|
|
|
|
a++;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
textview.SetBackgroundResource(Resource.Drawable.cell_shape_selected_light);
|
|
|
|
|
a++;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
textview.SetBackgroundResource(Resource.Drawable.cell_shape_removed_light);
|
|
|
|
|
a++;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
textview.SetBackgroundResource(Resource.Drawable.cell_shape_added_light);
|
|
|
|
|
a++;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
a = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-13 12:27:20 +00:00
|
|
|
|
tr1.AddView(textview);
|
|
|
|
|
};
|
|
|
|
|
API.HelyettesítésFrissítés().ContinueWith(t =>
|
2017-02-09 21:28:23 +00:00
|
|
|
|
{
|
2017-02-10 18:09:29 +00:00
|
|
|
|
handler.Post(() =>
|
|
|
|
|
{
|
2017-02-13 21:30:38 +00:00
|
|
|
|
TaskHiba(t);
|
2017-02-11 16:28:53 +00:00
|
|
|
|
{
|
2017-02-13 21:30:38 +00:00
|
|
|
|
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));
|
|
|
|
|
|
2017-02-11 16:28:53 +00:00
|
|
|
|
}
|
2017-02-13 21:30:38 +00:00
|
|
|
|
if ((t.Exception?.InnerExceptions?.Count ?? 0) == 0)
|
2017-02-11 16:28:53 +00:00
|
|
|
|
{
|
2017-02-13 12:27:20 +00:00
|
|
|
|
for (int j = 0; j < órarend.ÓrákAHét.GetLength(1); j++)
|
2017-02-11 16:28:53 +00:00
|
|
|
|
{
|
|
|
|
|
TableRow tr = new TableRow(this);
|
2017-02-13 21:30:38 +00:00
|
|
|
|
bool notnull = false;
|
2017-02-13 12:27:20 +00:00
|
|
|
|
for (int i = 0; i < órarend.ÓrákAHét.GetLength(0); i++)
|
2017-02-13 21:30:38 +00:00
|
|
|
|
{ //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 < órarend.ÓrákAHét.GetLength(0); i++)
|
|
|
|
|
addCell(órarend.ÓrákAHét[i, j] != null ? órarend.ÓrákAHét[i, j].EgyediNév : "", Color.Black, tr);
|
|
|
|
|
table.AddView(tr, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
|
|
|
|
|
}
|
2017-02-11 16:28:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-10 18:09:29 +00:00
|
|
|
|
});
|
2017-02-11 16:28:53 +00:00
|
|
|
|
});
|
2017-01-31 21:22:05 +00:00
|
|
|
|
}
|
2017-02-13 12:27:20 +00:00
|
|
|
|
|
|
|
|
|
public override bool OnCreateOptionsMenu(IMenu menu)
|
|
|
|
|
{
|
|
|
|
|
MenuInflater.Inflate(Resource.Menu.main_menu_light, menu);
|
|
|
|
|
return base.OnCreateOptionsMenu(menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool OnOptionsItemSelected(IMenuItem item)
|
|
|
|
|
{
|
|
|
|
|
switch (item.ItemId)
|
|
|
|
|
{
|
|
|
|
|
case Resource.Id.menu_refresh:
|
|
|
|
|
{
|
|
|
|
|
var bar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
|
|
|
|
|
handler.Post(() => bar.Visibility = ViewStates.Visible);
|
|
|
|
|
API.HelyettesítésFrissítés().ContinueWith(t => //TODO: Megjelenítés frissítése
|
|
|
|
|
{
|
|
|
|
|
handler.Post(() => bar.Visibility = ViewStates.Gone);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Resource.Id.menu_add: //TODO
|
|
|
|
|
break;
|
|
|
|
|
case Resource.Id.menu_edit: //TODO
|
|
|
|
|
break;
|
|
|
|
|
case Resource.Id.menu_preferences: //TODO
|
|
|
|
|
break;
|
|
|
|
|
case Resource.Id.menu_fullrefresh:
|
|
|
|
|
{
|
|
|
|
|
var bar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
|
|
|
|
|
handler.Post(() => bar.Visibility = ViewStates.Visible);
|
|
|
|
|
API.Frissítés().ContinueWith(t => //TODO: Megjelenítés frissítése
|
|
|
|
|
{
|
|
|
|
|
handler.Post(() => bar.Visibility = ViewStates.Gone);
|
|
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TaskHiba(Task t)
|
|
|
|
|
{
|
|
|
|
|
foreach (var ex in (IEnumerable<System.Exception>)t.Exception?.InnerExceptions ?? new System.Exception[0])
|
|
|
|
|
Hiba(ex.ToString());
|
|
|
|
|
}
|
2017-01-31 21:22:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|