Hi, There are numerous ways of dealing with such a situation. When negative thoughts strike you, act according to the situation you are in.
For example if you are sitting idle and doing nothing (like you have mentioned that it happens when you are alone at home like on Sunday) then start doing something you really like and which will occupy your attention completely. For instance, start reading your favourite author's book, surf on the internet looking at sites that interest you, listen to music, watch a favourite movie, but the best of all is to go spend some time with a friend or talk to them on the phone. You can also try doing something new you have always wanted to do in the past. For example, learn a new craft in spare time etc.
On the other hand if negative thoughts come when you are not being able to get something done then say to yourself "I can do this", it might seem silly but keep silently saying it to yourself and you'll see it works.
Finally, never stretch yourself too much. Sometimes when we get too tired or have been working too long on something our brain rejects the idea of working and negative thoughts hit us.
Keep a balance between work and leisure and you'll see the difference in no time. Hope this helps. Best of luck.