Orarend/OrarendAndroidApp/EditActivity.cs

99 lines
4.1 KiB
C#
Raw Normal View History

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;
using Orarend;
using Android.Graphics;
namespace OrarendAndroidApp
{
[Activity(Label = "AddActivity", Theme = "@android:style/Theme.Holo.Light")]
public class EditActivity : Activity
{
private bool add;
private int index;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.EditLayout);
Title = (add = Intent.Extras.GetBoolean("add")) ? "Hozz<7A>ad<61>s" : "Szerkeszt<7A>s";
index = Intent.Extras.GetInt("index");
var oszt<EFBFBD>lySpinner = FindViewById<Spinner>(Resource.Id.oszt<EFBFBD>lySpinner);
if (API.Oszt<EFBFBD>lyok == null)
{
MainActivity.Hiba(this, "Az oszt<7A>lylista <20>res! V<>laszd a Teljes friss<73>t<EFBFBD>st a men<65>b<EFBFBD>l.");
Finish();
}
oszt<EFBFBD>lySpinner.Adapter = new ArrayAdapter(this, Resource.Layout.simple_list_item_1, API.Oszt<EFBFBD>lyok);
if (!add)
{
var <EFBFBD>rarend = API.<EFBFBD>rarendek[index];
FindViewById<EditText>(Resource.Id.n<EFBFBD>vEditText).Text = <EFBFBD>rarend.N<EFBFBD>v;
int ix = Array.IndexOf(API.Oszt<EFBFBD>lyok, <EFBFBD>rarend.Oszt<EFBFBD>ly);
/*for (int i = 0; i < API.Oszt<EFBFBD>lyok.Length; i++)
{
var o = API.Oszt<EFBFBD>lyok[i];
}*/
oszt<EFBFBD>lySpinner.SetSelection(ix);
FindViewById<EditText>(Resource.Id.csoportokEditText).Text = <EFBFBD>rarend.Csoportok.Aggregate((a, b) => a + " " + b);
}
oszt<EFBFBD>lySpinner.LayoutParameters = new TableRow.LayoutParams((oszt<EFBFBD>lySpinner.Parent as View)?.Width - (oszt<EFBFBD>lySpinner.Parent as ViewGroup)?.GetChildAt(0)?.Width ?? TableRow.LayoutParams.MatchParent, TableRow.LayoutParams.WrapContent); //TODO
FindViewById<Button>(Resource.Id.saveButton).Click += SaveButtonClick;
var deleteButton = FindViewById<Button>(Resource.Id.deleteButton);
if (add)
deleteButton.Visibility = ViewStates.Gone;
else
{
deleteButton.SetBackgroundColor(Color.DarkRed);
deleteButton.Click += DeleteButtonClick;
Intent.Extras.PutBoolean("deleted", false);
}
}
private void DeleteButtonClick(object sender, EventArgs e)
{
new AlertDialog.Builder(this).SetTitle("T<>rl<72>s").SetMessage("Biztosan t<>rl<72>d ezt az <20>rarendet?")
.SetPositiveButton("Igen", (s, ea) =>
{ //T<>rl<72>s
API.<EFBFBD>rarendek.RemoveAt(index);
var intent = new Intent(Intent);
intent.PutExtra("deleted", true);
((AlertDialog)s).Dismiss();
((AlertDialog)s).Dispose();
API.Ment<EFBFBD>s(OpenFileOutput(MainActivity.DATA_FILENAME, FileCreationMode.Private));
SetResult(Result.Ok, intent);
Finish();
}).SetNegativeButton("Nem", (s, ea) =>
{
((AlertDialog)s).Dismiss();
((AlertDialog)s).Dispose();
}).Show();
}
private void SaveButtonClick(object sender, EventArgs e)
{
var n<EFBFBD>v = FindViewById<EditText>(Resource.Id.n<EFBFBD>vEditText).Text;
var oszt<EFBFBD>ly = API.Oszt<EFBFBD>lyok[FindViewById<Spinner>(Resource.Id.oszt<EFBFBD>lySpinner).SelectedItemPosition];
var csoportok = FindViewById<EditText>(Resource.Id.csoportokEditText).Text;
if (!add)
{
var <EFBFBD>rarend = API.<EFBFBD>rarendek[index];
<EFBFBD>rarend.N<EFBFBD>v = n<EFBFBD>v;
<EFBFBD>rarend.Oszt<EFBFBD>ly = oszt<EFBFBD>ly;
<EFBFBD>rarend.Csoportok = csoportok.Split(' ');
}
else
API.<EFBFBD>rarendek.Add(new <EFBFBD>rarend(n<EFBFBD>v, oszt<EFBFBD>ly, csoportok));
API.Ment<EFBFBD>s(OpenFileOutput(MainActivity.DATA_FILENAME, FileCreationMode.Private));
SetResult(Result.Ok, Intent);
Finish();
}
}
}