Covid-19 Support Response – Update

In my previous post I stated that ‘As Directors we are not able to furlough ourselves and therefore would not be eligible for the Governments Covid-19 Job Retention Scheme‘.

I also said ‘the details of these measures are still coming out and there is a great deal of confusion so what I’m about to write may well change going forward‘ – and it has (although a bit quicker than I expected).

If you don’t know who Martin Lewis is then check out the Money Saving Expert website. Basically, when this guy says something, especially it’s all in CAPS then he’s checked and double-checked the facts. He wouldn’t make this kind of statement without being absolutely sure.

If he says that Limited Company Directors CAN furlough themselves – even if they are the sole employee of the company, then that’s good enough for me.

So, what does that change?

Well, for me it doesn’t change anything at all. I am in a position where I can operate as normal, i.e. I have a dedicated, fully equipped home office. All I am missing right now is a client but, as I don’t intent to furlough myself, I can continue to search and engage as before. I can still work for the company – it’s business (almost) as usual in that respect.

Obviously, this may not be the case for everyone and if 80% of their salary would make a difference to their ability to see this thing out then they should take it.

But that’s the sting here isn’t it – most contractors pay themselves a minimal salary, topping them up with regular dividends. So 80% of £750 is £600 a month – in most cases this is far short of their normal income and maybe not enough to keep them afloat and that’s a major concern.

But contractors who are shouting about being ‘forgotten’ and ‘left out’ really don’t understand the slippery slope they are treading – especially with IR35 set to raise it’s ugly head once more.

Huh? What’s IR35 got to do with this?

This is what Andy Chamberlain from IPSE had to say about contractor complaining about being ‘left out’ of the Self Employee Income Support Scheme:

I urge you to click the above tweet and then read the rest of his thread.

If we want to be treated as regular businesses and not caught up in ill informed Employment Status determinations and blanket contractor bans then we have to accept the fact that we have done this to ourselves.

Help is being offered to us but as we decided to pay ourselves in the way we do and now it has come back to bite us.

Not a popular opinion I’m sure – but that’s where we are.

Covid-19 Support Response

Update: 28th March 2020

As I mentioned below ‘things may change’ – and they did, pretty quickly. See my update post on what changed

With the UK in lock-down due to the CoronaVirus (Covid-19) everyone is justifiably concerned about their jobs and their income.

In an unprecedented move the Chancellor, Rishi Sunak, has announced a raft of measures from mortgage holidays, deferment of tax payments as well as packages to pay 80% of people income (or £2500/mth).

As wide reaching as the measures are the contractor community is up in arms because we appear to have been left out in the cold.

Now, the details of these measures are still coming out and there is a great deal of confusion so what I’m about to write may well change going forward.

The two main packages are:

  • Coronavirus Job Retention Scheme (link)
  • Covid-19 Self-Employment Income Support Scheme (link)

Now, the first of these aims to prevent companies from having to make their staff redundant by paying 80% of their salary up to a maximum of £2500. The employees must be ‘furloughed’ which basically means that aside from training they are not allowed to do any work for the company.

While this is pretty generous for employed staff, the self-employed were up in arms that they had been left out. While there were other avenues opened up, e.g. Statutory Sick Pay which the self-employed are not normally entitled to, these provided much less in the way of financial support.

It took a week for the Chancellor to present the second scheme aimed at the self-employed which offered the same 80% but this time over the average monthly profit as submitted in the previous three years tax returns.

The fly in the ointment is that these payments won’t be available until the beginning of June 2020 but the Chancellor insisted that other sources of funds were available from banks etc and combined with the other measures, e.g. mortgage holidays, this was the best that could be done.

All sounds ‘good’ what’s the problem?

Now, all that is unprecedented – the government stepping in to pay employee salaries and the lost income of the self-employed, but where does it leave the UK’s contracted workforce? In particular what about those who, like myself, operate through a Limited Company.

Well, many contractors consider themselves to be self-employed; after all the company is theirs and they employ themselves so they presumed that they would be covered by yesterdays announcment.

Reading the details of the Self-Employed Income Support Scheme it was quickly found that this would not apply to us;

Those who pay themselves a salary and dividends through their own company are not covered by the scheme but will be covered for their salary by the Coronavirus Job Retention Scheme if they are operating PAYE schemes.

HM Treasury and The Rt Hon Rishi Sunak MP (26th March 2020)

Most contractors operate in this manner, i.e. we pay ourselves a minimal salary and then withdraw dividends from the company profits.

For the avoidance of doubt, yes we do this because it is more tax efficient than taking a ‘proper’ salary. This does not mean that we pay no tax at all – far from it. My company pays Corporation Tax and Employers National Insurance while I pay my Personal Income Tax via self assessment.

With that out of the way let’s look at the Coronavirus Job Retention Scheme as directed above.

Well, it will pay 80% of the our salary up to a maximum of £2500 a month. But as contractors normally pay themselves a minimal salary, circa £700-800 a month, this won’t add up to much at all.

It should also be remembered that the payment is dependent on the employee being ‘furloughed’ and essentially forbidden from performing any duties. But as Directors of the company, how can we do that? Monitoring the bank balance, paying invoices, marketing, chasing new contracts – this is all work and would mean that we would not be eligible for this scheme anyway.

[This is at least the current advise from my accountant and from many other sources out there. It is however a point of contention so as I said at the start, it may be subject to clarification]

So why are contractors being “left out”?

Well, step back for a minute. Is it just us that can’t claim from these schemes? Have we being singled out because we’ve been kicking off about IR35?

No, we haven’t.

All company directors will be in the same boat – none are self-employed and none can be furloughed (if the current understanding is correct).

I was a director of another Limited Company some years ago – nothing to do with contracting, just a “regular” business. From what I understand if I was still there I would be as ineligible as I am now.

Think about the directors of the last clients you worked for (assuming it was a Limited Company and not another Contractor) – what’s their position?

If we want to keep the argument against IR35 alive we need to realise that we are no different from those other companies.

Yes, it sucks that everyone else seems to be getting bailed out while we aren’t – but that’s just how it is.

We’ve all had periods ‘between contracts’ and while I don’t look forward to them I do try to plan for them. I know that I can survive a few months with nothing coming in. It’s uncomfortable to watch the bank balance draining but at the end of the day but that buffer is there for a reason.

And here’s the kicker – and it won’t be popular

If we raise Mary Hell about this then we are eroding our argument about IR35.

If we demand to be treated differently to all the other Limited Company Directors out there – then we are essentially saying “we are not like those regular companies”.

When we get through Covid-19, and we will get through it, will we then start saying – “we are just regular companies so IR35 shouldn’t apply to us”?

My standpoint (for what it’s worth)

I don’t see myself as ‘self-employed’. I am a Director of and employed by a Limited Company – a legal entity in it’s own right.

That company provides services to others (end-clients) but I remain an employee of the company and not of those clients.

Even if I was able to furlough myself from my company, which current advice says I cannot, then it really would not be worth it from a financial standpoint.

I would much rather make the effort to keep my company afloat, to dig in and work through this – or at least ride it out.

IR35 – Delayed; but not forgotten

Yesterday (17th March 2020) the Government announced that they would be postponing the rollout of IR35 changes into the private sector due to the Coronavirus outbreak.

Despite the Minister referring to ‘off roll payroll working rules‘ (maybe indicating that he has no real idea what they are) he confirms that the changes will be tabled again ready for implementation in April 2021.

This comes far too late for many genuine contractors and associated services such as accountants who have had to close their businesses down as clients imposed blanket bans or ‘Inside’ determinations requiring the engagement of Umbrella companies and significant reductions in income.

It also comes the day after HMRC provided evidence to the House of Lords and were found seriously wanting in their response to scrutiny. While the House of Lords cannot force Government to defer the bill we have to hope that this contributed to the decision to pause the rollout (regardless of what they say).

The #StopTheOffPayrollTax campaign has been very active on Twitter and in organising a march on Parliament – but it appears that it took the Global Coronavirus Pandemic for the Government to realise that the proposed implementation and it’s consequences were out of step with the rescue packages it had announced for ‘regular businesses’, i.e. not the self-employed.

Many people think that it’s just IT Contractors that were going to be affected but it soon became clear that the flexible workforce is woven throughout our society. From the hospitality sector to veterinary surgeries, from the NHS and pharmacies to driving instructors. As the extent of the impact became more widely understood the noise started to grow.

But when Dr Iain Campbell started to highlight the strain that the draconian changes to the IR35 legislation would bring to the front-line NHS staff treating those infected with the Coronavirus did things become very real indeed.

So What Now?

Well we are not out of the woods yet – not by a long shot.

In the above video clip the Government confirm that this is a delay and not a cancellation of the changes being rolled out into the private sector.

So, despite all the evidence the Governments standpoint is remains that;

‘People doing the same job should be taxed the same way’

The UK Government and HMRC

Apparently this is regardless of the fact that they will not receive the additional benefits that the tax contributions buy their employed counterparts, e.g. statutory sick pay.

The last few months has been a stark warning that unless the legislation is changed or proper guidance is provided to end-clients then we will be in the same position twelve months from now. Teetering on the edge of a flexible workforce implosion.

I think it’s far more likely that nothing will change from the Government apart from a renewed desire to get the changes implemented – so it’s down to the end-clients to get up to speed with the ins and outs of IR35, unless they want to see contractors walking off site in their droves (and they will – that’s been shown!).

Working Outside IR35 is not (in my opinion) that hard and by making very few changes to working conditions most (but not all) of the roles determined to be Inside can easily be moved Outside IR35- and in a manner which can be defended if need be.

The problem is that end-clients don’t understand IR35 enough to be able to say with confidence that the legislation does not apply to a role. This is further compounded by the fear that HMRC will come after them for tax which is deemed to be unpaid should they disagree with the employment status determination.

It is this fear that has left the flexible workforce facing extinction – being forced to make a choice between contract termination or being ’employed for tax purposes’, but not for employment rights!

But the onus doesn’t lay solely with the end-clients – we, the flexible workforce, need to take these twelve months to help them understand what Outside IR35 means and why we are so important to them.

And it’s not only the end-client that needs to be brought up to speed.

We all know that there are contractors out there who are operating contrary to the legislation (knowingly or otherwise). They need to be educated as to how to operate in a compliant manner or called out as a disguised employee.

Me

People are on Twitter claiming victory but we are a long, long way from winning!

The Government seem to accept that the changes were going to have a massive negative impact on a large number of businesses, otherwise the suspension of rollout due to the ‘ongoing spread of Covid-19 to help buinesses and individuals‘ would make little sense.

If they are set on this course of action then the flexible workforce and the end-clients we offer services to need to be ready for the changes which seem inevitable.

Using Fonts for Icons in Xamarin.Android

I’m currently working on a new privacy application for Android and in a previous post I guided you from the Xamarin.Android Drawer Navigation project template to something that actually worked (as in you could actually use the pretty navigation provided by the template).

Now I wanted to change the menu items to something more relevant with some appropriate icons – I mean, how hard can that be right?

Well, as with everything in development these days – things are not always as easy as they seem to be.

The source code from the previous post can be found on Github and if you take a look you will find the menu defined within an XML file at ..\Resources\menu\activity_main_drawer.xml. A number of items are defined here with the same basic attributes:

<item 
    android:id="@+id/nav_camera" 
    android:icon="@drawable/ic_menu_camera" 
    android:title="Import" />

So, all I need to do is to change the android:icon attribute to point to the drawable I want ….. and that’s where the “fun” started.

If you’ve worked with drawables in Android you will know that you need multiple versions of the same graphic at different resolutions. This will allow different devices, with different screen resolutions to display the appropriate graphic. You can find more information here: https://developer.android.com/training/multiscreen/screendensities.

If you look at the above article you will see that five different resolutions (screen densities) listed – that means you need five versions of each of your graphics for your app (although there are instances where you can get away without all of them).

There are online tools to perform the generation for you but the resulting assets still need to be extracted and copied into the project.

Then comes the small matter of what icons to use – and where to get them from.

Android comes with built-in icons, like the ic_menu_camera asset in the above menu item. But finding a list of these isn’t, as I’ve found, that easy and Google recommend copying the icons you need (at all require screen densities) into your project and not to rely on them being present on any particular users device.

So, is there a better way?

Well, as the title of this post eludes, we can use fonts instead – yes, you read correctly … Fonts!

After a little bit of searching I found a blog post by James Montemagno in which he describes using the FontAwesome font in Xamarin.Forms projects.

Well, I’m not using Xamarin.Forms, I’m using Xamarin.Android but if one can do it then surely the other can too.

After a little bit of Googling (actually Duck Duck Go) I stumbled on a post by Joan Zapata where he presents updates to his Iconify library for Android.

Checking out the Readme on Github it certainly looked like this was the answer to my problems, there was just one wrinkle – it was written in Java.

No problem you say – just man up, roll up your sleeves and create a Library Binding project. Yes, I could do that – or I could see if someone else had already ported it over to Xamarin – which of course they had.

If you head over to https://github.com/PragmaticIT/xiconify you will find the source and can dig through it at your leisure – but the Readme points to a nuget package which can be easily installed into your project, so that’s what I did and as you can see from the image below, I selected to ‘Material Design’ package.

Once the package is installed it needs to be initialised in the applications Main Activity:

protected override void OnCreate(Bundle savedInstanceState)
{
	base.OnCreate(savedInstanceState);
	Xamarin.Essentials.Platform.Init(this, savedInstanceState);
	SetContentView(Resource.Layout.activity_main);
	Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
	SetSupportActionBar(toolbar);

	Iconify.with(new MaterialModule());
	
	.
	.
	.
	.
	.
}

To replace the menu icons all we need to do is fetch a reference to each of them and call SetIcon passing in the required IconDrawable provided by the new package:

var myMenuItem = navigationView.Menu.FindItem(Resource.Id.nav_camera);
myMenuItem.SetIcon(
	new IconDrawable(this, 
					 MaterialIcons.md_message.ToString()
					 )
					.color(Color.Gray));

The result will look like this:

The great thing about this is that the font will scale as required without getting blocky – I don’t need to do anything more.

The Readme for the Xamarin ported version of Iconify also provided details for adding Font Icons to your XAML and even how to create your own Icon Packs.

So there you have it – a simple way to replace your icons with scalable fonts, doing away with the need to provide versions for each screen density.

IR35 and the Implosion of the Contracting Market

When I checked Twitter this morning my heart sank – I was watching the new Chancellor (Rishi Sunak) regurgitate the HMRC view of IR35 and the changes to be rolled out into the private sector in April.

He was essentially announcing the Death Knell of Flexible Working as we know it – the contract market will shortly implode even further than it already has.

We, the contracting community had hoped that the fresh faced minister would pause the roll-out and call for the review that was promised ahead of Decembers election.

Instead he stated “it’s not fair to all the people who is employed that someone else who is doing the same job is paying less tax” – the cornerstone of the HMRC argument for making the changes.

On the face of it that may be a reasonable stance to take – but they are not comparing apples with apples here (and they damn well know it).

While we make be doing the same job we are engaged on a very different basis.

We have structured ourselves to operate as service companies to offer clients a flexible resource as and when they need it for as long as they need it (and no longer).

Notwithstanding the fact that contractors are not entitled to sick pay, holiday pay, pension contributions and other benefits such as professional development (training), gym membership and health insurance. Sure, not all of these are covered by the tax & National Insurance they pay but the overall package makes them an employee.

Add to that the notice period that they benefit from, normally a month but can be more, and the fact that even if there is no real work for them to do their employer is still obliged to pay them for turning up. Even if they ‘let them go’ they would have to pay them for their notice period (and any untaken holiday pay!)

Contractors normally have very short notice periods, if they have one at all, and their contract can be terminated at anytime for just about any reason – there is no guarantee of work (and no expectation of it – that’s the life of a contractor).

So, what’s changed?

IR35 itself – the legislation (as complex and unfit for purpose as it may be) – will not change. Determinations on employment status will still need to be made with reference to this legislation.

What’s changed is who makes that determination after April 6th 2020.

Since it’s introduction around twenty years ago, it was the contractors responsibility to determine their employment status. If that determination indicated that the role was Inside IR35 then they would be liable for the payment of tax as if they were an employee. If it was Outside IR35 then this did not apply.

With the benefits of being Outside IR35 pretty clear cut – most contractors preferred that arrangement.

The problem is that some contractors were not as diligent (or just blatantly avoiding paying the additional tax) and declared themselves as being Outside IR35 when the contract and/or working conditions didn’t support that determination.

HMRC claims that as many as 9 out of 10 contractors are operating in this manner – but have not be able to substantiate this claim. The generally accepted figure is less than 30% of contractors are declaring themselves as being Outside when their working conditions are such that they should really be Inside.

So, in April 2020 HMRC will require the end-client to make the employment status determination instead of the contractor.

What could go wrong? If the end-client is using the same, unchanged, legislation as the contractors have been for years then surely this will put things right …. won’t it?

Well, along with the responsibility for making the determination comes the responsibility for getting it wrong. By wrong I mean making an ‘Outside’ determination which HMRC later decide should be ‘Inside’ (they won’t be interested in the other scenario).

Should an end-client incorrectly determine a role to be ‘Outside’ then they will be responsible for paying the tax that HMRC deems to be owed – which could be thousands of pounds here.

That’s the kicker here..! Companies are generally risk averse and locking horns with the taxman is something they would quite rightly want to avoid.

Companies have looked at their contractors and thought – “if we get it wrong and have to pay back-tax for them then is that a risk that we can sustain?”

The answer in most cases is, understandably, No!

Despite claims (lies?) by Finance Minister Jesse Norman in the House of Commons that it’s not happening, many companies are making blanket determinations that mean either:

  • They will not use contractors in anyway shape or form after the changes come into force
  • All roles will be deemed as Inside IR35 regardless of the outcome of a proper determination.

Many contractors are being walked out of the door by shortsighted clients fearful of HMRC while others are being told that they can stay only if they move to being ‘Inside’ (taking the tax hit in the process – for no perceivable benefit).

What are the implications?

This clearly shows a misunderstanding of the legislation and flies in the face of requirement for due diligence on a case by case basis that was assured (and even required by HMRC).

But just think about it for a minute – what are the implications of moving from being ‘Outside’ to ‘Inside’ with the same client? What is that actually saying?

Surely that indicates that, assuming the role hasn’t actually changed, the contractor accepts that they had previously been working on the wrong side of the legislation and is therefore liable for the tax they will now be deemed to have avoided as a result. Who in their right mind would sign up for that?

HMRC have apparently said that they will not investigate the retrospective status of contractors making this move from Outside to Inside – but after everything that’s gone on in the past few months, why would we trust them? Are they really saying that they would ignore cases of potential tax fraud?

Now, not all companies are making this blanket determinations – some are actually doing it properly and you can use the OffPayroll.org.uk website to see who is doing it right and who is not.

How’s the future looking?

If I’m being honest, as it stands right now, I’m not that hopeful. The House of Lords is conducting a review of the impact of the changes but I’m not sure what they will conclude. Even if they agree that the changes are excessively damaging I’m not sure whether they can actually call a halt to the roll-out or just make a recommendation.

It is clear that the government (small ‘g’ is intentional!) is going to plough ahead with the change – regardless of the evidence that it may mean that a significant number of contractors will be forced out of their current engagements and maybe have to close their businesses down. No doubt they will claim that these people were operating contrary to the legislation and that the changes have been successful in their aim.

Fortunately I’m currently engaged with a small start-up company which will be exempt from the proposed changes – so the employment determination remains with me.

I’ve had the contract independently reviewed and it has come back as being Outside IR35. The client is aware of IR35 and are happy for me to operate in a manner that will demonstrate that I am indeed Outside.

In a couple of months I will draw up a Working Conditions Declaration for the client to review and sign. This will help support the ‘implied contract’ concentrating on how the services are being provided and how they differ from employment.

The contract should run for another five months (but may finish earlier – I’m a genuine contractor remember) and when it concludes there is no obligation for the client to offer another (or for me to accept it).

So my hope is that, in the four months between the changes coming into place and the contract ending, clients will see that blanket determination and bans are not working for them and that the contract market is in recovery.

Failing that I will have to hope that I can secure a contract with another ‘small company’ where I will be responsible for my employment status determination or that a larger client is engaging with contractors and operating in a fair with regards IR35.

If these things do not come to pass then I will, with a heavy heart, have to close my business and look for a permanent position instead. My income will be lower and my flexibility will be gone but I will have employee benefits and paying the tax to ‘earn’ them.

Taken as a whole the taxes that HMRC will receive from me, i.e. personal and corporation, will be reduced as a result. With the stated intention of these changes being the increase of revenue this kind of flies in the face of what will actually happen.

There is still time for the government to delay the roll-out (maybe based on the outcome from the Lords, maybe common sense will prevail) – but all we, the Flexible Workforce, can do is watch and wait as nobody is listening to us.

Book Review: Mastering Xamarin.Forms

It may sound odd but from time to time I get approached to review a book which is either due to be or has just been published.

I say odd because I’m just a regular developer – not a podcasting rockstar (or even a blogging one). Why would my option be worth a free copy of a book?

Maybe it’s because I’m just a regular developer – just like most of us.

Some of these I let pass me by, especially if I have no real interest in the content, i.e. a technology that I am not using and have no plans to use – F# for example. I frequently say that ‘you have to pick your fights when it comes to technology – you can’t win them all’.

So, when Packt asked if I would review this book it made me wonder:

“How much of a master can I be after reading a book that’s ‘only’ 200 pages?”.

I’m certainly not belittling the authors efforts, but I have a Microsoft Press book ‘Creating Mobile Apps with Xamarin.Forms‘ which is more than twice that length and that doesn’t claim to be able to make me a ‘Master’.

I’ve developed a number of Xamarin.Forms applications and do so on a pragmatic basis, i.e. I do what I know works without necessarily knowing (or really needing to know) the ins and outs of why it works. I get the job done and (hopefully) produce robust applications for my clients that satisfy their requirements.

The thing is that time passes and, like most other technologies, Xamarin.Forms is being constantly updated. It’s very easy to get out of date. That said, trying to keep up with every iteration can be soul destroying resulting in development paralysis – not being able to move forward in case you make a ‘wrong’ decision that may cost you dear in the future.

Every now and then it’s a good idea to ‘take stock’ and sharpen that saw. We can never know it all and we don’t know what we don’t know.

So, what about the book?

By assuming that the reader has a working knowledge of Xamarin and Xamarin.Forms the book is able to build on this and not waste time going over the basics. That said, we do start by creating a new project, discussing MVVM and Data Binding. These are a building blocks of a Xamarin.Forms application and it’s always useful to reinforce our understanding. You never know, it may just fill in a grey area or it may introduce some syntactic sugar that will streamline your development.

For me, the early parts of the book demonstrated a pretty slick method the validation – using base classes and INotifyDataErrorInfo (a new one on me). I can’t say I’d struggled with validation but my solutions always seemed like I was using a bit more code that I’d like – creating a potential maintenance headache for the future.

When it comes to Navigation, as in moving between views rather than physically getting from A to B, most of us may well use the built in Navigation API or rely on something like MVVM Light. The author decides to create a custom Navigation Service (and explains why), based on the built-in API to create a ViewModel to ViewModel navigation (similar to MVVM Light) that streamlines the code moves it to a central location. I really liked the result and will definitely be using this in the future. Don’t get me wrong, MVVM Light is all well and good but the simplicity of the presented code was compelling.

The development of the Navigation Service leads onto the use of the built-in Dependency Service but then quickly demonstrates how to replace this with third-party Dependency Injection, the author used Ninject. I’d recently used Unity in a project so while I knew this was possible it was interesting to see a different approach.

Building up the architecture in stages, swapping out bits and pieces the whole thing came together pretty quickly.

Some books I’ve read contain code that won’t compile due to typos and missing quotes and/or parenthesis which makes you wonder about the quality of what you’re reading.

All the code in this book worked first time – bear in mind that I wasn’t copy/pasting the code, preferring to hand type it in so that it has half a chance of sticking in my aging brain in the process. The only minor glitch was a call to Device.OpenUrl which is now deprecated (although it will still compile) – but at the speed with which Xamarin.Forms is moving this is hardly surprising and easily fixed.

The book goes on to cover Custom Renderers and Platform-Specific functionality – topics which can sometimes be overlooked as ‘out of scope’.

It doesn’t stop there though – we get to create an Azure based API with a database back-end. Then we add authentication (albeit Facebook authentication), crash reporting and application monitoring.

The end result is a fully testable (did I mention the chapter on Unit Testing?) application, with ;

  • Mapping
  • Location
  • custom navigation
  • dependency injection
  • Azure API and data storage
  • Crash Reporting and Monitoring

All in less than 200 pages! That’s no mean feat. The pace didn’t feel rushed or labored – I took a couple of days to work my way through the chapters and enter the code.

Summary

So, am I now a Master of Xamarin.Forms?

Well, I have to say – probably not.

What I can absolutely say is that I have leveled up and feel much, much better equipped to develop my next Xamarin.Forms application.

I gave this book a 5 star rating on Amazon and it could be said that it should only have been 4 – because I’m not a Master as the book ‘promised’.

But I feel that I learnt a great deal – while strengthening the foundation skills and knowledge that I had already.

Getting Started with Visual Studio 2019 Android Navigation Drawer template

So, I’ve had an idea for another privacy-focused application, this time aimed at mobile devices – Android in particular (I know that Apple are a little touchy about encryption apps – maybe I’ll venture into iOS at a later date).

Notwithstanding my desire to keep my skills up to date I knew that the project I have in mind would require a lot of platform specific logic. While Xamarin Forms can handle this I prefer to take the hit, roll my sleeves up and I opted for a native Android project instead – and that’s where the trouble/fun started.

If you go through the ‘New Project’ process below you will end up with an application which will look something like the one above;

Yep -just what I needed, an application with a slide out menu. Now all I need to do is to replace the default options with my own and then open the appropriate views when they are clicked – what could be eaiser?

Well, when you venture into the code you will find the following event handler within the MainActivity class:

Hmm – so no actual code in place for when an option is selected then!? Running the app and selection various options confirms this is the case. So how hard can it be … really?

In the past I’ve used the Xamarin Forms Drawer Navigation model to create this sort of interface so was a little out of touch with the way native Android was doing things. I knew that I was probably looking at using Fragments, rather than Activities, to act as the content views but had never really used them.

Fragment is Obsolete – eh, what?

I know enough about Fragments to know that I needed a Fragment class and an associated Layout file (the view if you like).

I created a Fragments folder and, using the Add > New Item option, added a Fragment class.

The class was duly created and Visual Studio displayed a green squiggly under the Fragment base class reference. No, big deal – we’ve all seen this before, probably nothing too worrying;

Oh! It would appear that Fragment is deprecated – what the what?

This was rabbit hole number 1 – if Fragment is deprecated what do I use instead?

After a couple of hours trawling the Internet and generally getting frustrated I began to piece together fragments of information (pun intended) which led me to a solution, actually a couple of them.

  1. Drop the ‘Compile Target’ from 9.0 (Pie) to 8.1 (Oreo) where the Fragment class is not marked as obsolete.
  2. Reference the Support Library implementation of the Fragment class instead

Right, option 1 isn’t really an option unless you are happy to tether your application to Oreo. This may be fine for say a proof of concept but not really for a production application. An app compiled against Oreo should run fine on Pie and above – but your mileage may vary so make you you check that out!

Option 2 should not have come as a surprise to you or anyone else familiar with Android development – very few apps these days can be written without using the Support Libraries.

The complication came because when you search the Internet for information on the Android Support Libraries you will run into posts about AndroidX and Jetpack – which are essentially the new Support Library implementations. Trying to ties these back to Xamarin proved to be excessively time consuming and in the end I found that their implementations, e.g. nuget packages, are still in pre-release and documentation is sparce so I was reluctant to use them unless I really had no option. At this point I was considering using the Xamarin Forms option instead – but where’s the “fun” in that..?

The fix for my Fragment was to simply update the Android.App using statement to target the Support library instead:

No more green squiggly line and the application builds just fine – all I need now is to create the Layout and write the code to swap out the Fragments based on the selected option from the menu in the slide out drawer – simple…..!

Wiring Up the Fragments

If you look at the structure of the solution that the template generated you will see that the content of the displayed in the main area of the UI is contained in a Layout view called content_main (Resources > layout > content_main.xml).

Opening this up we can see that this layout consists of a RelativeView with a TextView inside it.

Fairly straightforward stuff here – but how do we swap our fragments in and out?

Well, as it stands – we can’t..! What we need to do is to change the RelativeLayout to a FrameLayout, give it an Id and remove the TextView (as it won’t be needed).

Now we have a container for our fragments we need to respond to the menu selections, inflate the appropriate fragment and ‘inject’ it into our FrameLayout.

I have created three fragment classes with associated layouts – these are pretty basic with the layouts containing a single TextBox each and the corresponding classes just inflating them. You can download the finished solution from the link in the resource section at the bottom of this post.

The first thing we need to do is to set the initial layout state and for this we will display the ‘Welcome’ fragment as out ‘Home/Landing Page’

To do this we will need a FragmentManager, in particular – a Support Fragment Manager. Fortunately our generated MainActivity inherits from AppCompatActivity so it already has a property containing an instance of this class.

To set our initial layout we will need to create and commit a transaction via the Fragment Manager – don’t panic, it’s three lines of code which needs to be added to the OnCreate method of the MainActivity.

        protected override void OnCreate(Bundle savedInstanceState)
        {
            .
            .
            .
            .
            var welcomeTransaction = SupportFragmentManager.BeginTransaction();
            welcomeTransaction.Add(Resource.Id.fragment_container, new Welcome(), "Welcome");
            welcomeTransaction.Commit();
        }

This will add in instance of a WelcomeFragment to the FrameLayout – essentially pushing the view onto it’s internal stack.

Now, I’ve seen a couple of trains of thought as to how to handle displaying the appropriate transaction based on the menu selection and they each have pros and cons;

  1. Add all of the required fragments to the FrameLayout, showing and hiding them as required (the FrameLayout will store the fragments in a Stack)
  2. Swap out fragments on demand so that the FrameLayout only ever contains a single child view.

With option 1 all of the fragments are loaded into the FrameLayout we are using as a Fragment Container with all but the initial view, in our case the Welcome fragment, hidden as part of the transaction. The upside of this approach is that it will maintain the state of each fragment even when it is hidden. The downside is that you will need to keep track of the currently displayed fragment so that it can be hidden when another menu option is selected and of course there is the memory consumption to think about – but this may not be a concern depending on your requirements.

Because my app is aimed at a persons privacy I don’t want all of the state to be kept in memory – when a menu option is selected I want the current fragment to be destroyed. With this in mind I’ll be implementing Option 2 and replacing the fragments as required so that the FrameLayout stack only ever contains a single fragment.

Scrolling down to the OnNavigationItemSelected handler we can now add our code to swap out the fragments (I’ve just updated the Gallery and Slideshow options here)

            else if (id == Resource.Id.nav_gallery)
            {
                var menuTransaction = SupportFragmentManager.BeginTransaction();
                menuTransaction.Replace(Resource.Id.fragment_container, new Fragment1(), "Fragment1");
                menuTransaction.Commit();
            }
            else if (id == Resource.Id.nav_slideshow)
            {
                var menuTransaction = SupportFragmentManager.BeginTransaction();
                menuTransaction.Replace(Resource.Id.fragment_container, new Fragment2(), "Fragment2");
                menuTransaction.Commit();
            }

So, almost the same three line as when we added the Welcome fragment (so a refactoring target) but this time we are replacing the contents of the FrameLayout (not replacing the layout itself, just it’s child views).

The result will be when the menu it opened (using the hamburger button or swiping from the left edge of the screen) and the Gallery or Slideshow option is clicked that the appropriate fragment will be loaded into the FrameLayout, replacing the one that was already these.

In Summary

Most apps need some form of menu and the fact that the NavigationDrawer template provides all the nice UI it does leave the developer having to trawl the internet to work out what to do next.

Even though I knew that fragments would be required there was very little in the way of documentation to be found, specifically about extending this template. Add this to the rabbit hole that is AndroidX/JetPack and it can become frustrating for developers new to Xamarin development.

While this post walks you through one implementation there are doubtless others out there. If you feel I’ve missed something then either leave a comment below or head over to the Github repository to post an issue of submit a pull request (whichever works best for you).

Resources

Full Source Code

IR35 – Living with a Broken Promise

Well I guess it’s old news now, although it was quite foreseeable, but despite a pre-election promise the Conservatives have reneged on their commitment to review the IR35 legislation. Instead they will review the process for rolling the changes into the private sector – not the same thing at all.

Instead of me going over old ground, take a look at my previous IR35 post which was published prior to the election (and it’s broken promises).

In the weeks that have followed Twitter has been ablaze with tweets tagged with #IR35 – many are mine. There is a lot of anger out there and our worst fears, that end clients would take the ‘easy option’ and just stop using contractors altogether has come to pass (despite HMRC saying it wouldn’t).

Take a look at the OffPayroll.org.uk site and you’ll see the extent of the problem that is unfolding.

Many contractors are being let go and the work is being farmed out overseas. Those clients choosing to keep their flexible workforce are either making blanket assessments that all roles are ‘Inside IR35’ (as they see it safer that way) or using the HMRC CEST tool with limited understanding on how to answer the questions it asks – this will normally result in an ‘Inside IR35’ determination.

Many will point at the CEST results and declare that most historic roles should have been deemed ‘Inside IR35’ so the system is working correctly and that we have all be fleecing the system for years.

There is no doubt that some contractors, knowingly or otherwise, have been operating on the wrong side of IR35 – it would be foolish of me to say otherwise. But why is it that whenever a minority are found to be bending or breaking the rules everyone has to suffer the consequences?

So where does that leave me?

Well, I guess I’m lucky in that I’m in the process of securing a role with a client that will be exempt from the changes – they are a start up and satisfy the ‘Small Business’ definition. This means that I’m responsible for making the IR35 determination. I’ve discussed this with the client and they am not an employee and that I’m providing a service via a business-to-business arrangement.

The project involves the development of a viable proof of concept and the contract will last 6 months.

Maybe the dust will have settled a bit by August 2020 and clients will realise that banning PSCs or imposing blanket ‘Inside IR35’ decisions isn’t working for them.

I’m sure that the government (small ‘g’ was deliberate!) won’t have changed their stance – they will more than likely spin whatever happens to their advantage, that’s what they do.

But it all comes down to this – what happens if, when this contract comes to an end, all the suitable roles are ‘Inside IR35’? What will I do then?

Well, it’s simple – if I cannot find an ‘Outside IR35’ role or secure a role with an exempt company, I’ll have to look for a permanent role instead and to close down my Personal Service Company.

I will not work ‘Inside IR35’ as a ‘No Rights Employee’ – period. It won’t happen, ever!

Dave Carson (On The Fence Development) January 2020

This would be a shame and frankly it makes little sense for the government (small ‘g’ is deliberate remember) to stand there and accept that.

I pay more tax as a contractor that I would as a permanent employee – many contractors are the same. So by forcing us out of business there will be an inevitable loss in revenue – where is the sense in that?

Unit Testing with the Xamarin.Forms MessagingCenter

While we all know that Test Driven Development (TDD) is a good idea, in practice it’s not always viable. It could be a time constraint, a resource issue or the project just doesn’t warrant it.

While TDD may sometimes be an option, unit tests themselves should really be considered to be a must. They will save you a lot of time in the long run and while they may not prevent you from going grey, ask me how I know, they will reduce your stress levels when bugs raise their ugly heads.

So, whether you write your tests before you write the code or vice-versa, if you are developing production code you really should write tests to cover it.

Now, one of the requirements for unit testing is the ability to mock out a components dependencies so that you are only testing the component itself.

Normally you would use the Dependancy Injection pattern to help develop loosely coupled systems but Xamarin.Forms has a few components which can be a fly in the ointment – one of these is the MessagingCenter.

MessagingCenter allows you to send messages from one component to another using the publish-subscribe pattern to do so in a loosely coupled manner.

It’s build into Xamarin.Forms and is very easy to use;

On one side of the process you will send (publish) your message;

MessagingCenter.Send(this, "ForceLogout", message);

One the other side you will subscribe to the message;

 MessagingCenter.Subscribe<WelcomePage, string>
  (this, "ForceLogout", async (sender, arg) => {
    await ForceLogout(arg); 
});

The problem is that MessagingCenter cannot be mocked and injected into your class – so how do you unit test it?

Well, the answer is embarrassingly straightforward – you may already be using a similar approach to test for events being raised (I know I am).

Basically, all we need to do is to subscribe to the message in our test, setting a flag when the message is received;

var messageSent = false;

// Arrange 
MessagingCenter.Subscribe<WelcomePage, string>
  (this, "ForceLogout", (sender, arg) =>
        {
            messageSent = true;
        });

// Act
.
.
// Assert
Assert.IsTrue(messageSent);

It really is as simple as that. While we can’t mock out the MessagingCenter, we can simply subscribe to the message we are interested in – just as we would in the application code itself.

IR35 2020 – Thoughts from the Coal Face

I’ve been contracting for over eight years now and in that time I’ve been careful to ensure that, to the best of my abilites, I operate in a manner that places me outside of the IR35 legislation. That is, to provide a service to my clients and not to be seen as an employee.

Currently it is my responsibility to determine the employment status of a role with regards IR35. I do this by having contracts independantly reviewed to ensure that they comply with the legislation and take steps to ensure that the actual working conditions are in accordance with service provision rather than employment.

If I get it wrong then it is down to me to justify my determination, in court if need be, and pay any unpaid taxes should I be unable to do so.

However, in April 2020 that determination could largely be taken out of my hands and placed in those of the fee payer, e.g. the client if I’ve been engaged directly or otherwise a recruitment agency that have facilited the engagement.

HMRC have decided to make this change stating their belief that most contractors are incorrectly self-declaring themselves as being outside of IR35 and avoiding paying the correct level of tax.

They have not been able to substantiate these claims, despite repeated calls to do so – but that’s not the reason for this post.

There are a number of problems with this, seemingly subtle shift in responsibilities but, as I see it, the main one that a great many end clients have no concept of IR35 or how to interpret it. Until now they’ve really not had to worry about it – the contractor turned up, did the work and left again. The client paid the contractors Limited Company or the recruitment agency an agreed fee and life was simple.

From April 2020, fee payers that meet the size and turnover criteria will need to determine whether IR35 applies and is so deduct tax as source prior to paying the contractors company. However, the IR35 legislation is complex and confusing – with HMRC losing more cases than it wins it is clear that they don’t fully understand it either.

If, in the eyes of HMRC, the fee payer gets the IR35 determination wrong and have deemed a contract to be outside of the legislation instead of inside then they will be responsible for paying the overdue tax – which may not be trivial. So what do we think clients are going to do? Are they going to invest the time into understanding IR35 so that they can defend and ‘outside’ determination or just take the ‘easy’ route?

Well, in spite of HMRC saying it wouldn’t happen, many major clients, particularly in the banking sector, have already stated that they will either not be engaging with contractors after April 2020 or will be considering ALL contract positions to be within IR35. That way they will stay on the right side of HMRC and everything is simple again.

The problem is that while HMRC may be happy with this, afterall they will be receiving additional revenue from these blanket IR35 determinations, many contractors are not.

Without getting into the nitty-gritty of IR35 it is not easy to see the problems that this will create for contractors but I think that there is an opportunity to educate the clients here. To make them aware of the difference between contractors, who provide a business-to-business service, and their permanent employees.

Provision of Services – A ‘Tradesperson’

First of all imagine that you run a company and want to freshen the office up a little bit.

You contact a decorating company and explain your requirements and agree on a price and timescale for the work. The company duly send a suitably qualified decorator to your site, you tell them what you want done and they get on and they get on and do it.

When they are done they leave and if you are happy with the work you pay the invoice.

So, what have you done here?

You have engaged with a company to provide you with a service. They have sent one (or more) of their employees to carry out the work and then invoiced you for that work.

The key here is that the company has provided you with a service – you have not directly employed the person who arrived to do the work. You don’t need to pay their taxes or into their pension. If they are unavailable the company can send someone else, suitably qualified of course, to continue with the work.

If the work was scheduled to take a week and it’s finished in three days then you are not obliged to provide additional work to fill the time – and neither is the decorator or company obliged to accept it if you do. The engagement was for a set piece of work and once that is done the engagement is over.

Now, I think that’s pretty straightforward and nobody should have a problem with that. But the thing is that the provision of service is somewhat clear cut; you have engaged with a company who provide services that your company is not skilled in.

Provision of Services – Contractors

Imagine now that you run a company which has a Software Development aspect to it and you need some additional resource to fulfil a project on time.

You reach out, directly or via an agency, to a company providing contracted software development services, explain your requirements and agree on a price and timescale for the work.

The contractor arrives on site, is told what needs to be done and gets on and does it.

Once the work is completed there is no expectation that further work needs to be offered or accepted and the engagement is over.

During the engagement should the contractor fall ill there is no expectation that their services will be invoiced unless they are able to send a suitable replacement (at the contracting companies cost) to continue with the work.

Does this sound familiar? It should do – it’s pretty much the same as the previous example with the decorator.

The difference is that the service being provided is something that your company already does and the contractor is probably expected to work within an existing team.

This is where the lines start to blur and the grey areas start to appear.

Why does this make a difference?

With a contractor more embedded in the business and it’s team it is easy for the client to see them as an employee and attempt to treat them as such.

I’ve had instances where a client will attempt to dictate my working hours (despite working a standard 7.5 hours) and my dress code (I was wearing a polo shirt with my company branding).

Would the client feel able to do this with their decorator? I think not.

If they arrive at 9 and leave at 3 but get the work done to the required standard and complete the job on time then surely that’s what matters. If the quality isn’t there or the job isn’t finished then that’s another matter altogether.

The client wouldn’t expect to be able to dictate the dress code for these external workers, or when they take their lunch breaks so why expect to do it with a contractor?

I may well sound like a bit of a diva here – I mean, who do I think I am? But this is the reality of the matter. The client has engaged my company, directly or indirectly, to provide a service – I am not their employee.

Now, in order to integrate into a team a contractor will normally work similar hours but their hours should only really be dictated by their ability to access the building (assuming they are working on site).

I will obviously make efforts to integrate with the team and working conditions but this is in order to maximise the value of the services I provide – I’m kinda old school like that.

The Take Away

I believe that unless clients can understand this concept then they will have little chance of being able to make an accurate determination of employment status.

If they see contractors as employees, albeit temporary, then they will simply not grasp the importance of determining an accurate employment status with regards IR35.

It may well be that a particular role is correctly deemed to be within IR35 and if this is the case then that’s fine.

However, clients should avoid taking the stance that all contracts are within IR35 – doing so will not only damage the contracting industry in the UK but the client will also severely hamper their ability to engage with an experienced, temporary and flexible workforce to delivery their project and products.