Skip to content

Instantly share code, notes, and snippets.

View dsibinski's full-sized avatar

Dawid Sibiński dsibinski

View GitHub Profile
@dsibinski
dsibinski / MainActivity.cs
Created March 11, 2017 08:18
Android activity
[Activity(Label = "MoneyBack", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
_amount = 0.00m;
_result = 0.00m;
_numberOfPeople = 0;
protected override void OnStart()
{
base.OnStart();
RefreshUserInputsFromVariables();
}
// ...
private void RefreshUserInputsFromVariables()
{
_inputAmount.SetText(_amount.ToString(CultureInfo.InvariantCulture), TextView.BufferType.Editable);
_txtResultDecimal.SetText(_result.ToString(CultureInfo.InvariantCulture), TextView.BufferType.Editable);
protected override void OnResume()
{
base.OnResume();
InitializeUserControlsEvents();
// TODO: retrieving variables (amount, number of people) from persistent storage (file, database)
}
// ...
private void InitializeUserControlsEvents()
{
protected override void OnPause()
{
base.OnPause();
DetatchUserControlsEvents();
// TODO: saving variables (amount, number of people) to persistent storage (file, database)
}
// ...
private void DetatchUserControlsEvents()
{
_btnCalculate.Click -= _btnCalculate_Click;
private bool AddNewCity(string cityName, string countryIso)
{
var city = CountriesCitiesDbService.GetNewCity();
var europeanCountries = CountriesCitiesDbService.GetAllEuropeanCountries();
var country = europeanCountries.FirstOrDefault(ec => ec.IsoCode.Equals(countryIso));
if (country == null)
throw new ArgumentException($"Country with ISO Code {countryIso} does not exist!");
city.Name = cityName;
private List<Country> _europeanCountries;
public List<Country> EuropeanCountries =>
_europeanCountries ?? (_europeanCountries = CountriesCitiesDbService.GetAllEuropeanCountries());
private bool AddNewCity(string cityName, string countryIso)
{
var city = CountriesCitiesDbService.GetNewCity();
var country = EuropeanCountries.FirstOrDefault(ec => ec.IsoCode.Equals(countryIso));
// the rest of method's code...
}
namespace MoneyBack.Entities
{
[Table("People")]
public class Person
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public class Constants
{
public static readonly string DbFilePath =
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"moneyback.db"
);
}