My experience as a developer is that many projects or tickets are a mix of a short and focused very interesting task (e.g., designing some API or a platform to solve something) and a lot of repetitive and mundane tasks that cannot be automated (such as certain refactorings to use the API or platform, implementation of certain tests, some GUI handling, etc). I believe that this is the nature of our profession, unless we are high-level architects or managements and can delegate this work.
The only item in my personal arsenal when dealing with these tasks is to devote some of my attention to radio or audiobooks (preferably not in English as I find it hard to concentrate on two "streams" of English at the same time). I maintain sufficient attention to carry the task and don't lose concentration as fast.
I'm wondering how others cope with these and maintain concentration.