Helyettesítések, ...

This commit is contained in:
Norbi Peti 2017-02-17 15:33:49 +01:00
parent 7505ec8406
commit e9bcba3493
10 changed files with 182 additions and 82 deletions

View file

@ -20,11 +20,13 @@ namespace Orarend
/// <returns></returns> /// <returns></returns>
public static Osztály[] Osztályok { get; private set; } public static Osztály[] Osztályok { get; private set; }
public static List<Órarend> Órarendek { get; } = new List<Órarend>(); public static List<Órarend> Órarendek { get; } = new List<Órarend>();
public static Settings Beállítások { get; private set; } //TODO: Settings public static Settings Beállítások { get; private set; } = new Settings();
public static List<Helyettesítés> Helyettesítések { get; } = new List<Helyettesítés>();
/// <summary> /// <summary>
/// Frissíti az osztálylistát és az eredeti órarendet, első megnyitásnál, és egy órarend hozzáadásánál/szerkesztésénél, majd hetente elegendő meghívni /// Frissíti az osztálylistát és az eredeti órarendet, első megnyitásnál, és egy órarend hozzáadásánál/szerkesztésénél, majd hetente elegendő meghívni
/// <param name="s">A file stream, ahova mentse az adatokat, hogy ne kelljen külön meghívni</param>
/// </summary> /// </summary>
public static async Task Frissítés() public static async Task Frissítés(Stream s)
{ {
Func<string, Task<HtmlDocument>> load = async (url) => Func<string, Task<HtmlDocument>> load = async (url) =>
{ {
@ -52,6 +54,7 @@ namespace Orarend
var doc = await load("http://deri.enaplo.net/ajax/orarend/orarendoszt.php?p=" + Uri.EscapeDataString(órarend.Osztály.Azonosító)); var doc = await load("http://deri.enaplo.net/ajax/orarend/orarendoszt.php?p=" + Uri.EscapeDataString(órarend.Osztály.Azonosító));
await Task.Run(() => await Task.Run(() =>
{ {
Osztályok = doc.GetElementbyId("uok").ChildNodes.Where(node => node.HasAttributes).Select(node => new Osztály { Azonosító = node.GetAttributeValue("value", ""), Név = node.NextSibling.InnerText }).ToArray();
bool ahét = true; bool ahét = true;
foreach (var node in doc.GetElementbyId("oda").FirstChild.FirstChild.ChildNodes[1].ChildNodes) foreach (var node in doc.GetElementbyId("oda").FirstChild.FirstChild.ChildNodes[1].ChildNodes)
{ {
@ -68,8 +71,8 @@ namespace Orarend
int x = int.Parse(node.FirstChild.InnerText) - 1; int x = int.Parse(node.FirstChild.InnerText) - 1;
órarend.Órakezdetek[x] = TimeSpan.Parse(node.FirstChild.Attributes["title"].Value.Split('-')[0].Trim()); órarend.Órakezdetek[x] = TimeSpan.Parse(node.FirstChild.Attributes["title"].Value.Split('-')[0].Trim());
for (int i = 0; i < 5; i++) //Napok for (int i = 0; i < 5; i++) //Napok
{ //TODO: for ciklus az egy időben tartott órákhoz { //TODO: for ciklus az egy időben tartott órákhoz
var óranode = node.ChildNodes[i + 1].FirstChild; var óranode = node.ChildNodes[i + 1].FirstChild;
var óra = (ahét ? órarend.ÓrákAHét : órarend.ÓrákBHét)[i, x]; var óra = (ahét ? órarend.ÓrákAHét : órarend.ÓrákBHét)[i, x];
if (óranode.ChildNodes.Count == 0) if (óranode.ChildNodes.Count == 0)
continue; continue;
@ -78,7 +81,6 @@ namespace Orarend
continue; continue;
if (óra == null) if (óra == null)
(ahét ? órarend.ÓrákAHét : órarend.ÓrákBHét)[i, x] = óra = new Óra(); (ahét ? órarend.ÓrákAHét : órarend.ÓrákBHét)[i, x] = óra = new Óra();
óra.Sorszám = x + 1;
óra.Csoportok = new string[] { csoport }; //Az állandó órarendben osztályonként csak egy csoport van egy órán óra.Csoportok = new string[] { csoport }; //Az állandó órarendben osztályonként csak egy csoport van egy órán
óra.Azonosító = óranode.ChildNodes[2].InnerText; óra.Azonosító = óranode.ChildNodes[2].InnerText;
óra.TeljesNév = óranode.ChildNodes[2].Attributes["title"].Value; óra.TeljesNév = óranode.ChildNodes[2].Attributes["title"].Value;
@ -93,15 +95,18 @@ namespace Orarend
} }
} }
} }
ÓrarendMentés(s);
OsztályMentés(s);
Thread.Sleep(10);
}); });
Thread.Sleep(10);
} }
} }
/// <summary> /// <summary>
/// Frissíti a helyettesítéseket, naponta, indításkor vagy gombnyommásra frissítse (minden nap az első előtérbe kerüléskor) /// Frissíti a helyettesítéseket, naponta, indításkor vagy gombnyommásra frissítse (minden nap az első előtérbe kerüléskor)
/// <param name="s">A file stream, ahova mentse az adatokat, hogy ne kelljen külön meghívni</param>
/// </summary> /// </summary>
public static async Task HelyettesítésFrissítés() public static async Task HelyettesítésFrissítés(Stream s)
{ {
HtmlDocument doc = new HtmlDocument(); HtmlDocument doc = new HtmlDocument();
var req = WebRequest.CreateHttp("http://deri.enaplo.net/ajax/print/htlista.php"); var req = WebRequest.CreateHttp("http://deri.enaplo.net/ajax/print/htlista.php");
@ -110,7 +115,7 @@ namespace Orarend
{ {
using (var sr = new StreamReader(resp.GetResponseStream())) using (var sr = new StreamReader(resp.GetResponseStream()))
doc.LoadHtml(sr.ReadToEnd()); doc.LoadHtml(sr.ReadToEnd());
}); }); //TODO
} }
public static void ÓrarendBetöltés(Stream s) public static void ÓrarendBetöltés(Stream s)
@ -140,7 +145,16 @@ namespace Orarend
} }
} }
public static void ÓrarendMentés(Stream s) public static void HelyettesítésBetöltés(Stream s)
{
using (s)
{
var serializer = new DataContractJsonSerializer(typeof(Helyettesítés[])); //TODO: Tényleges órarendből állapítsa meg azt is, hogyha egyáltalán nincs ott egy óra, és máshol sincs, és ezt írja ki
Helyettesítések.AddRange((Helyettesítés[])serializer.ReadObject(s));
}
}
private static void ÓrarendMentés(Stream s)
{ {
using (s) using (s)
{ {
@ -149,7 +163,7 @@ namespace Orarend
} }
} }
public static void OsztályMentés(Stream s) private static void OsztályMentés(Stream s)
{ {
using (s) using (s)
{ {
@ -166,5 +180,14 @@ namespace Orarend
serializer.WriteObject(s, Beállítások); serializer.WriteObject(s, Beállítások);
} }
} }
private static void HelyettesítésMentés(Stream s)
{
using (s)
{
var serializer = new DataContractJsonSerializer(typeof(Helyettesítés[]));
serializer.WriteObject(s, Helyettesítések);
}
}
} }
} }

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Orarend
{
public class Helyettesítés
{
public byte EredetiNap { get; set; }
public byte EredetiSorszám { get; set; }
public Óra EredetiÓra { get; set; }
public byte ÚjNap { get; set; }
public byte ÚjSorszám { get; set; }
public Óra ÚjÓra { get; set; }
}
}

View file

@ -35,6 +35,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="API.cs" /> <Compile Include="API.cs" />
<Compile Include="Helyettesítés.cs" />
<Compile Include="Osztály.cs" /> <Compile Include="Osztály.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" /> <Compile Include="Settings.cs" />

View file

@ -8,5 +8,25 @@ namespace Orarend
{ {
public class Settings public class Settings
{ {
public bool DarkTheme { get; set; }
public void UseCommonNames()
{
set("mateme", "Matek");
set("prgelm", "Programozás elmélet");
set("magny", "Nyelvtan");
set(";prggy", "Programozás gyakorlat");
set("testns", "Tesi");
set("tapism", "Töri");
set("matema", "Matek");
set("bioege", "Biosz");
set("foldra", "Föci");
set(";halgy", "Hálózat gyakorlat");
}
private void set(string id, string name)
{
if (ÓraTípus.Típusok.ContainsKey(id))
ÓraTípus.Típusok[id].EgyediNév = name;
}
} }
} }

View file

@ -10,7 +10,6 @@ namespace Orarend
{ {
private ÓraTípus Típus { get; set; } private ÓraTípus Típus { get; set; }
public Tanár Tanár { get; set; } public Tanár Tanár { get; set; }
public int Sorszám { get; set; }
public string Terem { get; set; } public string Terem { get; set; }
/// <summary> /// <summary>
/// Az órán résztvevő csoportok /// Az órán résztvevő csoportok
@ -59,5 +58,19 @@ namespace Orarend
Típus.EgyediNév = value; Típus.EgyediNév = value;
} }
} }
public bool VanEgyediNév
{
get
{
return Típus?.EgyediNév == null;
}
}
public void EgyediNévTörlése()
{
if (Típus != null)
Típus.EgyediNév = null;
}
} }
} }

View file

@ -1,8 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Orarend namespace Orarend
{ {
@ -12,6 +8,9 @@ namespace Orarend
public string Azonosító { get; set; } public string Azonosító { get; set; }
public string EgyediNév { get; set; } public string EgyediNév { get; set; }
/// <summary>
/// A kulcs az óra azonosítója
/// </summary>
public static Dictionary<string, ÓraTípus> Típusok { get; } = new Dictionary<string, ÓraTípus>(); public static Dictionary<string, ÓraTípus> Típusok { get; } = new Dictionary<string, ÓraTípus>();
} }
} }

View file

@ -26,6 +26,8 @@ namespace OrarendAndroidApp
{ {
base.OnCreate(bundle); base.OnCreate(bundle);
SetContentView(Resource.Layout.MainLayout); SetContentView(Resource.Layout.MainLayout);
ActionBar.SetDisplayShowTitleEnabled(false);
ActionBar.CustomView = FindViewById<Spinner>(Resource.Id.spinner);
handler = new Handler(); handler = new Handler();
string[] list = FileList(); string[] list = FileList();
if (list.Contains("beallitasok")) if (list.Contains("beallitasok"))
@ -34,56 +36,55 @@ namespace OrarendAndroidApp
API.ÓrarendBetöltés(OpenFileInput("orarend")); API.ÓrarendBetöltés(OpenFileInput("orarend"));
if (list.Contains("osztaly")) if (list.Contains("osztaly"))
API.OsztályBetöltés(OpenFileInput("osztaly")); API.OsztályBetöltés(OpenFileInput("osztaly"));
API.Frissítés().ContinueWith(t => if (list.Contains("osztaly"))
{ API.OsztályBetöltés(OpenFileInput("osztaly"));
handler.Post(() => if (API.Osztályok == null || API.Osztályok.Length == 0)
{ ÓrarendFrissítés();
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());
});
var timer = new Timer(CsengőTimer, null, TimeSpan.Zero, new TimeSpan(0, 0, 1)); var timer = new Timer(CsengőTimer, null, TimeSpan.Zero, new TimeSpan(0, 0, 1));
} }
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);
}
private void HelyettesítésFrissítés() private void HelyettesítésFrissítés()
{ {
var table = FindViewById<TableLayout>(Resource.Id.tableLayout1);
Action<string, Color, TableRow, bool, int[]> addCell = (text, color, tr1, clickable, tag) =>
{
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);
};
API.HelyettesítésFrissítés().ContinueWith(t => API.HelyettesítésFrissítés().ContinueWith(t =>
{ //TODO: Ezt ne itt, ne így { //TODO: Ezt ne itt, ne így
}); //TODO: Tárolja el a helyettesített órarendeket is valahogyan, akár külön osztály, hogy csak a változásokat tárolja
}
private void ÓrarendFrissítés()
{ //TODO: Meghívni minden tervezett alkalommal; hozzáadásnál csak a hozzáadott órarendet frissítse
API.Frissítés(OpenFileOutput("orarend", FileCreationMode.Private)).ContinueWith(t =>
{
handler.Post(() => handler.Post(() =>
{ {
TaskHiba(t); if(TaskHiba(t))
{ {
var table = FindViewById<TableLayout>(Resource.Id.tableLayout1);
table.RemoveViews(0, table.ChildCount); //TODO: Test
TableRow tr = new TableRow(this); TableRow tr = new TableRow(this);
addCell("", Color.Black, tr, false, null); addCell("", Color.Black, tr);
addCell("Hétfő", Color.Black, tr, false, null); addCell("Hétfő", Color.Black, tr);
addCell("Kedd", Color.Black, tr, false, null); addCell("Kedd", Color.Black, tr);
addCell("Szerda", Color.Black, tr, false, null); addCell("Szerda", Color.Black, tr);
addCell("Csütörtök", Color.Black, tr, false, null); addCell("Csütörtök", Color.Black, tr);
addCell("Péntek", Color.Black, tr, false, null); addCell("Péntek", Color.Black, tr);
addCell("Szombat", Color.Black, tr, false, null); addCell("Szombat", Color.Black, tr);
table.AddView(tr, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)); table.AddView(tr, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
}
if ((t.Exception?.InnerExceptions?.Count ?? 0) == 0)
{
for (int j = 0; j < órarend.ÓrákAHét.GetLength(1); j++) for (int j = 0; j < órarend.ÓrákAHét.GetLength(1); j++)
{ {
TableRow tr = new TableRow(this); tr = new TableRow(this);
bool notnull = false; bool notnull = false;
for (int i = 0; i < órarend.ÓrákAHét.GetLength(0); i++) for (int i = 0; i < órarend.ÓrákAHét.GetLength(0); i++)
{ //Kihagyja az üres sorokat { //Kihagyja az üres sorokat
@ -95,7 +96,7 @@ namespace OrarendAndroidApp
} }
if (notnull) if (notnull)
{ {
addCell((j + 1).ToString(), Color.Black, tr, false, null); addCell((j + 1).ToString(), Color.Black, tr);
for (int i = 0; i < órarend.ÓrákAHét.GetLength(0); i++) 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, true, new int[2] { i, j }); 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)); table.AddView(tr, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
@ -103,7 +104,7 @@ namespace OrarendAndroidApp
} }
} }
}); });
}); //TODO: Tárolja el a helyettesített órarendeket is valahogyan, akár külön osztály, hogy csak a változásokat tárolja });
} }
private TextView selected; private TextView selected;
@ -180,10 +181,20 @@ namespace OrarendAndroidApp
new AlertDialog.Builder(this).SetMessage(msg).SetNeutralButton("OK", (s, e) => { ((AlertDialog)s).Dismiss(); ((AlertDialog)s).Dispose(); }).SetTitle("Hiba").Show(); new AlertDialog.Builder(this).SetMessage(msg).SetNeutralButton("OK", (s, e) => { ((AlertDialog)s).Dismiss(); ((AlertDialog)s).Dispose(); }).SetTitle("Hiba").Show();
} }
private void TaskHiba(Task t) /// <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)
{ {
bool ret = true;
foreach (var ex in (IEnumerable<System.Exception>)t.Exception?.InnerExceptions ?? new System.Exception[0]) foreach (var ex in (IEnumerable<System.Exception>)t.Exception?.InnerExceptions ?? new System.Exception[0])
{
Hiba(ex.ToString()); Hiba(ex.ToString());
ret = false;
}
return ret;
} }
private void CsengőTimer(object state) private void CsengőTimer(object state)

View file

@ -93,47 +93,53 @@ namespace OrarendAndroidApp
// aapt resource value: 0x7f060001 // aapt resource value: 0x7f060001
public const int horizontalView = 2131099649; public const int horizontalView = 2131099649;
// aapt resource value: 0x7f060009
public const int idoTV = 2131099657;
// aapt resource value: 0x7f06000a // aapt resource value: 0x7f06000a
public const int kezdvegTV = 2131099658; public const int idoTV = 2131099658;
// aapt resource value: 0x7f06000b // aapt resource value: 0x7f06000b
public const int kovoraTV = 2131099659; public const int kezdvegTV = 2131099659;
// aapt resource value: 0x7f06000d
public const int menu_add = 2131099661;
// aapt resource value: 0x7f06000e
public const int menu_edit = 2131099662;
// aapt resource value: 0x7f060010
public const int menu_fullrefresh = 2131099664;
// aapt resource value: 0x7f06000f
public const int menu_preferences = 2131099663;
// aapt resource value: 0x7f06000c // aapt resource value: 0x7f06000c
public const int menu_refresh = 2131099660; public const int kovoraTV = 2131099660;
// aapt resource value: 0x7f06000f
public const int menu_add = 2131099663;
// aapt resource value: 0x7f060010
public const int menu_edit = 2131099664;
// aapt resource value: 0x7f060012
public const int menu_fullrefresh = 2131099666;
// aapt resource value: 0x7f060011
public const int menu_preferences = 2131099665;
// aapt resource value: 0x7f06000e
public const int menu_refresh = 2131099662;
// aapt resource value: 0x7f060007
public const int nevTV = 2131099655;
// aapt resource value: 0x7f060006 // aapt resource value: 0x7f060006
public const int nevTV = 2131099654; public const int pozTV = 2131099654;
// aapt resource value: 0x7f060005
public const int pozTV = 2131099653;
// aapt resource value: 0x7f060003 // aapt resource value: 0x7f060003
public const int progressBar1 = 2131099651; public const int progressBar1 = 2131099651;
// aapt resource value: 0x7f060005
public const int spiner_id = 2131099653;
// aapt resource value: 0x7f06000d
public const int spinner = 2131099661;
// aapt resource value: 0x7f060002 // aapt resource value: 0x7f060002
public const int tableLayout1 = 2131099650; public const int tableLayout1 = 2131099650;
// aapt resource value: 0x7f060008 // aapt resource value: 0x7f060009
public const int tanarTV = 2131099656; public const int tanarTV = 2131099657;
// aapt resource value: 0x7f060007 // aapt resource value: 0x7f060008
public const int teremTV = 2131099655; public const int teremTV = 2131099656;
static Id() static Id()
{ {

View file

@ -43,6 +43,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/actionMenuView1" /> android:id="@+id/actionMenuView1" />
<Spinner
android:id="@+id/spiner_id"
android:layout_width="wrap_content"
android:spinnerMode="dropdown"
android:layout_height="wrap_content" />
<TextView <TextView
android:id="@+id/pozTV" android:id="@+id/pozTV"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/spinner"
android:title="will be replaced anyway"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.Spinner" />
<item <item
android:id="@+id/menu_refresh" android:id="@+id/menu_refresh"
android:icon="@drawable/ic_autorenew_black_24dp" android:icon="@drawable/ic_autorenew_black_24dp"
@ -23,5 +27,5 @@
<item <item
android:id="@+id/menu_fullrefresh" android:id="@+id/menu_fullrefresh"
android:showAsAction="never" android:showAsAction="never"
android:title="Teljes frissítés" /> android:title="Órarendfrissítés" />
</menu> </menu>