This guy just isn't interested. Sad I know, and usually more of a 'male' problem where a girl is just not keen on a guy who likes her.
He flirted a little with you when he thought it was OK, as soon as he could see that it might be giving you a false impression, he cooled off, but now that he 'knows' you are not interested, it's safe to flirt again.
He's not messing you around - if anything he has tried to be mindful of your feelings.
Put your mind on someone else, and just admire him as an attractive man who simply doesn't feel the same way about you that you feel about him.