Skip to content

Instantly share code, notes, and snippets.

Avatar

Dawid Sibiński dsibinski

View GitHub Profile
View MainActivity.cs
[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);
}
View MainActivity_OnCreate.cs
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;
View MainActivity_OnStart.cs
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);
View MainActivity_OnResume.cs
protected override void OnResume()
{
base.OnResume();
InitializeUserControlsEvents();
// TODO: retrieving variables (amount, number of people) from persistent storage (file, database)
}
// ...
private void InitializeUserControlsEvents()
{
View MainActivity_OnPause.cs
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;
View AddNewCity.cs
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;
View EuropeanCitiesProperty.cs
private List<Country> _europeanCountries;
public List<Country> EuropeanCountries =>
_europeanCountries ?? (_europeanCountries = CountriesCitiesDbService.GetAllEuropeanCountries());
View AddNewCity_Corrected.cs
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...
}
View Person.cs
namespace MoneyBack.Entities
{
[Table("People")]
public class Person
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
View Constants_dbPath.cs
public class Constants
{
public static readonly string DbFilePath =
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"moneyback.db"
);
}